[9018] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2636 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 19 05:07:51 1998

Date: Tue, 19 May 98 02:00:35 -0700
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, 19 May 1998     Volume: 8 Number: 2636

Today's topics:
    Re: 500 Server Error: .../somescript.pl contained no bl (J|rgen P|nter)
    Re: 500 Server Error: .../somescript.pl contained no bl (J|rgen P|nter)
    Re: ActiveX in perl <NO@SPAM.COM>
    Re: can't find uninitialized value after while block, c mpeppler@mbay.net
    Re: Does Perl have a IDE?I don't like command line. (Chip Salzenberg)
    Re: Efficiently finding the first available UID on a Un <rootbeer@teleport.com>
    Re: extra element in array (Martien Verbruggen)
        Forms Forms Everywhere! (Treeskunk)
        generating hash of complex records <cstuber@census.gov>
    Re: Nuclear bombing of NEW YORK! Small countries can ta <no_sp.am@agd.nsw.gov.au.x>
        perl and HTML : local server for simulation?? <abcdm@wanadoo.fr>
    Re: perl text editor for windows95 geniusweb@my-dejanews.com
        Q: ICMP Ping module? (Chris Josephes)
    Re: Q: ICMP Ping module? <zenin@bawdycaste.org>
        RE question (Tom Mornini)
    Re: RE question <lr@hpl.hp.com>
    Re: RE question <danboo@negia.net>
    Re: regexp: replacing new line followed by "+" <mgregory@asc.sps.mot.com>
        Something like "Visual Perl"? <wettels@respublica.de>
    Re: Startup overhead (M.J.T. Guy)
    Re: translate A-Z to 1-26 <ljz@asfast.com>
    Re: translate A-Z to 1-26 <lr@hpl.hp.com>
    Re: translate A-Z to 1-26 (Craig Berry)
    Re: translate A-Z to 1-26 <ljz@asfast.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 19 May 1998 06:05:45 GMT
From: Juergen.Puenter@materna.de (J|rgen P|nter)
Subject: Re: 500 Server Error: .../somescript.pl contained no blank line separating header and data
Message-Id: <6jr7fp$14$1@penthesilea.Materna.DE>

In article <6jr36g$r5k$1@penthesilea.Materna.DE>, Juergen.Puenter@materna.de 
says...

>In that case, a proper HTTP-header could be 
>
>   print "Content-type: text/html\n\n";
>   (rest here)
>or 
>
>   print "Content-type: text/html";
>
>   (rest here)

Argh :-(( 

'The body was awake, but the brain was not'

What I wanted to say, of course, is this.

Perhaps the original poster's script had something in it like

print <<ende;
Content-Type: text/html

<html>...</html>
ende

which does not work if shortened to 

print <<ende;
Content-Type: text/html
<html>...</html>
ende

Sorry for my confusing earlier posts.

To the original poster: the above is called a 'here document'. 
'Learning Perl', 2nd ed. mentions these and other issues in chapter
19, which is about CGI-Programming. You might want to take a look.

My new rule 1 for the future: Don't post anything before 08:00.


Bye
   Juergen Puenter



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

Date: 19 May 1998 04:52:32 GMT
From: Juergen.Puenter@materna.de (J|rgen P|nter)
Subject: Re: 500 Server Error: .../somescript.pl contained no blank line separating header and data
Message-Id: <6jr36g$r5k$1@penthesilea.Materna.DE>

In article <Pine.GSO.3.96.980518082323.28732E-100000@user2.teleport.com>, 
rootbeer@teleport.com says...

CCed via mail to <rootbeer@teleport.com>

>On 18 May 1998, J=FCrgen P=FCnter wrote:
>
>> Or perhaps it read:
>>=20
>> print "Content-type: text/html";
>>      <-- notice empty line
>> print ...;
>>=20
>> and you 'tweaked' ;-) this into:
>>=20
>> print "Content-type: text/html";
>> print ...;
>>=20
>> which does not work.=20
>
>What makes you think that Perl cares about an empty line like that?

The context of the original question (Server error 500: missing
blank line between header and data) and another answer to that
question both made me think that the problem was about generating
html-output via Perl.

In that case, a proper HTTP-header could be 

   print "Content-type: text/html\n\n";
   (rest here)
or 

   print "Content-type: text/html";

   (rest here)

In the 2nd case the empty line matters. Perl itself, of course,
couldn't care less, but as I said I thought it had to do with 
generating html.

And now I'll mark today as the day I one of THE Perl Gurus 
replied to one of my posts, even if it was only meant to
chastise me ;-))

