Hello Perl Gurus!
I'm quite a perl neophyte so I'm looking for help understanding why print doesn't print correctly. This may be a totally stupid error....
He is my program. What it is doing is parsing a file of comma seperated values and trying to extract the address field every time the clock field transitions from a zero to a one.
[code=perl]
#! /usr/bin/perl
open(LISTING, "$ARGV[0]");
$line_count = 0;
$value_count = 0;
# skip first line of file
$line_read = <LISTING>;
$search_val = 1;
$array_index = 0;
# while not at end of file
while ($line_read = <LISTING>) {
$line_count++;
chop ($line_read);
# get values from line
($time, $status, $phase, $addr, $bft, $clk) = split(",", $line_read);
print "clock: ", $clk, " search value: ", $search_val, "\n";
#look for current search_val of clk
if ($clk == $search_val) {
# on the rising edge of the clock, capture the addr value
if ($clk == 1) {
#print "line count: " $line_count "\n" ;
$lst[$array_index++] = $addr;
$value_count++;
#toggle the clock value we are searching for
if ($search_val eq 1) {
$search_val = 0;}
else {
$search_val = 1;}
}
else {
#toggle the clock value we are searching for
if ($search_val eq 1) {
$search_val = 0;}
else {
$search_val = 1;}
}
}
else {
print "In Else, search value: ", $search_val, " clock value: ", $clk, "\n";
}
}
print "line_count : ", $line_count, " value_count: ", $value_count, "\n" ;
foreach $val (@lst) {
print $val, ",";
}
print "\n";
[/code]
Here is the data file I am using:
Time,STAT,CMD,A DDR,TRIG,CLK
1.1 ns,0,0,0,1,0
1.667 ns,0,0,0,1,1
1.667 ns,0,0,4,1,0
1.667 ns,0,0,104,1,0
88.333 ns,0,0,104,1,1
1.667 ns,0,0,104,1,1
48.333 ns,0,0,104,1,0
1.667 ns,0,0,26,1,0
85.000 ns,0,0,26,1,1
1.667 ns,0,0,26,1,1
And here is the console output:
% perl extract.pl tst.csv
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
In Else, search value: 0 clock value: 1
search value: 0
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
In Else, search value: 0 clock value: 1
line_count: 10 value_count: 3
0,104,26,
What is wrong with this print statement in that "clock: " is never printed?
print "clock: ", $clk, " search value: ", $search_val, "\n";
I'm quite a perl neophyte so I'm looking for help understanding why print doesn't print correctly. This may be a totally stupid error....
He is my program. What it is doing is parsing a file of comma seperated values and trying to extract the address field every time the clock field transitions from a zero to a one.
[code=perl]
#! /usr/bin/perl
open(LISTING, "$ARGV[0]");
$line_count = 0;
$value_count = 0;
# skip first line of file
$line_read = <LISTING>;
$search_val = 1;
$array_index = 0;
# while not at end of file
while ($line_read = <LISTING>) {
$line_count++;
chop ($line_read);
# get values from line
($time, $status, $phase, $addr, $bft, $clk) = split(",", $line_read);
print "clock: ", $clk, " search value: ", $search_val, "\n";
#look for current search_val of clk
if ($clk == $search_val) {
# on the rising edge of the clock, capture the addr value
if ($clk == 1) {
#print "line count: " $line_count "\n" ;
$lst[$array_index++] = $addr;
$value_count++;
#toggle the clock value we are searching for
if ($search_val eq 1) {
$search_val = 0;}
else {
$search_val = 1;}
}
else {
#toggle the clock value we are searching for
if ($search_val eq 1) {
$search_val = 0;}
else {
$search_val = 1;}
}
}
else {
print "In Else, search value: ", $search_val, " clock value: ", $clk, "\n";
}
}
print "line_count : ", $line_count, " value_count: ", $value_count, "\n" ;
foreach $val (@lst) {
print $val, ",";
}
print "\n";
[/code]
Here is the data file I am using:
Time,STAT,CMD,A DDR,TRIG,CLK
1.1 ns,0,0,0,1,0
1.667 ns,0,0,0,1,1
1.667 ns,0,0,4,1,0
1.667 ns,0,0,104,1,0
88.333 ns,0,0,104,1,1
1.667 ns,0,0,104,1,1
48.333 ns,0,0,104,1,0
1.667 ns,0,0,26,1,0
85.000 ns,0,0,26,1,1
1.667 ns,0,0,26,1,1
And here is the console output:
% perl extract.pl tst.csv
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
In Else, search value: 0 clock value: 1
search value: 0
search value: 1
In Else, search value: 1 clock value: 0
search value: 1
search value: 0
In Else, search value: 0 clock value: 1
line_count: 10 value_count: 3
0,104,26,
What is wrong with this print statement in that "clock: " is never printed?
print "clock: ", $clk, " search value: ", $search_val, "\n";
Comment