[10467] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4059 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 24 05:04:29 1998

Date: Sat, 24 Oct 98 02:00:20 -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           Sat, 24 Oct 1998     Volume: 8 Number: 4059

Today's topics:
    Re: # url_get.pl 1.15 27 Sep 1995 (Matthew Bafford)
        a question of scope <emills@harris.com>
    Re: a question of scope <emills@harris.com>
    Re: a question of scope (Larry Rosler)
        CGI Help <enyoung@echo-on.net>
        Execute as root <biela@netdienste.de>
    Re: Execute as root <tupshin@tupshin.com>
    Re: From scalar to array to output?? <rick.delaney@shaw.wave.ca>
    Re: interacting with alarm <msholund@wans.net>
    Re: Interpolated, squared? <emills@harris.com>
        io from /bin/sh to perl      (123) <snowe@rain.org>
        Javascript in Perl Problem? (TipTup JHA&HHA)
    Re: Javascript in Perl Problem? <tupshin@tupshin.com>
    Re: Need some guidance w/script <ebohlman@netcom.com>
        newbie help: helpfiles / expect <biela@netdienste.de>
    Re: Perl & Y2K - booby trap code (Mark-Jason Dominus)
    Re: Perl & Y2K - booby trap code (Bart Lateur)
        Perlshop: Invalid transmission #3 (Steve)
        Prevent Stop Service from stopping Perl Script on NT <whubley@mediaone.net>
        Problem in multiple searching <mhko@cs.cityu.edu.hk>
        Regular expressions.. ()
    Re: Regular expressions.. <eashton@bbnplanet.com>
    Re: Scripts <ppopour@infoave.net>
    Re: Single word ouptu from aa array <jakob@gemino.no>
        Sort Methods Compared (Bob N.)
        splitting on . <msholund@wans.net>
        Stranges errors messages <maurerf@post.ch>
    Re: Wanted: programming (humor?) <ismkoehlerism@nmism-us.campus.mci.net>
        where can i put in CGI program ? lyp22@yahoo.com
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 23 Oct 1998 19:55:49 -0400
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: # url_get.pl 1.15 27 Sep 1995
Message-Id: <MPG.109ae18d17f15af49896e1@news.scescape.net>

The following directed to both people in this thread:
=> [snip problems with url_get.pl]

Why not just use LWP?  It works great! :)

#!/usr/bin/perl -w
use LWP::Simple;
print get($ARGV[0]);
__END__

or, for the command-liners:

% perl -MLWP::Simple -we "getprint($ARGV[0]);" http://www.yahoo.com

Hope This Helps!

--Matthew
-- 
# clp died many moons ago.  For a much better chance of getting your
# question or comments noticed, please move your discussions to either
# comp.lang.perl.moderated, or comp.lang.perl.misc.


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

Date: Fri, 23 Oct 1998 10:17:16 -0400
From: "PERL ROCKS!" <emills@harris.com>
Subject: a question of scope
Message-Id: <36308FEC.C211A73@harris.com>

I'm using the famous Brigitte Jellinek perl module formlib.pl which
returns form fields in the %in{} hash. It works great, but I ran into a
snag today that I can't figure out.

I call formlib from the main package, but I find now that %in isn't
visable in external package namespaces from which I call subs. I thought
this would be resolved if I added:

local (%in);

but it appears to have no effect. Is there a means to make %in global to
main as well as all required packages? Of course %in is just an example-
what I'm really asking is how would I make variables that are visable to
main and all subs. "local" sounded like the way to go, but maybe I
didn't use it properly (I used it after the require statement- was that
wrong?)

E



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

Date: Fri, 23 Oct 1998 13:17:05 -0400
From: "PERL ROCKS!" <emills@harris.com>
Subject: Re: a question of scope
Message-Id: <3630BA11.718D82E8@harris.com>

In leiu of a global, I thought hell I'll just pass the hash as a reference
to the sub. Its cleaner anyhow-

After reading man perlmod & perlsub & perlref and screwing with it for like
2 hours, I reconsidered.  How does one pass a hash as a reference to a sub,
along with other values? For example:

  $a=2;
  $b=4;
  %h = ("a","b",1,2);
  mysub ($a,$b,\%in);
   .
   .
   sub mysub ($$\%);
   my %h = $_[2];
   (doesnt work)