Have a nice day
   Juergen Puenter



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

Date: Tue, 19 May 1998 05:01:03 GMT
From: "Mr Magoo" <NO@SPAM.COM>
Subject: Re: ActiveX in perl
Message-Id: <jm881.31$9c1.209917@news.randori.com>

Just out the html code in the script

Karin Popelier wrote in message <3560100B.3167@sd.be>...
>Is it possible to include an ActiveX-component (in my case I would like
>to put a grid on the interface) in a perl cgi? And how should I do this?
>Can anyone help me out ?
>
>Thanks in advance.
>
>Karin




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

Date: Tue, 19 May 1998 06:00:34 GMT
From: mpeppler@mbay.net
Subject: Re: can't find uninitialized value after while block, causing warning
Message-Id: <6jr763$qnp$1@nnrp1.dejanews.com>

In article <uu36n1hiw.fsf@ncs.com>,
  Scott Sutherland <suthsc@ncs.com> wrote:
>

> IMH(umble)O, the problem seems to be with the while call condition...
>
>   while ($dbh->ct_results($restype) == CS_SUCCEED) {
>            ^       ^         ^             ^
>            |       |         |             +-- a const function
>            |       |         |                 (autoloaded, i think)
>            |       |         +-- first use, set to undef when defined
>            |       |             and the call to ct_results sets this
>            |       +-- Sybperl function call which gets the type of
>            |           the result set to be fetched.
>            +-- a valid Sybase::CTlib object...

I didn't see the first message, but I think that doing:

my $restype = 0;

or something similar should fix this problem (at least if I understand the
problem correctly...)

Michael

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 19 May 1998 01:24:25 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Does Perl have a IDE?I don't like command line.
Message-Id: <6jqn39$8ql$1@cyprus.atlantic.net>

According to latsharj@my-dejanews.com:
>In article <6jkrqm$1k9$1@cyprus.atlantic.net>,
>  chip@mail.atlantic.net (Chip Salzenberg) wrote:
>> My personal anecdotes are mostly to the effect that commercial software
>> development is seriously scary in its atrocious and inexcusable badness.
>
> Thinking about Storage, are we - Chip???

Mike?

 ... but no, not Storage.  I would complain about the rest of UMI
before starting in on Storage.  DataTran ... ugh.

(Pay no attention, folks; these are internal project names, and aren't
probably going to mean much to you.  ...  Except of course that the
UMI code will be instrumental in the delivery of TV ratings someday.
Yes, I used to work at Nielsen Media Research.)
-- 
Chip Salzenberg                - a.k.a. -               <chip@pobox.com>
"I brought the atom bomb.  I think it's a good time to use it."  //MST3K
           ->  Ask me about Perl training and consulting  <-
     Like Perl?  Want to help out?  The Perl Institute: www.perl.org


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

Date: Tue, 19 May 1998 03:00:14 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Andrew Pollock <apollock@bit.net.au>
Subject: Re: Efficiently finding the first available UID on a Unix system
Message-Id: <Pine.GSO.3.96.980518195256.28659L-100000@user2.teleport.com>

On Tue, 19 May 1998, Andrew Pollock wrote:

> Does anyone have some sample code to find the first available UID on a
> Unix system in a relatively quick and efficient manner? 

    my $uid = 100;		# Lowest desired
    ++$uid while getpwuid $uid;
    print "Uid $uid seems to be available\n";

Is that sufficiently quick, efficient, and kind to your system? Hope this
helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 19 May 1998 05:47:45 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: extra element in array
Message-Id: <6jr6e1$ln5$1@comdyn.comdyn.com.au>

In article <6jqoqi$mb$1@nnrp1.dejanews.com>,
	mswain@my-dejanews.com writes:
> I am trying to search for certain files in a directory tree and save the
> filenames to an array. Invariably, the array ends up with an extra element at
> the end, typically 0 or 256. An example:
> 
>     @filelist=system("find /data -name \"*CSTSS*\"");
>     print @filelist;

You should be using backticks, not system.

# perldoc -f system
[snip]
This is I<NOT> what you want to use to capture
the output from a command, for that you should use merely backticks or
qx//, as described in L<perlop/"`STRING`">.
[snip

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | Inside every anarchy lurks an old boy
Commercial Dynamics Pty. Ltd.       | network - Mitchell Kapor
NSW, Australia                      | 


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

Date: Mon, 18 May 1998 23:06:20 -0500
From: Treeskunk@aol.com (Treeskunk)
Subject: Forms Forms Everywhere!
Message-Id: <Treeskunk-1805982306200001@beethoven.triplesoft.com>

I have found some great form scripts at:

http://www.cgi-resources.com/Programs_and_Scripts/Perl/Form_Processing/

My question is, which one is the best. I like AlienForm at:

http://cgi.tj/scripts/alienform/

Seems to have all the features I'm looking for and the price is right.

Any other suggestions?

-- 
Treeskunk (aka Mike T.)


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

Date: Tue, 19 May 1998 00:05:36 -0400
From: Chris Stuber <cstuber@census.gov>
Subject: generating hash of complex records
Message-Id: <35610510.E92579A6@census.gov>

I need to be able to store the equivilent of a C structure into
a hash.  I am sort of following a simple version of an example
on page 274 of the Camel book (Generation of a hash of complex
records.  The code below yields "George 21" which isnt quite what
I had hoped for.  I have tried dozens of different things, but
nothing working so far.  Any assistance would be greatly appreciated.

$rec = {};

$rec->{NAME} = "George";
$rec->{NUMBER} = "41";
$AA{ $rec->{NAME} } = $rec;

$rec->{NAME} = "Bob";
$rec->{NUMBER} = "21";
$AA{ $rec->{NAME} } = $rec;

$key = "George";
print "$key $AA{$key}{NUMBER}\n";


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

Date: Tue, 19 May 1998 18:36:11 +1000
From: Anthony Mandic <no_sp.am@agd.nsw.gov.au.x>
Subject: Re: Nuclear bombing of NEW YORK! Small countries can target with nukes!
Message-Id: <3561447B.806DBBAF@agd.nsw.gov.au.x>

Martien Verbruggen wrote:

> When I sent the first reply to the newsgroups, I didn't realise yet
> who the poster of that nasty little piece of prose was (note that

	Nasty little piece of prose? Compared to your sarcasm, English?
	So is this a case of your sarcasm is better than mine? I wonder
	what Oscar Wilde would have made of your blinding wit? More than
	likely he would have thought of you as a shining whit, English.

> he didn't use his real email address, so a personal email was not
> possible at that point). After rereading it, I suddenly recognised the
> name, after which I tracked down his real email address, and sent him

	Took you long enough, but then you always were a bit slow English.

> a personal email. This email he mentions but misrepresents and
> obviously misinterprets.

	Hmmm... that's interesting! Would you like me to post it here then,
	so that everyone can judge for themselves?

> I will not reply to Anthony Mandic's post, because I already sent him
> a personal email, which he didn't respond to. I don't know what his
> problem is, really, and I don't care. As far as I am concerned, this

	The "problem" is morons like yourself with nothing useful to
	contribute never the less feeling that your have to followup
	to a useless thread with more of the same drivel crossposted
	to inappropriate newsgroups. You felt you had to open your mouth
	so I felt I had to help you insert your foot in it. You deserved
	what you got.

> thing shouldn't have been on the newsgroups, and should have stayed in
> private email. Mr Anthony Mandic preferred to keep this public. I
> won't perpetuate it here after this.

	Good.

-am


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

Date: 19 May 1998 04:45:01 GMT
From: "DUTOIT" <abcdm@wanadoo.fr>
Subject: perl and HTML : local server for simulation??
Message-Id: <01bd82e0$a4f2c260$ec94fcc1@SIT.wanadoo.fr>

Hello,

I develop a program in Perl which may generate dynamical HTML pages.

At this time, I may test under DOS . I put in it a "query" for testing it ,
like:
  my $query = new CGI('nbcol8=20&nocde=2456&cache=A&devise=Franc');
and I verify generated HTML pages.

My problem is to test completly my PERL program in connection with my
dynamical  HTML pages. 

Can I use omnihttpd like a local server and how?

Other solution to test it easily?

Thanks you very much

Mr DUTOIT
abcdm@wanadoo.fr

Further informations in French below.



Bonjour,

Pour divelopper une application Internet sous Windows, j'utilise du HTML et

du script PERL5.Tester du HTML ne pose pas de problhme particulier.

Pour tester du PERL, j'ai aujourd'hui ` ma disposition:
- des pages HTML que je construis ` partir du PERL
- des utilitaires de visualisation de variables (dans des fichiers de
risultats)
- les "query" comme entries du programme PERL ` tester ,pour voir ce qu'il
ginhre:
  Ex:
  my $query = new CGI('nbcol8=20&nocde=2456&cache=A&devise=Franc');

Je teste le programme PERL en langant l'exicutable sous DOS.

L'objectif itant d'installer ce site que lorsqu'il aura iti testi 
complhtement, il me manquela possibiliti de SIMULER toute mon 
application PERL + HTML. En particulier, les ichanges PERL -> HTML et 
HTML-> PERL.

Je recherche donc (si g` existe ) un simulateur de serveur ou un 
logiciel iquivalent qui puisse me permettre de tester en stand-alone 
(hors connexion Internet) mon application.

omnihttpd peut-il faire l'affaire ? Mais alors, comment c` marche?

En vous remerciant d'avance pour votre aide,

Cordialement
DUTOIT
abcdm@wanadoo.fr
 





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

Date: Tue, 19 May 1998 04:25:50 GMT
From: geniusweb@my-dejanews.com
Subject: Re: perl text editor for windows95
Message-Id: <6jr1ke$gcu$1@nnrp1.dejanews.com>

In article <slrn6lp4mr.glh.arch@abts.net>,
  arch@abts.net wrote:
>
> Original message by: Diane Strahl <jimndi@sgi.net>
> Date: Thu, 14 May 1998 22:29:34 GMT
> Subject: perl text editor for windows95
>
> > Can someone recommend a good, easy-to-use text editor to use for writing
> > perl programs on windows95? I used bbedit on a friend's mac, which is
> > the sort of thing I'm looking for. I've looked at vim and emacs, but
> > they seem more complicated than what I want. Are they worth spending the
> > time to learn? What are the advantages of these? Anything out there with
> > pull-down menus rather than having to memorize all the commands which
> > need to be typed in? Right now I'm using the basic windows95 text
> > editors - notepad and wordpad. It'd be nice to use something that at
> > least had syntax coloring.

I'd go for Homesite.  http://www.allaire.com/

I use it for all my PERL programming as well as my HTML.  It's not really
going to color your PERL, but it has enough features to make up for it.
There's a free version available.

-Matt
http://www.geniusweb.com/

>
> BoxerTKO
>
> --
> Shaun L. Sides			arch@abts.net
> Business web site		http://www.abts.net/~arch
> Showershoe web site		http://www.abts.net/~arch/showershoe
> Recreational web site		http://sara.mmlc.nwu.edu/~arch
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 19 May 1998 04:33:39 GMT
From: cpj1@visi.com (Chris Josephes)
Subject: Q: ICMP Ping module?
Message-Id: <DY781.579$DJ5.2577688@ptah.visi.com>

I looked briefly in the CPAN documentaion for Net::Ping and it said that
this module used a UDP connection to reach a remote server, and not ICMP,
so it didn't necessarily function like the ping command.

Is there another Perl module out there that uses ICMP?  Or is the
Net::Ping module "good enough" to handle most needs?

-- 
-----------------------------------------------------------------------
Christopher Josephes    | http://www.visi.com/~cpj1 | 84 v30 Magna     
mailto:cpj1@visi.com    |     Recent Vent Riot      |                  
-----------------------------------------------------------------------


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

Date: 19 May 1998 06:46:02 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Q: ICMP Ping module?
Message-Id: <895560818.574545@thrush.omix.com>

Chris Josephes <cpj1@visi.com> wrote:
: I looked briefly in the CPAN documentaion for Net::Ping and it said that
: this module used a UDP connection to reach a remote server, and not ICMP,
: so it didn't necessarily function like the ping command.
:
: Is there another Perl module out there that uses ICMP?  Or is the
: Net::Ping module "good enough" to handle most needs?

	$ping = Net::Ping->new("icmp");

	But you'll need root ID to use it. -You'll note your ping program
	is suid root.  It would be nice if it could just wrap the ping
	program if asked for icmp without being root, but alas it does
	not (which is why I still backtick ping myself for most uses).

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Tue, 19 May 1998 05:08:25 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: RE question
Message-Id: <tmorniniEt6uA2.Mvn@netcom.com>

I spent far too long on this, and was wondering if someone could give
me the "textbook" of why #1 didn't work and #2 did. I've been using Perl
for a couple of years now, and I thought I groked simple REs pretty well.

The quest was matching and extracting the last two domain elements
in an e-mail address to summarize subscribers to a mailing list.

1) This didn't work.

   /(?:@|\.)(.+?)\.(.+?)$/;

2) This did work.

   /.*(@|\.)(.+?)\.(.+?)$/;

