On May 9, [EMAIL PROTECTED] said:
>(name = john)
>
>if I am trying to just extract "john" for the value $b, why would the
>following script not work. I thought it would take bothIt returns the
>full (name=john)
Let's run your regex through the regex explainer:
> (my $b=$_) =~ s/^(\() (\w+)/$2/;
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\( '('
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
' '
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
You can see that it's matching a '(', and then a ' '. You don't have a
space after the ( though. :(
Perhaps you want to use:
while (<TRY>) {
my ($name) = /^\(\w+ = (\w+)\)$/;
print "got: $name\n";
}
That regex matches the (, and then some "word", then " = ", and then saves
the next "word" it finds.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734