parse arguments passed to subroutines
Hello,
I usually use my ($arg1, $arg2) = [at] _;
to get the arguments parsed to a subroutine.
I want this to be smarter. Sometimes I want to pass $start, $end to
the sub, sometimes I want to pass $start, $count to the sub.
but in this case my ($arg1, $arg2) = [at] _; will get confused, it
doesn't know if the argument is meant to be $end or to be $count.
does subroutine have some mechanism like getopt::long and it can know
what kind of arguments are passed in?
Thank you in advance for pointers,
Jim
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: parse arguments passed to subroutines
Jim Green writes:
> Hello,
> I usually use my ($arg1, $arg2) = [at] _;
> to get the arguments parsed to a subroutine.
>
> I want this to be smarter. Sometimes I want to pass $start, $end to
> the sub, sometimes I want to pass $start, $count to the sub.
>
> but in this case my ($arg1, $arg2) = [at] _; will get confused, it
> doesn't know if the argument is meant to be $end or to be $count.
>
> does subroutine have some mechanism like getopt::long and it can know
> what kind of arguments are passed in?
>
Jim,
You could pass a hash reference instead.
%arg = (start=>'..',end=>'..',count=>'..');
the_func(\%arg);
Regards.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: parse arguments passed to subroutines
this will work, Thank you!
On 30 January 2011 22:00, <pyh [at] mail.nsbeta.info> wrote:
> Jim Green writes:
>>
>> Hello,
>> I usually use my ($arg1, $arg2) =3D [at] _;
>> to get the arguments parsed to a subroutine.
>> I want this to be smarter. Sometimes I want to pass $start, $end to
>> the sub, sometimes I want to pass $start, $count to the sub.
>> but in this case my ($arg1, $arg2) =3D [at] _; =A0will get confused, it
>> doesn't know if the argument is meant to be $end or to be $count.
>> does subroutine have some =A0mechanism like getopt::long and it can know
>> what kind of arguments are passed in?
>
> Jim,
> You could pass a hash reference instead.
> %arg =3D (start=3D>'..',end=3D>'..',count=3D>'..');
> the_func(\%arg);
> Regards.
>
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/