Accessing an array inside of a package

Discussion in 'Perl Misc' started by Ryan McCoskrie, Dec 9, 2008.

  1. I've been working on a little Polish notation
    calculator / interpreter just to get some
    idea of how to deal with these issues.

    However my design pins on having a package
    that describes a sum including all of the numbers
    in it and the perl interpreter won't accept this:

    @self->{num} = []; #my list of numbers
    .... #skip boring bit where the numbers are read in
    #and check to be numbers
    push @self->{num}, @input; #@input is the numbers

    What I get is this:
    Type of arg 1 to push must be array (not hash element) at
    sum.pm line 16, near "@input;"
    ------------------------------------------------------------------------
    Quote of the login:
    I haven't lost my mind -- it's backed up on tape somewhere.
     
    Ryan McCoskrie, Dec 9, 2008
    #1
    1. Advertising

  2. Ryan McCoskrie

    Jim Gibson Guest

    In article <ghkfec$odb$>, Ryan McCoskrie
    <> wrote:

    > I've been working on a little Polish notation
    > calculator / interpreter just to get some
    > idea of how to deal with these issues.
    >
    > However my design pins on having a package
    > that describes a sum including all of the numbers
    > in it and the perl interpreter won't accept this:
    >
    > @self->{num} = []; #my list of numbers


    $self->{num} = []; # reference to an anonymous array

    > ... #skip boring bit where the numbers are read in
    > #and check to be numbers
    > push @self->{num}, @input; #@input is the numbers


    push( @{$self->{num}}, @input ); # add elements to that array

    An anonymous array with a reference $ref to it is accessed as @{$ref}.

    >
    > What I get is this:
    > Type of arg 1 to push must be array (not hash element) at
    > sum.pm line 16, near "@input;"


    --
    Jim Gibson
     
    Jim Gibson, Dec 9, 2008
    #2
    1. Advertising

  3. Ryan McCoskrie wrote:

    First of sorry for not replying to the right message
    (news reader issues).

    Thanks for that, I was sure there would be an answer
    like that. I just haven't worked with perl enough
    to know that sort of thing.
    ------------------------------------------------------------------------
    Quote of the login:
    I haven't lost my mind -- it's backed up on tape somewhere.
     
    Ryan McCoskrie, Dec 9, 2008
    #3
  4. Ryan McCoskrie <> wrote:

    > the perl interpreter won't accept this:
    >
    > @self->{num} = []; #my list of numbers



    > push @self->{num}, @input; #@input is the numbers



    perldoc perlreftut


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Dec 9, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parvinder
    Replies:
    6
    Views:
    762
    Thomas G. Marshall
    Feb 27, 2005
  2. Demian
    Replies:
    1
    Views:
    1,399
    Victor Bazarov
    Nov 14, 2003
  3. HockeyFan
    Replies:
    1
    Views:
    1,013
    Masudur
    Jul 4, 2007
  4. none
    Replies:
    8
    Views:
    413
  5. Kiran More
    Replies:
    2
    Views:
    329
    Kiran More
    Nov 14, 2006
Loading...

Share This Page