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

Re: [MacPerl] Q&A Unix Perl 5.003 answer



mark@cheers.jsc.nasa.gov (Mark Manning/Muniz) writes:
}sub myFunc
}{
}    my $value = @_;
}
}    return( $value+1 );
}}
}
}I thought that the "my" command was the same as the "local"

No, but that's not what's screwing you up here.  If you had written:

my ($value) = @_;

or

my $value = $_[0];

it would have worked.  In a *scalar* context, the kind you're giving with
"my $value =", @_ is the number of items in the @_ array, 1.

The differences between my and local are explained in the Camel (or try
"man perlfunc" on your Unix machine), but the easy rule of thumb is to just
use my unless you know you can't.  You can't for filehandles, you can't for
the predefined globals like $/ and friends.


}command.  Obviously not.  The "my" version just returns the
}number "2" for everything.  Anyone want to comment on why
}this is so?  Thanks!  :-)
}
}
}***** Want to unsubscribe from this list?
}***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@pjstoaster.pg.md.us



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch