[22239] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4460 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 24 06:05:38 2003

Date: Fri, 24 Jan 2003 03:05:07 -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           Fri, 24 Jan 2003     Volume: 10 Number: 4460

Today's topics:
    Re: Advice for relative newbie on perl compiler... (Helgi Briem)
    Re: commenting out code <no_spam@fromyou.thanks-anyways.com>
    Re: commenting out code <hazelbigfoot@gmx.net>
    Re: Converting a string to a valid date.. <no_spam@fromyou.thanks-anyways.com>
    Re: function overriding (Helgi Briem)
    Re: hash of arrays using variable array names <cwilbur@mithril.chromatico.net>
    Re: hash of arrays using variable array names (qanda)
    Re: hash of hashes of arrays <news@tvreclames.nl>
    Re: Is there a better way to format numbers to use comm <goldbb2@earthlink.net>
    Re: Max Value of Variable? <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: Max Value of Variable? <jan.raether@zmnh.uni-hamburg.de>
        newbie question on reference ?? <thens@nospam.com>
    Re: newbie question on reference ?? <dha@panix2.panix.com>
        Perl & CGI Security <alex@alexbanks.com>
    Re: Perl & CGI Security <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Perl Thread Tk Web Server problem <goldbb2@earthlink.net>
        perlcc error on aix (baum)
    Re: perlcc error on aix (Helgi Briem)
    Re: Reading French-Accented Data <nmihai_2000@yahoo.com>
    Re: Reading French-Accented Data <hyagillot@tesco.net>
    Re: slow grep <goldbb2@earthlink.net>
        Strange Problem with Perl Mods and TCP/IP <anthonysaffer@NOSPAM.yahoo.com>
    Re: Strange Problem with Perl Mods and TCP/IP <eldar@nospam.iki.fi>
    Re: Strange Problem with Perl Mods and TCP/IP (Helgi Briem)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 24 Jan 2003 10:26:57 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Advice for relative newbie on perl compiler...
Message-Id: <3e311386.1754364472@news.cis.dfn.de>

On Thu, 23 Jan 2003 16:05:54 +0000, Adam Cheney
<adamcheney@spamtrap.kiwis.co.uk> wrote:

>I am writing a number of ClearCase trigger scripts at the moment, and 
>I'm thinking about deploying them as executables.  I see three major 
>advantages in this approach:
>1)   Perl version - the scripts (or exe) will actually get executed 
>locally on users' (Win32) machine, even though they're stored in a 
>central network location.  Using executables ensures that I don't need 
>to worry about installing Perl or the particular version present.

Install Perl on the server.  Wrap the perl script in a .bat
file that points to the perl version on the server.  Control
that and you'll be fine.

>2) Speed - I reckon this approach will be considerably faster.

Wrong.  There will be no speed advantage.

>3) Security - this is Windoze, after all.  Scripts will be version 
>controlled, and then compiled before deployment to the network storage 
>location.

It won't matter whether it's executable or a script wrapped
in a bat file.

>First, may I get your opinions on my reasons for deploying executables? 

Only as one-shot items. 

>  Second, your opinions on what to use (current favourites are PerlApp 
>from ActiveState or Perl2Exe from IndigoSTAR)? 

I have used Perl2exe and found it satisfactory.  

However, and this is a big but, an exe made by perl2exe
is simply the script + the perl compiler + any modules
bundled into one file.  It is not a  true .exe. 

They are large, typically over 1MB.  Perl2exe has the option
of bundling perl into a .dll, making each program smaller.

