Hi all! I am so happy to have come across this website, you might be able to tell me what I'm doing wrong. I haven't coded much, maybe written 5 tiny scripts, and I'm struggling a bit.

So I have some chemical structure files in a directory and I want to process them. What I try to achieve now is look for some empty files that their filename is a single number as in 4, 10 and so on. So I thought I would put them all in an array, called @emptyfiles, and each element of this array I would call $emptyfile. As you can see, I have commented out this attempt as I couldn't get it to work, but I had used push.

Anyway my second attempt is to set the array again (@emptyfiles) and then use foreach to loop through the elements of the array, and then say "match filenames that only have numbers as their name", if this match is true I move forward to an "if file is empty" check and then I ask for it to be printed. However it doesn't work. The best I have managed to do is get the script to return nothing, so it's not finding an empty "4" file I have in the directory. Can anybody tell me what I'm doing wrong???

#/bin/perl/ use strict; use warnings; my @emptyfiles; #my $emptyfile =~ m/(\d+)/; #push (@emptyfiles, $emptyfile); my $digit; my $emptyname; foreach (@emptyfiles) { /(\d+)/; $emptyname = $digit; if (-z "$emptyname") { print "found empty file $emptyname \n"; } }

In reply to 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.