[ Please preserve proper attributions when you reply. The text preceded
by >>> was written by you ]
....
This is some habit of myself, mostly because people
sometimes tend to quote "regexp's" by different
quotation marks themselves, in order to control
interpolation (in which case the above example could
fail without quoting the quotation marks, imho).
That makes no sense. You did not use " as a pattern delimiter. If you
had written
my $string = qq{ " hello world "\n };
$string =~ s"^\s*\"+"";
$string =~ s"\"+\s*$"";
I would have questioned your choice of a delimiter that requires that
you backslash more than necessary.
On the other hand, if one did not want interpolation (which makes no
difference here because there is nothing to be interpolated in the
pattern), one would have used:
my $string = qq{ " hello world "\n };
$string =~ s'^\s*"+'';
$string =~ s'"+\s*$'';
$string = [split /\s*\"+/, $string]->[1];
Only if you are into obfuscation, and only if no valid quotation marks
can appear in the middle of the string. Say what you mean, and mean what
you say.
#!/usr/bin/perl
use strict;
use warnings;
my $string = qq{" How about "this"? "};
my $result = (split /\s*\"+/, $string)[1];
print "$result\n";
__END__
--
A. Sinan Unur <
[email protected]>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html