Do you mean pass command-line arguments? If so, checkout the module Getopt::Long. Otherwise, are you looking for something like below?
#!/usr/bin/perl -w use strict; use IO::Dir; my $oggdir = '/media/tmp/'; ParseDirectory($oggdir); sub ParseDirectory { my $dir = shift; my $d = IO::Dir->new($dir) or die "Can not open directory $dir for read!"; while (defined(my $f = $d->read)) { if ($f =~ /.*_+.*\.[Oo][Gg]{2}$/) { # matching files my $new_name = $f; $new_name =~ s/_//; # remove _ # rename $f to $new_name, etc. } else { # non-matching files # do whatever, set to default, etc. } } }
And an example of using Getopt::Long to parse command-line arguments:
#!/usr/local/bin/perl -w use strict; use Getopt::Long; # Parse command line arguments and assign corresponding variables GetOptions ( 'i|init=s' => \( my $INIT = undef ), # Specify the root director +y 'u|upload' => \( my $UPLOAD = undef ), 'v|verbose' => \( my $VERBOSE = 0 ), ); unless ( defined $INIT ) { print <<EOF Kapiti Exception Report Usage: $0 [options] Options: -i|--init [file] Specify the path to initialization file -u|--upload Upload the result into database -v|--verbose Let the report generator print more information EOF ; exit(1); } # continue on...

In reply to Re: Using arguements and defaults by Roger
in thread Using arguements and defaults by sock

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.