Sorry guys, Another quick question:
I got this from perlmonks: #!/usr/bin/perl -w use strict; my @desired_cols = qw(colname1 colname3); #order matters here # reads first line to get actual column names my $header_line = (<DATA>); my @actual_cols = split(/\s+/,$header_line); # get column number of the actual column names my $pos =0; my %col2_num = map {$_ => $pos++}@actual_cols; # translate the desired col names into position numbers my @slice = map{$col2_num{$_}}@desired_cols; print join("\t",@desired_cols),"\n"; #header line while (<DATA>) { my @row = (split)[@slice]; print join("\t",@row),"\n"; #each data row } It is working great fro me and I understand almost all of it. The only thing I don't get is why you have to split the @slice array into the new @row array inside the while loop instead of using the @slice array. Doesn't using split on a array creates a list, which is then assigned to an array and in effect creates a copy of the original array? Thanks, Tiago On Mon, Apr 9, 2012 at 10:17 AM, Tiago Hori <tiago.h...@gmail.com> wrote: > Hi All, > > Thanks for all your inputs. > > Part of the problem I was having is that I was creating tab delimited > files in excel and I forgot the excel uses a different way to create > newlines, right? I remember having the same issue with MySQL. Now, i got it > working! > > Is there way around this issue? > > Thanks, > > Tiago > > > On Mon, Apr 9, 2012 at 6:22 AM, Dr.Ruud <rvtol+use...@isolution.nl> wrote: > >> On 2012-04-09 03:12, Tiago Hori wrote: >> >> Is there any way that I could parse a row at a time >>> >> >> while ( <$fh> ) { >> $_ eq 'foo' and print "$.:$_\n" >> for split /\t/; >> } >> >> -- >> Ruud >> >> >> -- >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> For additional commands, e-mail: beginners-h...@perl.org >> http://learn.perl.org/ >> >> >> > > > -- > "Education is not to be used to promote obscurantism." - Theodonius > Dobzhansky. > > "Gracias a la vida que me ha dado tanto > Me ha dado el sonido y el abecedario > Con él, las palabras que pienso y declaro > Madre, amigo, hermano > Y luz alumbrando la ruta del alma del que estoy amando > > Gracias a la vida que me ha dado tanto > Me ha dado la marcha de mis pies cansados > Con ellos anduve ciudades y charcos > Playas y desiertos, montañas y llanos > Y la casa tuya, tu calle y tu patio" > > Violeta Parra - Gracias a la Vida > > > Tiago S. F. Hori > PhD Candidate - Ocean Science Center-Memorial University of Newfoundland > -- "Education is not to be used to promote obscurantism." - Theodonius Dobzhansky. "Gracias a la vida que me ha dado tanto Me ha dado el sonido y el abecedario Con él, las palabras que pienso y declaro Madre, amigo, hermano Y luz alumbrando la ruta del alma del que estoy amando Gracias a la vida que me ha dado tanto Me ha dado la marcha de mis pies cansados Con ellos anduve ciudades y charcos Playas y desiertos, montañas y llanos Y la casa tuya, tu calle y tu patio" Violeta Parra - Gracias a la Vida Tiago S. F. Hori PhD Candidate - Ocean Science Center-Memorial University of Newfoundland