> > Hi, > > my $foo = 'http://10.20.30.40/gargle'; > my ($fee) = $foo =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g; > > Note the /g at the end.
> Note that it is the list context (i.e. 'my ($fee) =') that causes the pattern match to return the matching sub-expressions. The g modifier is redundant in this case, as only a single match is required. Yeah, the /g though is pretty neat this way. If you've got more than one IP say, on the line, you can use it like a little matching engine in a while loop my $foo = 'http://10.20.30.40/gargle http://10.20.30.41/gargle http://10.20.30.42/gargle'; my ($fee) = $foo =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g; print "Got an ip: $fee\n"; while ( $foo =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g ) { my $fee = $1; print "Got one ip: $fee\n"; } # while /g gets: Got an ip: 10.20.30.40 Got one ip: 10.20.30.40 Got one ip: 10.20.30.41 Got one ip: 10.20.30.42 However, you can't do: while ( my ($fee) = $foo =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g ) { as then the assignment to $fee is the main connective and the match restarts each loop. a Andy Bach Systems Mangler Internet: [EMAIL PROTECTED] VOICE: (608) 261-5738 FAX 264-5932 "CM/ECF is a complex unfinished suit. Pull on a loose cuff thread and your pants fall down." MEC _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