When using #1, I was getting greedy matches on the pair of (.+?) but
I thought the ? after the + avoided that behavior!

Any insights from the gurus?

-- Tom Mornini
-- InfoMania


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

Date: Mon, 18 May 1998 23:23:03 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: RE question
Message-Id: <6jr8h5$h3n@hplntx.hpl.hp.com>

[posted and emailed]

Tom Mornini wrote in message ...
>I spent far too long on this, and was wondering if someone could give
>me the "textbook" of why #1 didn't work and #2 did. I've been using
Perl
>for a couple of years now, and I thought I groked simple REs pretty
well.
>
>The quest was matching and extracting the last two domain elements
>in an e-mail address to summarize subscribers to a mailing list.
>
>1) This didn't work.
>
>   /(?:@|\.)(.+?)\.(.+?)$/;
>
>2) This did work.
>
>   /.*(@|\.)(.+?)\.(.+?)$/;
>
>When using #1, I was getting greedy matches on the pair of (.+?) but
>I thought the ? after the + avoided that behavior!
>
>Any insights from the gurus?
>
>-- Tom Mornini
>-- InfoMania

1) 'lr@hpl.hp.com' =~ /(?:@|\.)(.+?)\.(.+?)$/;
Match and discard '@'; $1 = 'hpl'; $2 = 'hp.com';
This is greedy from the left -- matches the '@' then moves ahead; match
and quit.

