Re: how to test if an element belongs to an array or hash





John Bokma wrote:
> wrote:
>
> > If I don't use iteration, how to test if an element belongs to an array
> > or hash?
>
> for a normal array: -> iteration
> for hash, exists

How about this way, without iteration? I know you can fool it into
thinking that 'apple banana' is an element though.

#!/usr/bin/perl
use strict;
use warnings;

my @array = ('apple','banana','peach','pear','mango');
my $string = join ' ', @array;
my $input = $ARGV[0];
print "$input is a value of the array\n" if $string =~ /$input/;

.



Relevant Pages