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:
- Interpolate the variables $i and $name into the string "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name"
- Assign the result of the interpolation to the variable $cmd1
- 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.
-
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.
|