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

Hi Friends,

In the code that my senior has written there is a function which has the first few lines as given below
sub WriteLog($$) { my ( $logtype, $logtext ) = @_; my ( $out,@items)=(); push @tems, ( ref($logtext) eq 'ARRAY' ) ? @$logtext : $logtext; } And the call to the WriteLog is like : WriteLog( "INFO","*******Import Begin *****"); =======================================
Two arguments are sent to the WriteLog but in the definition there is a $$ ..I couldnt understand why $$ is used here.
And what are ref , @$ used for ?
Can any one help me ?

Thanks in advance
Veera

formatting fixed by holli

Replies are listed 'Best First'.
Re: variable in perl
by tlm (Prior) on Jun 17, 2005 at 12:55 UTC

    The $$ is a prototype; it specifies that the function WriteLog takes two scalars as arguments (see prototypes in perlsub).

    In the expression @$logtext, $logtext is actually a reference to an array, and @$logtext dereferences this reference to access this array. ref is an operator that, when given a reference as argument, returns the type of reference it is (ref). To better understand ref and @$logtext see perlreftut.

    the lowliest monk

      Hi tlm , thanks for your reply.this helps me a lot... bye Veera
Re: variable in perl
by dorward (Curate) on Jun 17, 2005 at 12:59 UTC

    $$ is a prototype, described in perldoc perlsub.

    ref is described in perldoc -f ref, and is used here to find out if $logtext is a scalar or a reference to an array.

    @$ dereferences the array reference (thus treating it as a regular array).

      Hi dorward, thanks a lot for your response.i shall go through the help available in the perl man pages. Thanks Veera