[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [MacPerl-AnyPerl] Subroutine Argument Placeholder
Oops. I was really wanting to be able to call a Perl subroutine with
optional arguments specifically in the form
&sub_foo(arg1,,arg3);
But after delving into the pod files and finding that Perl interpolates
the list ((),(),()) as (), I concluded that Perl probably interprets the
actual arguments
to a subroutine as a list. The list (arg1,,arg3) then would probably be
parsed as (arg1,(),arg3) and interpolated into the list (arg1,arg3).
I am in the process of converting a C++ library to Perl modules and was
trying
to make the modules behave as closely as possible to the C++ library.
I was under the impression that one could omit an optional argument in a
C or C++
function call by just typing an extra comma in the argument list. But I
just
tried it in a C program, and the compiler puked. So what I was trying to
emulate is probably a non-existant capability in C++.
David Seay wrote:
>
> Richard L. Grubb wrote:
> >
> >Is there any way (or maybe I should say, How many ways are there) in
> >Perl to get a subroutine to recognize
> >a null argument?
> >
> >For instance, I would like subroutine sample below to
> >print out
> >
> >1
> >
> >2
> >
> >or
> >
> >1
> >NULL
> >2
> >
> >Instead, it prints
> >
> >1
> >2
> >
> >- ----------------- perl code snippet -----------
> >&sample(1.0,,2.0);
> >
> >sub sample
> >{
> > foreach (@_)
> > {
> > print "$_ \n";
> > }
> >}
> >
>
> $x = "1.0,,2.0";
> &sample;
>
> sub sample {
> @x = split(/,/, $x);
> foreach $i (0..$#x) {
> if($x[$i]) {
> $x=int($x[$i]);
> print "$x\n";
> } else {
> print "NULL\n";
> }
> }
> }
>
> __END__
==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org