in reply to Popping from method that returns a list in one line
$f->get_files returns a list.
To get into the details of what's going on: There is a difference between return ("foo","bar") (list) and return @quz (array) in scalar context. The context of the call is basically passed through to the return, so it's like $x = ("foo","bar"), where the comma operator in scalar context throws away the item on the left and returns the item on the right, and $x = @quz gets the number of elements in the array. So I suspect your method is probably returning an array instead of a list. That's also why neither of the forms you showed work, as @{...} provides scalar context, and you're getting the error because you can only give an actual array directly to pop (it currently has a prototype of (;\@), which means it accepts only things that start with an @). Two approaches might be ($fp->get_files)[-1], as others have already mentioned, or to actually return an array reference from the method, and dereference that with @{...}, but that'll change your API.
|
|---|