From: bobmct on
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

From: Scott Bryce on
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.
From: Scott Bryce on
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) {



From: bobmct on
On Sat, 14 Nov 2009 19:24:46 -0700, Scott Bryce
<sbryce(a)scottbryce.com> 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
From: Peter J. Holzer on
On 2009-11-15 02:26, Scott Bryce <sbryce(a)scottbryce.com> 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