in reply to Re: create array of empty files and then match filenames
in thread create array of empty files and then match filenames

You probably want something like this

#!/usr/bin/perl use strict; my @emptyfiles = grep { /^\d+$/ } grep { -f } glob '*'; foreach my $emptyfile (@emptyfiles) { my $previous = $emptyfile - 1; if ((-z $emptyfile) and (-f $previous)) { print "found previous conformation: $previous \n"; print "found new conformation: $emptyfile \n"; } # if -z loop. } #foreach loop.

Have a look at scalars and arrays in Perl variable types.

poj

Replies are listed 'Best First'.
Re^3: create array of empty files and then match filenames
by angela2 (Sexton) on Jan 07, 2016 at 18:32 UTC
    I wish I had seen this earlier! I tried "and" but I got compilation errors (again one more mistake lol) so in the end I did this:
    use List::Util qw( min max ); my @numbers; @numbers = grep { /^\d+$/ } grep { -f } glob '*'; my $max = max@numbers; my $previous = ($max)-1; foreach (@numbers) { if (-z "$max") { if (-z "$previous") { print "previous conf: $previous \n"; print "Latest conf: $max \n"; printf "Ready for conf %d \n",++$max; } } }
    Now I need to think about "else" messages/actions. Sorry, I changed my array name halfway through the thread, I just used directly the "@numbers" example from List::Util that I found at stack overflow

      Do you need a foreach loop ?.
      You are checking the same value of $previous regardless of the loop variable $_

      poj