Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Extracting numbers from a text file

by thanos1983 (Parson)
on Nov 02, 2019 at 18:36 UTC ( #11108251=note: print w/replies, xml ) Need Help??


in reply to Extracting numbers from a text file

Hello PetreAdi,

Something like that?

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array = ("aaa111bbb", "ab01ac d ab02ac ab03ac", "aaa222bbb", "ab04 +acab05ac r ab06ac", "aaa333bbb", "ab01ac t cab06acab10ac"); foreach my $str (@array) { my @all_nums = $str =~ /(\d+)/g; print Dumper \@all_nums; } __END__ $ perl test.pl $VAR1 = [ '111' ]; $VAR1 = [ '01', '02', '03' ]; $VAR1 = [ '222' ]; $VAR1 = [ '04', '05', '06' ]; $VAR1 = [ '333' ]; $VAR1 = [ '01', '06', '10' ];

On the Monastery it has been answered before this question (extracting number from string).

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: Extracting numbers from a text file
by PetreAdi (Acolyte) on Nov 02, 2019 at 18:54 UTC

    I have a variable my $content = get($url) (not array)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-05-31 14:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?