in reply to Re: How to access directly an element of an array / list returned by a function?
in thread How to access directly an element of an array / list returned by a function?

That doesn't work with the dereferencing operator (->), since the return of File::Spec->splitpath is not a reference. This works:

my $name = ( File::Spec->splitpath($path) )[2];
Steve
  • Comment on Re^2: How to access directly an element of an array / list returned by a function?
  • Download Code

Replies are listed 'Best First'.
Re^3: How to access directly an element of an array / list returned by a function?
by vic2608 (Initiate) on Aug 26, 2010 at 17:47 UTC
    Sorry, could have sworn I tried that first. Many thanks!!
      Your code used the [] markers around your function to create an anonymous array reference, with that the -> dereference was a correct, if scenic, choice.

      Tom's solution used () for precedence to help the parser understand that the list returned from the function is what needs slicing. Unfortunately he kept the -> which was incorrect.