Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl file rename

by kcott (Archbishop)
on Jun 03, 2015 at 21:20 UTC ( [id://1129002]=note: print w/replies, xml ) Need Help??


in reply to Perl file rename

G'day keltan,

"Yes this is my homework but i dont need direct answers i appreciate tips."

Thanks for being upfront and honest about that (++). Here's some tips:

  • Consider using the builtin module Getopt::Long for handling your command line arguments.
  • Consider using the warnings pragma instead of the '-w' switch. The documentation explains why.
  • The rename documentation points out some caveats:
    • The portability issues (rename in perlport) mentions "Win32"'D:\test' (in your code) indicates this may be relevant to you.
    • Consider the suggested, platform-independent move() function of the builtin module File::Copy.
  • Avoid package variables for directory handles (DIR in your posted code is an example): these have global scope and suffer from the same problems as all global variables. Prefer lexical variables whose scope you can control — readdir shows a couple of usage examples.
    • Unrelated to your current question but, for future reference, and for the same reasons, avoid package variables for filehandles — open has examples using lexical filehandles.

-- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1129002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-03-29 13:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found