Tiago Hori wrote:
Hi Guys,

Hello,

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;

That should be:

#!/usr/bin/perl
use warnings;
use strict;


my $name;
my $lastname;
my@array;

You don't use $name and $lastname anywhere and @array should be declared inside the loop as it is only used there.


open(FILE, "<", "columns.txt");

You should verify that open worked correctly before trying to use a possibly invalid filehandle.

open FILE, '<', 'columns.txt' or die "Cannot open 'columns.txt' because: $!";


while (<FILE>)
{

     @array = split (/\t/, $_);

That should be:

       my @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.

No it is not. split() will never add anything that is not already there. split's job is to remove things.


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.

You probably want to use a regular expression to "find a specific value".



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to