PERL ROCKS! wrote:

> I'm using the famous Brigitte Jellinek perl module formlib.pl which
> returns form fields in the %in{} hash. It works great, but I ran into a
> snag today that I can't figure out.



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

Date: Fri, 23 Oct 1998 17:28:02 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: a question of scope
Message-Id: <MPG.109abeebd9cf340d9898db@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <3630BA11.718D82E8@harris.com> on Fri, 23 Oct 1998 13:17:05 -
0400, PERL ROCKS! <emills@harris.com> says...
> ...  How does one pass a hash as a reference to a sub,
> along with other values? For example:
> 
>   $a=2;
>   $b=4;
>   %h = ("a","b",1,2);
>   mysub ($a,$b,\%in);
>    .
>    .
>    sub mysub ($$\%);
>    my %h = $_[2];
>    (doesnt work)

     my %h = %{$_[2]};

should work.  But if you really need a copy of the hash, why not pass it 
directly (prototype not wanted)?

     my ($a, $b, %h) = @_;

If you don't need a copy of the hash, you can always use the reference 
directly:

     $href = $_[2];
     $href->{KEY} = ...

or just:

     $_[2]{KEY} = ...

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 24 Oct 1998 00:30:19 -0400
From: Errol <enyoung@echo-on.net>
Subject: CGI Help
Message-Id: <363157DB.8337C46D@echo-on.net>

I am trying some simple scripts and want to test them on my win 95
desktop before uploading them.

I have Sambar set up but have some problems with it.

What are you all using as a test CGI environment for your scripts?

Errol




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

Date: Sat, 24 Oct 1998 01:17:10 +0100
From: Simon Biela <biela@netdienste.de>
Subject: Execute as root
Message-Id: <36311C86.8B4013DC@netdienste.de>

Hi,

I am new to perl. I wrote a script which should be executed as root.
If I execute it via telnet it works fine, but I'd like to execute it
over a browser. How does that work?

-- 
mit freundlichen Gr|_en

      Simon Biela

________________________________________
   netdienste  - Ihr einfacher Weg ins Internet
   Kirchenhof 4 - 50933 Kvln - Germany
   Tel.: 0221 - 947 30 10 - Fax.: 0221 - 947 30 11
   biela@netdienste.de -  www.netdienste.de


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

Date: 23 Oct 1998 17:40:08 PDT
From: "Tupshin Harper" <tupshin@tupshin.com>
Subject: Re: Execute as root
Message-Id: <70r7l8$l5c@journal.concentric.net>

The steps are as follows:
1) Don't do that
2) Read about tainting data
3) rewrite your script
4) read about suid bits
5) write a c wrapper for your CGI
6) rethink your whole approach.
7) Don't do that

-Tupshin Harper
-Programmer/Network Administrator
-Studio Verso

Simon Biela wrote in message <36311C86.8B4013DC@netdienste.de>...
>Hi,
>
>I am new to perl. I wrote a script which should be executed as root.
>If I execute it via telnet it works fine, but I'd like to execute it
>over a browser. How does that work?
>
>--
>mit freundlichen Gr|_en
>
>      Simon Biela
>
>________________________________________
>   netdienste  - Ihr einfacher Weg ins Internet
>   Kirchenhof 4 - 50933 Kvln - Germany
>   Tel.: 0221 - 947 30 10 - Fax.: 0221 - 947 30 11
>   biela@netdienste.de -  www.netdienste.de




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

Date: Sat, 24 Oct 1998 01:41:20 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: From scalar to array to output??
Message-Id: <363131E0.EE2B2384@shaw.wave.ca>

[posted & mailed]

Rob Bridal wrote:
> 
> How about just putting in this?
> 
> /(...)(...)(....)/;
> print "(".$1.") ".$2."-".$3;

Because it would look so much nicer as
    
    print "($1) $2-$3" if /(...)(...)(....)/;

You should alway check the success of m//.  Otherwise you can't be sure
what $1, etc. might hold.

Also, if you're going to use a regex then you might as well make sure
the phone number is all digits while you're at it.

    print "($1) $2-$3" if /^(\d{3})(\d{3})(\d{4})$/;

This was already suggested.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Thu, 22 Oct 1998 16:49:23 -0400
From: Mark Sholund <msholund@wans.net>
Subject: Re: interacting with alarm
Message-Id: <362F9A53.FA6FEEA8@wans.net>

