Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Perl: Split/format the output and append it to an array

by GrandFather (Saint)
on Sep 11, 2014 at 21:55 UTC ( [id://1100344]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-23 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found