Weird unequality compare questions?

B

bobmct

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
 
S

Scott Bryce

bobmct said:
# 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.
 
S

Scott Bryce

Scott said:
bobmct said:
# 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) {
 
B

bobmct

bobmct said:
# 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
 
P

Peter J. Holzer

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
 

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
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top