in reply to Regex shows only last match multiple times?
A data sample would have been helpful. Not your whole data set, but just enough to try your code by ourselves.
The problem with your code is that, foreach ( $w =~ /(capture)/g) will run the regex through the whole string, setting each time $1, and then start looping through the list. But the elements will be aliased to $_, not $1 which won't change. Write print "Photo: $count $_\n" instead, and all shall be well.
Instead of opening $ARGV[0] yourself, you could try using the diamond operator's magic.
This will loop through all the files in the parameters (which allow you to supply several filenames instead of one. The currently processed file is $ARGV. If @ARGV is empty, your script will work on STDIN instead.my $count = 0; while(<>) { $count+= () = m< photo/([a-z]+\.[a-z]{3}) >gxi; }
|
---|
In Section
Seekers of Perl Wisdom