Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Print all derefs and method calls in a directory (Friday golf)

by ikegami (Patriarch)
on Jan 09, 2009 at 04:57 UTC ( [id://735079]=note: print w/replies, xml ) Need Help??


in reply to Print all derefs and method calls in a directory (Friday golf)

It only picks up -> derefs but everyone here seems to code that way, so it's a win for me.

I don't believe that's true. I do

for (@$list) { ... }

and

for (keys %$table) { ... }

and

$grid[$x][$y]

regularly. I even do

our $buf; local *buf = $ref;

often enough. All of those contains derefs. Three of them aren't even possible to do with the arrow.

Replies are listed 'Best First'.
Re^2: Print all derefs and method calls in a directory (Friday golf)
by jepri (Parson) on Jan 09, 2009 at 05:08 UTC
    Unless I'm missing something, the examples you have are fairly simply structured - I'm having to deal with calls like:
    $people->{login}->{chair}->{height}
    and each level is tampered with by a different module.

    So in your examples I'd be seeing: for (@{$people->{login}->{desk}->{paperclips}){}

      There are four derefences in

      @{$people->{login}->{desk}->{paperclips}}

      but only three arrows.

      The rest of your post doesn't relate to what I said, so I have no comment on it save that I rarely have paths that long.

      for my $employee (@$employees) { for my $desk (@{ $employee->{desks} }) { $paperclips += $desk->{paperclips}; } }

      Four dereferences, but only two arrows. And the output of your script doesn't illustrate the structure at all. Data::Dumper will do that to some extent.

        I had to do this statically, because I didn't have full environment to run it in(so no Data::Dumper). I was trying to find the structure of a couple of large state hashes that get passed around, using only what I saw in the code. I'm sorry I wasn't clear about that.

        Both you and I might have written the code differently, but I had to tackle what was in front of me. This code has a lot of nested hash derefs, and when they are all listed by the command line, they form a convenient hierachy which shows the keys and sub-keys. A possible advantage over data dumper (in this case) is that it shows which keys are accessed by the program, rather than all the ones that exist.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found