in reply to Re^2: Making/Using a module.
in thread Making/Using a module.
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.sub promptFilename { my $prompt = shift;
Use the given string to display a prompt to the user.print $prompt . "\n";
NOTE: reading through this, i realized an error and updated my code here and above.my $file; while(! $file){ $file = <>;
Strip the newline.chomp($file);
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).$file =~ s/^"(.+)"$/$1/; # unquote
Close the loop, return the $file value, and close the function.} return $file; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Making/Using a module.
by Andrew_Levenson (Hermit) on Mar 09, 2006 at 03:30 UTC | |
by TGI (Parson) on Mar 09, 2006 at 06:10 UTC | |
|
Re^4: Making/Using a module.
by Andrew_Levenson (Hermit) on Mar 09, 2006 at 03:13 UTC |