Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

A lot depends on what you want to "clean." For the specific case you mention (with all those naughty barewords... put on some quotes, or you'll catch a horrible illness), you might be able to employ the builtin character class \w ("word" characters) or its negation, \W (not "word" characters). The perldoc perlre can help a lot here. Since I can't tell exactly what you're trying to fix, I'll assume you want to get rid of any non-word characters at the end of the string, for which

$directory =~ s/\W+$//;
ought to suffice. The $ anchors the match to the end of the string, and "\W+" matches "one or more non-word characters". It then replaces any such pattern found with nothing.


I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche

In reply to Re: the end of a word by arturo
in thread the end of a word by Sara

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.