[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell script or Perl?



At 2003-06-13T04:11:47Z, Steve Lamb <grey@dmiyu.org> writes:

>>     foreach $_ ($switch)
>>     {       
>>         /^a$/ and do { print "a"; };
>>         /^b$/ and do { print "b"; };
>>         /^c$/ and do { print "c"; };
>>     }

> BTW, the above is still not that idiomatic.  C'mon, any C programmer
> that's done a for loop over a set of pointers can catch that.  The far
> more idiomatic would be:

> foreach ($switch){
>   if ($hash{$_}){
>     print($hash{$_});
>   }
> }

Those "print" statements were example blocks of code.  Imagine instead:

    foreach $_ ($switch)
    {       
        /^a$/ and do { someFuncA(); };
        /^b$/ and do { print someFunkB(); exit; };
        /^c$/ and do { return; };
    }

Note that "$switch" is not an array; it's looping across a scalar.  How
often do you see that elsewhere?  :)
-- 
Kirk Strauser
In Googlis non est, ergo non est.

Attachment: pgpXwskiP_SOU.pgp
Description: PGP signature


Reply to: