"be consistent" | |
PerlMonks |
Re: convert whitespaces to underscoresby mattriff (Chaplain) |
on May 26, 2002 at 03:09 UTC ( [id://169329]=note: 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.
In Section
Cool Uses for Perl
|
|