in reply to Why repeated matches...

Less reformatting of code:

while (my $line = <FH>) { $line =~ m/\s([\w ]+? PRIMARY SCHOOL)/ || next; push @schools, $1; }

Or you could get sneaky:

@schools = grep {/\s([\w ]+? PRIMARY SCHOOL)/; $_ = $1} <FH>;

Replies are listed 'Best First'.
Re: Re: Why repeated matches...
by bart (Canon) on Dec 15, 2003 at 02:30 UTC
    Sneakier still:
    @schools = map /\s([\w ]+? PRIMARY SCHOOL)/, <FH>;
    map creates a list of matches, here consisting only of $1, when it matches, and an empty list when it fails to match.