So will implementing this suggestion solve my problem?

Ala Qumsieh wrote:
> 
> Mark Sholund <msholund@wans.net> writes:
> 
> >
> > while (1)
> > {
> >       $SIG(ALRM) = 'my_timer';
> 
>         This should be $SIG{ALRM} = \&my_timer;
> 
> --
> Ala Qumsieh               email: aqumsieh@matrox.com
> ASIC Design Engineer      phone: (514) 822-6000 x7581
> Matrox Graphics Inc.      (old) webpage :
> Montreal, Quebec          http://www.cim.mcgill.ca/~qumsieh

-- 
in accordance with prophecy.

	"The price of freedom is eternal vigilance."
              	- Admiral Tolwyn (Wing Commander IV)


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

Date: Fri, 23 Oct 1998 07:51:47 -0400
From: "PERL ROCKS!" <emills@harris.com>
Subject: Re: Interpolated, squared?
Message-Id: <36306DD3.7A1559B6@harris.com>

http://www.plover.com/~mjd/perl/varvarname.html  has an interesting article on
this. I like the approach. I asked about it here in this newsgroup and no one
countered so I guess its either accepted or not understood. Warning- the guy
who wrote the page above HATES it!

I use this technique frequently- actually its an old APL trick I learned, and
although its a debugger''s nightmare, it can prove quite effective. If I'm not
mistaken, its not a broadly applied technique, mainly because it's only
possible in interpreted environments. A compiled language which requires
declarations wouldn't allow it, and as many of us came up through the "c"
ranks, they probably never saw it before.

At any rate, here is a statement where I have 0..n global instances of a
variable seln (sel0, sel1, etc..). I think what you're missing is the
concatentation operator "." in your statement.

   for ($i=0;$i<=$in{recs};$i++)
     { if ($in{sel.$i}==1) {$dx += 1;} }

I found that its particularly useful in working with dynamic HTML where arrays
aren't possible.

E

Bill Steer wrote:

> I've just started reading this newsgroup, so apologize if this is a repeat
> question...
>
> How can I perform interpolation on variables in a nested fashion?  That is,
> suppose I have a variable, say $var, that contains a string that contains
> yet other variables (in my case, $1 and $2 after a match operation).  So
> my $var variable may look like "$1something$2".  And now I want to use
> $var in a substitute operation, like s/<something>/$var/, and want the
> $1 and $2 variables to be used.
>
> I've read the FAQs and can't find this, nor can I find it in my books.
>
> Thanks for any help/advice.
>
> B. Steer



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

Date: Fri, 23 Oct 1998 22:03:26 -0700
From: Nick Halloway <snowe@rain.org>
Subject: io from /bin/sh to perl      (123)
Message-Id: <Pine.SUN.4.05.9810232158410.10677-100000@coyote.rain.org>

I'm calling a perl script from a sh script.  I need to pass it a file, 
and get back a couple of character strings.  How would I do this?  
Here is what I tried so far:



#!/bin/sh

TMPFILE=$HOME/Mail/junk

# acknow is the name of the perl script below

acknow $TMPFILE $ACK $ACK_ADDRESS
# $ACK and $ACK_ADDRESS would be strings acknow passes back.





#!/usr/bin/perl5 -w

# how do you access the variables in here?

print "Hi\n";
while (< >) {
    chop;
    print;
print "Hi\n";
}




thanks ...



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

Date: Fri, 23 Oct 1998 17:06:28 -0600 (MDT)
From: TipTup@webtv.net (TipTup JHA&HHA)
Subject: Javascript in Perl Problem?
Message-Id: <21781-36310BF4-50@newsd-113.bryant.webtv.net>

alright I'm having a problem with writing Javascript.

print FILE "<script language=\"Javascript\">\n";
print FILE "function name(){\n";
print FILE "alert(\"This is a test\");\n";
print FILE "}\n";
print FILE "</script>";

for some reason this never works, any type of javascript that requires
quotes breaks the perl script...

Any other method to print to a new file (to save) that I can have the
script still work?


Thanks,
Could you please email me the response?

TipTup@webtv.net



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

Date: 23 Oct 1998 18:03:00 PDT
From: "Tupshin Harper" <tupshin@tupshin.com>
Subject: Re: Javascript in Perl Problem?
Message-Id: <70r904$mf2@journal.concentric.net>

This seems to print out valid JavaScript for me.  Can you tell me what
doesn't work?

Other approaches include(but by no means are limited to):
print FILE <<EOF;
print FILE 'blah"JavaScript blah" more blah";
print FILE q(they don't use parentheses in JavaScript, right?);
print FILE qq&ick&;

May I recommend chapter two of the camel book.

-Tupshin Harper
-Programmer/Network Administrator
-Studio Verso

TipTup JHA&HHA wrote in message
<21781-36310BF4-50@newsd-113.bryant.webtv.net>...
alright I'm having a problem with writing Javascript.

print FILE "<script language=\"Javascript\">\n";
print FILE "function name(){\n";
print FILE "alert(\"This is a test\");\n";
print FILE "}\n";
print FILE "</script>";

for some reason this never works, any type of javascript that requires
quotes breaks the perl script...

Any other method to print to a new file (to save) that I can have the
script still work?


Thanks,
Could you please email me the response?

TipTup@webtv.net





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

Date: Sat, 24 Oct 1998 05:36:50 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Need some guidance w/script
Message-Id: <ebohlmanF1BGxE.FBK@netcom.com>

baillie@my-dejanews.com wrote:

:                 while(<LOG>) {
:                         $/ = '';
:                         print if /\Q$keyword/s;
:                 }

The assignment of the input record separator needs to be moved before the 
loop; as it stands, the first iteration will snag a single line and 
subsequent ones will slurp whole paragraphs.  As a matter of good style, 
you should create a block to contain the assignment, which should be 
localized, and the loop; while it won't make any difference with your 
"perform one function and quit" architecture, in more general cases it 
will save you from having to keep track of what the current input record 
separator is and running into cases where it isn't what you think it is.



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

Date: Sat, 24 Oct 1998 00:34:33 +0100
From: Simon Biela <biela@netdienste.de>
Subject: newbie help: helpfiles / expect
Message-Id: <36311289.7DD54532@netdienste.de>

Hi,

1.) I heard something about the expect module in a german newsgroup. I'd
like to use this, but I don't know where to find the files of this
module. Where can I download them?

2.) I tried to leard more about a certain command in perl, but perldoc
command didn't work. How to look at the helpfiles?
-- 
mit freundlichen Gr|_en

      Simon Biela

