Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Making/Using a module.

by Andrew_Levenson (Hermit)
on Mar 09, 2006 at 01:40 UTC ( [id://535303]=note: print w/replies, xml ) Need Help??


in reply to Re: Making/Using a module.
in thread Making/Using a module.

Thanks for the additional info, and I hate to be a bother, but could you possibly explain some of the script you changed in the module? I think it may be a little ahead of where I am.

Replies are listed 'Best First'.
Re^3: Making/Using a module.
by davidrw (Prior) on Mar 09, 2006 at 02:41 UTC
    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.
      Alright, final question and i'll be done with this bit for now. In the search and replace bit, what is the $1?
        $file =~ s/^"(.+)"$/$1/; # unquote

        The parens in the regex capture text into numbered variables. The first set of parens grab into $1, the second into $2 and so forth. For more info check out perlre.

        It may be a bit off topic, but I'd really like to recommend that you pick up a copy of Learning Perl from a bookstore or your local library. It is the best introductory perl material I have seen. You'll be glad you did.


        TGI says moo

      Thank you, it works like a charm now.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-20 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found