in reply to Complex structures and function "map"

I don't see how your problem has anything to do with map. It appears that you don't know how to return values from a sub.

sub parsear { my $input = shift; $name = basename ( $input, @sufijos ); }
is basically the same as
sub parsear { my $input = shift; return $name = basename ( $input, @sufijos ); }

If you want to return one of elements of the arraylist returned by fileparse, you have a few alternatives.

Temporary storage:

sub parsear { my $input = shift; my ($name, $path, $suffix) = fileparse( ... ); return $name; }

List slice:

sub parsear { my $input = shift; return ( fileparse( ... ) )[0]; }

Relying on the fact that fileparse returns the right value in scalar context:

sub parsear { my $input = shift; return scalar( fileparse( ... ) ); }

PS — Use use strict; use warnings;! Also, I wouldn't use "&" in front of sub calls. This has an effect (ignoring the prototype) you should only use when needed.

Replies are listed 'Best First'.
Re^2: Complex structures and function "map"
by nando (Acolyte) on Oct 21, 2011 at 18:40 UTC

    Thank you

    But what I want is to store the three variables, not one of them. An array of arrays formed by the list that generates the "fileparse"

    ;)
      map doesn't store anything, it returns a list. What list do you want it to return, a list of references to arrays?
      sub func { ... return \@a; } map { func(...) } ...
      sub func { ... return [ ... ]; } map { func(...) } ...
      sub func { ... return ...; } map { [ func(...) ] } ...

        Great!

        Yes I feel that I did not explained correctly. Sometimes I do not know if Google Translator is a help or an additional problem.

        I would like to achieve a structure "@ array" whose elements were other arrays. As I was reading this afternoon, this is achieved by references, that being scalars, can be elements of an array.

        So ... żI can by "map" to get from the output of the "fileparse" (a list of three scalar), an @array structure ($scalar1, $scalar2, ... $scalarn) where $scalarn is a reference to the list ($name, $path, $suffix)?

        Perhaps the question does not even make sense, I'm blocked today

        :)

        Thanks for your effort to understand