Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Flip Flop III - Musical Buckets

by bobione (Pilgrim)
on Apr 25, 2001 at 14:31 UTC ( #75407=note: print w/replies, xml ) Need Help??


in reply to Flip Flop III - Musical Buckets

I try to understand your small code, and there is no way !!
Please MonkChow explain me the @_{5..29} functionality.
To understand how it works, I split //,"0123456789" into @_{..} with other indexes.
And this are my results...

0129345678   for @_{1..10}
0182934567   for @_{2..11}
4560718293   for @_{3..12}
9345607182   for @_{4..13}
8293456071   for @_{5..14}
7182934560   for @_{6..15}
3450617289   for @_{7..16}
2345061789   for @_{8..17}
1234506789   for @_{9..18}
0123456789   for @_{10..19}

I can't find no logic. Hope someone got the use enlightment ;)

BoBiOne KenoBi

Replies are listed 'Best First'.
Re: Re: Flip Flop III - Musical Buckets
by c-era (Curate) on Apr 25, 2001 at 16:23 UTC
    Add this to the bottom, it should help you understand what is going on.
    for (keys %_){ print "$_ = $_{$_}\n"; }
      It's supposed to help me ? :)
      Why %_ have this index order ???
      In the first line, why the 9 come between the 2 and the 3 ? ---> 1239345678 , Why this position ?
      After what on the second line, the 8 take place one number before the 9 ---> 128394567.
      On third line 7 go one number before the 8 ---> 172839456...
      It could be the rule but I am not sure at all !

      BobiOne
      Can Perl remain obfuscated for me ? ... No

        As it was my explanation in chatter that inspired this obfuscation, here is a quick explanation.

        A hashing function is a function that takes input (usually a string) and gives back a number in some range.

        A hash lookup algorithm takes keys, passes the keys to a hashing function, and then uses that number to select a bucket, then stores the key/value in the bucket in some way. Hopefully the keys are pretty much randomly distributed so each bucket has few things in it. Details vary, there are different hashing algorithms you can use, different ways to store things in buckets, often there is some dynamic decision on how many buckets to use, etc.

        Perl's hashes are called hashes because they use a hash lookup algorithm to store data. That is why lookups are fast. But when you ask for them back (with keys or values) it just walks the buckets, and returns things out of the buckets. The order you get back depends on all sorts of things, starting with the hashing function and number of buckets...

        As a test, anyone who can understand Re: Re: Shift, Pop, Unshift and Push with Impunity! probably understood this explanation perfectly.

        Anyways, the order that stuff comes back is entirely determined by internal details, looks random, but isn't. So if you figure out what order keys will give for (for instance) a series of numbers, then just put the values in matched to where you want them to go and voila! You get output sorted from values just right for no apparent reason! :-)

        Hash keys are not stored in order. They are stored by the fastest way to retrive the keys/values. If you want to know the exact reason why it is in that order, you will either need to look at the perl source code and figure it out, or talk with someone that <bold>REALLY</bold> knows the internals of perl. Also, you will notice that order is different in different versions of perl.
        I think it's got something to do with the order in which Perl stores hash keys.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2019-12-10 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?