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{
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 $.: $_";
> }
"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+)/ )
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
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/
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
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
>
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
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