Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Uniq and sort in perl

by slayedbylucifer (Scribe)
on Jul 12, 2012 at 09:22 UTC ( #981339=note: print w/replies, xml ) Need Help??


in reply to Re: Uniq and sort in perl
in thread Uniq and sort in perl

Utilitarian, I can't thank you enough. Your solution is **exactly** what I was looking for. Thank you very Much !!

But, unfortunately i am not able to decode or understand your oneliner. Could you guide me to some documentation for the same.

Thanks Again for the lightning fast response.

Replies are listed 'Best First'.
Re^3: Uniq and sort in perl
by Anonymous Monk on Jul 12, 2012 at 10:51 UTC
Re^3: Uniq and sort in perl
by Preceptor (Deacon) on Jul 15, 2012 at 11:26 UTC
    What is happening in that one liner:
    print "$vm, $filer, \n" if ! $seen{"$vm:$filler"}++

    It's quite an elegant piece of code, with a lot going on. So let's break it down:

    • The hash called '%seen' is being checked - to see if it contains a key called "$vm:$filler". The value of this is being tested for being 'false'. (because there's 'if !' which is 'if not') - which is literally 'if not seen'
    • So if $seen{"$vm:filler"} is _not_ 'true' - we haven't seen it, and so we print it.
    • And then that ++ kicks in, to post increment, 'adding one' to $seen{"$vm:$filler"}' - so the first time we try doing that, it's going to be undefined (and thus false) triggering a print. Second time, it'll be 'non zero' and so evaluate as 'true'.
    For bonus points, you can probably do:
    foreach my $key ( keys %seen ) { print "$key was seen $seen{$key} times\n"; }
    Does that make it any clearer?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981339]
help
Chatterbox?
[Yaerox]: I feel like i'm not seeing the forest for the trees. Can someone give me a hint how to research converting all kinds of files into ansi? If origin file is utf8 convert to ansi, is origin file is ansi then skip file.
[1nickt]: Yaerox probably best to whip up an SSCCE demonstrating the failure in what you have now and post to SoPW as a question.
[Corion]: Yaerox: That's a somewhat hard problem. Encode solves the conversion part, but for guessing what encoding a file is in, that's the hard part
[Corion]: Yaerox: There is Encode::Guess, but that needs a limited set of inputs, and it also cannot handle multiple single-byte encodings

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-03-28 13:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (331 votes). Check out past polls.