________________________________________
   netdienste  - Ihr einfacher Weg ins Internet
   Kirchenhof 4 - 50933 Kvln - Germany
   Tel.: 0221 - 947 30 10 - Fax.: 0221 - 947 30 11
   biela@netdienste.de -  www.netdienste.de


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

Date: 23 Oct 1998 23:04:10 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <70rg3a$d1g$1@monet.op.net>

In article <MPG.109a951cc238f130989838@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <70qqem$auj$1@monet.op.net> on 23 Oct 1998 16:54:46 -0400, 
>Mark-Jason Dominus <mjd@op.net> says...
>> It would have been really easy for people to define their month name
>> arrays with an extra dummy element 0 on the front:
>> 
>> 	@month =qw(Bad Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
>
>Or they might have designed it now -- when my laptop PC has 96M of RAM -
>- instead of then -- when everything had to be crammed into a few dozen 
>*K* on a PDP-11.  

I believe that time.h stuff wasn't designed until sometime around
1980, unless you'd like to correct me.  The waste space is only one
extra array element, a pointer.  That's four bytes; eight if you want
to be fancy and actually include the string "Bad".  What was the cost
of four bytes in 1978 or whenver time.h was invented?

I'll stick with my original assessment, which is that someone was a
little too clever for their own good.



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

Date: Sat, 24 Oct 1998 09:35:27 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <36349d97.3264632@news.ping.be>

Matt Knecht wrote:

>When I went from C
>to Perl, and read through perlfunc, localtime stuck with me, because it
>was exactly what I was used to.  It was nice.  It was easier.  But it
>wasn't the end all be all.

Hah.

Suppose that Larry had indeed used a "corrected" localtime, whicjh did
indeed return the full year, not the year since 1900. *As soon* as you
try out you C-inpired Perl code, you would notice that there's something
wrong with the year.

You then would have through a lot of trouble to turn this year into
something that is Y2K-unsafe. Very few people would actually use
something like ($year-1900) in their code.

As it is now, the year-related behaviour of localtime is just a lurking
Y2K bug waiting to happen over and over again. If a language design
choice is the cause of many (similar) bugs, it is a bad design.

	Bart.


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

Date: Sat, 24 Oct 1998 00:10:13 GMT
From: chubbys@cci-internet.com (Steve)
Subject: Perlshop: Invalid transmission #3
Message-Id: <36311adf.4065664@news.cci-internet.com>

I have Perlshop installed on 2 web sites but 1 location is now
returning an Invalid transmission #3 error thats from my IP address
when I try to enter the script.   After reading previous posts about
this problem I have checked for a PageHits.Lock and Searches.Lock but
they do not exist.  Also have tried setting the $create _page_log and
$create_search_log to "no" to see if that might solve the problem but
without success.  File and directory permissions are set properly.

Any help would be appreciated!


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

Date: Sat, 24 Oct 1998 00:37:24 -0400
From: Walter Hubley <whubley@mediaone.net>
Subject: Prevent Stop Service from stopping Perl Script on NT
Message-Id: <36315984.E40AFC13@mediaone.net>

Hello,

I have written two perl scripts that I run as Services on NT Server 4.0
SP3.  These scripts do stuff and then sleep for 60 seconds, then do
stuff again - and so on...

I'd like to be able to prevent stopping these services while they are
doing stuff and only allow stopping them while sleeping for 60 seconds.

Can this be done?

Thank you.
-- 
Walter Hubley
- One of the worlds foremost amateurs.


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

Date: Sat, 24 Oct 1998 11:27:17 +0800
From: KO <mhko@cs.cityu.edu.hk>
Subject: Problem in multiple searching
Message-Id: <36314915.AE180C85@cs.cityu.edu.hk>

For a text file contains the followings,

 .......
<tr>
<td>Hello
World
</td></tr>
 ......

How can I match the words "Hello World" ?
Do I need to read the whole file into a string before regexp matching ?

Thanks.

KO.



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

Date: 24 Oct 1998 03:27:38 GMT
From: root@delistic.dyn.ml.org ()
Subject: Regular expressions..
Message-Id: <slrn732eq2.46.root@delistic.dyn.ml.org>

Hello, and thank you for reading this message.

I was wondering if anyone knew about an online (preferably HTTP or FTP)
resource that had in-depth documentation about Perl regular expressions.
This seems like the hardest thing I am trying to tackle so far.

Any comments would be greatly appreciated.


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

Date: Sat, 24 Oct 1998 05:03:42 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Regular expressions..
Message-Id: <36315D24.A855C509@bbnplanet.com>

root@delistic.dyn.ml.org wrote:

> I was wondering if anyone knew about an online (preferably HTTP or FTP)
> resource that had in-depth documentation about Perl regular expressions.
> This seems like the hardest thing I am trying to tackle so far.

One comes with perl. Try 'perldoc perlre' from the command line. :)

