Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-26 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found