use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

$dirname="sosifiles";
$outdir="$dirname/out";
mkdir($outdir);
opendir ( DIR, $dirname );
@files= readdir(DIR); 
closedir(DIR);

if (1)
{


    unlink glob "$outdir/*.prj" ;
    unlink glob "$outdir/*.dbf" ;
    unlink glob "$outdir/*.shp" ;
    unlink glob "$outdir/*.shx" ;

foreach $file (@files)
{
  if ($file=~/\.sos$/ig)
  {
    open(IFIL,"$dirname/$file");
    @lines=<IFIL>;
    close(IFIL);

    open(UFIL,">$outdir/$file");
    foreach $line (@lines)
    {
      $line=~s/å/a/g;
      $line=~s/Åpen/Apen/g;
      $line=~s/ø/o/g;
      $line=~s/æ/a/g;
      print UFIL "$line";
    }
    close(UFIL);
    system("sosicon.exe -2shp $outdir/$file");
  }
}
}

opendir ( DIR, $outdir );
@files= readdir(DIR); 
closedir(DIR);

my $zip = Archive::Zip->new();
foreach $file (@files)
{
  if ($file=~/\.prj$/ig || $file=~/\.dbf$/ig || $file=~/\.shp$/ig || $file=~/\.shx$/ig)
  {
    $file_member = $zip->addFile( "$outdir/$file", "$file" );
  }
}
$zip->writeToFileNamed("$outdir/sosi_shp.zip")

