[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] minor debugging



At 21.26 -0800 1999.11.11, Nicholas G. Thornton wrote:
>perhaps I misunderstand what $_ and $_[0] are then.

Yes.  $_ is the default variable set by for() and some other things.  $_[0]
is the first element of the array which contains all the elements passed to
a subroutine.

Read perlsyn, perlsub, and perlvar for more complete information.


>while(1) {
>     print "\n--";
>     $input = <STDIN>;
>     chomp($input);
>     &test_input($input);
>}
>
>sub test_input {
>     if ($_ =~ /die/) {
>...
>
>Is the above code right for $_ having the same value as $input? I think I

No.  It should be $_[0].


>misassumed the special variable to be @_ thus calling the first value in the
>array. I take it (now) $_[0] would be no differant than $bill[0] or any other
>such?

Yes.  @_ and $_ follow the same rule as any other variable: $bill and @bill
are unrelated, so @_ and $_ are unrelated.  Now, they have similar purpose
and usage: both are default variables, but they have no direct relation to
each other.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org