Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Accessing an array inside of a package

Reply
Thread Tools

Accessing an array inside of a package

 
 
Ryan McCoskrie
Guest
Posts: n/a
 
      12-09-2008
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.
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      12-09-2008
In article <ghkfec$odb$(E-Mail Removed)>, Ryan McCoskrie
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Ryan McCoskrie
Guest
Posts: n/a
 
      12-09-2008
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.
 
Reply With Quote
 
Tad J McClellan
Guest
Posts: n/a
 
      12-09-2008
Ryan McCoskrie <(E-Mail Removed)> 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/"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array inside struct inside container none C++ 8 08-23-2011 09:20 AM
RowCommand: accessing ObjectDataSource from inside gridview inside a repeater? HockeyFan ASP .Net 1 07-04-2007 05:49 AM
Accessing USER CONTROL which is inside Masterpagethrough Another USER Control inside normal page. Kiran More ASP .Net Web Controls 2 11-14-2006 12:58 PM
single package import v/s the entire package Parvinder Java 6 02-27-2005 02:02 PM
Accessing array inside a VARIANT in VC++ Demian C++ 1 11-14-2003 03:38 PM



Advertisments