Re: Using $_ in a function if no argument is passed
From: Smoot Carl-Mitchell (smoot_at_tic.com)
Date: 04/02/04
- Next message: Paul Johnson: "Re: Using $_ in a function if no argument is passed"
- Previous message: Beau E. Cox: "Re: Using $_ in a function if no argument is passed"
- In reply to: Jupiterhost.Net: "Using $_ in a function if no argument is passed"
- Next in thread: Smoot Carl-Mitchell: "Re: Using $_ in a function if no argument is passed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 2 Apr 2004 10:26:46 -0700 To: beginners@perl.org
On Fri, 02 Apr 2004 10:37:14 -0600
"JupiterHost.Net" <mlists@jupiterhost.net> wrote:
> It just occurred to me that many Perl functions use $_ if not other
> value is supplied. chomp for instance..., which is very handy...
>
> If one wanted to write a function that used either the given argument
> or $_ how would you do that?
$_ is global, so do something like:
sub test {
my $arg;
$arg = shift or $arg = $_;
}
-- Smoot Carl-Mitchell Systems/Network Architect email: smoot@tic.com cell: +1 602 421 9005 home: +1 480 922 7313
- Next message: Paul Johnson: "Re: Using $_ in a function if no argument is passed"
- Previous message: Beau E. Cox: "Re: Using $_ in a function if no argument is passed"
- In reply to: Jupiterhost.Net: "Using $_ in a function if no argument is passed"
- Next in thread: Smoot Carl-Mitchell: "Re: Using $_ in a function if no argument is passed"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]