Bill Ng [bill.ng AT citigroup.com] wrote:
> Syntax issue (I think),
> 
> I'm trying to do the following:
> I need to execute a block of instructions for all items in an array
> except for one.
> 
> So if my array was:
> @a=(1,2,3,4,5);
> And we assume that I don't want to execute the block if the value of
$_
> is 3 ...
> 
> Then, in my head, I'm looking for the WORKING (key word there) version
> of this:
> -----------
> @a = (1,2,3,4,5);
> if ($_ != 3) for (@a)
> {
>   print "something";
>   &doSomething();
>   print "somethingelse";
>   &yada($yada{$ya})
> }
> -------------
> 
> But that if ... for line doesn't work.
> Neither does:
> ------------------------
> for (@a, $_ != 3) {}
> ------------------------
> 
> Anyone got any ideas?  I've always done this by running a standard for
> loop and having an if condition inside the loop .. but that seems
> inefficient to me right now and I'm looking for the easier way.

Don't think you'll find anything simpler than the old standard "next if
expr" :

for ( @a ) {
        next if $_ == 3;
        print "something";
        &doSomething();
        print "somethingelse";
        &yada($yada{$ya})
}

--
Mike Arms


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to