in reply to Don't write to a file if there's no data
Just make opening the file conditional on the array holding at least one value:
Also note the addition of or die $! to your open() call -- always a good idea to check whether it succeeded.if ( scalar @matches ) { make_path($parsed_dir); open my $out_fh, '>', "$parsed_dir/${basename}.$wanted.$rnumber.txt" or die $!; print $out_fh $_ for @matches; print $out_fh "\n"; close $out_fh; }
Hope this helps!
|
|---|