in reply to How do you add class array values

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Re: How do you add class array values
by ton (Friar) on Apr 12, 2001 at 22:12 UTC
    Actually, that won't work. You need this as the second line:
    push @{$this->{fields}}, "some value";
    push expects an array as its first argument, not an array reference, so you need to dereference the value of $this->{fields}.

    -Ton

    -----

    Be bloody, bold, and resolute; laugh to scorn
    The power of man...

Re: Re: How do you add class array values
by satchboost (Scribe) on Apr 12, 2001 at 22:16 UTC
    That would have to be push @{$this->{fields}}, $val. push requires a @-value, not a reference to a @-value, as its first argument.

    On a more general note, the way to think about an object in Perl is that it's a hash that knows how to call functions. So, if you want to push a value onto an array and a reference to that array is stored in the object, you treat it just like an array. Using bless just means it knows how to call functions in a given package. (There's a little more to it, but that's basically the gist.)