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);