Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Loops and variable usage

by JavaFan (Canon)
on Mar 23, 2012 at 19:18 UTC ( #961295=note: print w/ replies, xml ) Need Help??


in reply to Loops and variable usage

It seems like your code is equivalent to:

sub ddd { my $a = $_[0] == 1 ? 'p' : $_[0] == 2 ? 'pp' : $_[0]; my $b = $_[1] == 3 ? 'w' : $_[1]; my $c = $_[2]; print v " < $a > < $b > < $c >"; }
Having said that, I don't which problem you are trying to solve. I don't see any loops.


Comment on Re: Loops and variable usage
Download Code
Re^2: Loops and variable usage
by BillKSmith (Chaplain) on Mar 24, 2012 at 23:09 UTC
    I find nested ternaries are much clearer using the code layout suggested by the book "Perl Best Practices"
    sub ddd { # code # value my $a = $_[0] == 1 ? 'p' : $_[0] == 2 ? 'pp' : $_[0] ; my $b = $_[1] == 3 ? 'w' : $_[1] ; my $c = $_[2]; print v " < $a > < $b > < $c >"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (10)
As of 2014-10-31 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (221 votes), past polls