2) 'lr@hpl.hp.com' =~ /.*(?:@|\.)(.+?)\.(.+?)$/;
Match everything first; then keep backtracking until first match: $1 =
'hp'; $2 = 'com';

Try this also:
3) 'lr@hpl.hp.com' =~ /(?:@|\.)([^.]+)\.([^.]+)$/;
Match @ and fail; match first '.' and succeed: $1 = 'hp'; $2 = 'com';

Moral:  Be as explicit as you can about what you want to match.

--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com





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

Date: Tue, 19 May 1998 02:09:04 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: RE question
Message-Id: <35612200.9D312CF6@negia.net>

Tom Mornini wrote:

[SNIP]

> 
> The quest was matching and extracting the last two domain elements
> in an e-mail address to summarize subscribers to a mailing list.
> 
> 1) This didn't work.
> 
>    /(?:@|\.)(.+?)\.(.+?)$/;
> 
> 2) This did work.
> 
>    /.*(@|\.)(.+?)\.(.+?)$/;
> 
> When using #1, I was getting greedy matches on the pair of (.+?) but
> I thought the ? after the + avoided that behavior!
> 
> Any insights from the gurus?

no guru here, but i can hopefully offer some insight. for instance the
following script (using your exact RE's):

$_ = 'danboo@negia.net';

@parts = /(?:@|\.)(.+?)\.(.+?)$/;
print "@parts\n";

@parts = /.*(@|\.)(.+?)\.(.+?)$/;
print "@parts\n";

yields:

negia net
@ negia net

it seems to be doing what you want in my estimation. however, i would
probably use something like:

@last2 = (/([^.]+)/g)[-2,-1];

or even:

@last2 = (/([^.]+)/g)[-1,-2];

depending upon how i was going to sort them. and it goes without saying
that this, in no way, attempts to validate the e-mail address. ;-)

