no prob -- here's the promptFilename() disected.. note this was a replacement for both func1() and func2() :
sub promptFilename {
my $prompt = shift;
First, declare the function name with 'sub' .. then store the first argument in
$prompt. Since in your original you always displayed a string to user before reading in the filename, I thought it made sense to pull it into the function.
print $prompt . "\n";
Use the given string to display a prompt to the user.
my $file;
while(! $file){
$file = <>;
NOTE: reading through this, i realized an error and updated my code here and above.
Declare a
$file to hold the result. Start a loop that goes until we have something in
$file. Each iteration will start by reading a line from STDIN.
chomp($file);
Strip the newline.
$file =~ s/^"(.+)"$/$1/; # unquote
This a regex substituion (see
perlre) -- tries to match a quote at the beginning, anything in the middle, and a quote at the end. If it matches, it replaces everything with the middle part (i.e. it strips the quotes). If it doesn't match, it does nothing (cause the string wasn't quoted).
}
return $file;
}
Close the loop, return the
$file value, and close the function.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.