in reply to Help with parsing through a comma delimted file
#!/usr/local/bin/perl -w use strict; my @sorted=sort_file('data.txt'); my $cnt=0; my $size=@sorted; while ($cnt < $size) { print "$sorted[$cnt][0] is of type $sorted[$cnt][1] - $sorted[$cnt][ +2]\n"; $cnt++; } exit(); sub sort_file{ my $filename = shift; open DATA,$filename|| die "Unable to open file $filename :$!\n"; my @record; my $row =0; while (<DATA>) { chomp; #create Array one element per field my @line=split /,/; # move values into multi-dimensional array $record[$row][0]=$line[0]; $record[$row][1]=$line[1]; $record[$row][2]=$line[2]; $row++; } return (sort { $a->[0] <=> $b->[0] } @record); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 2: Help with parsing through a comma delimted file
by tilly (Archbishop) on Mar 15, 2001 at 16:46 UTC | |
|
Re: Re: Help with parsing through a comma delimted file
by jlawrenc (Scribe) on Mar 14, 2001 at 20:29 UTC | |
by tilly (Archbishop) on Mar 15, 2001 at 16:24 UTC |