Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re(2): Ternary Operator: Condition-Negation

by Arien (Pilgrim)
on Aug 28, 2002 at 23:23 UTC ( [id://193622]=note: print w/replies, xml ) Need Help??


in reply to Re: Ternary Operator: Condition-Negation
in thread Ternary Operator: Condition-Negation

Simplify?
for ($#history .. 0) { my $temp = pop @history; next if exists $history{ $temp }; $history{ $temp } ++; unshift @history; }

Why not follow through when you get to that point? Something like this seems just fine to me:

my %seen; for (1 .. @history) { my $item = pop @history; unshift @history, $item unless $seen{$item}++; }

Sure, the temporary variable is still there. But then, do you really prefer something along these lines?

my %seen; for (1 .. @history) { unshift @history, $seen{$history[-1]}++ ? $#history-- && () : pop +@history; }

I didn't think so either. ;-)

— Arien

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2025-02-09 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.