[27180] in Perl-Users-Digest
Perl-Users Digest, Issue: 9006 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 1 00:05:41 2006
Date: Tue, 28 Feb 2006 21:05:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 28 Feb 2006 Volume: 10 Number: 9006
Today's topics:
Perl 5.8.x, Unicode and In-memory Filehandles <cbkihong@hotmail.com>
Remote.pm (File::Remote) problem <tkoedge@comcast.net>
Re: Remote.pm (File::Remote) problem <1usa@llenroc.ude.invalid>
Re: Remote.pm (File::Remote) problem <tkoedge@comcast.net>
Re: Remote.pm (File::Remote) problem <1usa@llenroc.ude.invalid>
Re: Remote.pm (File::Remote) problem <tkoedge@comcast.net>
Re: Searching a sorted array of strings <tadmc@augustmail.com>
Re: Searching a sorted array of strings robic0
Re: Searching a sorted array of strings <uri@stemsystems.com>
Weighing the evidence, Perl is a GUESSING game !! robic0
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 01 Mar 2006 10:33:36 +0800
From: Bernard Chan <cbkihong@hotmail.com>
Subject: Perl 5.8.x, Unicode and In-memory Filehandles
Message-Id: <4405098a$0$4347$6d36acad@titian.nntpserver.com>
Hello all,
I have just started out experimenting the Unicode capabilities of Perl.
I am currently working on a Web development project involving both
output buffering with Perl's open() in-memory filehandles, and Unicode
handling. Separately they work fine, but I have spent a lot of time
integrating them onto one platform. Hopefully experts around here may
give me some insights as to what I have missed.
I have written a module IO::OutputBuffer which is expected to be used as
follows:
$buf_ctx = IO::OutputBuffer::start(\*STDOUT); # start in-memory buffer
# now STDOUT points to the in-memory buffer
print "blablabla"; # Everything goes to in-memory buffer
# Content verified; commit to real STDOUT
IO::OutputBuffer::flush($buf_ctx);
# Stop buffering
IO::OutputBuffer::end($buf_ctx);
# STDOUT reverted to original
Because stray output is likely to make Apache-CGI complain, I would like
to capture all the output, validate it and then eventually commit to the
actual output stream before the script exits (there is also a similar
facility for capturing STDERR to log file, but not shown).
Basically, as a next step, I would like to make use of PerlIO layers to
implement some encoding conversion for clients who do not support UTF-8.
Otherwise, I may need to use Text::Iconv but I guess if I can use PerlIO
I will keep using that. For instance, if the user profile (or HTTP
request header) indicates he prefers Big5, I will do a UTF-8->Big5
conversion, for instance.
As a test, I added some code within the buffering perimeters performing
a test reading of a Chinese file with UTF-8 encoding. I would like to
output its content to the client side, performing a simulated conversion
to Big5 before returning.
I have minimized the process to a script as short as below:
================================================
#!/usr/bin/perl -w
binmode(STDOUT, ":encoding(big5)") or die "$!"; # Output encoding
BEGIN {
require "require.pl";
}
#use IO::OutputBuffer;
#$b_out = IO::OutputBuffer::start(\*STDOUT);
my ($io_sys, $BUF);
open $io_sys, ">&", \*STDOUT; close STDOUT;
open STDOUT, ">", \$BUF;
open FILE, "<:encoding(utf8)", "utf8_1.txt";
@lines = <FILE>;
close FILE;
print (join("<br>\n", @lines));
#IO::OutputBuffer::flush($b_out);
my $buffered_content = $BUF;
$BUF = '';
seek STDOUT, 0, 0;
print $io_sys $buffered_content;
====================================
However, I cannot get the file content to display in proper Big5.
Instead, I got apparently Unicode code points as follows:
Wide character in print at output_minimal.pl line 20.
"\x{00e7}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00b9}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0081}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e9}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00ab}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0094}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e4}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00b8}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00ad}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e6}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0096}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0087}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e6}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00b8}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00ac}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e8}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00a9}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00a6}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e4}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00bb}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00a5}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e8}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00bc}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00b8}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e5}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0085}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00a5}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e6}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00bc}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00a2}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00e5}" does not map to big5-eten at output_minimal.pl line 28.
"\x{00ad}" does not map to big5-eten at output_minimal.pl line 28.
"\x{0097}" does not map to big5-eten at output_minimal.pl line 28.
UTF-8:
\x{00e7}\x{00b9}\x{0081}\x{00e9}\x{00ab}\x{0094}\x{00e4}\x{00b8}\x{00ad}\x{00e6}\x{0096}\x{0087}
<br>
<br>
\x{00e6}\x{00b8}\x{00ac}\x{00e8}\x{00a9}\x{00a6}\x{00e4}\x{00bb}\x{00a5}
UTF-8
\x{00e8}\x{00bc}\x{00b8}\x{00e5}\x{0085}\x{00a5}\x{00e6}\x{00bc}\x{00a2}\x{00e5}\x{00ad}\x{0097}
I guess that Perl has erroneously treated the content as non-Unicode and
thus tries to convert individual bytes as ISO8859-1 to Big5. I have
tried to insert utf8::upgrade($buffered_content) and then verified with
utf8::is_utf8() to ensure the input sequence is indeed valid UTF-8.
Anyone can help me? Thank you.
Regards,
Bernard Chan.
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
------------------------------
Date: Tue, 28 Feb 2006 18:50:57 -0800
From: Dayton Jones <tkoedge@comcast.net>
Subject: Remote.pm (File::Remote) problem
Message-Id: <tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast.com>
I've got a very simple script (see below) that uses the File::Remote
module. I've set up the script to use ssh/scp and there is no problem
for the user to ssh to the hosts - but the script fails with a
"permission denied" error on the copy command.
-- begin script
#!/usr/bin/perl
use File::Remote qw(:replace);
setrsh('/usr/bin/ssh');
serrcp('/usr/bin/scp');
settmp('/tmp');
copy("host1:/tmp/file","host1:/tmp/file2") or die ":: $!\n";
-- end script
On "host1" I can see the connection coming in:
Feb 28 18:46:48 host1 sshd(pam_unix)[20211]: session opened for user
XXXX by (uid=XXX)
Feb 28 18:46:49 host1 sshd(pam_unix)[20211]: session closed for user XXXX
So I don't know what is causing the permissions issue... Any ideas or
suggestions? What do I need to look at, what could be the cause?
Thanks is advance for any help...
------------------------------
Date: Wed, 01 Mar 2006 03:04:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Remote.pm (File::Remote) problem
Message-Id: <Xns9778E096789E4asu1cornelledu@127.0.0.1>
Dayton Jones <tkoedge@comcast.net> wrote in
news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast.com:
> I've got a very simple script (see below) that uses the File::Remote
> module. I've set up the script to use ssh/scp and there is no problem
> for the user to ssh to the hosts - but the script fails with a
> "permission denied" error on the copy command.
>
> -- begin script
>
> #!/usr/bin/perl
use strict;
use warnings;
missing.
> use File::Remote qw(:replace);
>
> setrsh('/usr/bin/ssh');
> serrcp('/usr/bin/scp');
*Ah-em*. Have you read the posting guidelines for this group?
...
> Thanks is advance for any help...
You can learn how to help others help you, and also how to help yourself
by following the posting guidelines.
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: Tue, 28 Feb 2006 19:46:44 -0800
From: Dayton Jones <tkoedge@comcast.net>
Subject: Re: Remote.pm (File::Remote) problem
Message-Id: <CfOdnXLeZoy5hJjZRVn-uA@comcast.com>
Sorry, no I hadn't read the guidelines but I will now.
I added the strict/warnings but had the same result -- with no extra
information.
A. Sinan Unur wrote:
> Dayton Jones <tkoedge@comcast.net> wrote in
> news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast.com:
>
>
>>I've got a very simple script (see below) that uses the File::Remote
>>module. I've set up the script to use ssh/scp and there is no problem
>>for the user to ssh to the hosts - but the script fails with a
>>"permission denied" error on the copy command.
>>
>>-- begin script
>>
>>#!/usr/bin/perl
>
>
> use strict;
> use warnings;
>
> missing.
>
>
>>use File::Remote qw(:replace);
>>
>>setrsh('/usr/bin/ssh');
>>serrcp('/usr/bin/scp');
>
>
> *Ah-em*. Have you read the posting guidelines for this group?
>
> ...
>
>
>>Thanks is advance for any help...
>
>
> You can learn how to help others help you, and also how to help yourself
> by following the posting guidelines.
>
> Sinan
>
------------------------------
Date: Wed, 01 Mar 2006 03:57:36 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Remote.pm (File::Remote) problem
Message-Id: <Xns9778E9A8EEE3Aasu1cornelledu@127.0.0.1>
Dayton Jones <tkoedge@comcast.net> wrote in
news:CfOdnXLeZoy5hJjZRVn-uA@comcast.com:
> A. Sinan Unur wrote:
>> Dayton Jones <tkoedge@comcast.net> wrote in
>> news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast.com:
>>
>>
>>>I've got a very simple script (see below) that uses the File::Remote
>>>module. I've set up the script to use ssh/scp and there is no
>>>problem for the user to ssh to the hosts - but the script fails with
>>>a "permission denied" error on the copy command.
>>>
>>>-- begin script
>>>
>>>#!/usr/bin/perl
>>
>>
>> use strict;
>> use warnings;
>>
>> missing.
>>
>>
>>>use File::Remote qw(:replace);
>>>
>>>setrsh('/usr/bin/ssh');
>>>serrcp('/usr/bin/scp');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
> I added the strict/warnings but had the same result -- with no extra
> information.
Well, did you fix the typo above?
I don't have File-Remote installed, by I doubt serrcp is correct.
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: Tue, 28 Feb 2006 20:02:31 -0800
From: Dayton Jones <tkoedge@comcast.net>
Subject: Re: Remote.pm (File::Remote) problem
Message-Id: <b7WdnSuPq7BLgZjZnZ2dnUVZ_sadnZ2d@comcast.com>
Yes, I noticed that when reading your original response -- changed it to
"setrcp="
A. Sinan Unur wrote:
> Dayton Jones <tkoedge@comcast.net> wrote in
> news:CfOdnXLeZoy5hJjZRVn-uA@comcast.com:
>
>
>>A. Sinan Unur wrote:
>>
>>>Dayton Jones <tkoedge@comcast.net> wrote in
>>>news:tZKdnQtkzPuPkZjZnZ2dnUVZ_sGdnZ2d@comcast.com:
>>>
>>>
>>>
>>>>I've got a very simple script (see below) that uses the File::Remote
>>>>module. I've set up the script to use ssh/scp and there is no
>>>>problem for the user to ssh to the hosts - but the script fails with
>>>>a "permission denied" error on the copy command.
>>>>
>>>>-- begin script
>>>>
>>>>#!/usr/bin/perl
>>>
>>>
>>>use strict;
>>>use warnings;
>>>
>>>missing.
>>>
>>>
>>>
>>>>use File::Remote qw(:replace);
>>>>
>>>>setrsh('/usr/bin/ssh');
>>>>serrcp('/usr/bin/scp');
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> ...
>
>
>>I added the strict/warnings but had the same result -- with no extra
>>information.
>
>
> Well, did you fix the typo above?
>
> I don't have File-Remote installed, by I doubt serrcp is correct.
>
> Sinan
>
------------------------------
Date: Tue, 28 Feb 2006 20:04:30 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Searching a sorted array of strings
Message-Id: <slrne0a09e.cgr.tadmc@magna.augustmail.com>
one man army <newsAT@screenlightDOT.com> wrote:
> It took me a
> while to write this simple routine, making most every mistake on the
> way. Perhaps it will be useful to someone.
> I tried to use qw( "name" "name space" ); and had problems, so I use the
> long form.
You cannot use qw() if your strings contain spaces.
> Constructive comments welcome.
Hmmm.
> #! /usr/bin/perl -w
> use warnings;
Keep the pragma, lose the -w.
I reduced the LOC a bit.
Here is my dense, terse, sup smart CRYPTO code.
----------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my %CA_Cities = map { chomp; $_, 1 } <DATA>; # hashes are for lookups
print "\n" . match_City( "ripon" );
print "\n" . match_City( "riPoN" );
print "\n" . match_City( "Ripon" );
print "\n" . match_City( "yorba linda" );
print "\n" . match_City( "Fred" );
sub match_City {
exists $CA_Cities{ lc $_[0] } ? lc $_[0] : "not found\n";
}
__DATA__
adelanto
agoura hills
alameda
alamo
albany
alhambra
newman
newport beach
nipomo
norco
north auburn
north highlands
norwalk
novato
oakdale
oakland
oceanside
oildale
ojai
olivehurst
ontario
opal cliffs
orange cove
orangevale
orcutt
orinda
orland
orosi
oroville east
oxnard
pacific grove
pacifica
palm desert
palmdale
palo alto
palos verdes estates
paradise
paramount
parkway-south sacramento
parlier
pasadena
patterson
petaluma
pico rivera
piedmont
pinole
pismo beach
placentia
placerville
pleasant hill
pleasanton
pomona
porterville
portola hills
poway
prunedale
quartz hill
ramona
rancho cordova
rancho cucamonga
rancho mirage
rancho san diego
rancho santa margarita
red bluff
redding
redlands
redondo beach
redwood city
reedley
rialto
richmond
ridgecrest
rio del mar
ripon
west whittier-los nietos
westlake village
westminster
westmont
whittier
wildomar
willowbrook
willows
windsor
winter
gardens
winters
winton
woodcrest
woodlake
woodland
yorba linda
yreka
yuba city
yucaipa
yucca valley
----------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 28 Feb 2006 18:15:38 -0800
From: robic0
Subject: Re: Searching a sorted array of strings
Message-Id: <ht0a02prsgbk5nrlr9ril1ruqn13nd61mr@4ax.com>
On Tue, 28 Feb 2006 20:04:30 -0600, Tad McClellan <tadmc@augustmail.com> wrote:
>one man army <newsAT@screenlightDOT.com> wrote:
>
>> It took me a
>> while to write this simple routine, making most every mistake on the
>> way. Perhaps it will be useful to someone.
>> I tried to use qw( "name" "name space" ); and had problems, so I use the
>> long form.
>
>
>You cannot use qw() if your strings contain spaces.
u mean "
>
>
>> Constructive comments welcome.
>
>
>Hmmm.
>
>
>> #! /usr/bin/perl -w
>
>> use warnings;
>
>
>Keep the pragma, lose the -w.
>
>
>I reduced the LOC a bit.
>
>Here is my dense, terse, sup smart CRYPTO code.
>
>----------------------------------
>#!/usr/bin/perl
>use warnings;
>use strict;
>
>my %CA_Cities = map { chomp; $_, 1 } <DATA>; # hashes are for lookups
>
>print "\n" . match_City( "ripon" );
>print "\n" . match_City( "riPoN" );
>print "\n" . match_City( "Ripon" );
>print "\n" . match_City( "yorba linda" );
>print "\n" . match_City( "Fred" );
>
>sub match_City {
> exists $CA_Cities{ lc $_[0] } ? lc $_[0] : "not found\n";
>}
>
>__DATA__
>adelanto
>agoura hills
>alameda
>alamo
>albany
>alhambra
>newman
>newport beach
>nipomo
>norco
>north auburn
>north highlands
>norwalk
>novato
>oakdale
>oakland
>oceanside
>oildale
>ojai
>olivehurst
>ontario
>opal cliffs
>orange cove
>orangevale
>orcutt
>orinda
>orland
>orosi
>oroville east
>oxnard
>pacific grove
>pacifica
>palm desert
>palmdale
>palo alto
>palos verdes estates
>paradise
>paramount
>parkway-south sacramento
>parlier
>pasadena
>patterson
>petaluma
>pico rivera
>piedmont
>pinole
>pismo beach
>placentia
>placerville
>pleasant hill
>pleasanton
>pomona
>porterville
>portola hills
>poway
>prunedale
>quartz hill
>ramona
>rancho cordova
>rancho cucamonga
>rancho mirage
>rancho san diego
>rancho santa margarita
>red bluff
>redding
>redlands
>redondo beach
>redwood city
>reedley
>rialto
>richmond
>ridgecrest
>rio del mar
>ripon
>west whittier-los nietos
>westlake village
>westminster
>westmont
>whittier
>wildomar
>willowbrook
>willows
>windsor
>winter
>gardens
>winters
>winton
>woodcrest
>woodlake
>woodland
>yorba linda
>yreka
>yuba city
>yucaipa
>yucca valley
>----------------------------------
------------------------------
Date: Wed, 01 Mar 2006 00:00:28 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Searching a sorted array of strings
Message-Id: <x78xruwyhf.fsf@mail.sysarch.com>
>>>>> "r" == robic0 <robic0> writes:
r> On Tue, 28 Feb 2006 20:04:30 -0600, Tad McClellan <tadmc@augustmail.com> wrote:
>> one man army <newsAT@screenlightDOT.com> wrote:
>>
>>> It took me a
>>> while to write this simple routine, making most every mistake on the
>>> way. Perhaps it will be useful to someone.
>>> I tried to use qw( "name" "name space" ); and had problems, so I use the
>>> long form.
>>
>>
>> You cannot use qw() if your strings contain spaces.
r> u mean "
no, he means qw(). wtf does " have to do with this? oops, it is robic0,
winner of maroon troll of the year.
and of course a 1 line useless reply to a full quoted email.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 28 Feb 2006 18:13:22 -0800
From: robic0
Subject: Weighing the evidence, Perl is a GUESSING game !!
Message-Id: <sru902ppeh3al23udfafhu0cnmnvc86gks@4ax.com>
I know there's some folks who hang their hat on Perl.
That notwithstanding, and without criticism to them,
given the extremely *poor* documentation of Perl and,
and. Have to stop the sentence because it worms to
infinity, not conducive to English.
I find it incredible to read some recent posts where
actual C pointers are somehow analogous to a Perl
construct. There is *nothing* available in Perl scripts
except pseudo C. There is *no* C, ie: addresses or
pointer arithmatic you can see, do, or say in Perl !!
The core of Perl is compiled. That is the end of contact
with Perl's core C code!! After that its an interfaced,
pseudo language thats provided to Perl programmers.
You have zero (0) control of the internals of Perl after that,
only to the extent of which is provided by such.
When you write Perl scripts, your so far away from C and the
operating system, you can't see!
After Perl is compiled there is not interaction with it, it
exists as a binary. There is no construct in Perl to alter
dynamic pointers in the C Perl core! Even if you wanted
to increment an address from a script, and it passed you the
(current) virtual memory location, the indirection would be
a killer! The time involved would be prohibitive. Perhaps
if there were pseudo C-like primitives in the native Perl
language, it would be feasable. It would involve multiple
indirection though. But what "++" construct from Perl?
How would that crash the machine, let me count the ways.
Boundries don't exists in the Perl population like it does
in C/C++. To let a Perl script control addressing would be
a nightmare!
Thats why they don't allow that shit!
If there's anybody who reads this who thinks otherwise
just post a follow. Otherwise *Perl* does not and will
never (because of the history off psudo languages) allow
access to and alteration of C core's.
I'm writing this because of the recent avalance of bullshit
on this subject by Abgail and Sunan and others on a single subject.
I'm ready to go to the mat on this one ...
-robic
------------------------------
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 9006
***************************************