in reply to Pattern Match in @array

Just loop over the array, one element at a time:
my $found; for (@list) { last if $found = /pattern/; } if (!$found) { open FILE, "> $filename"; close FILE; }


japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: Re: Pattern Match in @array
by azatoth (Curate) on Jun 11, 2001 at 20:28 UTC
Re: Re: Pattern Match in @array
by srawls (Friar) on Jun 11, 2001 at 23:40 UTC
    I may be going against the advice of mirod : "correct a mistake by a high-ranking monk: yeah, like anybody's going to believe you!" but oh well : )

    Actually, I believe (I may be wrong, it wasn't too clear), that the poster has an array of files, and he wants to check each one against a pattern, and if it doesn't match, then he will make the file. If the first file in the area of your example is good, the whole thing stops. Merely change that last to a next, and open the file right after you write next:

    for (@files) { next if /pattern/; #file didn't match pattern, so create it open(FH,">$_"); #do something with FH }

    The 15 year old, freshman programmer,
    Stephen Rawls