jryan has asked for the wisdom of the Perl Monks concerning the following question:

I want my overloaded operator sub join to return the array @meep, so I can access it in main. What needs to be the return value of the sub for this to work?

package aniftypackage; use overload ("." => "join_files"); # assume a working new sub is here; sub join { @meep = ("meep1", "meep2"); return @meep; } package main; $foo1 = new aniftypackage; $foo2 = new aniftypackage; $foo1 = $foo1.$foo2;

Replies are listed 'Best First'.
Re: Returning an array from a sub in a package
by japhy (Canon) on Aug 24, 2001 at 03:33 UTC
    Well, first, I think you want the function to be "join_files". But anyway, you can't return an array in scalar context and expect it to be an array -- maybe you want to return a reference to the array, or maybe you want to use the elements in the array as arguments to the new constructor...

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Yeah, woops, its supposed to be join_files. I was in a hurry. Exactly how would I return the reference?
        You'd do return \@array.

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;