equivalence of variables question

Discussion in 'Perl Misc' started by nun, Mar 8, 2007.

  1. nun

    nun Guest

    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
     
    nun, Mar 8, 2007
    #1
    1. Advertising

  2. nun

    Mirco Wahab Guest

    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.
     
    Mirco Wahab, Mar 8, 2007
    #2
    1. Advertising

  3. nun

    nun Guest

    Thanks! That of course did the trick.

    DB
     
    nun, Mar 8, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ALuPin

    Re: Equivalence checking

    ALuPin, Apr 5, 2004, in forum: VHDL
    Replies:
    1
    Views:
    874
    Thomas Stanka
    Apr 6, 2004
  2. Forgafun

    Equivalence checkers for clocks

    Forgafun, Oct 1, 2005, in forum: VHDL
    Replies:
    1
    Views:
    479
    Ralf Hildebrandt
    Oct 1, 2005
  3. Rick Jackson

    Equivalence checking

    Rick Jackson, Nov 23, 2005, in forum: VHDL
    Replies:
    5
    Views:
    1,271
  4. MS News \(MS ILM\)
    Replies:
    0
    Views:
    376
    MS News \(MS ILM\)
    Aug 28, 2003
  5. =?Utf-8?B?S2VubmV0aCBQ?=

    MySql's equivalence to MsSql's 'TOP' command/function/clause

    =?Utf-8?B?S2VubmV0aCBQ?=, Jan 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,788
    John Timney \(ASP.NET MVP\)
    Jan 8, 2005
Loading...

Share This Page