in reply to Perl script to delete files using regex
The lack of any filesystem interaction notwithstanding, your mistake is in comparing 2 regexen rather than matching a string. Here's an amended version of your script showing the match actually happening.
#!/usr/bin/env perl use strict; use warnings; use diagnostics; my $regex = qr/carlos\.txt/; my $file = 'juan_carlos.txt'; if (defined ($file) && ($file =~ $regex)) { print "File $file matched\n"; } else { print "File $file not matched\n"; }
I've named the variables appropriately. Note that there's nothing in this script to say that $file is anything to do with the filesystem (yet) - the variable just has a semantic name.
🦛
|
---|
In Section
Seekers of Perl Wisdom