in reply to Re: Perl: Split/format the output and append it to an array
in thread Perl: Split/format the output and append it to an array

For the most part if you find yourself writing significant code in a map, use a for loop instead. Your 7 line confusing map requiring multiple comments becomes:

for my $xlink (@xlinks) { push @xlinkpaths, $1 if $xlink =~ /xlink (.+?) /; }

Although you could instead write it:

@xlinkpaths = map {/xlink (.+?) / ? $1 : ()} @xlinks;
Perl is the programming world's equivalent of English

Replies are listed 'Best First'.
Re^3: Perl: Split/format the output and append it to an array
by Anonymous Monk on Sep 11, 2014 at 22:14 UTC
    or even
    @xlinkpaths = map /xlink (.+?)/, @xlinks;

    you think you're getting undefs (but you're not in this case)? simply prepend  grep defined,  map ...

Re^3: Perl: Split/format the output and append it to an array
by Eily (Monsignor) on Sep 12, 2014 at 07:21 UTC

    Well, yes, you are right. Actually I started with the short version that Anonymous Monk gave, and I thought it would be confusing for someone not used to reading that sort of things. I should have gone for your first solution when I wanted to make it more verbose.