#!/usr/bin/perl use strict; use warnings; use Spreadsheet::SimpleExcel; my @data; my $file = 'mailbox.txt'; my $delimiter = '\s{2,}|\t|\\'; my $columns = 2; my $xls_file = 'zieldatei.xls'; my $excel = Spreadsheet::SimpleExcel->new(); $excel->add_worksheet('Test'); open(my $fh,'<',$file) or die $!; while(my $line = <$fh>) { # alles was unten in __DATA__ steht symbolisiert eine Datei chomp $line; my @array = (split(/$delimiter/,$line))[0..($columns-1)]; foreach (@array) { s%^\s+%%g; # fuehrende und s%\s+$%%g; # abschliessende Blanks entfernen } # foreach push(@data,[@array]); } # while close $fh; my $format = ''; for my $i(0..scalar(@{$data[0]})-1){ my $max = find_longest(map{$_->[$i]}@data); $format .= '%-'.$max.'s '; } for my $entry(@data){ print sprintf($format . "<<\n",@$entry); $excel->add_row('Test',$entry); } $excel->output_to_file($xls_file); sub find_longest{ my $longest = 0; for(@_){ my $length = length($_); $longest = $length if($length > $longest); } return $longest; }