in reply to Regex for zip files.

Not sure what you're really doing but the /zip$/ works-

use warnings; # Don't leave out! use strict; # This neither! my @files = qw( zip.meta some.zip ); for my $file ( @files ) { print $file, "\n"; print $file =~ /zip$/ ? "\tZip!\n" : "\tNada y pues nada...\n"; }

I don't know exactly what you're doing but you always keep in mind that trusting user data or even file extensions is a mistake. Test/validate. Just because it ends in .zip doesn't mean it's a zip file. So you might want to ask about your final goal instead of your code difficulty with the matches.

Replies are listed 'Best First'.
Re^2: Regex for zip files.
by Karger78 (Beadle) on Jun 09, 2009 at 20:45 UTC
    The thing is though it's matching both. Where I want it to match one or the other when it's going though the array.

      It's not matching both. Try running my version and looking at the way ikegami broke it down above too. Make sure you are using strict and warnings in your code; they catch tons of simple problems.

        Your code didn't seem to work Your Mother. What I am doing is going though an array and matching zip files renaming them, then matching zip.meta and then renaming. It appears with the orignal code I had was matching zip on the first pass, then matching zip and zip.meta.