Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^5: Concatenating arrays fetched from different text files

by Laurent_R (Canon)
on May 29, 2014 at 20:17 UTC ( #1087865=note: print w/replies, xml ) Need Help??

in reply to Re^4: Concatenating arrays fetched from different text files
in thread Concatenating arrays fetched from different text files

Well, if I understand you correctly, you really need the 4th element of each array, which means that you only really need the 4th line of each file. If this is correct, then don't go into the trouble of storing all your files into arrays, but simply store into a single array the 4th line of each file (and you can stop reading the file as soon as you've reached the 4th line). Your code will be far simpler, will execute faster and use much less memory.

Assuming the files are passed as arguments to the script, you could have something as simple as this (untested):

my @array; # I would use a better name if I knew the array's contents for my $file (@ARGV) { open my $FH, "<", $file or die "cannot open $file $!" while (<$FH>) { chomp and push @array, $_ and last if $. == 4; } } print "@array\n";
Or did I misunderstand what you are after?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1087865]
[Discipulus]: yes I saw and i go to the tranlsator, but i supposed to be a pun, a normal sink in a normal roof.. congrats to our sister if so!
[Discipulus]: Insula Mona? they have the same flag of Sicily.. curious
[1nickt]: The Romans were everywhere!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-11-21 12:04 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (299 votes). Check out past polls.