#!/usr/local/bin/perl 


 $f=$ARGV[0];



open (FILE,"$f");
open (FILEout,'>addresses.dat');

#@z ist das geoeffnete File als Array




while (@z = <FILE>) {
 

 # $#z is last element of array @z as scalar var

   for ($u=0;$u<=$#z;$u ++) 

   {
 # deletes all strings "alias" 
 $z[$u]=~s/alias //g;
 
#if there are notes, they are removed here
$z[$u]=~s/note.*\s//g;
		 
#xxx will be met as dummytext for sorting 
		 $z[$u]=~s/(^\w.*)(\w.*,.*)/xxx$1$2/;

		 #search for groups
		 $z[$u]=~s/([\w]*) ([A-Za-z0-9_@]*,.*)/$1 GROUP@GROUP\nnoname $2/g;
		 }

# Sorting of the Array -> Groups are at the end of the File 
@gaga =sort @z;

for ($v=0;$v<=$#gaga;$v ++) 

     {

     # Remove xxxx
     $gaga[$v] =~s/xxx//g;

     #Split groups after member nbr. 2 
     

$gaga[$v] =~s/(,)/\nnoname /g;




     #Put bracket around eMailaddresses 
     $gaga[$v] =~s/([A-Za-z0-9_]*) (.*)/$1 <$2>/g;
     }

#Zeigt das Array @gaga am Bildschirm (optional)
#print @gaga;

# Writes the new File with  Filehandle FILEout
print FILEout @gaga;


}

#Closes the file with the Handle "FILE" and FILEout
close (FILE);
close (FILEout);
# schliesst das Programm, (1) schliesst das Programm nur als
# Droplet oder Runtimeversion

 


&MacPerl'Quit(2);
