Monks,

I have this little script that I'm using to disable unneeded services in Linux. It works fine the first time around, but when I run it again, say because I added a new service, it moves all of the other files like so:
.NO..NO.K74apmd
I thought my regex would not match on a .NO, so I'm not sure what's wrong. What should I do to make sure it won't match anything with a .NO in front of it? I haven't been coding much lately so please be kind if it's really obvious :-)
#!/usr/bin/perl -w use strict; # Script used to disable services that are not needed my @dirs = qw(rc0 rc1 rc2 rc3 rc4 rc5 rc6); my $expression = "autofs|apmd|isdn|lpd|netfs|nfs|nfslock|nscd|portmap |radvd|rstatd|rusersd|rwalld|rwhod|sendmail|ypbind|yppasswd|ypserv |ypxfrd"; my $result; my $i; for $i (@dirs){ opendir (DIR, "/etc/$i.d") or die "Can't open directory $_\n"; while (my $name = readdir(DIR)){ 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/; } closedir DIR; }
Thanks,
Dru
Another satisfied monk.

In reply to 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.