R
rajasekaran.natarajan
Hi all,
I am trying to write a program which extracts the data feom a text file
and stores it in a data structure. But there is some mistake and I
couldnt able to get over with.
I am a newbie (my 25th program or so) in Perl and I have checked the
oreilly books and perldoc but I have some limitations to understand to
be frank. (i mean unable to get the thing correct after reading)
below I had given my script and if anybody can thorw some light I will
be greatfull. Thanks in advance.
#!/usr/sbin/perl -w
#extracts grid data from test.dat and stores in dataStructure
$file1 = "test.dat";
open(CLIST,"$file1") || die ("Cant open input file \"$file1\", Unable
to Find, Check the file name and path");
while($line= <CLIST>){
if ($line =~ m/^GRID/) {
($gridNo,$cp,$xcor,$ycor,$coor,$cd)= unpack("x8 A8 A8 A8 A8
A8",$line);
$record = {
GRIDNO => $gridNo,
cp => $cp,
xcor => $xcor,
ycor => $ycoor,
zcor => $zcoor,
cd => $cd,
};
$grid{ $record->{GRIDNO} } = $record;
}
while( $gridNo = each %grid) {
printf "%s is grid no\n",$grid->{$gridNo};
}
}
close(CLIST);
I am trying to write a program which extracts the data feom a text file
and stores it in a data structure. But there is some mistake and I
couldnt able to get over with.
I am a newbie (my 25th program or so) in Perl and I have checked the
oreilly books and perldoc but I have some limitations to understand to
be frank. (i mean unable to get the thing correct after reading)
below I had given my script and if anybody can thorw some light I will
be greatfull. Thanks in advance.
#!/usr/sbin/perl -w
#extracts grid data from test.dat and stores in dataStructure
$file1 = "test.dat";
open(CLIST,"$file1") || die ("Cant open input file \"$file1\", Unable
to Find, Check the file name and path");
while($line= <CLIST>){
if ($line =~ m/^GRID/) {
($gridNo,$cp,$xcor,$ycor,$coor,$cd)= unpack("x8 A8 A8 A8 A8
A8",$line);
$record = {
GRIDNO => $gridNo,
cp => $cp,
xcor => $xcor,
ycor => $ycoor,
zcor => $zcoor,
cd => $cd,
};
$grid{ $record->{GRIDNO} } = $record;
}
while( $gridNo = each %grid) {
printf "%s is grid no\n",$grid->{$gridNo};
}
}
close(CLIST);