hope this helps,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: 19 May 1998 10:13:15 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: regexp: replacing new line followed by "+"
Message-Id: <r8n2cfum3g.fsf@asc.sps.mot.com>

"Lemaitre, Laurent" <r29173@email.sps.mot.com> writes:

> In a text file I want to replace a newline by a space
> only when the newline is followed by a +.

> I tried different options (/s,/m/ and so on) but all failed.

You should show us what you tried.   It seems trivial...

 @File = <FH>;  # slurp in whole file 

 $File = join('', @File);   # get whole file into a string, for substitution

 $File =~ s/\n\+/+/g;  

 print $File;

Of course, you probably wanted to get rid of the +'s as well, but that
is trivial too...

HTH.

Martin.

----------------------------------------------------------------------
-- Martin Gregory <mgregory@asc.sps.mot.com>          |    _--_|\ 
-- Program Manager, Modelling & Cosimulation Program  |   / MASC \ 
-- Motorola Australia Software Centre                 |   \_.-*._/
-- Phone: +61 8 8203 3612, Fax: +61 8 8203 3501       |         v
----------------------------------------------------------------------


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

Date: Tue, 19 May 1998 10:46:38 +0200
From: Heribert Wettels <wettels@respublica.de>
Subject: Something like "Visual Perl"?
Message-Id: <356146EE.6BC2E820@respublica.de>

