Front page | perl.beginners |
Postings from March 2002
Re: &&
Thread Previous
From:
Chas Owens
Date:
March 28, 2002 07:09
Subject:
Re: &&
Message ID:
1017327950.26085.282.camel@tert.icallinc.com
On Thu, 2002-03-28 at 09:44, MarcusWillemsen@compuserve.de wrote:
> Hi all,
>
>
> I have some arrays and like to trigger some events depending on which
> array or combination of arrays contains data. What I tried was
> something like:
> snippet
>
>
> if(@dates && !@themes && !@cities) {
>
>
> #do something with the data in @dates
>
>
> }
> elsif(!@dates && @themes && !@cities) {
> #do somthing with @themes
> }
> ...
> Alas! I doesn't work. Using "and" instead of "&&" doesn't help either.
> Or do I have to use "&" instead. Although it doesn't work either.
> instead
>
> Can someone help??
> Thanks
>
>
>
> Marcus Willemsen
> Online Redaktion
> Juve Verlag
> Agrippastr. 10
> 50676 Köln
>
>
> tel: ++49(0)221 91 38 80 16
> fax: ++49(0)221 91 38 80 18
> www.juve.de
> juve-newsline@juve.de
> marcus.willemsen@juve.de
What do you mean by "doesn't work"? I wrote this sample code and got
the following output:
<example>
#!/usr/bin/perl -w
use strict;
my @dates = (1);
my @themes;
my @cities;
do_something(\@dates, \@themes, \@cities);
@themes = (shift @dates);
do_something(\@dates, \@themes, \@cities);
shift @themes;
do_something(\@dates, \@themes, \@cities);
sub do_something {
my @dates = @{$_[0]};
my @themes = @{$_[1]};
my @cities = @{$_[2]};
if(@dates && !@themes && !@cities) {
#do something with the data in @dates
print "do something with the data in \@dates\n";
} elsif(!@dates && @themes && !@cities) {
print "do something with the data in \@themes\n";
} else {
print "do nothing\n";
}
}
</example>
<output>
do something with the data in @dates
do something with the data in @themes
do nothing
</output>
Which is exactly what I would expect. Perhaps you could post the
original code you had problems with?
--
Today is Boomtime the 14th day of Discord in the YOLD 3168
Missile Address: 33:48:3.521N 84:23:34.786W
Thread Previous
-
&&
by MarcusWillemsen
-
Re: &&
by MarcusWillemsen
-
RE: &&
by Nikola Janceski
-
RE: &&
by Nikola Janceski
-
RE: &&
by Nikola Janceski
-
Re: &&
by Chas Owens