
shawnhcorey
Enthusiast

Oct 8, 2008, 5:08 AM
Post #2 of 3
(1015 views)
|
Re: [spyke212] Appending columns to a file in Perl
[In reply to]
|
Can't Post
|
|
Hi, I am trying to append some columns of data to a file, however everytime I append a new column of data (written from an array) it just adds it to the bottom of the last column insted of beside it. Does anybody know how to write data to a file in a column by column basis? Thanks in advance S You have to add the column to the end of each line. That means you have to rewrite the entire file. Something like this:
#!/usr/bin/perl -i use strict; use warnings; my @new_column = (); # load the column array while( <> ){ chomp; sprintf "%-80s %s\n", $_, shift @new_column; } __END__ I love Perl; it's the only language where you can bless your thingy. Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib. Get Markup Help. Please note the markup tag of "code".
|