Re: while loops and the bedlam of the hash key

2008-09-06 Thread frazzmata
On Sep 5, 5:32 am, [EMAIL PROTECTED] (Hridyesh Pant) wrote: > in my case this works > while (<>) { >       chomp; >       my ($id, $record) = split(/\t+/,$_); >       push @{$table{$id}}, $record; >     } > >     foreach $id (sort keys %table) { >       print "$id "; >       my @records = @{$table{

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Fri, 2008-09-05 at 15:27 +0200, Dr.Ruud wrote: > Why use $1 if you can get the match by putting the regex in a list > context? > > while ( <$in> ) { > if( my ($id) = m/^\s*(\d+)/ ) { > $longz{$id} = $_; > } > else { > die "no ID in line $.: $_"; > }

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > while( ){ > if( /^\s*(\d+)/ ){ > my $id = $1; > $longz{$id} = $_; > }else{ > die "no ID in line $.: $_"; > } > } Why use $1 if you can get the match by putting the regex in a list context? while ( <$in> ) { if( my ($id) = m/^\s*(\d+)/ )

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Fri, 2008-09-05 at 20:35 +0800, Jeff Pang wrote: > 2008/9/5 Mr. Shawn H. Corey <[EMAIL PROTECTED]>: > > > if( /^\s*(\d+)/ ){ > >my $id = $1; > >$longz{$id} = $_; > > I prefer the shorter one: > > $longz{$1} = $_; I prefer defencive programming techniques. After every match, assign

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Jeff Pang
2008/9/5 Mr. Shawn H. Corey <[EMAIL PROTECTED]>: > if( /^\s*(\d+)/ ){ >my $id = $1; >$longz{$id} = $_; I prefer the shorter one: $longz{$1} = $_; -- Regards, Jeff. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Hridyesh Pant
in my case this works while (<>) { chomp; my ($id, $record) = split(/\t+/,$_); push @{$table{$id}}, $record; } foreach $id (sort keys %table) { print "$id "; my @records = @{$table{$id}}; print join ', ', sort @records; print "\n"; } --Hridyesh fraz

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Thu, 2008-09-04 at 14:03 -0700, frazzmata wrote: > I have a problem > I am trying to take lines in a text file that look like this. although > there are 500 more or so (and they have more realistic names) > > 25727 dude, some M MEX.AMER. DORM1 > 25797 dude, other M BLACK DORM2 >

Re: while loops and the bedlam of the hash key

2008-09-05 Thread John W. Krahn
frazzmata wrote: I have a problem I am trying to take lines in a text file that look like this. although there are 500 more or so (and they have more realistic names) 25727 dude, some M MEX.AMER. DORM1 25797 dude, other M BLACK DORM2 29291 guy, randomM BLACK DORM3 3024

while loops and the bedlam of the hash key

2008-09-05 Thread frazzmata
I have a problem I am trying to take lines in a text file that look like this. although there are 500 more or so (and they have more realistic names) 25727 dude, some M MEX.AMER. DORM1 25797 dude, other M BLACK DORM2 29291 guy, randomM BLACK DORM3 30249 fella, helluva