H
Harish
Hi,
I am having a problem while indexing an element in perl.
Problem Details:
I have a data file which looks like the below
0.5 2 0.01 0 92 44 19818
0.5 2 0.015 0 62 42 19869
0.5 2 0.02 0 49 37 19902
0.5 2 0.025 0 40 30 19920
0.5 2 0.03 0 32 27 19935
0.5 2 0.035 0 28 31 19942
0.5 2 0.04 0 23 24 19952
I need to selectively take few lines from this file store it into
another file.
I'm doing this by storing the file into an array. Then i would
generate the index where the line that i'm interested in is located
and then access the line and store in another file.My program seems to
be working fine for everything except for few lines.
if i have $x=4 then when i say $temp[$x] it prints the previous line
but when i say $temp[4] it prints the line that i'm interested in.
This does not happen for all the lines.It is just happening for few
lines.
Could u let me know where I'm going wrong here.
Thanks
Harish
P.S.
I'm attaching the code below. Here $x is used to generate the index
number.There is nothing wrong in the logic of genrating $x.
if (!open(INFILE,"<f1.dat"))
{
die("cannot open file data.dat\n");
}
@temp = <INFILE>;
close(INFILE);
if (!open(OUTFILE,">testdata1.dat"))
{
die("cannot open file validation$a.dat\n");
}
@aspect = (0.5);
@delay=(0.01,0.02,0.03);
@msizes = (2);
foreach $line1 (@aspect)
{
$p =($line1-0.5)*20;
foreach $line2 (@msizes)
{
$q = ($line2-2);
foreach $line3 (@delay)
{
$r = (($line3-0.01)*200);
$x = $p*836+$q*19+$r;
print OUTFILE "$temp[$x]\n";
}
}
}
I am having a problem while indexing an element in perl.
Problem Details:
I have a data file which looks like the below
0.5 2 0.01 0 92 44 19818
0.5 2 0.015 0 62 42 19869
0.5 2 0.02 0 49 37 19902
0.5 2 0.025 0 40 30 19920
0.5 2 0.03 0 32 27 19935
0.5 2 0.035 0 28 31 19942
0.5 2 0.04 0 23 24 19952
I need to selectively take few lines from this file store it into
another file.
I'm doing this by storing the file into an array. Then i would
generate the index where the line that i'm interested in is located
and then access the line and store in another file.My program seems to
be working fine for everything except for few lines.
if i have $x=4 then when i say $temp[$x] it prints the previous line
but when i say $temp[4] it prints the line that i'm interested in.
This does not happen for all the lines.It is just happening for few
lines.
Could u let me know where I'm going wrong here.
Thanks
Harish
P.S.
I'm attaching the code below. Here $x is used to generate the index
number.There is nothing wrong in the logic of genrating $x.
if (!open(INFILE,"<f1.dat"))
{
die("cannot open file data.dat\n");
}
@temp = <INFILE>;
close(INFILE);
if (!open(OUTFILE,">testdata1.dat"))
{
die("cannot open file validation$a.dat\n");
}
@aspect = (0.5);
@delay=(0.01,0.02,0.03);
@msizes = (2);
foreach $line1 (@aspect)
{
$p =($line1-0.5)*20;
foreach $line2 (@msizes)
{
$q = ($line2-2);
foreach $line3 (@delay)
{
$r = (($line3-0.01)*200);
$x = $p*836+$q*19+$r;
print OUTFILE "$temp[$x]\n";
}
}
}