Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: appending multiple values in an array

by jonnyfolk (Vicar)
on Mar 18, 2009 at 14:45 UTC ( #751457=note: print w/replies, xml ) Need Help??


in reply to appending multiple values in an array

Well, if you're sure that the result is being overwritten, then you have probably declared the array within the foreach loop:
my @array = (1,2,3,4,5); foreach my $line (@array) { my @newarray; push (@newarray, $line); print @newarray; }
To prevent overwriting you should declare the new array outside the loop:
my @array = (1,2,3,4,5); my @newarray; foreach my $line (@array) { push (@newarray, $line); } print @newarray;
Of course, you could be doing something entirely different - so difficult to know without seeing the code...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://751457]
help
Chatterbox?
[Corion]: Hurr. Yesterday I played around with ffmpeg as a new toy and found its "scene" filter great - it detects scene changes. Now I could write a module that splits a given video on its cuts into different scenes. Except I have no use case for that :)
[Corion]: (and also, writing yet another FFmpeg module just to wrap system() and grep through its output isn't all that great ...)
[erix]: cut out advertisements from movies? :)
[erix]: robably not possible (or it would have been done already)
[Corion]: erix: Oooh - yeah, that would be a good application of this, true (except that I don't consume movies-with- separate- advertisements that much nowadays :) )

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2018-05-24 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?