> (Ideally, I'd like to consider freeware products, too)

I don't know of any useful ones.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 24 Jan 2003 06:48:42 GMT
From: "Bullet" <no_spam@fromyou.thanks-anyways.com>
Subject: Re: commenting out code
Message-Id: <el5Y9.11869$F7.3129597062@newssvr10.news.prodigy.com>

cperl-mode .. is that somehow different from perl-mode?

I just do M-x perl-mode then you can use M-x comment-region..

You need to mark your region first.. by going to the beginning and hitting
Ctrl-Space to mark the beginning then.. direction keys to the end.. and
Ctrl-Space again..

Then the region is marked.. and you can use M-x comment region..




------------------------------

Date: Fri, 24 Jan 2003 09:54:40 +0100
From: Jens Hoehne <hazelbigfoot@gmx.net>
Subject: Re: commenting out code
Message-Id: <3E30FF50.B2200D53@gmx.net>

Bullet wrote:
> 
> cperl-mode .. is that somehow different from perl-mode?
Yep. Quite.  
Heaps of Options - basically it's like the auctex equivalent for tex
files. You just can't live without it. I like C-c C-e for automatic
paranthese insertation.
Try it out with M-x cperl-mode.

Regards,
Jens


------------------------------

Date: Fri, 24 Jan 2003 05:49:30 GMT
From: "Bullet" <no_spam@fromyou.thanks-anyways.com>
Subject: Re: Converting a string to a valid date..
Message-Id: <Kt4Y9.11865$0N7.3128476736@newssvr10.news.prodigy.com>

Well, actually - in the initial post I did define the Hash within the sub..
But I conceded that I shouldnt have done that.. it was a simple
oversight in my original code which was more written as a test
case than anything else..

In fact .. when I posted the results of my test I also posted
the amended code which I used when I ran the test.

The main thing I was wondering about speedwise was the way
split was used to break the string and strip the comma in a one shot
as opposed to mutliple operations - as well as the use of sprintf to
format the output ..

Anyhow.. when run with the Hash defined outside of the sub for both
my benchmark results were as follows. .

Benchmark: timing 200000 iterations of modified, original...
  modified: 24 wallclock secs (24.32 usr +  0.00 sys = 24.32 CPU) @
8223.68/s (n=200000)
  original: 17 wallclock secs (16.89 usr +  0.00 sys = 16.89 CPU) @
11841.33/s (n=200000)
            Rate modified original
modified  8224/s       --     -31%
original 11841/s      44%       --

The sub that used the sprintf function and the fancier split ran noticeably
slower..

Since I am figuring on using this function on a website thats heavily taxed
CPU wise
already.. any spare cycles I can save cant hurt..

Obviously theres no wrong way to do it however .. and I learned a lot ..
basically
I am just always interested in whether a way that seems like it should be
faster
actually is when it comes time to run the code..

I played around with it a bit more and more testing..

From my tests I beleive there is two things that are happening to make the
'fancier' code slower.. one thing.. is the regexp must need to be
'recompiled' for lack of a better word every time through the loop.. and
since its slightly more complex.. it takes slightly more time/processor. .
also. . and I think sprintf does a lot more work to add a leading zero than
a
simple if statement..

Anyhow.. as I said before.. thanks for the input. . its been a learning
experience and
that was the whole point. .




------------------------------

Date: Fri, 24 Jan 2003 10:16:14 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: function overriding
Message-Id: <3e311256.1754059614@news.cis.dfn.de>

On Thu, 23 Jan 2003 15:38:07 GMT, "David"
<perl-dvd@darklaser.com> wrote:

>"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
>news:b0oidl$9vo$3@mamenchi.zrz.TU-Berlin.DE...
>> David <perl-dvd@darklaser.com> wrote in comp.lang.perl.misc:
>>
>> >     I've got a nice test of this groups skills.
>>
>> No, thanks.  Trying to present a mundane question as a "challenge"
>> is not going to win you points.
>
>If you can't say something helpful, please refrain from posting.
>
>Jerk ... *plonk*.

Anno was right.  You are wrong.  Cease and desist.

*plonk*
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 24 Jan 2003 05:15:20 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: hash of arrays using variable array names
Message-Id: <87r8b32kxw.fsf@mithril.chromatico.net>

>>>>> "UG" == Uri Guttman <uri@stemsystems.com> writes:

    UG> so the upshot is that PLAIN DATA STRUCTURES should not be
    UG> using the symbol table. if you are, then your code is BAD,
    UG> BROKEN, WILL SHOOT YOU IN THE FOOT, MURDER YOU IN BED and it
    UG> will GIVE YOU BAD BREATH.

You have left out --

sign you up for all sorts of 'opt-in only' mailing lists,
sleep with your girlfriend/boyfriend/pets,
drink all your beer, 
and cause your cell phone to have terrible reception.

Otherwise, good rant.

Charlton


------------------------------

Date: 24 Jan 2003 00:08:04 -0800
From: fumail@freeuk.com (qanda)
Subject: Re: hash of arrays using variable array names
Message-Id: <62b4710f.0301240008.530c59fb@posting.google.com>

A big thank you for the replies.
Brian McCauley <nobull@mail.com> wrote in message news:<u9y95b3fec.fsf@wcl-l.bham.ac.uk>...
> > 		my @flds = split( /,/, $_, -1 ); 	
> 
> Why the -1?  You only ever use $flds[0] anyhow?
The posted script and example data is a cut down version of what I am
actually working with, I'm working with records that contain hundreds
of fields, many are empty and I must maintain field numbering.  My
understanding is the negative limit to split will keep trailing null
fields.
> 
> > 	print STDOUT "aa_array: $hoa{$atype}[0]\n";
> 
> STDOUT is the default output stream unless you've been playing with select.
Sure, where possible I prefer to be explicit rather than implicit with
things like this.
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> sub func1 {
>     my %hoa;
>     local $_;
>     while( <DATA> ) {
> 	chomp;
> 	my ($fld0) = split /,/;
> 	push @{$hoa{$fld0}}, $_;
>     }
>  \%hoa;
> }
> 
> sub func2 {
>     my $hoa = shift;
>     my $type = shift;
>     print "printing (arg)$type ...\n";
>     for my $i( 0 .. $#{ $hoa->{$type} } ) {
> 	print "    $hoa->{$type}[$i]\n";
>     }
> }
> 
> my $hoa = func1();
> func2($hoa,'aa');
> func2($hoa,'bb');
> 
> __DATA__
> aa,f2,f3,f4,line1
> bb,f2,f3,f4,line2
> cc,f2,f3,f4,line3
> dd,f2,f3,f4,line4
> aa,f2,f3,f4,line5
> bb,f2,f3,f4,line6

I've said in other replies that simple working programs like yours
really help with learning and understanding.  Thank you so much again
- it makes a big difference.

One question though, when I run your script (copy and paste) I get the
following:
Use of uninitialized value in hash element at ./pnga line 12, <DATA>
line 7.
Use of uninitialized value in hash element at ./pnga line 12, <DATA>
line 7.
Is this a problem?


------------------------------

Date: Fri, 24 Jan 2003 09:34:25 +0100
From: "Bart van den Burg" <news@tvreclames.nl>
Subject: Re: hash of hashes of arrays
Message-Id: <1043397266.471234@news.knoware.nl>

Tad McClellan wrote:
> Bart van den Burg <news@tvreclames.nl> wrote:
>
>> I'm trying to create a hash of hashes of arrays, but I'm getting
>> really confused here
>> I'm creating it like this:
>>
>> my %channels = ("#channel1" => {"ops" => [], "voice" => [], "normal"
>> => []}, "#channel2" => {"ops" => [], "voice" => [], "normal" => []});
>
>
> So far so good, as verified by the Data::Dumper module:
>
>    print Dumper(\%channels), "\n";
>
>
>> at first, I want to add some "ops" to the list, so I do:
>>
>> unshift($channels}{"#channel1"}{"ops"}, "nickname");
>                    ^
>                    ^
>
> That is not your real code. Please don't waste our time
> troubleshooting
> code that does not even exist.
>
>     Do not re-type Perl code
>         Use copy/paste or your editor's "import" function rather than
>         attempting to type in your code. If you make a typo you will
>         get followups about your typos instead of about the question
>         you are trying to get answered.
>
>
>> in return, I get the error:
>> Type of arg 1 to unshift must be array (not hash element) at ./rb.pl
>> line 114, near ""nickname")"
>
>
> I do to, after fixing the typo that you introduced.
>
>
>> Could anyone tell me how to do this correctly?
>
>
> Apply "Use Rule 1" from:
>
>    perldoc perlreftut
>
>
> First, pretend it is a plain old everyday array:
>
>       unshift( @array, "nickname");
>
> Then replace the _name_ of the array with a block:
>
>       unshift( @{                             }, "nickname");
>
> Then put something in the block that returns a reference to an array:
>
>       unshift( @{$channels{"#channel1"}{"ops"}}, "nickname");

