Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Stumped Regular expressions

by kabeldag (Hermit)
on Jun 11, 2008 at 13:48 UTC ( [id://691464]=note: print w/replies, xml ) Need Help??


in reply to Stumped Regular expressions

I stuck a 'global' modifier on the end:
use strict; use warnings; my $line_count = 0; open(F, "test.htm"); while(<F>) { my @a = $_ =~ m{(http://hosting/image\d+\.jpg)}g; for my $url (@a) { print "URL [ $url ] found on line ($line_count)\n"; } $line_count++; } close(F);

Replies are listed 'Best First'.
Re^2: Stumped Regular expressions
by toolic (Bishop) on Jun 11, 2008 at 16:34 UTC
    This could be further simplified by using the special variable $. (INPUT_LINE_NUMBER) instead of $line_count:
    open(F, "test.htm"); while(<F>) { my @a = $_ =~ m{(http://hosting/image\d+\.jpg)}g; for my $url (@a) { print "URL [ $url ] found on line ($.)\n"; } } close(F);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://691464]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 03:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found