Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re: Getting a Regex Not to Match Again by mdillon
in thread Getting a Regex Not to Match Again by dru145

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found