Thanks vishal, brian and tad!
This isn't actually the first time I had trouble with it, but it is the
first time someone was able to tell me how to do it correctly, and for that,
I thank you, cause now I'll know next times
About that typo... Don't know how that got there, actually :/
I did copy paste everything, I just think it was an accidential keystroke

thx
Bart




------------------------------

Date: Fri, 24 Jan 2003 01:02:45 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is there a better way to format numbers to use commas?
Message-Id: <3E30D705.E8B8AF44@earthlink.net>

Harald H.-J. Bongartz wrote:
> 
> Tad McClellan wrote:
> > (from the 5.6.1 version of perlfaq5, modified
> > to be bound to $num, the double-reverse method was in there too)
> 
> Damn, I knew I had seen that code before. ;-)
> (And was a bit puzzled not to see it in the 5.8.0 FAQ. Thanks.)

As cool as it was for my code to go into the FAQ, I'd prefer that the
older pieces of code had remained.

Esp. since the main reason I wrote that regex code like that was to see
if it was possible to do the commafication with a single s///, without
any other code -- and although I didn't *design* it to be obfuscated, it
certainly isn't something perl neophytes can easily understand.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


------------------------------

Date: Fri, 24 Jan 2003 09:00:38 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Max Value of Variable?
Message-Id: <newscache$2xk79h$5te$1@news.emea.compuware.com>

