in reply to Re^4: How to match regex over multiline file
in thread How to match regex over multiline file
I don't know about your regex, but since you don't limit @sentences to the context of your while loop with my, it's a global variable. It doesn't go out of context at the end of the loop, so each time through the loop it retains the elements it already had, and then you push the next paragraph's sentences onto it. Like this:
for my $l ('a'..'d'){ @list; push @list, $l; } print @list: # prints qw( a a b a b c a b c d );
You should learn to localize variables within a block with my, and use strict to tell you when you forgot to do that. Failing that, you should empty @sentences at the start of each loop with @sentences=(); . But really, learn strict and my.
Aaron B.
Available for small or large Perl jobs; see my home node.
|
|---|