Anyone have any idea why the -f and -d operators are not working properly here:

Section 1: the code

Section 2: what is in the directory using ls -l

Section 3: what the code outputs.

Section 1: =========================================================

use strict; use gfrmGlobals; my @files = (); my $flNm = ""; opendir (DIR, $GCdfltDBexpPrmPthNm) || die "can't open directory\n"; @files = readdir(DIR); closedir (DIR); foreach $flNm (@files) { if ( -f $flNm) { print "is a file: $flNm\n"; } elsif ( -d $flNm) { print "is a dir: $flNm\n"; } else { print "neither file nor dir: $flNm\n"; } }

Section 2: From a terminal window =========================================================

gfrmDev$ cd DBexportFiles gfrmDev$ ls -l total 1536 -rw-r--r-- 1 andynic staff 66192 17 Feb 17:43 export_of_gfrm_20110217_ +174314.zip -rw-r--r-- 1 andynic staff 66192 17 Feb 17:51 export_of_gfrm_20110217_ +175005.zip -rw-r--r-- 1 andynic staff 66193 17 Feb 18:30 export_of_gfrm_20110217_ +183048.zip -rw-r--r-- 1 andynic staff 66193 17 Feb 22:08 export_of_gfrm_20110217_ +220832.zip -rw-r--r-- 1 andynic staff 505830 17 Feb 20:27 importLogOf_export_of_g +frm_20110217_183048.log drwxr-xr-x 7 andynic staff 238 18 Feb 12:52 xxxx

Section 3: The code output; ========================================================= (I would have expected 5 files (*.zip, and *.log) and 3 directories (., .., xxxx), but instead:

gfrmDev$ perl -w x.pl is a dir: . is a dir: .. is a file: .DS_Store neither file nor dir: export_of_gfrm_20110217_174314.zip neither file nor dir: export_of_gfrm_20110217_175005.zip neither file nor dir: export_of_gfrm_20110217_183048.zip neither file nor dir: export_of_gfrm_20110217_220832.zip neither file nor dir: importLogOf_export_of_gfrm_20110217_183048.log neither file nor dir: xxxx

Am I doing something weird that I don't see?

perl version 5.10

Mac OS X 10.6

Thanks,

Andynic


In reply to Perl file operators seem to behave strangely by andynic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.