e.

After all, the cultivated person's first duty is to
always be prepared to rewrite the encyclopedia.  - U. Eco -


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

Date: 15 Oct 1998 20:09:26 GMT
From: "Paul Popour" <ppopour@infoave.net>
Subject: Re: Scripts
Message-Id: <01bdf877$800b1ad0$8db2d886@23dgwpr-p200>



Commitman <commitman@digitalnet.com.br> wrote in article
<6vdr4s$c9t$1@srv4-poa.nutecnet.com.br>...
> Who need perl (and other languages) CGI scripts, try to get in
> 
> www.cgi-resources.com
> www.superscripts.com
> www.cgiresources.com
> 
> Have many good programs (between many shit programs)
> 
> =:-)
> 
> Who want some help: commitman@digitalnet.com.br
> 
> 
> 


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

Date: Sat, 24 Oct 1998 10:14:36 +0200
From: "Jakob V. Nielsen" <jakob@gemino.no>
Subject: Re: Single word ouptu from aa array
Message-Id: <70s2k8$klo$1@elle.eunet.no>

Do it like this:

open (INFILE, "c:\\csv\\cpu_in\\test.txt");
@csvfiles = <INFILE>;
close (INFILE);
foreach $FILESTR (@csvfiles) {
    print $FILESTR;
}


