in reply to Perlish while loop
rovf's suggestion with using a hash to store the mapping of filenames to file descriptions is definitely the way to go for longer-term maintenance, since it allows you to expand the range of things you're looking for by simply adding a new hash entry, turning this into:... $people = 1 if ($filename eq 'people.pdf'); $animal = 1 if ($filename eq 'animal.pdf'); $msi = 1 if ($filename eq 'setup.msi'); } } print "People not found\n" unless defined $people; print "animal not found\n" unless defined $animal; print "MSI file not found\n" unless defined $msi; ...
my %filenames = ( people.pdf => 'Person', animal.pdf => 'animal', setup.msi => 'MSI file', ); ... for (keys %filenames) { delete $filenames{$_} if $filename eq $_; } } } for (values %filenames) { print "$_ not found\n"; } ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perlish while loop
by doug (Pilgrim) on Jul 16, 2009 at 19:45 UTC | |
by dsheroh (Monsignor) on Jul 17, 2009 at 08:55 UTC |