A few thoughts:

I'm pretty sure that chdir("-") will only work under certain UNIX shells. Actually, in limited testing, it doesn't seem to work for me even when the Perl script is run from a shell (tcsh) that does support that.

UPDATE: In retrospect, as merlyn has pointed out, this would in fact never work. My pre-post testing actually bore that out. No more late (for me) night posting...

You can omit the quotes around lone variable names. That is, "$file" and $file are the same in all of your cases.

As an aside, if you use the Cwd module and its getcwd() function, your code will be portable to non-UNIX systems (that probably don't have a pwd command to shell out to). You don't really need to use either method, though. Since you are presumably in the directory you want to open, you can use: opendir(DIR,'.').

I say presumably because the code really should be checking to see if the chdir() you did succeeded, or you could end up with unexpected results. Likewise, you might consider using the -e test to see if a file named $file already exists before you rename(), so you don't overwrite something accidentally.

- Matt Riffle


In reply to Re: convert whitespaces to underscores by mattriff
in thread convert whitespaces to underscores by painehope

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.