Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

@$ variable type

by Anonymous Monk
on Jan 12, 2012 at 20:24 UTC ( [id://947630]=perlquestion: print w/replies, xml ) Need Help??

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

Here is the snippet of code that I am looking at:
my ($sets) = IO::Select->select($socket_set, undef, undef, 0); ... foreach (@$sets) { $buf = <$_>; if($buf) { if($buf =~ "^VIEWLOG") { ...
What is @$ doing in front of sets? I keep thinking that it is some kind of hash, but it is probably wrong.

Replies are listed 'Best First'.
Re: @$ variable type
by toolic (Bishop) on Jan 12, 2012 at 20:31 UTC
    The @ is used to dereference an array reference: perldoc perlreftut.

    From perldoc IO::Select (for the select method):

    The result will be an array of 3 elements, each a reference to an array which will hold the handles that are ready for reading, writing and have exceptions respectively.

    See also: Writeup Formatting Tips

      but then why is there a foreach? What is that loop actually doing to the sets variable?

        Though select returns three elements, your code is only using the first one, $sets, a reference to an array of handles ready for reading. To de-reference this array reference $sets, you use @$sets, as described in the perlreftut link already provided by toolic. Note that @$sets is equivalent to @{$sets} (the form more commonly used in perlreftut). You need to take the time to read perlreftut and to understand how references work in Perl.

Re: @$ variable type
by luis.roca (Deacon) on Jan 12, 2012 at 22:41 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-03-28 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found