Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Array Filter and Lookahead

by moritz (Cardinal)
on Nov 20, 2012 at 19:06 UTC ( #1004778=note: print w/ replies, xml ) Need Help??


in reply to Array Filter and Lookahead

If you really want the last integer in a string, you can find that as /.*(?<!\d)(\d+)/, and get the numbers as

my @filtered = map { /.*(?<!\d)(\d+)/; $1 // '' } @lines;

However you seem to want to turn 3.0 into 3 (and not 0), and I don't know the rules behind that. Do you want to permit decimals, and cut off zero-decimals behind the dot? Or something else?


Comment on Re: Array Filter and Lookahead
Select or Download Code
Re^2: Array Filter and Lookahead
by AnomalousMonk (Monsignor) on Nov 20, 2012 at 20:00 UTC
    >perl -wMstrict -le "my @lines = ('xx', '0 xx', '1 xx 3.2'); ;; 'Zonk' =~ m{ (\w+) }xms; ;; my @filtered = map { /.*(?<!\d)(\d+)/; $1 // '' } @lines; printf qq{'$_' } for @filtered; " 'Zonk' '0' '2'
Re^2: Array Filter and Lookahead
by daugh016 (Initiate) on Nov 20, 2012 at 21:00 UTC
    Thanks for the feedback! The numbers are actually section numbers so sometimes they are written "section 1" and sometimes it could be "section 1.", "section 1)", "section 1.)", etc.

      So what's the extraction rule? One can make a guess based on the examples just given, but an explicit definition is always nice to have.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-09-02 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (29 votes), past polls