G'day angela2,

Welcome to the Monastery.

"Can anybody tell me what I'm doing wrong???"

There's many issues with the code you've posted:

To be honest, and I don't mean this in any sort of nasty way, I rather think you just threw code at the problem and hoped it would work instead of having any real idea of what was going on. Accordingly, I think you'd be well served by reading "perlintro -- a brief introduction and overview of Perl": it's not particularly long and should really help you to understand the code you're writing.

The next step is how to resolve these issues.

Take a look at the readdir function to "get a directory listing". You'll see in the first example it uses the -f file test (to check for plain files); like the -z you used in your code (to check for files of zero size). [For reference, here's all the unary file test operators.] That example also uses a regex: I addressed your regex above (i.e. /^\d+$/).

Making a small modification to that example, and putting it in a script:

#!/usr/bin/perl -l use strict; use warnings; use autodie; my $dir = '.'; opendir(my $dh, $dir); my @emptyfiles = grep { -f && /^\d+$/ && -z } readdir $dh; closedir $dh; print for @emptyfiles;

With these files available (and 12 being the only one with any content):

$ ls -l 1 12 123 -rw-r--r-- 1 ken staff 0 8 Jan 03:00 1 -rw-r--r-- 1 ken staff 7 8 Jan 03:00 12 -rw-r--r-- 1 ken staff 0 8 Jan 03:00 123

Running that script, gives this output:

1 123

— Ken


In reply to Re: create array of empty files and then match filenames by kcott
in thread create array of empty files and then match filenames by angela2

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.