Opera and CSV is one post, that should trigger my attention :)

Nice try, but there are a few problems in this script.

The first line of your output would be:

Id##Name##Created##Active##Mail##Icon##Id##Name##Created##Mail##Icon## +Id##Name##Created##Mail##Icon##Id##Name##Created##Mail##Icon##Id##Nam +e##Created##Mail##Icon##Id##Name##Created##Mail##Icon##Id##Name##Crea +ted##Mail##Icon##Id##Name##Created##Mail##Icon##Id##Name##Created##Ma +il##Icon##

Where my corrected (and much shorter) version will generate:

Id,Name,Created,Active,Mail,Icon

As I do not use Opera's mail, my address books are too small to see any problematic data, but what would happen is names or addresses contain diacriticals (accented letters) or the chosen delimiter character(s)? If the .adr files are stored in UTF-8, the "<" in open should be "<:encoding(utf-8)". Here's a cleaned up version that uses Text::CSV_XS for output generation.

#!/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", -verbo +se => 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 i +s addresses.csv =back =cut

Enjoy, Have FUN! H.Merijn

In reply to Re: Convert Opera Contacts in .adr format to csv by Tux
in thread Convert Opera Contacts in .adr format to csv by walto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.