Grant wrote:
Can anyone show me how to save to a variable the contents of a set of
double-quotes in a string? The string could look like any of these:
phrase1 "phrase2" phrase3
"phrase2" phrase3
phrase1 phrase3 phrase4
In all of these examples, phrase2 would be saved to the variable.
Many thanks to anyone who can show me how to do this.
$ perl -le'
my @strings = (
q/phrase1 "phrase2" phrase3/,
q/"phrase2" phrase3/,
q/phrase1 phrase3 phrase4/,
);
for my $string ( @strings ) {
my ( $phrase ) = $string =~ /"([^"]+)"/;
print $phrase if $phrase;
}
'
phrase2
phrase2
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/