From: christopher j bottaro <[EMAIL PROTECTED]>
> hello again,
> all my c instincts tell me i shouldn't write a function like this: sub
> myfunc() {
> my $aref = [];
> if ( some_cond ) {
> return undef;
> }
> else {
> #populate @{$aref}
> return $aref;
> }
> }
> but its cool, right?
Yes this is fine in Perl. Perl simply does the right thing :-)
> i know what i really should do is this:
> sub myfunc() {
> my @array;
> if ( some_cond ) {
> return undef;
> }
> else {
> #populate @array
> return [ @array ];
> }
> }
Well ... I would use
return \@array;
it's a bit more Perlish and actually I expect it to be quicker.
(Benchmarking is left to the reader)
> anyways, second question: how do i create/invoke a function ref?
>
> i wanna do something like this:
> sub myfunc() {
> #blah blah
> }
> my $fref = \&myfunc(); # is this right?
without the ():
my $fref = \&myfunc;
> &{$fref}($arg1, $arg2); #is this right? are there any shortcuts like
> $fref->($arg1, $arg2)? i know this is the syntax for invoking a
> method, but i don't wanna go thru the hassle of making a class
Both these syntaxes are OK. No need for any classes or whatever.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]