Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: returning tied array

by ysth (Canon)
on Jan 07, 2007 at 18:57 UTC ( #593422=note: print w/replies, xml ) Need Help??

in reply to returning tied array

You seem to have discovered that subs return lists, not arrays. I'm not sure why you want a lexical @F; seems to me that if you want to emulate perl's -a switch, you want to set the global @F and $_, and if you don't want to, using a returned arrayref is fine.

But I hope one of the things suggested by others helps you get where you want.

Replies are listed 'Best First'.
Re^2: returning tied array
by WiseGuru (Initiate) on Jan 08, 2007 at 00:11 UTC
    Hi all, (please ignore the "intermidate" thing) as far as i know, returning anything from a sub, object etc, usualy returns an array, sorry dont have time to check the script, but try,
    @MyArray = &YourFunction(pass variables here); ## or $MyString = &YourFunction(pass variables here); ##might work! -------------- sub YourFunction{ @array =@_; (do something) return $YourString; ##wich ya get a string return @YourArray; ##wich ya get an array, i think the array objects seperated by spaces! (and furthermore you can change the space to something else through a special command to the perl interperter! :P ) } ---------------
    calling objects is done a different way! :P if your going to pass hashes there is another way to do it, but ya gonna have to ask! :P

    c ya, have fun!

      If you return a list from a subroutine, then you get that list back. If it was in scalar context, then you only get the first item of the list.

      You can use wantarray to see what context you were called in.

      Update: s/\barray\b/list/g per chromatic's comment.

        You can only return scalars and lists and (nothing) from subroutines. You can't return arrays or hashes directly, only as lists or references.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://593422]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-06-22 01:52 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (100 votes). Check out past polls.