TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TCLUG:15822] perl and text-delim database
Ben Luey wrote:
>
> I've got I think a simple perl question:
>
> I've got a mailing list in a text-delim format:
>
> name1<tab>address1<tab>stuff1
> name2<tab>address2<tab>stuff2
> ...
>
> How can I get that into an array or something in perl, so I can control
> each field?
>
> Right now I have
>
> open(list, "file"){
> @list = <list>
>
> but I don't know how to manipulate each field in a row
>
> ex:
>
> print (@list[1]);
>
> prints the 2nd line, but how I can print out the 2nd field of the second
> line?
>
> Any links to good web-sites with tutorials would be great.
>
> Thanks,
>
Use the split function to seperate a row by some delimiter:
($name1, $address1, $stuff1) = split /\t/, @list[1];
Another way is to read the file line-by-line:
open(list, "file") or die "Unable to open file $!\n";
while (<list>) {
($name1, $address1, $stuff1) = split /\t/, $_;
foreach $item (@linearray) {
dosomething;
}
}
Not the best way of doing it, but it's pretty easy to understand.
I would strongly recommend buying the camel book, as well as the Perl
Cookbook. I don't think I could live without the Perl Cookbook.
--
Clay Fandre
Twin Cities Linux Users Group
http://www.mn-linux.org