MSmith skrev i meldingen <0%Mx1.338$ML4.1093024@news4.mia.bellsouth.net>...
>Im new to Perl. I'M trying to place a file, a txt file, into an array..then
>print out the first character of the first line..and then the second
>character....etc..but IM having a bit of trouble.  IM only able to print
out
>a line at a time:
>
>open (INFILE, "c:\\csv\\cpu_in\\test.txt");
>@csvfiles = <INFILE>;
>close (INFILE);
>print @csvfiles[0];
>
>
>




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

Date: 24 Oct 1998 00:14:43 GMT
From: bobn@interaccess.com (Bob N.)
Subject: Sort Methods Compared
Message-Id: <70r65j$ou1$1@supernews.com>
Keywords: sort orcish orcache schwartzian

Some postings here on routines for sorting IP addresses got me thinking,
so I did a little (very) testing some of the suggestions and came up with
the following (hope there's nothing dumb here):


($upper_limit = 90)
For 5 Sorts of an an array containing 22500 elements:
 16.44 Orcish_Inline Avg
 16.98 Schwartzian Avg
 18.54 Quazi-Schwartzian Avg
 23.04 Orcish_half_sub Avg
 24.40 Orcish_sub Avg

($upper_limit = 9)
For 50 Sorts of an an array containing 2250 elements:
 12.14 Orcish_Inline Avg
 12.59 Schwartzian Avg
 13.79 Quazi-Schwartzian Avg
 16.80 Orcish_half_sub Avg
 18.00 Orcish_sub Avg

The details of the approaches are shown int the program below.

The orcish inline is the 'or cache(sp?)' approach that someone suggested,
but implemented with no subroutine calls from inside the sort routine. 
This was the fastest.  The original presentation of this called a
subroutine from inside the sort subroutine - this was the slowest tested,
shown as Orcish_sub. Apparently the overhead involved in subroutine calls
is fairly severe.

The remaining routines were a 'quasi-Schwartizian transform', using a map
sort map construct, but not using the array references, as the transform
used to make the values sortable had a simple commutative transform, so I
used that.  Also tested were a 'real' Schwartzian transform and a 'orcish'
mnaeuver that was a hybrid between the fully inline method and the fully
subroutined version.  The hybrid had perfrom nearly as bad as the fully
subroutined version.  The Quasi and Schartzian routines were nearly as
fast as the orcish inline.

My conclusion: 

it's best to minimize the stuff in the sort portion because that will be
repeated many times per list element.  The Schwartzian transform does this
by converting the list to something sortable using a map statement which
will execute the code once per element. 

However, if the thing done during the sort is written to minimize the work
done there,then the orcish maneuver can be the fastest. 

In particular, don't use subroutine calls in the sort. 


The program that generated this is :

#!/usr/local/bin/perl -w
use diagnostics;



$upper_limit = 9;
# upperlimit determines the multiple of 250 ip addresses
$inner_loop = int 450/$upper_limit;

for $Third ( 1..$upper_limit ) {
    $Third = 255 - $Third;
    for (1..250) {
        push(@In, sprintf("255.255.$Third.%d", 255 - $_));
    }
} 


printf 
"For $inner_loop Sorts of an an array containing %d elements:\n", 
scalar @In;

for $sort_sub ( keys(%sort_type)) {
    for (1..5) {
        $Start = time();
        for (1..$inner_loop) {
            &{$sort_type{$sort_sub}};
        }
        $End = time();
        $Delta = $End - $Start;
        # print "$sort_sub = $Delta\n";
        push @Times, $Delta;
    }
    for (@Times) {
        $Avg += $_ ;
    }
    $Avg = $Avg/(scalar @Times);
    printf " %02.2f $sort_sub Avg\n", $Avg;
}

BEGIN {
    $sort_type{"Orcish_Inline"} = sub {
            %Cache = ();
            @Out =
            sort { 
            ($Cache{$a} ||= pack("C4", split('\.', $a)))
                        cmp
            ($Cache{$b} ||= pack("C4", split('\.', $b)))
            } @In;
    };

    $sort_type{"Orcish_half_sub"} = sub {
            %Cache = ();
            @Out =
            sort { 
                ($Cache{$a} ||= pack_split($a))
                            cmp
                ($Cache{$b} ||= pack_split($b))
            } @In;
    };
    sub pack_split {
        $Called++;
        pack("C4", split('\.', shift));
    }
    
    $sort_type{"Orcish_sub"} = sub {
        %Cache = ();
        @Out =
        sort { 
            compare_ips();
        } @In;
    };

    sub compare_ips {
        ($Cache{$a} ||= pack_split($a))
                    cmp
        ($Cache{$b} ||= pack_split($b))
    }

    $sort_type{"Schwartzian"} = sub {
        @Out =
        map  { $_->[1] }
        sort { $a->[0] cmp $b->[0] } 
        map  { [pack("C4", split('\.')), $_] } @In;
    };

    $sort_type{"Quazi-Schwartzian"} = sub {
        @Out =
        map { join('.', unpack("C4",$_) ) }
        sort  
        map { pack("C4", split('\.')) } @In;
    };
}



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

Date: Thu, 22 Oct 1998 16:59:13 -0400
From: Mark Sholund <msholund@wans.net>
Subject: splitting on .
Message-Id: <362F9CA1.F4EE5E11@wans.net>

I have been trying to split a string into parts that are delimited by
periods.  I started by trying split(/./,$IP), but since "." matches
everything, split has no effect.

I have found a way around this by split(/\W/,$IP) (split by
non-alphanumic characters), but what if I wanted to split time such as
"12:00:00.000543" into "12:00:00" and "000543"?  Splitting by
non-alphanumerics will split it into four parts, not two.
-- 
in accordance with prophecy.

	"The price of freedom is eternal vigilance."
              	- Admiral Tolwyn (Wing Commander IV)


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

Date: Sat, 24 Oct 1998 09:36:25 +0200
From: "Felix Maurer" <maurerf@post.ch>
Subject: Stranges errors messages
Message-Id: <70s13k$qs9@gd2inews.swissptt.ch>

Hello all,

Since yesterday, I'm having stranges errors on my system when using perl.
The simple following command is an example:

# perl -e 'print "test";'
use: Command not found.
cnt: Undefined variable.
#

I was developing a small program which contains a use and a variable $cnt,
but I can't explain me why all perl programms are affected by this. And I
also tryed to reboot my system, but it's still the same.

My program looks so at the moment and is producing the same error as above:

# Program start

use lib "/usr/local/lib/perl5";

$cnt     = 0;
@files   = glob("$dir/*.sh");

while ($cnt < @files)
{ $cnt++ ;
  $file = $files[$cnt];
  next if -t $file;
  print ($file);}

ftp_xfer();

sub ftp_xfer {
  my $ftp_host          = "some_node";
  my $ftp_con           = "ftp -in $ftp_host";
  my $ftp_login         = "user username pwd";
  my $ftp_dir           = "ls";
  my $ftp_logout        = "bye";

  use FileHandle;
  STDOUT->autoflush("1");
  STDIN->autoflush("1");

  exec $ftp_con;
  return;
 }

__END__


Any hints on that problem would be greatly appreciated as I cannot use perl
at all at the moment.

Felix




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

Date: Fri, 23 Oct 1998 21:35:16 -0600
From: "Rick K" <ismkoehlerism@nmism-us.campus.mci.net>
Subject: Re: Wanted: programming (humor?)
Message-Id: <70rhtq$6l0$1@news.campus.mci.net>

>stevenjm@olywa.net cryptically writes:
>
> I have encrypted my email address with a secret process I
> developed.  I have done this to ensure only the best and
> brightest will be able to reply.
>
> Reply to:
>
> teveSay ayMay
> tevenmsay@lackwaterbay-acificpay.omcay


I really wanted to reply to you via email, since this sounds like a
fantastic encryption process.  But even though I used a room full
of TI 99/4A computers for 12 hours now, no luck in deciphering
your encryption.  How fiendishly clever!  The only clue I have came
in Run #5,098,445,292, when this spewed out:

"Italnay Ipgay Inay Tisay"

Of course, now you are faced with the moral dilemma of whether
you should market your encryption technique ... did you use
freeware to create it?  =8^)





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

Date: Sat, 24 Oct 1998 04:55:23 GMT
From: lyp22@yahoo.com
Subject: where can i put in CGI program ?
Message-Id: <70rmjr$u0l$1@nnrp1.dejanews.com>

Can any one tell me:
Any free web side that i can put in my own CGI program?
please reply by e-mail
Thank.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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