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