۰۵آذر
#!/usr/local/bin/perl
#
# search for an item in a numeric list.
# numeric list is privided by command line arguments.
# next we will read item to be searched from standard input.
#
use warnings;
use strict;
sub search {
my $toSearch = shift @_;
foreach my $i (@_) {
return 1 if ($i == $toSearch);
}
return 0;
}
my $progName = __FILE__;
if (!@ARGV) {
print STDERR "usage: $progName [num-list]\n";
exit 1;
}
print "list is [@ARGV]. Enter what to search?! ";
my $toSearch = <STDIN>;
chomp $toSearch;
my $result = search($toSearch, @ARGV) ? "in" : "not in";
print "$toSearch is $result [@ARGV]\n";
۹۳/۰۹/۰۵