Jan Räther wrote (Thursday 23 January 2003 14:30):

> DBD::mysql::st execute failed: You have an error in your SQL
> syntax near ' , 0, 0, 200302314)' at line 1 at update.pl line 225.


This is your main problem. MySQL doesn't grok the SQL.
1. print the SQL command before executing, and see if anything seems broken.
2. carefully check the passed values against the data types of the columns.

In the end it might lead to a broken Perl statement somewhere (or some other 
problem), but initially you need to start debugging here.

HTH.

-- 
KP



------------------------------

Date: Fri, 24 Jan 2003 10:30:30 +0100
From: =?iso-8859-1?q?Jan_R=E4ther?= <jan.raether@zmnh.uni-hamburg.de>
Subject: Re: Max Value of Variable?
Message-Id: <pan.2003.01.24.10.30.27.780606.18235@zmnh.uni-hamburg.de>

On Fri, 24 Jan 2003 09:00:38 +0100, Koos Pol wrote:

> Jan Räther wrote (Thursday 23 January 2003 14:30):
> 
>> DBD::mysql::st execute failed: You have an error in your SQL syntax
>> near ' , 0, 0, 200302314)' at line 1 at update.pl line 225.
> 
> 
> This is your main problem. MySQL doesn't grok the SQL. 1. print the SQL
> command before executing, and see if anything seems broken. 2. carefully
> check the passed values against the data types of the columns.
> 
> In the end it might lead to a broken Perl statement somewhere (or some
> other problem), but initially you need to start debugging here.
> 
> HTH.
> 

Thanks for the hint, but this was actually not my Problem. The Problem
was that one of the switches returns no value for some SNMP Counters due
to an too old Cisco IOS Release. So the variable doesn't get initialized.

Jan

-- 
Jan Räther
Universität Hamburg
Zentrum für Molekulare Neurobiologie
Service-Gruppe EDV
Falkenried 94
20251 Hamburg
Germany
Tel.: 040 - 428 - 03 - 6619
Fax.: 040 - 428 - 03 - 6621

- "There's a door"
- "Where does it go?"
- "It stays where it is, I think."

	-- (Terry Pratchett, Eric)


------------------------------

Date: Fri, 24 Jan 2003 11:44:25 +0530
From: Thens <thens@nospam.com>
Subject: newbie question on reference ??
Message-Id: <20030124114425.5fed5632.thens@nospam.com>

