Re: how to test if an element belongs to an array or hash
- From: ioneabu@xxxxxxxxx
- Date: 31 May 2005 11:57:23 -0700
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/;
.
- References:
- how to test if an element belongs to an array or hash
- From: biomahui
- Re: how to test if an element belongs to an array or hash
- From: John Bokma
- how to test if an element belongs to an array or hash
- Prev by Date: how to sort hash by value, where value is a valid date
- Next by Date: Re: how to sort hash by value, where value is a valid date
- Previous by thread: Re: how to test if an element belongs to an array or hash
- Next by thread: Re: how to test if an element belongs to an array or hash
- Index(es):
Relevant Pages
|