Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: extracting integers from bracketes when reading from file...

by pg (Canon)
on Nov 13, 2005 at 02:25 UTC ( #508055=note: print w/ replies, xml ) Need Help??


in reply to extracting integers from bracketes when reading from file...

If the problem was that you were not catching those 57's, it was because of those blanks within [], so just modify your regexp to allow it:

use strict; use warnings; while (my $file_content = <DATA>) { if ( $file_content =~ m/Vc3/ ) { my @numbers = $file_content =~ /\[\s*(\d+)\s*\]/g;#modified { local $,=':'; print @numbers; print $/ } } } __DATA__ Item no.0: NameDepth [2] <0> Class: [1] NetElementObjectClass Instance +: (int) [2] <1> Class: [ 57 ] Vc3TtpSnkObjectClass Instan +ce: (int) [3] Item no.1: NameDepth [2] <0> Class: [1] NetElementObjectClass Instance +: (int) [2]

This prints:

57:3 57


Comment on Re: extracting integers from bracketes when reading from file...
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-10-30 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (211 votes), past polls