Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Array Filter and Lookahead

by Kenosis (Priest)
on Nov 20, 2012 at 19:13 UTC ( #1004779=note: print w/ replies, xml ) Need Help??


in reply to Array Filter and Lookahead

Here's another option:

my @test_filtered = map { (/(\d+)[\d.]*/g)[-1] // '' } @test;

Update: changed to // to handle 0s. Thanks again, AnomalousMonk.


Comment on Re: Array Filter and Lookahead
Select or Download Code
Replies are listed 'Best First'.
Re^2: Array Filter and Lookahead
by AnomalousMonk (Abbot) on Nov 20, 2012 at 20:13 UTC
    >perl -wMstrict -le "my @test = ('0 xx', 'xx 0', '0'); ;; my @test_filtered = map { (/(\d+)[\d.]*/g)[-1] || '' } @test; printf qq{'$_' } for @test_filtered; " '' '' ''

    Update:  // vice  || does the trick.

      Excellent catch, thank you! Changed disjunct positions...

        Changed disjunct positions...

        But that just causes a problem for strings that have no digits at all, e.g., 'xxx', which daugh016 wants to extract as '' (empty string).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2015-07-08 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls