Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > equivalence of variables question

Reply
Thread Tools

equivalence of variables question

 
 
nun
Guest
Posts: n/a
 
      03-08-2007
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
 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      03-08-2007
nun wrote:
> ...
> 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.
 
Reply With Quote
 
 
 
 
nun
Guest
Posts: n/a
 
      03-08-2007
Thanks! That of course did the trick.

DB
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalence checking Rick Jackson VHDL 5 11-24-2005 08:38 AM
Equivalence checkers for clocks Forgafun VHDL 1 10-01-2005 03:58 PM
MySql's equivalence to MsSql's 'TOP' command/function/clause =?Utf-8?B?S2VubmV0aCBQ?= ASP .Net 1 01-08-2005 09:28 PM
Re: Equivalence checking ALuPin VHDL 1 04-06-2004 06:56 AM
What is the equivalence of ActiveX, COM, COM+ and DCOM in .NET MS News \(MS ILM\) ASP .Net 0 08-28-2003 09:30 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57