[LA.pm] push question

Kevin Scaldeferri kevin+lapm at scaldeferri.com
Thu Mar 3 23:37:35 PST 2005


On Mar 3, 2005, at 11:29 PM, Robin Rowe wrote:

>> What are you doing in your real program, what do you expect to see, 
>> and
>> what are you actually seeing?
>
> These are the only lines that matter.
>
> @lines = <FILE>;
> push(@lines,$string);
>
> I simply want to append another line to an array of lines read from a 
> file, but push doesn't do what I expected. Does anyone know how to 
> push a string onto an array of strings read from a file?

Just like that:

[kevin]% cat foo
foo
bar
[kevin]% perl -e 'open FOO, "foo"; @lines = <FOO>; push @lines, 
"baz\n"; print @lines'
foo
bar
baz


Maybe you can explain what output you are getting that is not what you 
expect.


-kevin



More information about the Losangeles-pm mailing list