dirtdog has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I'm hoping someone can assist with if there is a way to split on the results of a split command as a one liner.

For example, I have swift tags formatted like the one below and I want to ultimately stuff the values separated by whitespace (ISIN and DE000GH2MY35) into my aref variable.

:35B:ISIN DE000GH2MY35

  $aref = [split(split /:/, $_) [1]];

I thought the above line would do it, but it's not working. I thought the interior split would give me the values (ISIN DE000GH2MY35) and then the outer split just splits on whitespace by default so i'd end up with $aref->[0] evaluating to 'ISIN' and $aref->1 evaluating to 'DE000GH2MY35', but i'm getting a syntax error.

Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: split on split?
by LanX (Saint) on Feb 01, 2022 at 19:22 UTC
    That's what you want?
    DB<58> $_ = ":35B:ISIN DE000GH2MY35" DB<59> x split /\s+/, (split /:/, $_)[2] 0 'ISIN' 1 'DE000GH2MY35' DB<60> DB<61> x [ split /\s+/, (split /:/, $_)[2] ] 0 ARRAY(0x2ec4d88) 0 'ISIN' 1 'DE000GH2MY35' DB<63>

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      That's it!...thank you!