Hi,
   I recently encountered this in one of the message in this group. What
does this piece of code mean

 $row = +{};

It says this creates a new entry in the DS.

TIA for your help.

Thanks and Regards
Thens.



------------------------------

Date: Fri, 24 Jan 2003 06:32:12 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: newbie question on reference ??
Message-Id: <slrnb31nfc.qjn.dha@panix2.panix.com>

In article <20030124114425.5fed5632.thens@nospam.com>, Thens wrote:
> Hi,
>    I recently encountered this in one of the message in this group. What
> does this piece of code mean
> 
>  $row = +{};
> 
> It says this creates a new entry in the DS.

What says that?  And what's "the DS"?

As far as what it does purely in terms of perl, it appears to be
equivalent to the same code without the plus sign.  That, in turn,
assigns an (empty) anonymous hash reference to the $row scalar
variable. (perldoc perlref for more info on hash references).

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Just Install Perl.      - Chris Nandor


------------------------------

Date: Fri, 24 Jan 2003 10:09:08 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Perl & CGI Security
Message-Id: <3e3110c9$0$232$cc9e4d1f@news.dial.pipex.com>

Would be grateful if someone could recommend an up-to-date security guide
for CGI Perl.

Thanks,


Alex




------------------------------

Date: Fri, 24 Jan 2003 11:16:12 +0100
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Perl & CGI Security
Message-Id: <si423v89to0gsc2tfng2uuad5kvmd4oltg@4ax.com>

On Fri, 24 Jan 2003 10:09:08 -0000, "Alex Banks" <alex@alexbanks.com>
wrote:

>Would be grateful if someone could recommend an up-to-date security guide
>for CGI Perl.


A start:


perldoc perlsec


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


------------------------------

Date: Fri, 24 Jan 2003 00:37:02 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl Thread Tk Web Server problem
Message-Id: <3E30D0FE.81953F79@earthlink.net>

Michael wrote:
> 
> I'm trying to write a very simple Peer-to-Peer application using Perl
> Tk and Threads. I'm using ActiveState Perl v5.8 on Windows XP Home,
> and using the Threads and Threads:shared modules.
> 
> My application should have both a server and client part, for
> receiving and sending information. The information being sent is just
> database results, so nothing difficult or complex.
> 
> I create a GUI using Tk with start and stop buttons, and when I start
> the server part I spawn a new thread so the GUI remains active while
> the server sits and listens. The server and client parts I have up and
> running so no problems there. It's killing the thread on exit of the
> Perl program that's the issue.

I think you mean, killing the thread when the 'stop' button is pressed
that's the problem.

