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