Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
XP is just a number
 
PerlMonks  

Re: Re: Re: Learning Exercise

by jarich (Curate)
on Jul 19, 2002 at 01:06 UTC ( #183099=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Learning Exercise
in thread Learning Exercise

  • 1a. /l/ says if there is an 'l' in $_ return true. This means that if you type ' l ' ('l' with some spaces) it'll still match. It will also match on 'list', 'look' and 'isn't that a nice whale over there?'. Personally I'd have done:
    s/\s//; # remove all whitespace from $_ if($_ eq "l") { entry_list(); } elsif($_ eq "a") { addentry();} #etc
    $_ is equivalent to your $option.
  • 1b. &s can be left off subroutine calls if the call is unambiguously a subroutine call. In this case (calling the subroutine with a pair of parens) the parens make it unambiguous. Calling the subroutine without parens but with & means that the subroutine gets given the contents of @_ as it's argument list. This is discouraged because it often frightens people.

    So there are these ways to call a subroutine (ignoring object methods):

    subroutine; # doesn't pass strict. &subroutine; # passes @_ as argument list &subroutine(); # looks weird, passes arguments in () subroutine(); # generally preferred method
  • 2. || does mean "or" but they are not equivalent in associativity. Look at "perldoc perlop" for more information.
  • 3. | allows alternation in regular expressions (those things between the //s). So yes, it does allow you to specify more than one option in an or-like fashion.
  • 4. Looks like it probably clears the screen/terminal. Have you tried using it?
  • 5. Yep. I think debiandude had originally intended tmp to be an array. my $tmp; has essentially the same effect. Of you can use my $tmp = undef;.
Hope it helps

jarich


Comment on Re: Re: Re: Learning Exercise
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2013-05-24 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (512 votes), past polls