equivalence of variables question

N

nun

I have the following hunk of perl:

###############################
# load image names into array
my $image_names_file="image_list.txt";
open(DAT, $image_names_file) || die("Could not open file!");
my @image_names=<DAT>;
close(DAT);

for my $this_image_name (@image_names) {
my $AA = $SKU;
my $BB = $this_image_name;

if($AA eq $BB){
print "YAY! AA,BB is $AA,$BB";
}
else {
print "BOO! AA,BB is $AA,$BB";
}

}
#################################################

The $SKU variable is defined elsewhere in the script. The script runs,
but the if($AA eq $BB) seems never to be true.... the relevant line out
output is puzzling to me:

BOO! AA,BB is EL-0001468271,EL-0001468271

They sure look equal to me. Can anyone tell me what I'm not
comprehending here ?

DB
 
M

Mirco Wahab

nun said:
...
for my $this_image_name (@image_names) {
my $AA = $SKU;
my $BB = $this_image_name;

if($AA eq $BB){
print "YAY! AA,BB is $AA,$BB";
}
else {
print "BOO! AA,BB is $AA,$BB";
}
...
BOO! AA,BB is EL-0001468271,EL-0001468271

They sure look equal to me. Can anyone tell me what I'm not
comprehending here ?

1) Try to reverse the output:
...
if($AA eq $BB){
print "YAY! BB,BB is $BB,$AA";
}
else {
print "BOO! BB,AA is $BB,$AA";
}
...


2) Find the "missing link"
(perldoc -f chomp)

3) retry the example with pattern matching,
eg.
if( $BB =~ /$AA/ ){
...


Regards

M.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top