#!/pro/bin/perl use strict; use warnings; use autodie; use Getopt::Long; use Text::CSV_XS; use Pod::Usage; my $input = ""; my $output = "addresses.csv"; GetOptions ( "i|input=s" => \$input, "o|output=s" => \$output, ); $input or pod2usage (-message => "Missing input file name :\n", -verbose => 1); open my $in, "<", $input or die "Can not open $input ", $!, "\n"; my @chunks = split m/^#/m, do { local $/; <$in> }; close $in; my (@table, %cols, @cols); foreach my $chunk (@chunks) { $chunk =~ s/CONTACT// && $chunk =~ m/\n/ or next; my %data; foreach my $line (split m/\n+/ => $chunk) { $line =~ m/^\s*(.+?)\s*=\s*(.+)/ or next; my ($col, $val) = (ucfirst lc $1, $2); $cols{$col}++ or push @cols, $col; $data{$col} = $val; } keys %data and push @table, \%data; } my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, eol => "\n" }); open my $out, ">", $output or die "Can not open $output", $!, "\n"; $csv->print ($out, \@cols); $csv->print ($out, [ @{$_}{@cols} ]) for @table; close $out; __END__ =head1 NAME operaadr2csv.pl - Converts Opera .adr files to csv file =head1 SYNOPSIS operaadr2csv.pl -i [inputfile] [options] Options: -i | input -o | -output =head1 DESCRIPTION This program will convert contacts from opera browser .adr fileformat to a csv list. =head1 OPTIONS =over 4 =item -i Sets the name of the input file. This option is mandatory. =item -o Sets a name for the outputfile. The default name for the output file is addresses.csv =back =cut