On Mon, Jan 3, 2011 at 8:24 AM, Sunita Rani Pradhan
wrote:
> How can I define default arguments in Perl subroutine? Can
> anybody explain with examples?
I would probably do something like:
#!/usr/bin/env perl
use strict;
use warnings;
sub foo
{
my $bar = shift || 'default bar';
>
>How can I define default arguments in Perl subroutine? Can
> anybody explain with examples?
>
Sure. But as per usual, there is more than one way to do it. This requires a
Perl 5.10 or newer, for say[0] and the defined-or[1] operator; say can be
replaced with a print and a trailing n
Hi Sunita,
On Monday 03 Jan 2011 15:24:54 Sunita Rani Pradhan wrote:
> Hi All
>
>
>
> How can I define default arguments in Perl subroutine? Can
> anybody explain with examples?
>
One option is to extract each arguments one by one and assign default values
to them using "||":
su
Hi Sunita,
On Mon, Jan 3, 2011 at 2:24 PM, Sunita Rani Pradhan
wrote:
>How can I define default arguments in Perl subroutine? Can
> anybody explain with examples?
Sure, the best thing to do is to use named arguments for a subroutine,
by means of using a hash. This is in general bette
On Monday 03 Jan 2011 17:51:08 Michiel Beijen wrote:
> Hi Sunita,
>
> On Mon, Jan 3, 2011 at 2:24 PM, Sunita Rani Pradhan
>
> wrote:
> >How can I define default arguments in Perl subroutine? Can
> >
> > anybody explain with examples?
>
> Sure, the best thing to do is to use named a
On Mon, Jan 3, 2011 at 5:04 PM, Shlomi Fish wrote:
> Your subroutine implementation and the example do not match. Either add {...}
> around the subroutine parameters to make it an anonymous hash reference, or
> (less preferably IMHO) convert $param_ref to my %params = @_ (and omit the
> ->).
:) t
Thank you all for you help . I have got my answer .
Regards
Sunita
-Original Message-
From: Michiel Beijen [mailto:michiel.bei...@gmail.com]
Sent: Monday, January 03, 2011 9:56 PM
To: Shlomi Fish
Cc: beginners@perl.org; Sunita Rani Pradhan
Subject: Re: default arguments in subroutine