in reply to searching an array
A hash is handy for these type of jobs.
#!/usr/bin/perl use strict; use warnings; my @array = (qw(peter paul john mary)); my $name = 'jim'; my %lookup = map { $_ => undef} @array; die "$name not found\n" unless exists $lookup{$name}; print "found $name\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: searching an array
by Articuno (Beadle) on Jan 03, 2006 at 15:45 UTC | |
by Roy Johnson (Monsignor) on Jan 03, 2006 at 15:51 UTC | |
by Articuno (Beadle) on Jan 03, 2006 at 16:09 UTC | |
|
Re^2: searching an array
by holli (Abbot) on Jan 03, 2006 at 18:26 UTC |