[31339] in Perl-Users-Digest
Perl-Users Digest, Issue: 2584 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 4 18:10:08 2009
Date: Fri, 4 Sep 2009 15:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 4 Sep 2009 Volume: 11 Number: 2584
Today's topics:
Re: create a form with cgi and a multidimensional array <mstep@podiuminternational.org>
Re: Data cleaning issue involving bad wide characters i <jurgenex@hotmail.com>
Re: Data cleaning issue involving bad wide characters i sln@netherlands.com
Re: Data cleaning issue involving bad wide characters i <r.ted.byers@gmail.com>
Re: Data cleaning issue involving bad wide characters i <r.ted.byers@gmail.com>
Re: Data cleaning issue involving bad wide characters i <hjp-usenet2@hjp.at>
FAQ 4.34 How do I extract selected columns from a strin <brian@theperlreview.com>
FAQ 4.45 How do I find the first array element for whic <brian@theperlreview.com>
Re: need help, will pay <hjp-usenet2@hjp.at>
Re: Using MIME::Lite to send email and hash sln@netherlands.com
Re: Using MIME::Lite to send email and hash (Jens Thoms Toerring)
Re: Using MIME::Lite to send email and hash <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Sep 2009 07:22:57 -0700 (PDT)
From: Marek <mstep@podiuminternational.org>
Subject: Re: create a form with cgi and a multidimensional array (0/1)
Message-Id: <dd09ab61-1925-462a-b2b6-721804527c0d@v36g2000yqv.googlegroups.com>
On 4 Sep., 12:01, s...@netherlands.com wrote:
> snip
Wow! -sln I am very grateful for your help! I learned a lot! Here just
for fun, my adaptation a bit more complicate ...
Best greetings from Munich
marek
#! /usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard escapeHTML);
use CGI::Carp qw(fatalsToBrowser);
$CGI::DISABLE_UPLOADS =3D $CGI::DISABLE_UPLOADS =3D 1;
$CGI::POST_MAX =3D $CGI::POST_MAX =3D 4096;
my $color;
my @element_liste =3D (
{
type =3D> "ueberschrift",
name =3D> "Abholdatum/Abholzeit",
color =3D> "#C0C0C4"
},
{
type =3D> 'popup',
bez =3D> 'Tag/Monat/Jahr/ - std:min',
date_time1 =3D> [
{
name =3D> 'day',
value =3D> [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31"
]
},
{
name =3D> 'month',
value =3D> [
"Jan", "Feb", "M=E4r", "Apr", "Mai", "Jun",
"Jul", "Aug", "Sep", "Okt", "Nov", "Dez"
]
},
{
name =3D> 'year',
value =3D> [ '2009', '2010', '2011', '2012' ]
}
],
date_time2 =3D> [
{
name =3D> 'hour',
value =3D> [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24"
]
},
{
name =3D> 'minutes',
value =3D> [
"05", "10", "15", "20", "25", "30",
"35", "45", "55", "55"
]
}
]
}
);
print header ( -charset =3D> 'utf-8' ),
start_html(
{
-dtd =3D> '-//W3C//DTD XHTML 1.0 Transitional//EN',
-title =3D> 'FormTest',
-style =3D> { 'src' =3D> 'http://www.munich-taxis.de/style/
style_giessl.css' }
}
);
my $table_start =3D <<"EOF";
<table width=3D"1006" align=3D"center" border=3D"0" cellspacing=3D"0"
cellpadding=3D"0">
<tr>
<td align=3D"left" valign=3D"middle" bgcolor=3D"#0E1E3F" rowspan=3D"7">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
<td align=3D"left" valign=3D"middle" bgcolor=3D"#0E1E3F" colspan=3D"2">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
<td align=3D"left" valign=3D"middle" bgcolor=3D"#0E1E3F" rowspan=3D"7">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
</tr>
<tr>
<td bgcolor=3D"#EDD4C3" colspan=3D"2">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
</tr>
EOF
my $table_end =3D <<"EOF";
<tr>
<td bgcolor=3D"#EDD4C3" colspan=3D"2" height=3D"3">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
</tr>
<tr>
<td bgcolor=3D"#0E1E3F" colspan=3D"2" height=3D"3">
<img src=3D"../pix/grafix/transparent.gif" alt=3D"" width=3D"3"
height=3D"3" />
</td>
</tr>
</table>
EOF
# Dispatch to proper action based on user selection
my $aktion =3D lc( param("aktion") ); # aktion: beim Auslesen
kleinschreiben
if ( $aktion eq "" ) # erster Aufruf der Skripts
{
show_form( \@element_liste );
}
print end_html();
exit(0);
#
----------------------------------------------------------------------
# Eingabe-Formular anzeigen
sub show_form {
my $element_liste_ref =3D shift;
my @zeilen;
print start_form ( -action =3D> url() );
print $table_start;
foreach my $f ( @{$element_liste_ref} ) {
my $type =3D $f->{type};
my $bez =3D $f->{bez};
if ( $type eq "ueberschrift" ) {
$color =3D $f->{color};
my $ueberschrift =3D $f->{name};
push(
@zeilen,
Tr(
{ -bgcolor =3D> "$color" },
td( { -colspan =3D> '2' }, h1($ueberschrift) )
)
);
}
elsif ( $type eq 'popup' and $f->{bez} =3D~ /Monat/ ) {
my @menus1 =3D ();
my @menus2 =3D ();
for ( @{ $f->{date_time1} } ) {
push @menus1,
popup_menu(
-name =3D> $_->{name},
-value =3D> $_->{value}
);
}
for ( @{ $f->{date_time2} } ) {
push @menus2,
popup_menu(
-name =3D> $_->{name},
-value =3D> $_->{value}
);
}
push @zeilen,
Tr(
{ -bgcolor =3D> "$color" },
td( { -align =3D> 'center' }, $f->{bez} ),
td( { -align =3D> 'left' }, join( "/", @menus1 ) . " -
" . join( ":", @menus2 ) )
);
}
}
foreach my $zeile (@zeilen) {
print $zeile;
}
print qq(<tr><td bgcolor=3D"#EDD4C3" colspan=3D"2">);
print p( { -align =3D> 'right' },
submit( -name =3D> "aktion", -value =3D> "Absenden" ) );
print "</td></tr>";
print $table_end;
print endform;
print "<p> </p>";
}
__END__
------------------------------
Date: Fri, 04 Sep 2009 11:22:18 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Data cleaning issue involving bad wide characters in what ought to be ascii data
Message-Id: <2am2a5tff2i6alkcel98unc06djuenscof@4ax.com>
Ted Byers <r.ted.byers@gmail.com> wrote:
>On Sep 4, 1:44 am, Mart van de Wege <mvdw...@mail.com> wrote:
>> Jürgen Exner <jurge...@hotmail.com> writes:
>> > Ted Byers <r.ted.by...@gmail.com> wrote:
>> >>I thought I'd have to resort to a regex, if I could figure out what to
>> >>scan for, but if there is a perl package that will make it easier to
>> >>deal with this odd character, great.
>>
>> > Forgot to mention:
>> > There is Text::Iconv (see
>> >http://search.cpan.org/~mpiotr/Text-Iconv-1.7/Iconv.pm) which will
>> > convert text between different encodings. However I have no idea what it
>> > does with characters that do not exist in the target character set.
>>
>> If it uses iconv, or works the same as iconv, it'll drop them.
>>
>> Mart
>>
>> --
>> "We will need a longer wall when the revolution comes."
>> --- AJS, quoting an uncertain source.
>
>Does it work on Windows?
What "it" are you referring to? According to your quoting style it must
be the revolution in Mart's signature. However I find that rather
unlikely. There has never been anything revolutionary about Windows.
Or are you referreing to the iconv tool that Mart mentioned? I know
nothing about that.
Or are you referring to the Text::Iconv module that I mentioned?
I used it a lot several years ago on Windows.
>I don't find it on any of the repositories
>identified in Activestate's PPM, and haven't had much luck installing
>packages from cpan that aren't in at least one of those PPM
>repositories. The documentation for it says nothing about
>dependencies.
I had no problems installing Text::Iconv from CPAN on Windows (XP and
Server2000). However as I mentioned that was several years ago, no
recent experience.
jue
------------------------------
Date: Fri, 04 Sep 2009 15:01:09 -0700
From: sln@netherlands.com
Subject: Re: Data cleaning issue involving bad wide characters in what ought to be ascii data
Message-Id: <1a33a519mqgi1349niste9u82bakkhdq4u@4ax.com>
On Fri, 4 Sep 2009 10:59:59 -0700 (PDT), Ted Byers <r.ted.byers@gmail.com> wrote:
>On Sep 3, 8:22 pm, s...@netherlands.com wrote:
>> On Thu, 03 Sep 2009 16:07:07 -0700, s...@netherlands.com wrote:
>> >On Thu, 3 Sep 2009 07:10:36 -0700 (PDT), Ted Byers <r.ted.by...@gmail.com> wrote:
>>
>
> I learned plenty from this, and
>Jue's posts about this.
>
>Cheers,
>
>Ted
Looking back, it can for the most part be boiled down to this.
A roll-your-own, simple regex, that covers all cases.
Good luck!
-sln
-------------
use strict;
use warnings;
use Encode;
binmode (STDOUT, ':utf8');
#my $charset = 'utf8'; # Decode raw bytes that are in $charset encoding
#my $str = decode ($charset, "Your recieved string"); # encoded octets
# Example: $str is utf8 via decoding recieved sample and is like this:
my $str = "Rec\x{2019}d, copyright \x{00A9} 2009, trademark\x{2122} affixed";
# Select Unicode to ascii char-to-string substitutions
# ----
my %unisub = (
"\x{00A9}" => '(c)',
"\x{2018}" => "'",
"\x{2019}" => "'",
"\x{201C}" => '"',
"\x{201D}" => '"',
);
# Substitute non-ascii (code points 80 - 1fffff) with ascii equivalent
# (or blank if not in hash)
# ----
$str =~ s/([\x{80}-\x{1fffff}])/ exists $unisub{$1} ? $unisub{$1} : ''/ge;
print $str,"\n";
__END__
Output:
Rec'd, copyright (c) 2009, trademark affixed
------------------------------
Date: Fri, 4 Sep 2009 10:57:15 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Data cleaning issue involving bad wide characters in what ought to be ascii data
Message-Id: <b3ba2652-7689-477b-a0ed-1b95a4e0f178@r36g2000vbn.googlegroups.com>
On Sep 4, 1:44=A0am, Mart van de Wege <mvdw...@mail.com> wrote:
> J=FCrgen Exner <jurge...@hotmail.com> writes:
> > Ted Byers <r.ted.by...@gmail.com> wrote:
> >>I thought I'd have to resort to a regex, if I could figure out what to
> >>scan for, but if there is a perl package that will make it easier to
> >>deal with this odd character, great.
>
> > Forgot to mention:
> > There is Text::Iconv (see
> >http://search.cpan.org/~mpiotr/Text-Iconv-1.7/Iconv.pm) which will
> > convert text between different encodings. However I have no idea what i=
t
> > does with characters that do not exist in the target character set.
>
> If it uses iconv, or works the same as iconv, it'll drop them.
>
> Mart
>
> --
> "We will need a longer wall when the revolution comes."
> --- AJS, quoting an uncertain source.
Does it work on Windows? I don't find it on any of the repositories
identified in Activestate's PPM, and haven't had much luck installing
packages from cpan that aren't in at least one of those PPM
repositories. The documentation for it says nothing about
dependencies.
Thanks,
Ted
------------------------------
Date: Fri, 4 Sep 2009 10:59:59 -0700 (PDT)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Re: Data cleaning issue involving bad wide characters in what ought to be ascii data
Message-Id: <dd319ab6-0405-470c-a75d-e1e24b821edb@d34g2000vbm.googlegroups.com>
On Sep 3, 8:22=A0pm, s...@netherlands.com wrote:
> On Thu, 03 Sep 2009 16:07:07 -0700, s...@netherlands.com wrote:
> >On Thu, 3 Sep 2009 07:10:36 -0700 (PDT), Ted Byers <r.ted.by...@gmail.co=
m> wrote:
>
> >You can strip these after you decode. Something like this:
>
> >$str =3D decode ('utf8', "your recieved string"); # utf-8 octets
> >$str =3D~ s/\x{2018}/'/g;
> >$str =3D~ s/\x{2019}/'/g;
> >$str =3D~ s/\x{201C}/"/g;
> >$str =3D~ s/\x{201D}/"/g;
>
> >etc, ...
>
> -sln
> ------------------
> use strict;
> use warnings;
> use Encode;
>
> binmode (STDOUT, ':utf8');
>
> my $str =3D decode ('utf8', "Rec\342\200\231d"); # utf8 octets
> my $data =A0=3D "Rec\x{2019}d"; # Unicode Code Point
>
> if ($str eq $data) {
> =A0 =A0 =A0 =A0 print "yes thier equal\n";}
>
> print ordsplit($data),"\n";
>
> # Substitute select Unicode to ascii equivalent
> my %unisub =3D (
> "\x{2018}" =3D> "'",
> "\x{2019}" =3D> "'",
> "\x{201C}" =3D> '"',
> "\x{201D}" =3D> '"',
> ); =A0
> $str =3D~ s/$_/$unisub{$_}/ge for keys (%unisub);
> print $str,"\n";
>
> # OR -- Substitute all Unicode code points, 100 - 1fffff with ? character
> $data =3D~ s/[\x{100}-\x{1fffff}]/?/g;
> print $data,"\n";
>
> exit;
>
> sub ordsplit {
> =A0 =A0 =A0 =A0 my $string =3D shift;
> =A0 =A0 =A0 =A0 my $buf =3D '';
> =A0 =A0 =A0 =A0 for (map {ord $_} split //, $string) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 $buf.=3D sprintf ("%c %02x =A0",$_,$_);
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 return $buf;}
>
> __END__
>
> output:
>
> yes thier equal
> R 52 =A0e 65 =A0c 63 =A0G=C7=D6 2019 =A0d 64
> Rec'd
> Rec?d
Thank you very much. Brilliant. I learned plenty from this, and
Jue's posts about this.
Cheers,
Ted
------------------------------
Date: Fri, 4 Sep 2009 22:25:37 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Data cleaning issue involving bad wide characters in what ought to be ascii data
Message-Id: <slrnha2tu2.tnk.hjp-usenet2@hrunkner.hjp.at>
On 2009-09-03 16:09, Ted Byers <r.ted.byers@gmail.com> wrote:
> On Sep 3, 11:51 am, Jürgen Exner <jurge...@hotmail.com> wrote:
>> Ted Byers <r.ted.by...@gmail.com> wrote:
>> >Again, I am trying to automatically process data I receive by email,
>> >so I have no control over the data that is coming in.
>>
>> >The data is supposed to be plain text/HTML, but there are quite a
>> >number of records where the contraction "rec'd" is misrepresented when
>> >written to standard out as "Rec\342\200\231d"
>>
>> >When the data is written to a file, these characters are represented
>> >by the character ' when it is opened using notepad, but by the string
>> >'’' when it is opened by open office.
>>
>> >So how do I tell what character it is when in three different contexts
>> >it is displayed in three different ways?
>>
>> By explicitely telling the displaying program the encoding that was used
>> to create/save the file. In your case it very much looks like UTF-8.
>>
> My program needs to store the data as plain ascii regardless of how
> the original data was encoded. And apart from this string, it looks
> like all the data can be safely treated as ascii. The data comes as a
> text/html attachment to the emails, so I am wondering if the headers
> to the email might tell me something about the encoding ...
Don't wonder, look! If you look at the source code of the email you will
probably see a header like
Content-Type: text/html; charset=utf-8
This tells you that the encoding is UTF-8.
Or maybe the HTML part itself contains a meta element.
>> >How can I make certain that when I either print it or store it in my
>> >DB, I get the correct "rec'd" (or, better, "received")?
>>
>> >I suspect a minor glitch in the software that makes and send the email
>> >as this is the ONLY string where what ought to be an ascii ' character
>> >is identified as a wide character.
Looks like somebody tried to be cute and used a right single quotation
mark ("\x{2019}", "’") instead of an apostrophe ("\x{27}", "'").
>> That's not a wide character. A wide character is something totally
>> different.
>>
> I have done almost no programming dealing with i18n, so I called it a
> wide character because that's what Emacs called it when my program
> wrote the data to standard out.
In Perl jargon a "wide character" is usually a character with a code
greater than 255, although sometimes it is used to refer to character in
a character string. "\x{2019}" (RIGHT SINGLE QUOTATION MARK) is a wide
character by both definitions. So emacs is right although I suspect that
it uses a different definition.
>> >Regardless of how that happens (as
>> >I don't control that), I need to clean this. Â And it gets confusing
>> >when different applications handle the i18n differently (Notepad is
>> >undoubtedly using the OS i18n support and Open Office is handling it
>> >differently,
The OpenOffice import filter for text files is absolutely horrible.
In this case it obviously interprets the file as ISO-8859-1 (or
something similar) instead of UTF-8.
>> >and Emacs is doing it differently from both).
Emacs 22.2.1 handles UTF-8 files fine on Linux. I think it has done so
for quite a while, although I don't normally use it. Either your Emacs
is very old or the Windows port is broken or there is some setting which
you need to change.
>> Yep. If the file doesn't contain information about the encoding and/or
>> the application either doesn't support this encoding or misinterprets it
>> or cannot guess the encoding correctly then you will have to tell the
>> application which encoding to use (or use a different application).
>>
>> Does the file have a BOM? AFAIR Notepad uses the BOM to determine if a
>> file is in UTF-8 in disregard of UTF-8 being a byte sequence and thus
>> files in UTF-8 typically neither having nor needing a BOM.
>>
>> jue
> I don't know what a BOM is, let alone how to tell if a file has one.
>
> Is there a safe way to ensure that all the data that is being
> processed is plain ascii? I have seen email clients displaying this
> data so I know that there are never characters in it, as displayed,
> that would not be valid ascii.
RIGHT SINGLE QUOTATION MARK is not valid ASCII. It may look very
similar to APOSTROPHE, but it is not the same character. From the
context you know that it should be an apostrophe and not a quotation
mark, but that is your knowledge about the English language and has
nothing to do whether an email client can display it (most email clients
today will happily display characters from all the major languages in
the world).
> I thought I'd have to resort to a regex, if I could figure out what to
> scan for, but if there is a perl package that will make it easier to
> deal with this odd character, great.
Text::Unidecode replaces Non-ASCII characters with ASCII sequences. The
result may or may not be usable (in your case it is because it replaces
’ with '). Or you could just read the file character by character (*not*
byte by byte!) and replace all characters with a code >= 128 with a
useful substitute (since there are about 100000 characters you probably
want to define substitutions for only a few and let your script to
complain about all others).
In both cases you need to decode your file properly (see perldoc -f
binmode and perldoc -f open).
hp
------------------------------
Date: Fri, 04 Sep 2009 22:00:08 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.34 How do I extract selected columns from a string?
Message-Id: <I5gom.194655$ZN.119225@newsfe23.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.34: How do I extract selected columns from a string?
(contributed by brian d foy)
If you know where the columns that contain the data, you can use
"substr" to extract a single column.
my $column = substr( $line, $start_column, $length );
You can use "split" if the columns are separated by whitespace or some
other delimiter, as long as whitespace or the delimiter cannot appear as
part of the data.
my $line = ' fred barney betty ';
my @columns = split /\s+/, $line;
# ( '', 'fred', 'barney', 'betty' );
my $line = 'fred||barney||betty';
my @columns = split /\|/, $line;
# ( 'fred', '', 'barney', '', 'betty' );
If you want to work with comma-separated values, don't do this since
that format is a bit more complicated. Use one of the modules that
handle that format, such as "Text::CSV", "Text::CSV_XS", or
"Text::CSV_PP".
If you want to break apart an entire line of fixed columns, you can use
"unpack" with the A (ASCII) format. by using a number after the format
specifier, you can denote the column width. See the "pack" and "unpack"
entries in perlfunc for more details.
my @fields = unpack( $line, "A8 A8 A8 A16 A4" );
Note that spaces in the format argument to "unpack" do not denote
literal spaces. If you have space separated data, you may want "split"
instead.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Fri, 04 Sep 2009 16:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.45 How do I find the first array element for which a condition is true?
Message-Id: <7Qaom.9754$ec2.4087@newsfe13.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.45: How do I find the first array element for which a condition is true?
To find the first array element which satisfies a condition, you can use
the "first()" function in the "List::Util" module, which comes with Perl
5.8. This example finds the first element that contains "Perl".
use List::Util qw(first);
my $element = first { /Perl/ } @array;
If you cannot use "List::Util", you can make your own loop to do the
same thing. Once you find the element, you stop the loop with last.
my $found;
foreach ( @array ) {
if( /Perl/ ) { $found = $_; last }
}
If you want the array index, you can iterate through the indices and
check the array element at each index until you find one that satisfies
the condition.
my( $found, $index ) = ( undef, -1 );
for( $i = 0; $i < @array; $i++ ) {
if( $array[$i] =~ /Perl/ ) {
$found = $array[$i];
$index = $i;
last;
}
}
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Fri, 4 Sep 2009 22:33:16 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: need help, will pay
Message-Id: <slrnha2ucd.tnk.hjp-usenet2@hrunkner.hjp.at>
On 2009-09-02 19:09, Jens Thoms Toerring <jt@toerring.de> wrote:
> boman <shambo_p@yahoo.com> wrote:
>> On Sep 2, 2:23 pm, Nathan Keel <na...@gm.ml> wrote:
>> > I see, well then you might need to get someone to take a look or give
>> > you different options. There are some things you can try, but if
>> > you've set the buffering in the script, then the problem does lie
>> > elsewhere. You also might consider something like a server-push
>> > solution or just saying "click here to view the results", which can
>> > then open a file or read in the data as its happening (perhaps not via
>> > a CGI script).
>
>> The link idea could be a fall back, but I'd like to automate that. I
>> would think you can do that by setting the refresh parameter in
>> cgi::pm's header call, but I cannot figure out how to get the refresh
>> to exit once the process is complete, it just refreshes and refreshes
>> and refreshes, even when the process completes.
>
> That should be simple, just don't send the meta refresh anymore
> with the last page when the program is done.
>
> The real problem is more that this can't be done with a simple
> CGI script because when the browser (re-)loads the page the
> web server will start a new CGI script that doesn't know any-
> thing about what happened before.
I think you haven't read the "stonehenge article" mentioned by boman.
Here it is: http://www.stonehenge.com/merlyn/LinuxMag/col39.html
> So you will probably need some background process that waits for
> requests from the CGI script and then passes back the newly calculated
> data back to it (which the CGI script then sends on to the web server
> that transmits them to the browser).
No, the idea is to have a long-running process just write information to
a file. The CGI script then just has to look at the file to determine
what it should send back to the client.
>
> Since there could be several browsers asking simultaneously
> for new pages you also would have to be able to handle cal-
> culations in parallel within that background process.
Just use several background processes.
> And you would have to rely on some mechanism, e.g. cookies, to know
> which results are for which client.
Query parameters are more reliable for that.
hp
------------------------------
Date: Fri, 04 Sep 2009 04:37:58 -0700
From: sln@netherlands.com
Subject: Re: Using MIME::Lite to send email and hash
Message-Id: <lqu1a55jecp97oouoenv8pbceg0cf03iqu@4ax.com>
On Fri, 4 Sep 2009 02:54:31 -0700, "a" <a@mail.com> wrote:
>Hi,
>
>I am trying to use MIME::Lite to automate some testing cases.
>This module requires the following to initialize the email.
>my $msg = MIME::Lite->new(
> To =>'to_email@address.com',
> From =>'from_email@domain.com',
> Subject =>'Too Too Too Simple Email',
> Data =>"TESTING"
> );
>I put all these information in an xml file as the following, and load the
>file in a hash.
>my $ref = XMLin("sample_email.xml");
>my %h = %{$ref->{email}->[1]};
> <config>
> <email>
> </email>
> <email>
> <from>me.host@mymail.com</from>
> <to>to_email@domain.com</to>
> <subject>This is a simple email</subject>
> <data>This is a very simple email</data>
> </email>
> </config>
>
>Is there any way to put the hash in the MIME::Lite->new( <argument contained
>in hash> ) to initialize it?
>
>I have tried the following but not success
>my $ref = XMLin("sample_email.xml");
>my %h = %{$ref->{email}->[1]};
> my $msg = MIME::Lite->new();
> foreach (keys %h)
> {
> $msg->set($_=>$h{$_});
> or
> $msg->add($_=>$h{$_});
> or
> $msg->attr($_=>$h{$_});
> }
>
>
>
Just a guess:
my $ref = XMLin("sample_email.xml");
my $msg = MIME::Lite->new( %{$ref->{email}->[1]} );
Because, the below works.
-sln
=====================
use strict;
use warnings;
my %h = (
from => 'me.host@mymail.com',
to => 'to_email@domain.com',
subject => 'This is a simple email',
data => 'This is a very simple email'
);
MIME_Lite_new (%h);
exit;
sub MIME_Lite_new {
while (my ($parm,$value) = splice @_,0,2) {
printf "%-8s => '%s'\n", $parm,$value;
}
}
------------------------------
Date: 4 Sep 2009 11:52:22 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Using MIME::Lite to send email and hash
Message-Id: <7gcdbmF2o8jo8U1@mid.uni-berlin.de>
a <a@mail.com> wrote:
> Hi,
> I am trying to use MIME::Lite to automate some testing cases.
> This module requires the following to initialize the email.
> my $msg = MIME::Lite->new(
> To =>'to_email@address.com',
> From =>'from_email@domain.com',
> Subject =>'Too Too Too Simple Email',
> Data =>"TESTING"
> );
> I put all these information in an xml file as the following, and load the
> file in a hash.
> my $ref = XMLin("sample_email.xml");
> my %h = %{$ref->{email}->[1]};
> <config>
> <email>
> </email>
> <email>
> <from>me.host@mymail.com</from>
> <to>to_email@domain.com</to>
> <subject>This is a simple email</subject>
> <data>This is a very simple email</data>
> </email>
> </config>
> Is there any way to put the hash in the MIME::Lite->new( <argument contained
> in hash> ) to initialize it?
> I have tried the following but not success
> my $ref = XMLin("sample_email.xml");
> my %h = %{$ref->{email}->[1]};
> my $msg = MIME::Lite->new();
> foreach (keys %h)
> {
> $msg->set($_=>$h{$_});
> or
> $msg->add($_=>$h{$_});
> or
> $msg->attr($_=>$h{$_});
> }
Why not simply use
my $msg = MIME::Lite->new( %h );
or, if you really need the MIME::Lite object before you got the
hash with the required data
my $msg = MIME::Lite->new( );
$msg->build( %h );
The add() method is for appending to the end of the email header,
attr() is for MIME attributes, and I didn't find a set() method
in the documentation. If you want to set the data you have to
use the data() method as far as I can see. So you can't blindly
use one of those methods for all the stuff you have to pass to
the MIME::Lite object.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Fri, 04 Sep 2009 07:13:24 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Using MIME::Lite to send email and hash
Message-Id: <slrnha20eg.rdg.tadmc@tadmc30.sbcglobal.net>
a <a@mail.com> wrote:
> I am trying to use MIME::Lite to automate some testing cases.
> This module requires the following to initialize the email.
> my $msg = MIME::Lite->new(
> To =>'to_email@address.com',
> From =>'from_email@domain.com',
> Subject =>'Too Too Too Simple Email',
> Data =>"TESTING"
> );
> I put all these information in an xml file as the following, and load the
> file in a hash.
> my $ref = XMLin("sample_email.xml");
> my %h = %{$ref->{email}->[1]};
> <config>
> <email>
> </email>
> <email>
> <from>me.host@mymail.com</from>
> <to>to_email@domain.com</to>
> <subject>This is a simple email</subject>
> <data>This is a very simple email</data>
Case matters for non-header Lite arguments:
<Data>This is a very simple email</Data>
> </email>
> </config>
>
> Is there any way to put the hash in the MIME::Lite->new( <argument contained
> in hash> ) to initialize it?
>
> I have tried the following but not success
> my $ref = XMLin("sample_email.xml");
> my %h = %{$ref->{email}->[1]};
> my $msg = MIME::Lite->new();
my $msg = MIME::Lite->new( %{$ref->{email}->[1]} );
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2584
***************************************