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

I saw a script like this: join ("\n", @$msg ) $msg is just a text message with several lines. What does @$msg mean?

Replies are listed 'Best First'.
Re: what does @$ mean?
by kyle (Abbot) on Sep 30, 2008 at 15:49 UTC
Re: what does @$ mean?
by runrig (Abbot) on Sep 30, 2008 at 15:52 UTC
    $msg is likely a reference to an array of text messages. @$msg dereferences that reference, turning it into an array of text messages. And those messages are joined together in your code example. See perlref and perlreftut.
Re: what does @$ mean?
by lamp (Chaplain) on Sep 30, 2008 at 16:22 UTC
    '@$msg' dereference the array reference '$msg'.
    'join ("\n", @$msg )' is used for join the '$msg' array reference elements into a string separated by "\n". For eg.
    #!/usr/bin/perl use strict; use warnings; my $msg = ['apple', 'banana', 'orange']; # array reference my @msg = @$msg; # dereferncing the arreay ref print "Dereferenced: @msg\n"; print join("\n",@$msg); # prints the array elem +ents sperated by "\n".
    Please go through perlref and join for more information.
Re: what does @$ mean?
by Your Mother (Archbishop) on Sep 30, 2008 at 19:02 UTC

    What everyone else said + I prefer this syntax: @{$msg} in part because it helps convey what's going on.

      in part because it helps convey what's going on Not any more or less than @$msg alone

        The braces make it clear that @$ is not a special sigil; that it's still an array with something going on inside. It also enhances readability on long or compound (deep hash access, for example) variable names. IIRC, there used to be a case where it further was necessary to disambiguate the resolution of variables but I'm not sure about that or if it's still true.