At 10:42 PM -0230 4/8/12, Tiago Hori wrote:
Hi Guys,
I know there are modules for parsing tab delimited files, but I am
trying to develop a script as a learning exercise to learn the
better, so any help would be appreciated.
Let's say I have two columns and two rows:
Joe \t Doe
Jane \t Doe
So here is what I got:
#!usr/bin/perl
use strict;
my $name;
my $lastname;
my@array;
open(FILE, "<", "columns.txt");
while (<FILE>)
{
@array = split (/\t/, $_);
print "$array[0]\n";
print "$array[1]\n";
}
close(FILE);
So right now this prints Joe and Jane. It seems the split is putting
a column in the array. Is there any way that I could parse a row at
a time, with each element becoming a entry in the array? My goal is
to be able to go through each row at a time and find a specific
value.
If you want to save the data in an array for later processing, you
can use an array-of-arrays. Do something like this:
my@array;
while (<FILE>) {
push( @array, [ split (/\t/);
}
The first record will be saved as $array[0][0] = "Joe" and
$array[0][1] = "Doe", and so on.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/