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

I don't know what the square brackets in the following code might be for

#function returns an array reference to $trvs $trvs = $ad->fetch_all_by_Transcript([$transcript_obj]); #$transcript_obj is an object/instance variable
I don't know why the object reference is in square brackets. The parameter is supposed to be a listref. Are you creating an anonymous array and putting the object reference in it and then passing the anonymous array reference to the function?

thanks

Replies are listed 'Best First'.
Re: Beginner - what is the function of these square brackets
by Utilitarian (Vicar) on Oct 21, 2010 at 15:58 UTC
    Are you creating an anonymous array and putting the object reference in it and then passing the anonymous array reference to the function?
    That is exactly what you are doing.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: Beginner - what is the function of these square brackets
by halfcountplus (Hermit) on Oct 21, 2010 at 16:05 UTC
    The parameter is supposed to be a listref.

    And that's what that is. An array (or list) reference is a reference to an "anonymous" array, eg:

    my $ref = [];

    That's a reference to an empty array.

    my $ref = [$transcript_obj];

    Would be a reference to an array with one element.

      An array (or list) reference....

      There's no "or list"; how do you take a reference to a list?