Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Using arguements and defaults

by vladdrak (Monk)
on Nov 24, 2003 at 06:13 UTC ( #309456=note: print w/replies, xml ) Need Help??


in reply to Using arguements and defaults

How about something like:
#!/usr/bin/perl use strict; # @ARGV is = to @_ by default my $path=shift or die "Usage: $0 <directory|file>\n"; # Is it a directory or a file? if (-d $path) { opendir(DIR,$path) or die "could not open $path: $!\n"; for my $file (readdir(DIR)) { if ($file =~ /\_/) { nounder($file); } } closedir(DIR); } else { nounder($path); } sub nounder { my $file=shift; my $newfile=$file; $newfile=~s/\_/ /g; rename($file,$newfile) or die "couldn't rename $file: $!\n"; print "renamed $file to $newfile\n"; }
-vladdrak

Replies are listed 'Best First'.
Re: Re: Using arguements and defaults
by holo (Monk) on Nov 24, 2003 at 06:30 UTC

    @ARGV is != to @_! It's just that shift works differently in the main file's scope.

    See perldoc -f shift and perldoc perlvar.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-02-07 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?