Here is a slightly modified version:

#!perl -w
use strict;

my @array = <DATA>;   # use DATA so don't have to play with file
my @phone;              
my $MyErrors = 0;  # let me know if errors
foreach (@array) {
  chomp;                 # remove linefeed
  next if ( /^\s*$/ ); # if blank line bypass
  if (/\s+(\d{3})\s+(\d{3})\s+(\d{4}):/ )  { # assuming std format of 3 3 4 and each 
line should                                                           # have one
     push(@phone, $1 . ' ' . $2 . ' ' . $3 ); # just push on and add a space between
   }else {
     printf "Expecting a phone number in line, but did not find one in\n";
     printf "correct format.\nData received follows:\n%-s\n", $_;
     $MyErrors++
   }
}
if ( $MyErrors ) {
   printf "There were errors in processing. Please check and rerun\n";
 }
__DATA__
Firstname Lastname 650 156 7190:somfield:somefield:somefield
Firstname Lastname 408 256 7290:somfield:somefield:somefield
Firstname Lastname 510 3456 7390:somfield:somefield:somefield
^--------------------- Script ends here

Wags ;)


-----Original Message-----
From: Anidil Rajendran-Raj [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 11:46
To: [EMAIL PROTECTED]
Subject: newbie question


Firstname Lastname 650 156 7190:somfield:somefield:somefield
Firstname Lastname 408 256 7290:somfield:somefield:somefield
Firstname Lastname 510 3456 7390:somfield:somefield:somefield

I have the above lines in a file and I am trying to create an array of =
phone numbers

open (FILE,"thefile") or die;
@array =3D <FILE>;
my @phone;
for each $string (@array) {
  $phone[$i] =3D ($string =3D~ /\s\d+\s\d+\s\d+:/) ;
  $i++;
}

This  does not work, what am I doing wrong? or it there a better way?

Thanks



raj
[EMAIL PROTECTED]
650.730.8271
<www.netliant.com>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to