Can I also ask one more thing that I will need later? I was just trying to sketch on a paper how it would go but didn't manage to do it. If I have two files in my directory, the same way I described, that have only numbers in their filenames, for example 8 and 9, this line

my @emptyfiles = grep { /^\d+$/ } grep { -f } glob '*';

would match both of them. How could I match them separately? As in, put the "biggest number" in a variable and the "biggest number minus 1" in another variable?

I tried this:
my $emptyfile; #structure file, new. my $previous; #structure file, alternative conformation. my @emptyfiles = grep { /^\d+$/ } grep { -f } glob '*'; $previous = ($emptyfile)-1); #set that $previous is the previous alter +native conformation. #print "previous is $previous \n"; #push (@emptyfiles, $emptyfile); #push (@emptyfiles, $previous); foreach (@emptyfiles) { if (-z "$emptyfile") { print "found previous conformation: $previous \n"; print "found new conformation: $emptyfile \n"; } # if -z loop. } #foreach loop.

But this obviously doesn't work. It keeps saying that $previous is -1, although in my example I have used files by the number of 8 and 9. So it should say yes, I found 9 and then I found 8.

When I use the push command again it doesn't work, so I obviously don't know how to use it and have to do some homework.

I found this http://stackoverflow.com/questions/10701210/how-to-find-maximum-and-minimum-value-in-an-array-of-integers-in-perl that mentions function "List::Util", does that sound correct for my purpose?"

Also sorry for the extensive commenting on my script, I need it so that I won't get lost.


In reply to Re: create array of empty files and then match filenames by angela2
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.