Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Getting a Regex Not to Match Again

by mdillon (Priest)
on Oct 10, 2002 at 20:43 UTC ( #204318=note: print w/replies, xml ) Need Help??

in reply to Getting a Regex Not to Match Again

I don't think that this:
my $cmd1 = "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name" or print "/etc/$i.d/$name not found\n"; `$cmd1` if $name =~ /\b(K|S)\d{2}?$expression\b/;
Does what you are expecting... It looks like you think $cmd1 will be some sort of "command" that when used in the backticks will either move the file or print your message if it fails. To achieve this, you're better of using Perl's builtin rename command:
if ($name =~ /^[KS]\d{2}$expression$/) { rename "/etc/$i.d/$name", "/etc/$i.d/.NO.$name" or print "/etc/$i.d/$name not found\n"; }
Notice that I used the modified regex as suggested by sauoq.

In case you're wondering, the first line of your code that I quoted above does this:

  1. Interpolate the variables $i and $name into the string "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name"
  2. Assign the result of the interpolation to the variable $cmd1
  3. If the return value of the assignment is false, print "/etc/$i.d/$name not found\n"

The return value of an assignment expression is the value assigned (isn't that a mouthful). Since the interpolation you're doing will never have a false value (i.e. it will never interpolate into "" or 0), the return value of the assignment will always be true and the print statement will never be executed.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2022-12-08 23:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found