Has anybody heard about a programming environment for Perl similar to
Visual Basic? Or at least an editor that creates indents and does some
highlighting?

Heribert

--
PGP fingerprint:  4B 68 BF FA B0 81 59 F7  E2 86 5C D2 78 B9 37 28
Public key at: http://www.respublica.de/pgp/wettels-pubkey.txt




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

Date: 19 May 1998 08:19:03 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Startup overhead
Message-Id: <6jrf9n$4ik$1@lyra.csx.cam.ac.uk>

In article <6jf487$gbk$1@nnrp1.dejanews.com>,  <kathryn.nelson@usa.net> wrote:
>Running the Benchmark module showed .83 seconds of cpu time. I imagine
>the other 6 seconds is overhead at start up.  I removed all my "use"
>statements like strict, diagnostics, constant and left only "use CGI;".
>
>Now I'm down to about 3 seconds.

You'll probably find that most of that gain came from removing
"use diagnostics;".   That reads and munges the whole file of error
messages during startup, which is quite expensive.    I'd be very
surprised if the overhead from "use strict;" or "use constant ... "
was measurable.


Mike Guy


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

Date: 18 May 1998 23:39:35 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: translate A-Z to 1-26
Message-Id: <ltaf8fapzc.fsf@asfast.com>

Yary Hluchan <yary@apicom.com> writes:

> This will work for any char set, and upper and lower (feature or bug?)
> 
> # setup
> $c = 1;
> for $a ('a' .. 'z') {
>   $b{$a} = $b{"\u$a"} = $c++;
> }
> 
> # go
> $_="Just another perl hacker,";
> s/([A-Za-z])/$b{$1}/egi;
> print;

