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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |