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