But in EBCDIC, the set ('a' .. 'z') contains 41 elements.

 ... or would Perl guarantee 26 elements irrespective of the character
set?


-- 
 Lloyd Zusman   ljz@asfast.com
 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'


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

Date: Mon, 18 May 1998 20:48:09 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: translate A-Z to 1-26
Message-Id: <6jqvec$eeo@hplntx.hpl.hp.com>

Yary Hluchan wrote in message <3560E358.48E5@apicom.com>...
>This will work for any char set, and upper and lower (feature or bug?)
>
># setup
>$c = 1;
>for $a ('a' .. 'z') {
>  $b{$a} = $b{"\u$a"} = $c++;
>}


%b = map { $_, ++$c, uc, $c } 'a' .. 'z'; # One-liner. TMTOWTDI :-)

>
># go
>$_="Just another perl hacker,";
>s/([A-Za-z])/$b{$1}/egi;
>print;

[You don't need either the 'e' or the 'i' in that last substitution.]

Unfortunately, this won't work for *any* char set that doesn't represent
its characters sequentially between 'a' and 'z' (such as EBCDIC, and
Latin-1 sets that include characters in the upper half of the eight-bit
representation).  This is also another problem with the previous regex
approach:

s/([A-Z])/ord($1) - ord('A') + 1/eg;

It was to avoid this kind of insidious A{merican}SCII-isms that C
introduced functions/macros such as isalpha(c) instead of

if ('A' <= (c & 040) && (c & 040) <= 'Z') ...

Gasp.  Several flavors of regex include set specifiers [within square
brackets] such as :letter: to represent isalpha.  The closest Perl can
come, at least now, is:

use locale;
/[^\W_\d]/;

which matches only and all the letters included in \w in the current
locale, but doesn't solve the problem of case distinctions.

On a somewhat brighter note, I know of no character sets in which the
ten decimal digits aren't contiguous and monotonically increasing.  So
[0-9] is safe.  Whew...

--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com





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

Date: 19 May 1998 04:45:02 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: translate A-Z to 1-26
Message-Id: <6jr2oe$514$1@marina.cinenet.net>

Larry Rosler (lr@hpl.hp.com) wrote:
: Replacing the 64 by ord('A') - 1 seems wise.  But your expression has to
: be much more elaborate to work for the EBCDIC character set:

Doh.  That'll teach me to be flip...and to reveal that I've relied on
black-box tools to slurp outre' data for way to long.  You're entirely
correct, of course.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 19 May 1998 00:59:13 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: translate A-Z to 1-26
Message-Id: <lt4symc0v2.fsf@asfast.com>

"Larry Rosler" <lr@hpl.hp.com> writes:

> Yary Hluchan wrote in message <3560E358.48E5@apicom.com>...
> >This will work for any char set, and upper and lower (feature or bug?)
> >
> ># setup
> >$c = 1;
> >for $a ('a' .. 'z') {
> >  $b{$a} = $b{"\u$a"} = $c++;
> >}
> 
> 
> %b = map { $_, ++$c, uc, $c } 'a' .. 'z'; # One-liner. TMTOWTDI :-)

And to work in all character sets, your one-liner could change to
this:

 %b = map { $_, ++$c, uc, $c } split(//, 'abcdefghijklmnopqrstuvwxyz');

> >
> ># go
> >$_="Just another perl hacker,";
> >s/([A-Za-z])/$b{$1}/egi;
> >print;
> 
> [You don't need either the 'e' or the 'i' in that last substitution.]
>
> Unfortunately, this won't work for *any* char set that doesn't represent
> its characters sequentially between 'a' and 'z' (such as EBCDIC, and
> Latin-1 sets that include characters in the upper half of the eight-bit
> representation).  This is also another problem with the previous regex
> approach:
> 
> [ ... remainder (which I agree with) cut to conserve bandwidth ... ]

-- 
 Lloyd Zusman   ljz@asfast.com
 perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2636
**************************************

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