#!/usr/bin/perl

#################################################
# PROGRAM:  Parse Phone Numbers (PPN) V2.0
#
# PPN reads lines from standard input and if the
# line contains a phone number, prints out the
# area code, first block and second block of the
# number.  Only the first number on any line is
# processed.
#################################################

while(<>)
{
  ###############################################
  # Parse input line
  ###############################################
  $line = $_;
  $match_query = 
    $line =~ /      
      (1|1\-|1\w)?               # Possible 1 or 1-
	
      ((\d\d\d)|\((\d\d\d)\))    # Area code (possibly in parens)
	  
      (\-|\s)?                   # Space or dash or nothing
	    
      (\d\d\d)                   # Block one
	      
      (\-|\s)?                   # Space or dash or nothing
		
      (\d\d\d\d)                 # Block two
    /x;

  ###############################################
  # If line contains Phone#, print out componants
  ###############################################
  if ($match_query) 
  {	
    $ac = $3.$4; # $3 is the ()-free area code, $4 is the area code inside ()s.  
                 # One or the other will be empty, so the concatenation is the area code!
    $b1 = $6;
    $b2 = $8;

    print "area code is $ac\n";
    print "block one is $b1\n";
    print "block two is $b2\n";
  }
}