M
Marek Stepanek
Hello happy Perlers,
my aim is to transform a large Address list in html to a LaTeX-Address-List
for a series (?) letter (=the same letter with many different addresses).
My html-address-list you may find on following internet address:
http://podiuminternational.org/addresses/competitions/competitionsfunds.htm
This file I am reading in without line breaks, or say I read in the whole
file as one line (I understand this like that, I am beginner), setting $/ to
undef. First I am reading in the file, removing the html; result is the
array @complete_address. The next step is to transform these entries of
@complete_address into a LaTeX File of the form:
\addrentry
{Lastname}
{Firstname}
{Address}
{Telephone}
{F1 } = m (ännlich) w (eiblich) u (zwitter oder unbekannt)
{F2 } = Firma
{F3 } = email
{F4 } = Kommentar
{KEY} = Schlüssel
I find these LaTeX-entries far too short - if somebody has an Perl-solution
for a series letter in LaTeX, I would really appreciate a hint! So this part
is my question, and it is still in work. Problem is: @complete_address
contains variables, with different lines, which I would like to read in line
by line. So I set $/ = "\n"; but this seems not to work.
And a construct of
foreach my $addr (@competitions)
{ $/ = "\n";
while (<$addr>)
{
...
}
}
seems not valid Perl.
Thank you for your patience
marek
Here my script so far:
#! /usr/bin/perl
use strict;
use warnings;
use HTML::Entities;
$/ = undef;
my (@competitions, @complete_address);
while (<>)
{
foreach my $entry (m"<dd>(.+?)</dd>"g)
{
push (@complete_address, $entry);
}
}
foreach my $e (@complete_address)
{
$e =~ s!<span\s+class="comp2">([^<]+)</span>!"Competition: " . $1 .
"\n\n"!ge;
$e =~ s!<br />!\n!g;
$e =~ s!<[^>]+>!!g;
push (@competitions, $e);
}
my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, "> $out_file1" or die "Connot create your out_file: $!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, ">> $out_file2" or die "Connot create your out_file: $!";
my ($competition, $email, $first_name, $last_name, $gender);
foreach my $addr (@competitions)
{
$/ = "\n";
($competition) = $addr =~ m"^Competition:\s+(.+)";
$addr =~ s/^(International|National) Competition\s*$//i; # not working
($gender, $first_name, $last_name) = $addr =~
/^(Mr\.?|Mrs\.?)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+)\s*$/;
# not working either
if ($gender)
{
if ($gender eq m/Mrs\.?/ )
{
$gender = "w";
}
elsif ($gender eq m/Mr\.?/ )
{
$gender = "m";
}
elsif ($gender == 'undef' )
{
$gender = "u";
}
}
($email) = $addr =~ m"((&#\d+
+)";
$email = decode_entities($email) if $email;
}
print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";
print OUT2 "\\addrentry\n";
print OUT2 "\t{$first_name}\n" if $first_name;
print OUT2 "\t{$last_name}\n" if $last_name;
print OUT2 "\t{$competition}\n";
print OUT2 "\t{$gender}\n" if $gender;
print OUT2 "\t{$email}\n" if $email;
close OUT1;
close OUT2;
my aim is to transform a large Address list in html to a LaTeX-Address-List
for a series (?) letter (=the same letter with many different addresses).
My html-address-list you may find on following internet address:
http://podiuminternational.org/addresses/competitions/competitionsfunds.htm
This file I am reading in without line breaks, or say I read in the whole
file as one line (I understand this like that, I am beginner), setting $/ to
undef. First I am reading in the file, removing the html; result is the
array @complete_address. The next step is to transform these entries of
@complete_address into a LaTeX File of the form:
\addrentry
{Lastname}
{Firstname}
{Address}
{Telephone}
{F1 } = m (ännlich) w (eiblich) u (zwitter oder unbekannt)
{F2 } = Firma
{F3 } = email
{F4 } = Kommentar
{KEY} = Schlüssel
I find these LaTeX-entries far too short - if somebody has an Perl-solution
for a series letter in LaTeX, I would really appreciate a hint! So this part
is my question, and it is still in work. Problem is: @complete_address
contains variables, with different lines, which I would like to read in line
by line. So I set $/ = "\n"; but this seems not to work.
And a construct of
foreach my $addr (@competitions)
{ $/ = "\n";
while (<$addr>)
{
...
}
}
seems not valid Perl.
Thank you for your patience
marek
Here my script so far:
#! /usr/bin/perl
use strict;
use warnings;
use HTML::Entities;
$/ = undef;
my (@competitions, @complete_address);
while (<>)
{
foreach my $entry (m"<dd>(.+?)</dd>"g)
{
push (@complete_address, $entry);
}
}
foreach my $e (@complete_address)
{
$e =~ s!<span\s+class="comp2">([^<]+)</span>!"Competition: " . $1 .
"\n\n"!ge;
$e =~ s!<br />!\n!g;
$e =~ s!<[^>]+>!!g;
push (@competitions, $e);
}
my $out_file1 = 'letter_comp_addr_01.adr';
open OUT1, "> $out_file1" or die "Connot create your out_file: $!";
my $out_file2 = 'letter_comp_addr_02.adr';
open OUT2, ">> $out_file2" or die "Connot create your out_file: $!";
my ($competition, $email, $first_name, $last_name, $gender);
foreach my $addr (@competitions)
{
$/ = "\n";
($competition) = $addr =~ m"^Competition:\s+(.+)";
$addr =~ s/^(International|National) Competition\s*$//i; # not working
($gender, $first_name, $last_name) = $addr =~
/^(Mr\.?|Mrs\.?)?([A-Z][a-z]+(?:\s+[A-Z][a-z]+\.?)?)\s+([A-Z][a-z]+)\s*$/;
# not working either
if ($gender)
{
if ($gender eq m/Mrs\.?/ )
{
$gender = "w";
}
elsif ($gender eq m/Mr\.?/ )
{
$gender = "m";
}
elsif ($gender == 'undef' )
{
$gender = "u";
}
}
($email) = $addr =~ m"((&#\d+
$email = decode_entities($email) if $email;
}
print OUT1 join ("\n\n", @competitions);
print OUT1 "\n\n";
print OUT2 "\\addrentry\n";
print OUT2 "\t{$first_name}\n" if $first_name;
print OUT2 "\t{$last_name}\n" if $last_name;
print OUT2 "\t{$competition}\n";
print OUT2 "\t{$gender}\n" if $gender;
print OUT2 "\t{$email}\n" if $email;
close OUT1;
close OUT2;