This is my first script. I created it to change any files that have the '_' character to a single space in a given directory. I'm using regex to select the files and a simple foreach statement to sift through the given files but how would i be able to pass arguments and have defaults for those not passed?
~ Nick
#!/usr/bin/perl -ws use strict; my $oggdir = '/media/tmp/'; chdir $oggdir or die "can't chdir to $oggdir: $!\n\n"; opendir(DIR, $oggdir) or die "can't open $oggdir for read: $!\n\n"; my @files = grep { /.*_+.*\.[Oo][Gg]{2}$/ } readdir(DIR); closedir(DIR) or warn "error closing $oggdir: $!\n\n"; foreach ( @files ) { my @chars = split(/_+/, $_); my $final=join(" ", @chars); print "Original: $_ \n"; print "New: $final \n"; rename $_, $final; print "Conversion Complete.\n"; }

In reply to 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.