Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: correct angle on tackling a problem

by roboticus (Chancellor)
on Aug 24, 2012 at 22:43 UTC ( #989651=note: print w/ replies, xml ) Need Help??


in reply to Re^2: correct angle on tackling a problem
in thread correct angle on tackling a problem

diamondsandperls:

He means logic like:

my %seen; for my $key (0 1 2 1 2 3 2 3 4 3 4 5) { print $key unless $seen{$key}++; }

This (untested) script should just print the values 0 through 5 in order. The $key value is just the data you use to tell whether it's identical or not. When you first check the %seen hash for the value 0, there won't be an entry for zero, so the print will execute. The line also increments the value in the %seen hash to 1, so the next time you see 0 it *won't* print.

You just need the %seen hash, the data you use for the $key, and an action you want to control.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


Comment on Re^3: correct angle on tackling a problem
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2015-07-30 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls