AltBlue has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -Twl use strict; { local undef $/; my $string = <DATA>; # extract strings from 'usual' quotes: print 'MATCH: ', $2 while $string =~ /\bq([^\w{([])(.+?[^\\])\1/sg +; # extract strings from 'bracketted' quotes: for (( [ qw'{ }' ], [ qw'[ ]'], [ qw'( )' ] )) { print 'MATCH: ', $1 while $string =~ /\bq\Q$_->[0]\E(.+?[^\\])\Q$_->[1]\E/sg; } } __DATA__ my $km = q'BEGIN simple foo bar baz END'; my $kv = q#BEGIN foo bar \# baz END#; my $kk = q{BEGIN super foo bar banzai END}; my $kt = q{BEGIN super foo \{super\} bar banzai END};
... i really wonder how my code would have looked like if i was supposed to match interpolated stuff like qq{ foo $bar{baz} :) } .. but that's another story to think of :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: matching single-quoted-like strings (q{}, q//)
by merlyn (Sage) on Apr 03, 2003 at 22:09 UTC | |
by AltBlue (Chaplain) on Apr 03, 2003 at 22:48 UTC | |
|
Re: matching single-quoted-like strings (q{}, q//)
by BrowserUk (Patriarch) on Apr 04, 2003 at 08:24 UTC | |
|
Re: matching single-quoted-like strings (q{}, q//)
by BrowserUk (Patriarch) on Apr 04, 2003 at 05:48 UTC | |
|
Re: matching single-quoted-like strings (q{}, q//)
by dmitri (Priest) on Apr 03, 2003 at 22:39 UTC | |
by AltBlue (Chaplain) on Apr 03, 2003 at 22:53 UTC |