Ask a Question related to PERL Beginners, Design and Development.
-
Hazael #1
Checking prototype with objects
--
Hi there.
I am trying to use prototype functions with object but this seems not
to work, I mean perl does not check for the type of arguments.
I usually do this.
sub array_print(\@);
...
....
sub array_print(\@)
{
# my code
}
Then when I call it as:
array_print(@this_array);
Perl is supposed to check the prototype and change the array by its
reference. Now I try to put this same behavior but with object, and
then when I call the same function as:
$obj_array->array_print(@this_array);
Perl sends the complete array to the function and not the reference.
So I need to do this
$obj_array->array_print(\@this_array);
Does any one knows how to force perl to behave as normal?
Cheers
Hazael Guest
-
RIA Prototype Developer contract position
RIA Prototype Developer Bank of America eCommerce User Centered Design & Research is currently interviewing candidates for Contract positions... -
setInterval + prototype referencing
I'm having two problems which are no doubt related I've got my Showbox functions working so that all images download and the program traces "file... -
MovieClip.prototype - movement
THE PROBLEM: ------------------ The goal is to use a custom prototype OnClipEvent(enterFrame) of 2 or more movieclips, that will "pause" for a... -
MX when to assign the prototype for a class
In the AS-code for the radiobutton-component in MX, the statement that assigns a prototype to the function is placed at te thop of the script, well... -
Movieclip.prototype.status
Hi. Does someone know why Movieclip.prototype.status = function(msg) { getURL("javascript:window.status='"+msg+"';void(0)"); }; will not... -
Rob #2
Re: Checking prototype with objects
Hazael Maldonado Torres wrote:
There is no way of prototyping object methods as run-time inheritance
means that Perl cannot know which subroutine will provide the
method until it is actually called.
Perl isn't C, and it's hardly ever a good idea to prototype
Perl subroutines. It's far more useful to be able to pass an array,
an array or hash slice, or a list of scalars (or a mixture of these)
to a subroutine that simply expects a LIST.
If you must, you can code
sub array_print {
my $array = shift;
die unless ref $array eq 'ARRAY';
}
but I would expect something like 'array_print' to look at
least something like the built-in 'print' operator which
takes a list of values.
HTH,
Rob
Rob Guest
-
R. #3
Re: Checking prototype with objects
Hazael Maldonado Torres wrote:
Your immediate problem here is that you are trying to use an expression as a
formal argument. Formal arguments in Perl can only take storage types. Really,
the only meaningful ones are scalar and list. The list, if it is present, must
be the last parameter, and there can only be one, since any list will consume
all arguments offered from there on.
The formal parmeter expressions you show are both array references. These are
scalars. They should be prtotyped as $.
Joseph
R. Guest
-
Randal #4
Re: Checking prototype with objects
>>>>> "Hazael" == Hazael Maldonado Torres <com> writes:
Hazael> I am trying to use prototype functions with object but this seems not
Hazael> to work, I mean perl does not check for the type of arguments.
Exactly. Prototypes are meant for one thing only: to have a Perl function
emulate a built-in.
They are not meant for "checking argument lists". And there are no
built-ins that have odd argument processing for method calls, which is
why they don't need to work there either.
Please do not use prototypes until you understand why you should not
use prototypes. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal Guest
-
Rob #5
Re: Checking prototype with objects
R. Joseph Newton wrote:
>
> Your immediate problem here is that you are trying to use an expression as a
> formal argument. Formal arguments in Perl can only take storage types. Really,
> the only meaningful ones are scalar and list. The list, if it is present, must
> be the last parameter, and there can only be one, since any list will consume
> all arguments offered from there on.
>
> The formal parmeter expressions you show are both array references. These are
> scalars. They should be prtotyped as $.[/ref]
Sorry Joseph. This from perldoc perlsub
Prototypes
Perl supports a very limited kind of compile-time argument checking
using function prototyping. If you declare
sub mypush (\@@)
then "mypush()" takes arguments exactly like "push()" does.
Cheers,
Rob
Rob Guest
-
R. #6
Re: Checking prototype with objects
Rob Dixon wrote:
> >
> > Your immediate problem here is that you are trying to use an expression as a
> > formal argument. Formal arguments in Perl can only take storage types. Really,
> > the only meaningful ones are scalar and list. The list, if it is present, must
> > be the last parameter, and there can only be one, since any list will consume
> > all arguments offered from there on.
> >
> > The formal parmeter expressions you show are both array references. These are
> > scalars. They should be prtotyped as $.[/ref]
>
> Sorry Joseph. This from perldoc perlsub
>
> Prototypes
>
> Perl supports a very limited kind of compile-time argument checking
> using function prototyping. If you declare
>
> sub mypush (\@@)
>
> then "mypush()" takes arguments exactly like "push()" does.
>
> Cheers,
>
> Rob[/ref]
Thanks, Rob,
That information actually makes prototypes at least marginally more useful. If you
can specify the type to which a references refers, that certainly offers more
information than the simplescalar and list types I have seen. It also provides a way
to set up more complicatedparameters lists and still use prototypes.
Joseph
R. Guest



Reply With Quote

