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

RE: RE: Postfix, whole-object dereference operators

by cwest (Friar)
on Jul 21, 2000 at 19:21 UTC ( #23598=note: print w/ replies, xml ) Need Help??


in reply to RE: Postfix, whole-object dereference operators
in thread keys function question

I think he's directly refering to the situation where you have a few references in a row, particularly in hashes... I too, think this is ugly:

%{$ref->[0]->{param}->[1]->{name}};
and you can't do this:
%$ref->[0]->{param}->[1]->{name};
so, I think it's a gripe about the ugly looks of the syntax. IMHO, I don't mind it, I consider it something like "Variable Encapsulation" in syntax. However, I could see a secondary syntax, as a prefix.

Perhaps:

print foreach HASH $obj->{param}; # or we don't like barewords print foreach 'HASH' $obj->{param}; # or parhaps it's really in a prag +ma use dereference qw/HASH/; print foreach HASH $obj->{param}; # or it stays the same print foreach %{$obj->{param}};
--
Casey


Comment on RE: RE: Postfix, whole-object dereference operators
Select or Download Code
RE: RE: RE: Postfix, whole-object dereference operators
by japhy (Canon) on Jul 21, 2000 at 19:38 UTC
    The pragma would have to be very magical, since it's a waste to return a potentially LONG list, like an array or hash, and functions like each() and keys() and values() and push() and pop() (etc) require ACTUAL hashes or arrays in their first argument, not things RETURNING them.

    As for %{$ref->[0]->{param}->1->{name}} being ugly, ADD WHITESPACE, and REMOVE ARROWS:
    %{ $ref->[0]{param}[1]{name} }
RE: RE: RE: Postfix, whole-object dereference operators
by japhy (Canon) on Jul 22, 2000 at 02:01 UTC
    I've written a preliminary version of this pragma (it's horrible and ugly, by the way).
    use deref; $href = { 1,2,3,4 }; for (sort keys HASH{ $href }) { print "$_ -> $href->{$_}\n"; }
    I'm working on a second one that doesn't require the { }. It's difficult, because I have to parse perl, and pretty much the only language that can parse perl is Perl. I mean, my first version breaks in places like:
    print "This breaks the HASH{} thing.\n"; # becomes print "This breaks the %{} thing.\n";
    I suppose I could run the code through B::Deparse, but that might break parts of it, which would be A Bad Thing. $_="goto+F.print+chop;\n=yhpaj";F1:eval

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-04-21 06:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls