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

Re^11: Is there any difference between prototype % and @ ?

by AnomalousMonk (Monsignor)
on Feb 23, 2013 at 16:56 UTC ( #1020324=note: print w/ replies, xml ) Need Help??


in reply to Re^10: Is there any difference between prototype % and @ ?
in thread Is there any difference between prototype % and @ ?

it's a common idiom to use map to create listified hashes map { $_ => 0 } LIST

A hash is commonly initialized from a list, e.g.
    my %hash = qw(a 1  b 2  c 3);
Does the quoted idiom do anything other than generate another list with which to initialize a hash? Can a hash so initialized be considered in any way distinct from a hash created in any other way; in particular, can it usefully be distinguished as 'listified'?

orthogonality always makes sense!

A hash is commonly initialized from a list as in the example given above, and a hash is seamlessly 'listified' in list context as in a statement like
    print %hash;
or
    my @array = %hash;
but are lists (and, by extension, arrays) really orthogonal with hashes? Despite certain conceptual similarities, my inclination would be to say no: there are just too many differences:

  • A hash can be assigned to an array and all the information inherent in the hash can be accessed and manipulated using standard array and list operators, but this is rarely anything other than an exercise in masochism;
  • An array can be assigned to a hash, but the information inherent in the array is largely destroyed thereby.

Prototypes are just not mature enough!!!

Amen to that, brother! Or rather, they are just not well-named enough. Had they been better named, people like myself who come from C/C++land and adjacent regions would not know instantly what they are – and be instantly wrong!


Comment on Re^11: Is there any difference between prototype % and @ ?
Select or Download Code
Re^12: Is there any difference between prototype % and @ ?
by LanX (Canon) on Feb 23, 2013 at 18:17 UTC
    simple test, try to chain my and BUKs implementation of hgrep, 2 in a row!

    I'll try to propose a solution for all of this including lazy lists after GPW in March.

    Cheers Rolf

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-08-30 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls