Weird unequality compare questions?

Discussion in 'Perl Misc' started by bobmct, Nov 15, 2009.

  1. bobmct

    bobmct Guest

    I know my eyesight is getting bad but I'm pounding my head with this
    rather simple unequal compare.

    I have a text file, the starting portion of which appears below. The
    fir field is a filename followed by a tab and the second field is a
    full path

    I simply wish to print the filename if/when it changes from the
    previous record processed.

    I've also printed some fields and logic results for debugging
    purposes. The output of the debugging also appears below and of
    course my code loop is there as well.

    Can some of you please look at my unequal compare statement to help me
    determine why it is NOT detecting a difference in MOST of the records?

    Thanks


    input file snippet
    -------------------

    - dsl line only service agreement 1.15.02.pdf C:\Documents and
    Settings\bobm3\My Documents\My Files\pdf\

    -Release Notes-.rtf C:\Documents and Settings\bobm3\My
    Documents\My PaperPort Documents\Samples\

    4622XL.cfg C:\Documents and Settings\bobm3\My
    Documents\Source\netopia\

    !finallo.bmp C:\Documents and Settings\bobm3\My Documents\My
    Files\fdcx1\usr\

    !finallo.bmp C:\Documents and Settings\bobm3\My Documents\My
    Files\fdcx1\usr\

    !finallo.jpe C:\Documents and Settings\bobm3\My Documents\My
    Files\fdcx1\usr\

    !finallo.jpe C:\Documents and Settings\bobm3\My Documents\My
    Files\fdcx1\usr\

    # 001 bronze training form.wpd C:\Documents and Settings\bobm3\My
    Documents\My Files\training contract unit lists\

    # 001 gold training form.wpd C:\Documents and Settings\bobm3\My
    Documents\My Files\training contract unit lists\

    code snippet
    ---------------

    # Process Sequence File Listing File
    while (<IFH>) {
    chomp;
    ($filename, $path) = split /\t/;
    print "filename=[$filename],priorfilename=[$priorfilename]\n";
    # Determine if filename should print
    if ("$filename" != "$priorfilename") {
    print "printing filename\n";
    $priorfilename = $filename;
    $~ = "OFH_Filename";
    write(OFH);
    } else {
    print "NOT printing\n";
    }
    # Now output path info
    $~ = "OFH_Detail";
    write(OFH);
    }

    debugging output snippet
    ------------------------------

    filename=[- dsl line only service agreement
    1.15.02.pdf],priorfilename=[]
    NOT printing
    filename=[-Release Notes-.rtf],priorfilename=[]
    NOT printing
    filename=[ 4622XL.cfg],priorfilename=[]
    printing filename
    filename=[!finallo.bmp],priorfilename=[ 4622XL.cfg]
    printing filename
    filename=[!finallo.bmp],priorfilename=[!finallo.bmp]
    NOT printing
    filename=[!finallo.jpe],priorfilename=[!finallo.bmp]
    NOT printing
    filename=[!finallo.jpe],priorfilename=[!finallo.bmp]
    NOT printing
    filename=[# 001 bronze training form.wpd],priorfilename=[!finallo.bmp]
    NOT printing
     
    bobmct, Nov 15, 2009
    #1
    1. Advertising

  2. bobmct

    Scott Bryce Guest

    bobmct wrote:
    > # Process Sequence File Listing File
    > while (<IFH>) {
    > chomp;
    > ($filename, $path) = split /\t/;
    > print "filename=[$filename],priorfilename=[$priorfilename]\n";
    > # Determine if filename should print
    > if ("$filename" != "$priorfilename") {


    if ("$filename" ne "$priorfilename") {


    != compares numbers. ne compares strings.
     
    Scott Bryce, Nov 15, 2009
    #2
    1. Advertising

  3. bobmct

    Scott Bryce Guest

    Scott Bryce wrote:
    > bobmct wrote:
    >> # Process Sequence File Listing File
    >> while (<IFH>) {
    >> chomp;
    >> ($filename, $path) = split /\t/;
    >> print "filename=[$filename],priorfilename=[$priorfilename]\n";
    >> # Determine if filename should print
    >> if ("$filename" != "$priorfilename") {

    >
    > if ("$filename" ne "$priorfilename") {


    Someone will probably point out that the strings don't need to be quoted.

    if ($filename ne $priorfilename) {
     
    Scott Bryce, Nov 15, 2009
    #3
  4. bobmct

    bobmct Guest

    On Sat, 14 Nov 2009 19:24:46 -0700, Scott Bryce
    <> wrote:

    >bobmct wrote:
    >> # Process Sequence File Listing File
    >> while (<IFH>) {
    >> chomp;
    >> ($filename, $path) = split /\t/;
    >> print "filename=[$filename],priorfilename=[$priorfilename]\n";
    >> # Determine if filename should print
    >> if ("$filename" != "$priorfilename") {

    >
    > if ("$filename" ne "$priorfilename") {
    >
    >
    >!= compares numbers. ne compares strings.



    Duh! I should have caught that. Thanks for your quick response.

    B
     
    bobmct, Nov 15, 2009
    #4
  5. On 2009-11-15 02:26, Scott Bryce <> wrote:
    > Scott Bryce wrote:
    >> bobmct wrote:
    >>> if ("$filename" != "$priorfilename") {

    >>
    >> if ("$filename" ne "$priorfilename") {

    >
    > Someone will probably point out that the strings don't need to be quoted.
    >
    > if ($filename ne $priorfilename) {


    And someone else will point out that

    use warnings;
    use strict;

    at the beginning of each script is always a good idea.

    hp
     
    Peter J. Holzer, Nov 15, 2009
    #5
    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. dorayme
    Replies:
    1
    Views:
    623
    richard
    Jan 21, 2011
  2. richard
    Replies:
    0
    Views:
    586
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    618
    richard
    Jan 21, 2011
  4. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    440
    Captain Paralytic
    Jan 21, 2011
  5. David Segall
    Replies:
    0
    Views:
    633
    David Segall
    Jan 22, 2011
Loading...

Share This Page