> As I have found out, the easiest and most recommended way to end a
> thread is to complete/end the function you spawned the thread as.
> Simple enough and I've done this as a simple exercise. However, the
> accept() function in Perl sits and listens (as it's supposed to)
> waiting for connections. Therefore the function never exits.

How about this:

   # in parent thread:
   my $stopped : shared;
   my $thr = threads->create( \&thesub, \$stopped, @params );
   ... time passes, and now you want to kill $thr ...
   { lock $stopped; $stopped = 1; $thr->detatch; undef $thr }

   # in created thread:
   sub thesub {
      my ($am_i_stopped, @args) = @_;
      .... set up listening socket ...
      while() {
         { lock $$am_i_stopped; return if $$am_i_stopped; }
         my $sock = $listener->accept();
         { lock $$am_i_stopped; return if $$am_i_stopped; }
         # process $sock.
      }

> I don't want to detach the thread because I want to communicate
> between the main thread and the server thread and I also want to be
> able to control the server at certain points.

Detatching a thread doesn't prevent you from communicating with it ...
all it does is prevent you from using ->join to wait for it to exit and
collect it's return value.

You can always use shared variables for communication, regardless of
whether or not the thread you're communicating with is detatched.

> My only way so far of returing from the server thread has been to use
> the client part of my application to communicate with the server
> thread by calling localhost and forcing the server to end. Utter
> madness!! Apart from being messy, security goes out the window.

Heh, that does sound mad.  Here's another idea, which is *almost* as
mad... what happens if one thread is calling ->accept on a socket, and
that filehandle is closed in another thread?  Eg:

   # in parent thread:
   my $accfd : shared;
   my $thr = threads->create( \&thesub, \$accfd, @params );
   ... time passes, and now you want to kill $thr ...
   {  lock $accfd;
      cond_wait $accfd until defined $accfd;
      open( my($fh), ">&$accfd" );
      close $fh;
      $thr->detatch;
      undef $thr
   }

   # here's the other thread:
   sub thesub {
      my ($fdref, @args) = @_;
      .... set up listening socket ...
      {  lock $$fdref;
         $$fdref = fileno $listener;
         cond_signal $$fdref;
      }
      while() {
         my $sock = $listener->accept();
         # process $sock.
      }

A combination of these two techniques might be best.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


------------------------------

Date: 23 Jan 2003 23:21:20 -0800
From: baum@linuxmail.org (baum)
Subject: perlcc error on aix
Message-Id: <881dc1b8.0301232321.6796534e@posting.google.com>

hi

im using perl 5.6.1 on aix 5.1/4.3.3. i wanted to compile a script
with the perl compiler. but there seems to be a linker error.

qx16754@olek scripte/ccperl >perlcc iobench.pl -o iobench
ld: 0711-317 ERROR: Undefined symbol: .boot_Fcntl
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.

how can i use c compiler flags with perlcc? or does somebody know
about that linker error?

regards

christian


------------------------------

Date: Fri, 24 Jan 2003 10:36:26 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: perlcc error on aix
Message-Id: <3e3116f0.1755237998@news.cis.dfn.de>

On 23 Jan 2003 23:21:20 -0800, baum@linuxmail.org (baum)
wrote:

>im using perl 5.6.1 on aix 5.1/4.3.3. i wanted to compile a script
>with the perl compiler. but there seems to be a linker error.
>
>qx16754@olek scripte/ccperl >perlcc iobench.pl -o iobench
>ld: 0711-317 ERROR: Undefined symbol: .boot_Fcntl
>ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
>information.
>
>how can i use c compiler flags with perlcc? or does somebody know
>about that linker error?

Perlcc doesn't work and never really has.  It is not
under development and there are no plans to fix it
in future.  Forget about it.  It serves no useful 
purpose anyway.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

Date: Fri, 24 Jan 2003 10:32:10 GMT
From: "Mihai N." <nmihai_2000@yahoo.com>
Subject: Re: Reading French-Accented Data
Message-Id: <Xns930D19CE8D45FMihaiN@204.127.202.16>

> My script reads files, line by line and dumps the line (temporarily)
> into a string variable.
> data is coming from a windows source.
> prints a &#9567; character.
I may be able to help, but I need a little more details.
 - what file format are we talking about?
   is it HTML or XML (as &#...; sugests)?
   is the data from a Web form or something? 
 - the files are from windows and I understand the script is also running 
on win. But is it running normal or as a CGI script?
 - if you open in notepad the file you want to read, is is ok and looks 
French?

I am also trying to give some answers:
 - you can use (some) POSIX calls on windows, and setlocale is one of them
   but it is useless for encoding conversions, it will affect things like
   date/time/number formats, upper/lower case comparison/conversion,
   sorting,  etc.
 - if the file looks ok in Notepad, then just
    	$line = <INFILE>;
    	print $line;
   should be enough. You need no binmode, no utf8, no conversion,
   no nothing (if windows is English other locale using 1252 as code page)
 - if in Notepad you see &#9567;, then something is really wrong.
   this is xml/html "escaping" and the unicode value not a valid french
   character. The encoding of the file you read is wrong. If it is comming
   from web forms, it may be that the browser sends data as 1252
   (or something else) and the server (or the application saving to file)
   interprets it as utf8 (or the other way arround).
   But first make sure the file you are using for the perl script looks
   ok in Notepad. And if it is Win 2K/XP it may still look ok in Notepad
   and have problems in perl, because wsk/wxp notepad knows unicode
   both as utf8 and utf16
   Tell me what you see (or send me a file sample if it is no secret)
   and will take it from there.
 - if this is solved, you should have no problems with any other language
   using 1252 (which is slightly different than ISO Latin1, even if MS
   pretends to forget this)

Regards,
Mihai


------------------------------

Date: Fri, 24 Jan 2003 10:46:38 +0000 (UTC)
From: "W K" <hyagillot@tesco.net>
Subject: Re: Reading French-Accented Data
Message-Id: <b0r5ie$g6a$1@knossos.btinternet.com>


"Dave Fraleigh" <dave@fraleigh.net> wrote in message
news:22f677f.0301231805.249d5b74@posting.google.com...
> I'm working on a script that will parse a large amount of data, some
> of which MAY include french (or other extended-ascii characters in the
> 128-150 range).  Unfortunately, when reading a character with an ASCII
> value beyond the lower-ascii set, it seems to translate the read
> character without much rhyme or reason... I'm wondering why.

Half the answer is- No such thing as ascii above 128.
Most software these days is using Latin-1 or its illegitimate twin ANSI.
Many terminals and telnet progs will have the very different IBM code pages.

<...>
> $line = <INFILE>;
> $line =~ s/\Ç/'cedille'/g;

I actually use teraterm, which has both types of coding in different fonts.
As such if I have two terminals open with different fonts, the "C"ced would
look different in both cases.

> Instead of printing a Ç character, it prints a &#9567; character.

Try and find out if it is printing that or whether it is actually the
terminal.
Get the character somehow and see what  "ord" thinks it is.

> but that doesn't seem to work.  Does anybody have any suggestions on
> handling alternative language data (which is still in the ISO latin1
> character set) on a Windows machine?

It depends. I have code that searches for pound signs, and in the code with
certain fonts it looks like an accented "u" - I'm used to it, but I could
imagine it causing confusion. Those poor C coders need enough help anyway.
OTOH you could use something like  s/\xff/character 255/g




------------------------------

Date: Fri, 24 Jan 2003 00:54:22 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: slow grep
Message-Id: <3E30D50E.4C46B9E6@earthlink.net>

Matija Papec wrote:
> 
> X-Ftn-To: Benjamin Goldberg
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> >  a => sub { my @a = grep /5\z/, 0..99; 0 },
> >  b => sub { my @a = grep { /5\z/ } 0..99; 0 },
> >  c => sub { my @a; /5\z/ && push @a, $_ for 0..99; 0 },
> >} );
> >__END__
> >Benchmark: running a, b, c, each for at least 5 CPU seconds...
> >a:  5 wallclock secs ( 5.06 usr +  0.00 sys =  5.06 CPU) @ 2106.13/s (n=10657)
> >b:  6 wallclock secs ( 5.06 usr +  0.00 sys =  5.06 CPU) @ 716.01/s (n=3623)
> >c:  6 wallclock secs ( 6.10 usr +  0.00 sys =  6.10 CPU) @ 1133.11/s (n=6912)
> >    Rate    b    c    a
> >b  716/s   -- -37% -66%
> >c 1133/s  58%   -- -46%
> >a 2106/s 194%  86%   --
> >
> >So, grep without a block is fastest, then foreach, and in last place comes
> >grep with a block.
> 
> Hm, braceless grep is only 194% faster. :) IMHO this should go into grep
> perldoc.

It's not grep-specific that {} slows things down.

perl -MBenchmark=cmpthese
cmpthese( -1, {
   map {
      $_ => eval q[sub {] . "{"x$_ . '0+@_' . "}"x$_ . q[}];
   } 0..5, 10, 20, 50
} );
__END__
[first part of output snipped]
       Rate    50    20    10     5     4     3     2     1     0
50   5191/s    --  -67%  -84%  -89%  -90%  -92%  -93%  -95%  -98%
20  15515/s  199%    --  -52%  -68%  -71%  -77%  -79%  -84%  -94%
10  32312/s  522%  108%    --  -33%  -39%  -52%  -57%  -67%  -88%
5   48584/s  836%  213%   50%    --   -8%  -29%  -35%  -50%  -82%
4   52949/s  920%  241%   64%    9%    --  -22%  -29%  -46%  -81%
3   67997/s 1210%  338%  110%   40%   28%    --   -9%  -30%  -75%
2   74472/s 1335%  380%  130%   53%   41%   10%    --  -23%  -73%
1   97169/s 1772%  526%  201%  100%   84%   43%   30%    --  -64%
0  273412/s 5167% 1662%  746%  463%  416%  302%  267%  181%    --

Running with a trial longer than 1 second each should provide better
results.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


------------------------------

Date: Fri, 24 Jan 2003 01:15:37 -0600
From: Anthony Saffer <anthonysaffer@NOSPAM.yahoo.com>
Subject: Strange Problem with Perl Mods and TCP/IP
Message-Id: <hpp13vg40ocofk781kk6d50icrium9g2mp@4ax.com>

Hello Everyone,

I've been having a very strange problem that I'm hoping someone here
can help me figure out. For some reason when I use any network enabled
module (like Net::FTP or Net::IRC or Net::NNTP) the program is unable
to make a successful connection to the remote server. I've made sure
that the remote host is available and accepting connections from other
clients but my Perl program can't make a successful connection. So I
thought I was writing the code wrong and I sent the code to a friend.
He made no modifications to my code and it ran fine right away. His
machine is Win 98 SE just like mine and niether of us or on a LAN.

Can anyone clue me in on what's going on here? This is really making
development hard. Oh, and another strange thing: I can write clients
with IO::Socket fine. It will work. Any ideas?

Thanks in Advance,
Anthony


------------------------------

Date: Fri, 24 Jan 2003 08:07:22 GMT
From: "perlsage" <eldar@nospam.iki.fi>
Subject: Re: Strange Problem with Perl Mods and TCP/IP
Message-Id: <_u6Y9.25682$ws6.518095@news2.nokia.com>


"Anthony Saffer" <anthonysaffer@NOSPAM.yahoo.com> wrote in message
news:hpp13vg40ocofk781kk6d50icrium9g2mp@4ax.com...
> Hello Everyone,
>
> I've been having a very strange problem that I'm hoping someone here
> can help me figure out. For some reason when I use any network enabled
> module (like Net::FTP or Net::IRC or Net::NNTP) the program is unable
> to make a successful connection to the remote server. I've made sure
> that the remote host is available and accepting connections from other
> clients but my Perl program can't make a successful connection. So I
> thought I was writing the code wrong and I sent the code to a friend.
> He made no modifications to my code and it ran fine right away. His
> machine is Win 98 SE just like mine and niether of us or on a LAN.
>
> Can anyone clue me in on what's going on here? This is really making
> development hard. Oh, and another strange thing: I can write clients
> with IO::Socket fine. It will work. Any ideas?
>
> Thanks in Advance,
> Anthony

How about trying this:

$ftp = Net::FTP->new($target, Debug => 1)




------------------------------

Date: Fri, 24 Jan 2003 10:35:20 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Strange Problem with Perl Mods and TCP/IP
Message-Id: <3e311662.1755096064@news.cis.dfn.de>

On Fri, 24 Jan 2003 01:15:37 -0600, Anthony Saffer
<anthonysaffer@NOSPAM.yahoo.com> wrote:

>I've been having a very strange problem that I'm hoping someone here
>can help me figure out. For some reason when I use any network enabled
>module (like Net::FTP or Net::IRC or Net::NNTP) the program is unable
>to make a successful connection to the remote server. I've made sure
>that the remote host is available and accepting connections from other
>clients but my Perl program can't make a successful connection. So I
>thought I was writing the code wrong and I sent the code to a friend.
>He made no modifications to my code and it ran fine right away. His
>machine is Win 98 SE just like mine and niether of us or on a LAN.

Try fixing your proxy settings.  You should have
the environmental variable FTP_PROXY (and HTTP_PROXY)
and it should be something like: 

ftp://yourproxy.yourdomain:PORT,

the same as your web browser.  If not, set it in the manner
dictated by your OS.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


------------------------------

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.  

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 4460
***************************************


home help back first fref pref prev next nref lref last post