On Thursday 29 Apr 2010 20:57:18 Akhthar Parvez K wrote:
> On Thursday 29 Apr 2010, Shlomi Fish wrote:
> > Just do:
> > 
> > my ($name) = Function1 ($arg);
> > 
> > This will evaluate Function1 in list context (instead of scalar or void
> > context) and only get the first element. But the @_ of a function is not
> > affected by calls to other functions inside it.
> 
> Correct and thanks for clearing my misconception! Is there any way to catch
> only the second return value then? I am not so sure but I think I had done
> it in the past using the method that I mentioned earlier (or similar).

As John noted, you can do it like this:

        my (undef, $name) = Function1 ($arg);

Or alternatively (and less preferably):

        my $name = (Function1 ($arg))[1];

Note that you shouldn't return too many individual and distinct values out of 
your subroutines (unless you're returning a list of values of arbitrary length 
and clobbering the return list instead of passing it as an array reference), 
and instead opt for either named return values:

[code] # Untested
sub myfunc
{
        .
        .
        .
        return
        {
                first => "Bart",
                last => "Simpson",
                city => "Springfield",
                country => "USA",
                .
                .
                .
        };
}
[/code]

Or preferably make a good use of Perl's Object Oriented Programming features.

Regards,

        Shlomi Fish

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

God considered inflicting XSLT as the tenth plague of Egypt, but then
decided against it because he thought it would be too evil.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to