s/\s+$//;

I don't know how familiar you are with regexs so don't get offended if I overexplain. :)

s/// is the substitute operator. It will take the pattern on the left hand side and replace the first match with what's on the right. There is a lot more that can be done with this with optional flags, etc.

the \s is a character class that represents any whitespace character. (Not everyone agrees on what is whitespace!)

the + tells it to match one or more of the previous characters.

And the $ says that it should be anchored at the end of the string (the line in $_ in this case).

Because there is nothing on the right hand side of the substitute, the space at the end of the string that matches this gets replaced with nothing.

Basically this says "match one or more whitespace characters at the end of the string and replace it with nothing."

As far as info on programming in Perl, the O'Reilly books are a must have, several of which are written by merlyn himself, if you are going to buy them, help him out by getting them here.

If money is tight, go for the Perl CD Bookshelf which has a CD-ROM version of most of the ones you want. IMHO, they are a must have for any Perl programmer and are indispensable.

Don't forgot www.perl.com, under documentation there are several tutorials of interest.

And of course, don't forget to power search the Monastary!

Good luck.

In reply to Re: Re: Re: Re: Re: mkdir mode troubles by shotgunefx
in thread mkdir mode troubles by newatperl

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.