Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: How to add column into array from delimited tab file

by NetWallah (Canon)
on Feb 17, 2014 at 04:05 UTC ( [id://1075120]=note: print w/replies, xml ) Need Help??


in reply to How to add column into array from delimited tab file

You have the right idea, in collecting data into your (hopefully declared earlier) arrays : @data1, @data2 etc.

The problem area is when you open and write to the output file WITHIN the read loop for each row.

You need to move the output file open and Write OUTSIDE the file read loop, something like this:

# Outside the read loop, after closing input file.... mkdir "$pathname" or die "Error couldn't create new Directory"; open my $OUT1, ">", "$pathname/column.txt" or die "error couldn't open + output file"; print $OUT1 "$_\n" for @data1; close $OUT1;
(Made some adjustments to localize the file handle, and use the "3 argument" open - see other writeups to understand why this is a good idea.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1075120]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-20 00:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found