Hello htmanning,
If the phone numbers are punctuated with spaces rather than hyphens, you will need a different strategy. Here is one such approach (which builds on aaron_baugher’s solution):
#! perl use strict; use warnings; use Data::Dump; while (<DATA>) { chomp; # Trim trailing newline my @apts = /[- \d]+/g; # Get all sequences of digits, spaces, & h +yphens s/^[ ]+ //x for @apts; # Trim initial spaces s/ [ ]+$//x for @apts; # Trim trailing spaces @apts = grep { /^\d{3,4}$/ } @apts; # Get 3- or 4-digit sequen +ces only dd \@apts; } __DATA__ John Smith lives in Apts. 123 & 456, home number: 555-6666-7777 Please phone Jane Doe on 111 2222 3333. She lives in apartment 789 in +the Main building. Please phone Janet Roe on 88899990123. She lives in apartment 100 in t +he Main building.
Output:
12:51 >perl 1211_SoPW.pl [123, 456] [789] [100] 12:51 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Pull 3-digit and 4-digit numbers from string
by Athanasius
in thread Pull 3-digit and 4-digit numbers from string
by htmanning
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |