Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

understanding symbols

by baperl (Sexton)
on Aug 03, 2011 at 19:10 UTC ( #918360=perlquestion: print w/replies, xml ) Need Help??

baperl has asked for the wisdom of the Perl Monks concerning the following question:

hi, can you please help me understand what this means:
$|=1;
also, why are there 2 { in this code:
@puts = @{$h0{'puts'}};
and does the below return a hash?
my %h1 = %{$hr1};

Replies are listed 'Best First'.
Re: understanding symbols
by toolic (Bishop) on Aug 03, 2011 at 19:22 UTC
    See $| in perlvar
    perldoc -v '$|'

    h0 is probably a HASHES OF ARRAYS data structure. The inner {} return the puts key. The outer {} dereference the array.

    %{$hr1} dereferences a hash reference. See perlreftut

      thanks toolic, that helps :-)
Re: understanding symbols
by dreadpiratepeter (Priest) on Aug 03, 2011 at 19:24 UTC

    the first is a special variable. In this case the OUTPUT_AUTOFLUSH variable that controls whether the output is buffered. You can read about it an other variables by typing perldoc perlvar

    In the second case you have a hash that contains references to arrays. something like

    %h = (a => [1,2], b => [3,4]);
    . the  $h0{puts} part returns a <b>reference</b> to an array. To dereference it you need to put a '@' in front of it.  so to dereference $a, you would type <code>@$a. you a more complex expression that yields a reference you would use @{} to dereference it for clarity.

    Similarly, in the third example you are dereferencing a reference to a hash $hr1 to get a hash. The third could by written more succinctly as %$hr1

    Typing perldoc perlreftut will teach you about references and dereferencing.

    It also sounds like you could use a good introduction to Perl. I would suggest Learning Perl or Modern Perl.



    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
      thanks Pete, that clarifies. I will look up the perl docs and books you suggested :-)
Re: understanding symbols
by planetscape (Chancellor) on Aug 03, 2011 at 23:28 UTC
Re: understanding symbols
by Anonymous Monk on Aug 04, 2011 at 03:26 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2022-07-02 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My most frequent journeys are powered by:









    Results (103 votes). Check out past polls.

    Notices?