[25856] in Perl-Users-Digest
Perl-Users Digest, Issue: 8091 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 18 11:05:23 2005
Date: Wed, 18 May 2005 08:05:06 -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 Wed, 18 May 2005 Volume: 10 Number: 8091
Today's topics:
Re: adding columns to table <someone@somewhere.com>
Re: Clean out accents in French names <thundergnat@hotmail.com>
Re: Clean out accents in French names <do-not-use@invalid.net>
DBI: adding columns to table <someone@somewhere.com>
replace variable in html page <alexj@freesurf.ch>
Re: replace variable in html page <1usa@llenroc.ude.invalid>
Re: replace variable in html page <alexj@freesurf.ch>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 May 2005 15:59:06 +0100
From: "Bigus" <someone@somewhere.com>
Subject: Re: adding columns to table
Message-Id: <d6fl7q$si4$1@blackmamba.itd.rl.ac.uk>
Hmm, fixed it... A flash of inspiration just caused me to try using
back-ticks, ie:
$db->do("ALTER TABLE list_headers ADD `$k` TEXT");
and it worked! Can't say I understand it at all because I've used
single-quotes for everything else for the past 2 years and there doesn't
appear to be any mention of it in the DBI manual (and prepare should have
used backticks if that was what was needed anyway).
"Bigus" <someone@somewhere.com> wrote in message
news:d6fk9t$s6j$1@blackmamba.itd.rl.ac.uk...
> Has anyone had probs adding columns to a table using DBI and the ALTER
> TABLE command?
>
> I've been sending the command in a loop that processes some key/value
> pairs, checks if the column already exists and if not attempts to create
> it:
>
> foreach my $k(keys %keyvals){
> my $result = $db->do("DESCRIBE list_headers '$k'");
> logit("Failed to describe column $k ".$db->errstr,0) if $db->errstr ;
> if($result != 1){
> $db->do("ALTER TABLE list_headers ADD '$k' TEXT");
> logit("Failed to add column $k ".$db->errstr,1) if $db->errstr ;
> }
> }
>
> The error that's returned is:
>
> DBD::mysql::db do failed: You have an error in your SQL syntax; check
> the manual
> that corresponds to your MySQL server version for the right syntax to
> use near
> ''owner' TEXT' at line 1 at header.pl line 44.
>
> That's where $k = "owner". If I remove the single quotes round $k in teh
> ALTER TABLE line then the owner column is created fine, but of course it
> then falls over when $k = "reply-to" because of the hyphen.
>
> When I use PHPMyadmin to create the owner column it works fine and tells
> me it's used the syntax:
>
> ALTER TABLE `list_headers` ADD `owner` TEXT
>
> I've tried using the prepare & execute method but it falls over with
> exactly the same error.
>
> This sounds like a MySQL problem to me but if that's the case why does
> PHPMyadmin work? Anyone had this prob and got round it?
>
> Bigus
>
>
------------------------------
Date: Wed, 18 May 2005 08:45:16 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: Clean out accents in French names
Message-Id: <NvOdnaV7s9NEpRbfRVn-uA@rcn.net>
Patrick L. Nolan wrote:
> I have a script that takes information, including people's
> names, and builds an XML file. I just found that the
> application that reads the XML is fussy about characters.
> It choked on the name "Jean-Paul le Fevre", where there
> was an accent over the first e in Fevre. I don't know
> how to type that on this keyboard. I edited the file
> by hand, changing that character to a plain "e", and
> all was OK. By the way, this isn't Unicode, it's just
> extended ASCII.
>
> I think I know how to identify "non-printing" characters
> like that, but I would like to translate each one to
> its nearest equivalent in the basic ASCII character
> set. Thus the various e's with acute, grave and
> circumflex accents would all go to "e", and so forth.
> Has this problem been solved?
>
As has been pointed out in several other posts, there
are many reasons to avoid doing this, or at least to
do it very sparingly.
Never-the-less, I have written routines in the
past to do this, for when I need to aphabetize a list
of words which could contain Latin-1 characters > 127
but I could not be certain of a particular locale
setting.
sub deaccent{
my $phrase = shift;
return $phrase unless ($phrase =~ m/[\xC0-\xFF]/);
$phrase =~ tr/ÀÁÂÃÄÅàáâãäåÇçÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖØòóôõöøÑñÙÚÛÜùúûüÝÿý/AAAAAAaaaaaaCcEEEEeeeeIIIIiiiiOOOOOOooooooNnUUUUuuuuYyy/;
$phrase =~ s/\xC6/AE/g;
$phrase =~ s/\xE6/ae/g;
return $phrase;
}
That could then be used to sort a word list hash like:
sort {deaccent(lc $a) cmp deaccent(lc $b)} keys %wordlist
Again though, you should NOT use this lightly, as it can
completely change the meaning of words.
------------------------------
Date: 18 May 2005 15:05:31 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Clean out accents in French names
Message-Id: <yzdis1gy99g.fsf@invalid.net>
thundergnat <thundergnat@hotmail.com> writes:
> Patrick L. Nolan wrote:
> > I have a script that takes information, including people's
> > names, and builds an XML file. I just found that the
> > application that reads the XML is fussy about characters.
> > It choked on the name "Jean-Paul le Fevre", where there
> > was an accent over the first e in Fevre. I don't know
> > how to type that on this keyboard. I edited the file
> > by hand, changing that character to a plain "e", and
> > all was OK. By the way, this isn't Unicode, it's just
> > extended ASCII.
> > I think I know how to identify "non-printing" characters
> > like that, but I would like to translate each one to
> > its nearest equivalent in the basic ASCII character
> > set. Thus the various e's with acute, grave and
> > circumflex accents would all go to "e", and so forth.
> > Has this problem been solved?
> >
>
> As has been pointed out in several other posts, there
> are many reasons to avoid doing this, or at least to
> do it very sparingly.
>
> Never-the-less, I have written routines in the
> past to do this, for when I need to aphabetize a list
> of words which could contain Latin-1 characters > 127
> but I could not be certain of a particular locale
> setting.
>
>
> sub deaccent{
> my $phrase = shift;
> return $phrase unless ($phrase =~ m/[\xC0-\xFF]/);
> $phrase =~ tr/ÀÁÂÃÄÅàáâãäåÇçÈÉÊËèéêëÌÍÎÏìíîïÒÓÔÕÖØòóôõöøÑñÙÚÛÜùúûüÝÿý/AAAAAAaaaaaaCcEEEEeeeeIIIIiiiiOOOOOOooooooNnUUUUuuuuYyy/;
> $phrase =~ s/\xC6/AE/g;
> $phrase =~ s/\xE6/ae/g;
> return $phrase;
> }
A few Latin-1 characters are not taken care of by the above function:
upper and lowercase Icelandic thorn (Þ, þ);
upper and lowercase Icelandic eth (ð, Ð);
German ess-zet (ß) (there is no uppercase version).
The following additions may be appropriate:
$phrase =~ s/\xDE/TH/g;
$phrase =~ s/\xFE/th/g;
$phrase =~ s/\xD0/TH/g;
$phrase =~ s/\xF0/th/g;
$phrase =~ s/\xDF/ss/g;
Thorn and eth are certainly not equivalent, but I leave it to an
Icelandic speaker to say whether there is a better conversion.
------------------------------
Date: Wed, 18 May 2005 15:43:09 +0100
From: "Bigus" <someone@somewhere.com>
Subject: DBI: adding columns to table
Message-Id: <d6fk9t$s6j$1@blackmamba.itd.rl.ac.uk>
Has anyone had probs adding columns to a table using DBI and the ALTER TABLE
command?
I've been sending the command in a loop that processes some key/value pairs,
checks if the column already exists and if not attempts to create it:
foreach my $k(keys %keyvals){
my $result = $db->do("DESCRIBE list_headers '$k'");
logit("Failed to describe column $k ".$db->errstr,0) if $db->errstr ;
if($result != 1){
$db->do("ALTER TABLE list_headers ADD '$k' TEXT");
logit("Failed to add column $k ".$db->errstr,1) if $db->errstr ;
}
}
The error that's returned is:
DBD::mysql::db do failed: You have an error in your SQL syntax; check
the manual
that corresponds to your MySQL server version for the right syntax to
use near
''owner' TEXT' at line 1 at header.pl line 44.
That's where $k = "owner". If I remove the single quotes round $k in teh
ALTER TABLE line then the owner column is created fine, but of course it
then falls over when $k = "reply-to" because of the hyphen.
When I use PHPMyadmin to create the owner column it works fine and tells me
it's used the syntax:
ALTER TABLE `list_headers` ADD `owner` TEXT
I've tried using the prepare & execute method but it falls over with
exactly the same error.
This sounds like a MySQL problem to me but if that's the case why does
PHPMyadmin work? Anyone had this prob and got round it?
Bigus
------------------------------
Date: Wed, 18 May 2005 15:23:12 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: replace variable in html page
Message-Id: <428b41c3$0$1155$5402220f@news.sunrise.ch>
Hi,
I would like to implement a function who will
1) read a page
2) replace label data with selected language
3) display page
I'm trying to do something like that but not sure on the loadPage
function if when I want to display the page on the browser I'm doing
this rigth
sub loadLanguage {
my $dir = "C:/indigoperl/apache/htdocs/recordz/lang";
open (FILE, "<$dir.$lang.conf") or die "cannot open file";
while (<FILE>) {
(my $label, my $value) = split ($_,"=");
$SERVER{$label} = $value;
}
}
sub loadPage {
my $page = param('page');
my $dir = "C:/indigoperl/apache/htdocs/recordz/";
open (FILE, "<$dir.$page.html") or die "cannot open file";
while (<FILE>) {
$LABEL{'login_username_label'} = SERVER{'login_username_label'};
$LABEL{'login_password_label'} = SERVER{'login_password_label'};
print $_;
}
}
thanks in advance
------------------------------
Date: Wed, 18 May 2005 13:51:37 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: replace variable in html page
Message-Id: <Xns965A6425DFA72asu1cornelledu@127.0.0.1>
Alexandre Jaquet <alexj@freesurf.ch> wrote in news:428b41c3$0$1155
$5402220f@news.sunrise.ch:
> I would like to implement a function who will
>
> 1) read a page
> 2) replace label data with selected language
> 3) display page
I have been adoring and flirting with
http://search.cpan.org/~nwclark/perl-5.8.6/lib/Locale/Maketext.pod#3
for a while.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Wed, 18 May 2005 16:30:24 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: replace variable in html page
Message-Id: <428b5182$0$1151$5402220f@news.sunrise.ch>
A. Sinan Unur a écrit :
> Alexandre Jaquet <alexj@freesurf.ch> wrote in news:428b41c3$0$1155
> $5402220f@news.sunrise.ch:
>
>
>>I would like to implement a function who will
>>
>>1) read a page
>>2) replace label data with selected language
>>3) display page
>
>
> I have been adoring and flirting with
>
> http://search.cpan.org/~nwclark/perl-5.8.6/lib/Locale/Maketext.pod#3
>
> for a while.
>
> Sinan
I finally use :
sub loadPage {
my $page = param('page');
if (!$page) { $page = "main";}
my $dir = "C:/indigoperl/apache/htdocs/recordz/";
open (FILE, "<$dir/$page.html") or die "cannot open file
$dir/$page.html";
print "Content-type: text/html\n\n";
while (<FILE>) {
s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
print $_;
}
}
------------------------------
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 V10 Issue 8091
***************************************