Aruna Goke wrote:
Chris E. Rempola wrote:
How would you match Parenthesis in Perl?

- STRING -
Received: from 10.143.205.68.abc.def.gh.com (10.205.143.238)
- /STRING -

I want to be able to grab the IP address in (10.205.143.238).

Thanks in advance.

#/usr/bin/perl

use warnings;
use strict;
#use re 'debug';

my $f = "Received: from 10.143.205.68.abc.def.gh.com (10.205.143.238)";

print $&, if $f=~m/\S+$/;

perldoc perlre
[ snip ]
    WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the
    program, it has to provide them for every pattern match.  This may
                                                              ^^^^^^^^
    substantially slow your program.  Perl uses the same mechanism to produce
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    $1, $2, etc, so you also pay a price for each pattern that contains
    capturing parentheses.  (To avoid this cost while retaining the grouping
    behaviour, use the extended regular expression "(?: ... )" instead.)  But
    if you never use $&, $` or $', then patterns without capturing parentheses
    will not be penalized.  So avoid $&, $`, and $' if you can, but if you
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    can’t (and some algorithms really appreciate them), once you’ve used them
    once, use them at will, because you’ve already paid the price.  As of
    5.005, $& is not so costly as the other two.


Why is there a comma after the variable? Did you forget to include another variable?



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to