Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me understand the Loop and Condition logic here.

Status
Not open for further replies.
Apr 30, 2003
56
US
I have this written script below:

$driver_list="/dsk01/apps/toshiba/oracle/perl/print_driver_list.fle";
open (LIST, $driver_list)||die "Can't open driver list file!\n";
$count = 0;
while ($line = <LIST>) {
($a1,$a2) = split(/:/, $line);
#print "$a2"; #for debugging
$a3 = substr($a2, 0, 1);
#print "$a3\n"; #for debugging
if ($a3 eq "e")
{
opendir (DIR, "/dsk01/apps/baan1/bse/lib/printinf/e");
foreach $file (readdir(DIR)) {
next if $file =~ /^\./; # skip ., .., etc
#print "$file | $a2\n"; # for debugging
if ($file eq $a2) {
$obj1="/dsk01/apps/baan1/bse/lib/printinf/e/$file";
$obj2="/dsk01/apps/baan1/bse/lib/printinf/e_hold/$file";
#print "diff $obj1 $obj2 \n"; # for debugging
system ("diff $obj1 $obj2 >> /dsk01/apps/toshiba/oracle/perl/print_driver_file_comparison_result.rpt");
}
}
closedir (DIR);
}
$count++ }
close (LIST);

And for debugging purpose I print out $file and $a2 for comparison. It returned the following list:
epson_fx | epson_fx
epson_tic | epson_fx
test | epson_fx
epson_fx.nw | epson_fx
esc_p | epson_fx
epson_fx_rwb | epson_fx
epson_fx_SP9 | epson_fx

The thing I don't understand is that during one of the loop $file is equal to $a2 as shown by epson_fx | epson_fx; however, the statements in the if ($file eq $a2) block will not execute and when I change the eq to ne, it worked. Why is that?

 
There is possibly some whitespace that's causing the if statement to return false... Try adding something around your variables on the print statementto make sure there's no extra whitespace there.

- George
 
Hi George (Rieekan);

I tried to print those two variables separately as debugging.
When I issued print "$file\n";, I got the following list:
epson_fx
epson_tic
test
epson_fx.nw
esc_p
epson_fx_rwb
epson_fx_SP9

When I issued print "$a2\n";, I got the following list:
epson_fx

epson_fx

epson_fx

epson_fx

epson_fx

epson_fx

epson_fx

I assume there is extra whitespace like you said, but how would I able to do to get rid of those extra whitespace? Do you have any suggestions?
 
Add this in as the first line in your `while' loop:
Code:
chomp $line;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top