[LA.pm] push question

Ofer Nave ofer at netapt.com
Thu Mar 3 23:09:46 PST 2005


<email1>

On Thu, 3 Mar 2005, Robin Rowe wrote:

> Hi. Having a little trouble with 'push' not doing what I'd hoped.
> 
> I'm reading an array from a file:
> 
>  @lines = <FILE>;
> 
> I want to append some additional data to the array, but it doesn't do what I 
> expect.
> 
> Here's a test program that illustrates what I'm doing.
> 
> @lines={1,2,3};
> push(@lines,4);
> push(@lines,5);
> 
> foreach(@lines)
> { printf "%s-", $_
> }
> 
> Here's the output:
> 
> % perl pushtest.pl
> HASH(0x334ca0)-4-5
> 
> What I want is 1-2-3-4-5. How?

<email2>

> Nice thought, but changing a line of example code that's only in my test 
> program isn't going to get me far! As mentioned, in my real program that 
> input is '@lines = <FILE>;'. Pushing onto that is what I'm trying to 
> figure out.

The reason you're getting HASH(0x334ca0)-4-5 from your test program is 
that you have a bug in your test program.  Since you only posted your test 
program, that's the only thing we can help you with.

If you post your *real* code, or at least describe what problem you are 
having with push in your *real* code, then we can help you solve your 
*real* problem.

What are you doing in your real program, what do you expect to see, and 
what are you actually seeing?

-ofer



More information about the Losangeles-pm mailing list