SeekerOKnowledge has asked for the wisdom of the Perl Monks concerning the following question:

I appreciate the previous responses received, but I'll take this question in a slightly different direction. The following code does not do what I want. If I substitute back in the commented out line, I restore the functionality I want. Is there a way to format qr blocks such that they can be more easily read by the uninitiated?
#!/usr/bin/perl my $s = "blah,blah,blah <PgfTag `Normal \(T\)'> yadda,yadda,yadda"; print "s =\t\"$s\"\n"; #my $pattern = qr{\s*<PgfTag `Normal \(T\)'>\s*}; my $pattern = qr{ \s* <PgfTag `Normal \(T\)'> \s* }; my $k = 0; $s =~ s/$pattern/++$k && ','/gex; print "$k change(s)\n"; print "s =\t\"$s\"\n";
Thanks again for any comments passed on.

Replies are listed 'Best First'.
Re: commenting regular expressions (take two)?
by Zeroth (Beadle) on Sep 04, 2003 at 18:32 UTC
    The /x modifier does exactly what you want. See the section about modifiers in perldoc perlre.
Re: commenting regular expressions (take two)?
by tcf22 (Priest) on Sep 04, 2003 at 18:32 UTC
    Use the x modifier in the qr//.
    my $pattern = qr/ \s* <PgfTag `Normal \(T\)'> \s* /x;
      Thanks for all replies. The /x did the trick, but I also had to escape the spaces within the desired strings as well.