Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Perl script to delete files using regex

by hippo (Chancellor)
on Nov 04, 2020 at 17:31 UTC ( #11123400=note: print w/replies, xml ) Need Help??


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.


🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11123400]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2021-01-27 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?