EXTERN Chakirov Timour (TZ CIS; DS/ESQ3) wrote:
Hello,

I know it's a dummy question, however I could not find a quick answer in
perl documentation.


So my question: is any form of "logical-IN" operator in perl? I.e. I have a
scalar $var and a list @colors = ['red', 'yellow', 'green']. All I want is
to check

if ($var in @color) {
        traffic_lite($var)
}

How could I realise this code in perl?

Something like this?


my @colors = ('red', 'yellow', 'green');
my $var = 'yellow';

if (in($var,[EMAIL PROTECTED])) {
  print($var);
}

sub in {
  my ($var, $array_ref) = @_;
  my $count;
  for (@$array_ref) {
    $count++ if $var eq $_;
  }
  return $count;
}

--
  Simon Oliver

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to