[11051] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4651 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 14 13:03:25 1999

Date: Thu, 14 Jan 99 10:01:39 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 14 Jan 1999     Volume: 8 Number: 4651

Today's topics:
    Re: Need help with cookies (Abigail)
    Re: NEED SCRIPT BAD!!!!!! (Tad McClellan)
    Re: perl  & cgi books (Bill Moseley)
    Re: Perl Criticism droby@copyright.com
    Re: Perl Criticism droby@copyright.com
    Re: Perl Criticism tiptopmind@my-dejanews.com
    Re: Perl Criticism tiptopmind@my-dejanews.com
        Perl/NT and Long Dir Names?? <rmanno@voicenet.*nospam*.com>
    Re: pipe both in and out (Tad McClellan)
        Question on Perl Faq 9 - Editing .htaccess files <michael@datahost.com>
    Re: Question on Perl Faq 9 - Editing .htaccess files (brian d foy)
    Re: read/write same file (Tad McClellan)
    Re: read/write same file (Larry Rosler)
        reading and returning data from a file <mikeob@itas.net>
    Re: Removing Blank lines (Larry Rosler)
    Re: script produced no output (Tad McClellan)
        Search engine for HTML doc from the distribution. <stefan.nonneman@cec.be>
        sort 2-dim array <astauder@iiic.ethz.ch>
    Re: split question dave@mag-sol.com
        spread rows from a huge textfile? ThorstenBelka@gmx.de
    Re: spread rows from a huge textfile? (Greg Ward)
    Re: Syntax help wanted:  "use strict" and sort $a and $ <aqumsieh@matrox.com>
    Re: warning errors (Greg Ward)
    Re: Way to measure memory / performance hits of script? (Andrew M. Langmead)
    Re: Way to measure memory / performance hits of script? <eugene@snailgem.org>
    Re: Which Perl reference book? <uri@home.sysarch.com>
    Re: Which Perl reference book? <matthew.sergeant@eml.ericsson.se>
    Re: Year 2038 problem (Andrew M. Langmead)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 14 Jan 1999 17:21:37 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Need help with cookies
Message-Id: <77l931$m6r$2@client2.news.psi.net>

Alex Guberman (alex@digi-q.com) wrote on MCMLXII September MCMXCIII in
<URL:news:369D90FF.661B@digi-q.com>:
%% Hi,
%% 
%% I was wondering what is wrong with my script that is suppose to send a
%% cookie if a person comes in for the first time and recognize that person
%% if s/he comes in for the second time:
%% 
%% if(! defined $ENV{'HTTP_COOKIE'})
%% {
%%   print "Content-type: text/html\n"; 
%%   print "Set-Cookie: Cook=Here; path=/cgi-bin/;
%% domain=rec-online.com\n\n";
%%   print "<HTML><BODY>Test Cookies Set</BODY></HTML>";
%%   
%% } else {
%% 
%%   print "Content-type: text/html\n\n";
%%   print "You've already got a cookie";
%% }


Well, it's clear neither "<HTML><BODY>Test Cookies Set</BODY></HTML>"
nor "You've already got a cookie" are valid HTML documents.


Of course, if you have problems with the Perl aspects of your program,
go to a group that deals with perl, sci.crypto for instance. Be sure
not to mention what you expect the script to do, and what it actually
does. 



Abigail


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

Date: Thu, 14 Jan 1999 07:48:33 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: NEED SCRIPT BAD!!!!!!
Message-Id: <hjsk77.14a.ln@magna.metronet.com>

Derk Voss (derk@sonic.net) wrote:
: Tad McClellan (tadmc@metronet.com) wrote:
: :    open(OUT, ">$filename_that_i_can_choose.txt") ||

: open(pleeeeeeaaaassssseeeee, ">$filename_that_i_can_choose.txt") ||

: Desperate times call for desperate filehandles ;-)


   open(PLEEEEEEAAAASSSSSEEEEE, ">$filename_that_i_can_choose.txt") ||


   1) -w clean

   2) screaming makes it more likely that you will receive
      volunteer help

   :-)


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 14 Jan 1999 09:22:20 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: perl  & cgi books
Message-Id: <MPG.1107c7a87c603355989684@nntp1.ba.best.com>

In article <369E2393.93442C03@rational.com>, arogers@rational.com says...
 
> I am just getting started with the web and perl cgi can anybody
> recommend any books on the subject.

The FAQ has some recommendations, but here's mine:

Pick your favorite on-line bookstore and order:

Learning Perl 2nd Edition - Schwartz/Christiansen
Programming Perl 2nd Edition - Wall/Schwartz/Christiansen
Perl Cookbook - Christiansen/Torkington
Official Guide to Programming with CGI.pm - L. Stein.



-- 
Bill Moseley mailto:moseley@best.com


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

Date: Thu, 14 Jan 1999 15:14:58 GMT
From: droby@copyright.com
Subject: Re: Perl Criticism
Message-Id: <77l1l9$361$1@nnrp1.dejanews.com>

In article <slrn79lo34.fmt.sholden@pgrad.cs.usyd.edu.au>,
  sholden@cs.usyd.edu.au wrote:
>
> Damn I posted to this thread... I blaim abigail... that post caused the thread
> to move up a bit (since I am one of the few that enjoys abigail's posts) so
> I actually read a little of it...
>

Wrong.  Everyone enjoys abigail's posts.  Except perhaps some of the hapless
newbies.

> I think I might make the 'I obviously have no life list' from the people who
> have posted to this thread except during the initial 'I didn't realise it
> was a religious nut' period.
>

Looks to me like even the very early responders knew he was a troll.  So we
should all be on your list.  Even Abigail.  Except she only bothered to post
to this thread once.  Perhaps you should establish an 'I obviously have no
life' threshold.

--
Don Roby

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


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

Date: Thu, 14 Jan 1999 16:17:42 GMT
From: droby@copyright.com
Subject: Re: Perl Criticism
Message-Id: <77l5as$6hj$1@nnrp1.dejanews.com>

In article <77hhmt$2om$1@nnrp1.dejanews.com>,
  topmind@technologist.com wrote:

> > Many computer scientists have fallen into the trap of trying to define
> > languages like George Orwell's Newspeak, in which it is impossible to
> > think bad thoughts. What they end up doing is killing the creativity
> > of programming.
> >  -- Larry Wall
>
> Well then I have to disagree with Larry Wall a bit. For one
> he assumes that creativity and cryptology are one in the same.

Not.  Creativity is needed for cryptology but not vice-versa.  Choices are
needed for creativity, and one of the virtues of Perl is, as I'm sure you've
heard, "There's more than one way to do it."  Your insistence on taking out
everything that might be dangerous in the hands of an idiot will lead to a
language in which idiots can program as well as geniuses and neither can
easily accomplish much that's very useful

> Second, I aim to fix the worst 3rd, not the middle or the top.
>
> Actually, I seem to fall somewhere in between the OOPers who
> are anal about protecting everything, and Perlers who think
> saving keystrokes is the ultimate goal.
>

Perlers who think saving keystrokes is the ultimate goal?  Where?  Any of you
guys think that?

--
Don Roby

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


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

Date: Thu, 14 Jan 1999 16:56:49 GMT
From: tiptopmind@my-dejanews.com
Subject: Re: Perl Criticism
Message-Id: <77l7kc$8mj$1@nnrp1.dejanews.com>

In article <77hgnn$1u2$1@nnrp1.dejanews.com>,
  topmind@technologist.com wrote:

>GO TO HELL YOU SICK, LYING CREEP!!!!!!!!!

Now that is not nice.

Sounds like something Howard Stern might say.  Are you a big Howard fan top? 
I know you are interested in UFO's so you must be fascinated with
coincidences too.  Here is an interesting one.

A Bryce Jacobs has a homepage devoted to Howard Stern at
http://ourworld.compuserve.com/homepages/nerdwod/
where he also complains that that his wife gives him grief about the size of
his stomach.

On the home page there is link to a UFO page (containing some javascript
errors).  The link points to:
http://www.geocities.com/Area51/Corridor/5004/ufobs.htm
which includes the the email address: nerdwod@geocities.com.

Wow, nerdwod must be a popular name for it to appear so frequently.

Interestingly topmind has a link to the very same UFO site stating:
My UFO page - written with skeptics in mind.  Interesting.  Man it is a small
world.  I wonder if Bryce knows that topmind says that UFO page is his.
Someone might want to let him know, his email address is:
75041.621@compuserve.com

TipTop


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


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

Date: Thu, 14 Jan 1999 16:56:46 GMT
From: tiptopmind@my-dejanews.com
Subject: Re: Perl Criticism
Message-Id: <77l7k8$8mg$1@nnrp1.dejanews.com>

In article <77hgnn$1u2$1@nnrp1.dejanews.com>,
  topmind@technologist.com wrote:

>GO TO HELL YOU SICK, LYING CREEP!!!!!!!!!

Now that is not nice.

Sounds like something Howard Stern might say.  Are you a big Howard fan top? 
I know you are interested in UFO's so you must be fascinated with
coincidences too.  Here is an interesting one.

A Bryce Jacobs has a homepage devoted to Howard Stern at
http://ourworld.compuserve.com/homepages/nerdwod/
where he also complains that that his wife gives him grief about the size of
his stomach.

On the home page there is link to a UFO page (containing some javascript
errors).  The link points to:
http://www.geocities.com/Area51/Corridor/5004/ufobs.htm
which includes the the email address: nerdwod@geocities.com.

Wow, nerdwod must be a popular name for it to appear so frequently.

Interestingly topmind has a link to the very same UFO site stating:
My UFO page - written with skeptics in mind.  Interesting.  Man it is a small
world.  I wonder if Bryce knows that topmind says that UFO page is his.
Someone might want to let him know, his email address is:
75041.621@compuserve.com

TipTop


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


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

Date: Thu, 14 Jan 1999 10:08:01 -0500
From: "Reno " <rmanno@voicenet.*nospam*.com>
Subject: Perl/NT and Long Dir Names??
Message-Id: <rNnn2.631$pP1.5171887@news2.voicenet.com>

Hi all!

New to PERL. I've written a little utility that deletes files x number of
days old. It works beautifully.... sometimes. I pass in 3 arguments:
Directory, filespec, #days.... IE( C:\Temp "*.LOG" 10). In this case it
works like a charm. However, if I try to use a directory, and I don't know
if it's because it's a LONG DIR or that it contains SPACES, such a
C:\Program Files\Integration Logs\, it simply does not do *ANYTHING*. I have
printed out all the args and they all appear fine.

Here is the code that does the unlinking:

while (defined($nextname = <'${filestodelete}'>)) {
   print "filename $nextname\n";
  $age = (-M $nextname);
  print "$age\n";
  if (int($age) >= $daysold)

  print "$nextname\n";
 unlink ($nextname);
 print LOGFILE "$nextname \n";
        }
}

I imagine the $filestodelete is not being interpretted correctly, but as I
said, when I print it out it looks fine!

I can use some help since I have been banging my head for days over this and
I have given up!

Any tips? Hints? Suggestions?

THANKS!!

RM




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

Date: Thu, 14 Jan 1999 08:31:01 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: pipe both in and out
Message-Id: <53vk77.tba.ln@magna.metronet.com>

Harald Viste (visteh@oslo.geco-prakla.slb.com) wrote:

: What I want is really:
: open(INOUT,"| mycommand |")

: Can anyone tell me how to do this?


   You should check the FAQ before posting.

   That is common courtesy.


   Perl FAQ, part 8:

      "How can I open a pipe both to and from a command?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 14 Jan 1999 09:00:17 -0800
From: Michael Stearns <michael@datahost.com>
Subject: Question on Perl Faq 9 - Editing .htaccess files
Message-Id: <369E223E.4FE2@datahost.com>

Hello:

I read "How do I edit my .htpasswd and .htgroup files with Perl?" in
Perl Faq 9.

I was wondering if there is an alternative to generating an htpasswd
file that does not use PERL modules?

I don't currently have access to install perl modules on this system (or
at least it appears that way, since I get an error when running perl
Makefile.pl).

Thanks,
-- Michael
---------------------------------------------------------
Michael Stearns        		                 Datahost
michael@datahost.com               37540 Wallace Creek Rd
phone: 541-746-6418		    Springfield, OR 97478
fax: 541-746-7176  
pager: 541-718-2752
---------------------------------------------------------


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

Date: Thu, 14 Jan 1999 12:58:37 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Question on Perl Faq 9 - Editing .htaccess files
Message-Id: <comdog-ya02408000R1401991258370001@news.panix.com>

In article <369E223E.4FE2@datahost.com>, michael@datahost.com posted:

> I read "How do I edit my .htpasswd and .htgroup files with Perl?" in
> Perl Faq 9.
> 
> I was wondering if there is an alternative to generating an htpasswd
> file that does not use PERL modules?

you could edit the file directly if you knew what you are doing,
but...

> I don't currently have access to install perl modules on this system (or
> at least it appears that way, since I get an error when running perl
> Makefile.pl).

ahhh, the real problem comes out.  perhaps we should fix that
so you can install and use modules.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: Thu, 14 Jan 1999 08:16:49 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: read/write same file
Message-Id: <h8uk77.tba.ln@magna.metronet.com>

Steen Angelo (angelo@acsoft.dk) wrote:

: Where do I find perlfaq5:

   It comes with the perl distribution.

   If you have a properly installed perl, then the FAQs are
   already on your hard disk somewhere.


   So you find perlfaq5 by searching your hard drive   ;-)


   For the perly challenged, you can get the standard docs from:


      http://language.perl.com/info/documentation.html


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 14 Jan 1999 07:26:13 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: read/write same file
Message-Id: <MPG.1107ac729592897f989989@nntp.hpl.hp.com>

In article <369DC60E.F60B1475@acsoft.dk>, angelo@acsoft.dk says...
> Where do I find perlfaq5:

If you have perl installed on your computer, it is on your hard disk.  If 
you have Internet access, you can find it starting from 
http://www.perl.com/.  If neither of the above, what are you doing in 
this newsgroup? :-)

The FAQs (or at least the list of questions) are well worth reading end-
to-end!

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


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

Date: Thu, 14 Jan 1999 16:06:19 GMT
From: Mike O'Brien <mikeob@itas.net>
Subject: reading and returning data from a file
Message-Id: <369E15F0.107DA8C3@itas.net>

This is a multi-part message in MIME format.
--------------4A2496489AE1A0B0795D6E88
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi everyone.

How can I search a text file for | , return the numeric position, search
for | again,return the position subtract the two and then return the
lenght of the data inbetween the two |'s. Depending on the data's length
I want to read it in to an scalar.

Any ideas?

Seek()
read()?

Mike

--------------4A2496489AE1A0B0795D6E88
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Michael O'Brien
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Michael O'Brien
n:              O'Brien;Michael
org:            Island Tel Advanced Solutions
adr;dom:        57 Fitzroy Street;;;Charlottetown ;Prince Edward Island;;
email;internet: mikeob@itas.net
title:          Business Analyst / EDI Co-ordinator
tel;work:       Toll free 1-877-809-8358
x-mozilla-cpt:  ;-1
x-mozilla-html: TRUE
version:        2.1
end:            vcard


--------------4A2496489AE1A0B0795D6E88--



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

Date: Thu, 14 Jan 1999 07:46:22 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Removing Blank lines
Message-Id: <MPG.1107b12661023f9498998b@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <jm0k77.ji7.ln@magna.metronet.com>, tadmc@metronet.com says...
> Dale Bohl (dbohl@sgi.com) wrote:
> : How do I delete blanks lines from an array?
> 
>    perldoc -f splice

That doesn't sound very helpful.  The arguments to 'splice' are indexes 
and counts, and how would one determine that?  Furthermore, to remove 
several lines that are not contiguous gets one into O(n**2) complexity.

What about 'grep'?

@array = grep length, @array;

if the definition of 'empty line' is no characters, or

@array = grep !/^$/, @array;

if the definition of 'empty line' is no characters or nothing but a new-
line character.

>    although it is probably better to not put them into the
>    array in the first place...

Indeed, but life is not always that simple.

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


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

Date: Thu, 14 Jan 1999 08:50:50 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: script produced no output
Message-Id: <a80l77.tba.ln@magna.metronet.com>

mikael j (mj@alb.se) wrote:
: I get the message "script produced no output " when my gustbook script are


   That message comes from your web server, not from perl.


: going to write to the guestbook HTML-page. It seems like the information
: disappear from the webserver. Can anyone help me with this?


   We can help with Perl problems in the Perl newsgroup.

   But you don't have a Perl problem.

   Try asking in a CGI or server newsgroup:

      comp.infosystems.www.authoring.cgi
      comp.infosystems.www.servers.ms-windows


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 14 Jan 1999 18:12:38 +0100
From: Stefan Nonneman <stefan.nonneman@cec.be>
Subject: Search engine for HTML doc from the distribution.
Message-Id: <369E2572.92B55DAE@cec.be>

Dear all,

I recently installed PERL on my PC (under Windows NT). While working
with it I
find the HTML documentation very good, BUT...

Is there a way to search through the whole doc set ? I was working the
last years
on Sun systems under UNIX, with the 'man xxxx'-command it is possible to
find
the function xxxx in the manpages. Perl being very powerfull, there must
be anywhere a search engine for the HTML documentation installed on my
PC.

As far as I browsed through the doc, I couldn't find any reference to
this type of
engines.

Thanks for the help !

Stefan





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

Date: Thu, 14 Jan 1999 18:29:25 +0100
From: Andreas Stauder <astauder@iiic.ethz.ch>
Subject: sort 2-dim array
Message-Id: <369E2975.71D0D2E0@iiic.ethz.ch>

hi,

can everybody explain me how to sort the columns of a 2-dim array?

for example

4	four	red
2	two	green
3	three	blue
1	one	white

becoms

1	one	white
2	two	green
3	three	blue
4	four	red

thanx batomo


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

Date: Thu, 14 Jan 1999 15:58:02 GMT
From: dave@mag-sol.com
Subject: Re: split question
Message-Id: <77l465$5e3$1@nnrp1.dejanews.com>

In article <Pine.SOL.3.96.990113160519.28504A-100000@ux5.cso.uiuc.edu>,
  Bryan Camp <b-camp@students.uiuc.edu> wrote:
> I'm having a problem using the split command.
> I have a file with the following format:
>
> SRC1=A510I52616300 AMP|52453
>
> I want the output of this line to look like this:
>
> SRC1=A510I52616300_52453|AMP
>
> So what I tried to do was split on " ",
> which gives me SRC1=A510I52616300 as the
> first value in my array and AMP|52453 as the
> second value in my array.  Next, I tried to
> split the second value in the array on "|",
> but this isn't working for me.  I'm not
> sure what's going wrong here.  Any help
> would be greatly appreciated.  The script is
> below, and the output follows.
>
> #!perl -w
> while(<>) {
>
> @array1 = split(" ", $_);
> $source1 = $array1[0];
> $source2 = $array1[1];
>
> @array2 = split("|", $source2);
> $source3 = $array2[0];
> $source4 = $array2[2];
>
> printf "%s_%s|%s\n", $source1, $source4, $source3;
> }
>
> OUTPUT: SRC1=A510I52616300_P|A

#!perl -w
while(<>) {
    chomp;
    my ($one, $two, $three) = split /[| ]/;

    print "${one}_${three}|${two}\n";
}

--
Dave Cross
Magnum Solutions Ltd: <http://www.mag-sol.com/>
London Perl M[ou]ngers: <http://london.pm.org/>

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


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

Date: Thu, 14 Jan 1999 14:58:26 GMT
From: ThorstenBelka@gmx.de
Subject: spread rows from a huge textfile?
Message-Id: <77l0mc$274$1@nnrp1.dejanews.com>

Dear perl community, what4s the most performant way to spread (cut&paste)
rows from a huge (about 250 MB) textfile to several others if different
criteria match? It is important that a row is written to a file only once.


Thank you for all help

Thorsten

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


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

Date: 14 Jan 1999 16:57:58 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: spread rows from a huge textfile?
Message-Id: <77l7mm$8kt$1@news0-alterdial.uu.net>

ThorstenBelka@gmx.de <ThorstenBelka@gmx.de> wrote:
> Dear perl community, what4s the most performant way to spread (cut&paste)
> rows from a huge (about 250 MB) textfile to several others if different
> criteria match? It is important that a row is written to a file only once.

That strongly depends on what your criteria are, and what the most
expensive operation you're worried about is.  If you're doing relatively
cheap things to each line from the input file, then your main concern is
to write each input line only once; however, if you're doing really
computationally intensive things to each line, then you'll probably want
to optimize those a bit in addition to optimizing I/O.

You'll almost certainly be using one of the idiomatic alternatives Perl
provides for a case statement, eg. cascading if/elsif/.../else, or this
common trick:

   LINE:
   while (defined ($line = <INFILE>))
   {
      (write $line to file1), next LINE if ($line meets condition1);
      (write $line to file2), next LINE if ($line meets condition2);
      (write $line to file3), next LINE if ($line meets condition3);
      (write $line to file4), next LINE if ($line meets condition4);
   }

If the various conditions are all expensive and all roughly equally
expensive , you want to put the ones that are met most commonly up front
-- that way, only uncommon lines have to be tested against all the
expensive conditions.

On the other hand, if the cost of testing the various conditions is all
over the map, but you don't really know expect certain conditions to be
met more commonly than others, it makes sense to put the cheap
conditions first, and the expensive conditions later.  That way, not all
lines will be tested against the expensive conditions -- just the ones
that fail the cheap conditions.

Finally, if your conditions are regular expressions, you can definitely
improve their performance by thinking carefully about what they do and
how the regex engine behaves.  The best way to learn how to do this is
to read Jeffrey Friedl's fine book *Mastering Regular Expressions*
(O'Reilly & Associates, ISBN 1-56592-257-3).  It tells you more than you
ever thought you could know about regex engines and performance.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Thu, 14 Jan 1999 10:42:45 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Syntax help wanted:  "use strict" and sort $a and $b parameters...
Message-Id: <x3yg19drhca.fsf@tigre.matrox.com>


posting.account@lookout.com (William Herrera) writes:

> 
> # Is this how this should work in Perl 5.001?

WARNING ... upgrade to a newer version. Check www.perl.com/CPAN for
the latest version.

> # I get an error regarding how $a and $b are
> # defined with "use Strict" here. Why?

I don't get any errors. That's probably a bug in your version of
Perl. Upgrade.

PS. I have perl, version 5.004_04 built for sun4-solaris



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

Date: 14 Jan 1999 16:41:41 GMT
From: gward@thrak.cnri.reston.va.us (Greg Ward)
Subject: Re: warning errors
Message-Id: <77l6o5$80a$1@news0-alterdial.uu.net>

jschueler@detroit.usweb.com <jschueler@detroit.usweb.com> wrote:

> sub warntest {
>   my $handle = shift ;
>   defined $handle or return undef ;
>   while (<$handle>) {
>     ## etc
>     }
>   return "" ;
>   }
> 
> This function must accept the (hard to reference) perl file-handle type, not a
> blessed FileHandle object.

OK, but -- if you "use IO::File" -- you can still treat filehandles as
FileHandle's (except they're called IO::Handle's since 5.003 or so).
That's nor your problem, though.  Also, filehandles aren't really hard
to reference, it's just hard to find out how to do it.  Once you know,
it's a snap:

  open (FILE, $filename) || die "...";
  warntest (\*FILE);

That \*FILE thingy is a "glob reference", which is the canonical way for
passing filehandles around.  AFAIK, you can always treat a glob
reference just like a filehandle or an IO::Handle (or the older
FileHandle) object.  Wish I could refer you to the documentation, but I
honestly can't remember where I learned this trick.  Probably on
USENET...

> when I perform perl -cw on the file containing this subroutine, I get the
> following error:
> 
> Value of <HANDLE> construct can be "0"; test with defined() at display.pm
> line 6 65535.

Imagine if the last line of the file you were reading ended with the
single digit "0", with no newline (eg. a broken text editor created it).
Then <$handle> for that line would return the string "0", which -- as we
all know from our very earliest experiences with Perl -- is a false
value.  Thus, you'd exit the loop without processing the final line of
your file, a bug by most accounts.

The fix is to check that <$handle> is really returning end-of-file, not
an actual string from the file that just happens to be false.  So
instead of using 
   while (<$handle>)

as your loop, use 
   while (defined <$handle>)

I think you'd have to worry about this even if $handle were an
IO::Handle object, except of course you'd say 
   while (defined $handle->getline)

Anyone know what other circumstances this matters under?  I can only
think of one, where the last two characters of a text file are "\n0"
(newline, digit zero).  Err, I guess different patterns would cause
problems depending on the value of $/.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Thu, 14 Jan 1999 15:14:32 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Way to measure memory / performance hits of script?
Message-Id: <F5K2C8.M5z@world.std.com>

"Charles R. Thompson" <design@raincloud-studios.com> writes:

>Is there any way to see what resources my Perl script demands of my
>server while or after running?

For determing the memory used on a Unix system, you might want to use
the "ps" command. For CPU utilization, you can get an overall by using
the "time" command. For a breakdown of where your program spends its
time, there is the Devel::DProf module.

>Is there a maximum ballpark figure in total filesize I should shoot for
>in a coding sense (including scripts, libraries, etc)?

The compilation phase of the perl interpreter is pretty quick. You can
judge that with the "-c" command line flag. What is most often the
problem is the execution time. In Perl, there are so things that might
be inefficient. (The old "enough rope to hang yourself" problem) Off
the top of my head, I can think of things like:

   Doing linear searches through an array to find a specific
   element. (The solution would be to use a hash instead.)

   Overly complex sort subroutines. (The solution is to precalculate
   the data that the sort subroutines needs and have it only perform
   simple comparisons.)

   Passing humungous arrays to subroutines, (You might want to pass a
   reference instead.)

   foreach loops that might be better coded with grep().

   grep() statements that might be better coded with foreach.

And there are a zillion others.
-- 
Andrew Langmead


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

Date: Thu, 14 Jan 1999 10:41:04 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: Way to measure memory / performance hits of script?
Message-Id: <369E1010.BC84648@snailgem.org>

Andrew M. Langmead wrote:
> 
> "Charles R. Thompson" <design@raincloud-studios.com> writes:
> 
> >Is there any way to see what resources my Perl script demands of my
> >server while or after running?
> 
> For determing the memory used on a Unix system, you might want to use
> the "ps" command. For CPU utilization, you can get an overall by using
> the "time" command. For a breakdown of where your program spends its
> time, there is the Devel::DProf module.
> 
> >Is there a maximum ballpark figure in total filesize I should shoot for
> >in a coding sense (including scripts, libraries, etc)?
> 
> The compilation phase of the perl interpreter is pretty quick. You can
> judge that with the "-c" command line flag. What is most often the
> problem is the execution time. In Perl, there are so things that might
> be inefficient. (The old "enough rope to hang yourself" problem) Off
> the top of my head, I can think of things like:
> 
>    Doing linear searches through an array to find a specific
>    element. (The solution would be to use a hash instead.)
> 
>    Overly complex sort subroutines. (The solution is to precalculate
>    the data that the sort subroutines needs and have it only perform
>    simple comparisons.)
> 
>    Passing humungous arrays to subroutines, (You might want to pass a
>    reference instead.)
> 
>    foreach loops that might be better coded with grep().
> 
>    grep() statements that might be better coded with foreach.
> 
> And there are a zillion others.


Maybe not zillions, but here's another big one:

combining backreferences with multiple wildcards in regular expressions


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

Date: 14 Jan 1999 11:30:20 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Which Perl reference book?
Message-Id: <x7btk1hl5v.fsf@home.sysarch.com>

>>>>> "JV" == Johan Vromans <JVromans@Squirrel.nl> writes:

  JV> Uri Guttman <uri@home.sysarch.com> writes:
  b> Programming Perl (2nd Edition)
  b> The Perl Cookbook

  JV> Do not forget the Perl5 Pocket Reference (Camel + Llama).
  JV> http://www.oreilly.com/catalog/perlpr2/.

how can i? i have 3 copies!

but for a newbie it isn't a ncessity IMO. and it is not a true reference
as it is highly condensed. very useful tho!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Thu, 14 Jan 1999 17:31:45 +0000
From: Matt Sergeant <matthew.sergeant@eml.ericsson.se>
Subject: Re: Which Perl reference book?
Message-Id: <369E2A01.9514B006@eml.ericsson.se>

Uri Guttman wrote:
> 
>   JV> Do not forget the Perl5 Pocket Reference (Camel + Llama).
>   JV> http://www.oreilly.com/catalog/perlpr2/.
> 
> how can i? i have 3 copies!
> 
> but for a newbie it isn't a ncessity IMO. and it is not a true reference
> as it is highly condensed. very useful tho!

Can you tell me why I would want the pocket reference? Does it tell you
more than the online docs, or is it just good for reading on the train?

-- 
<Matt email="matt@teamamiga.org" />

| Fastnet Software Ltd              |   Perl in Active Server Pages   |
| Perl Consultancy, Web Development |   Database Design   |    XML    |
| http://come.to/fastnet            |    Information Consolidation    |


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

Date: Thu, 14 Jan 1999 15:37:53 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Year 2038 problem
Message-Id: <F5K3F6.Fwr@world.std.com>

stephen farrell <sfarrell@farrell.org> writes:

>michal@gortel.phys.ualberta.ca (Michal Jaegermann) writes:

>> Once again - applications are not limited to storing time in
>> seconds in time_t format and quite often they do not.  OTOH
>> Unix file systems maintain file time stamps in such way.

>And they do it with 32 bit integers, unfortunately.  This is a
>problem.

Its a problem because people made assumptions about the sizes of
types. Either they assumed a long was 32 bits (where it is only
guaranteed to be as large or larger than an int) or that time_t was 32
bits. (where it is only guaranteed to be an arithmetic type)

There is no reason why OS designers couldn't change the meaning of the
32 bit date field in their current filesystems now. (Something like if
the high bit is set, the other bits contain the number of even seconds
since 1970-01-01) since the current files won't have that bit pattern.

Also, finding where localtime() and gmtime() are used, and if their
return value is used inappropriately (stored into a smaller type or
used in any sort of I/O) is fairly simple and code be done with
automated tools. It would be kind of like perl's taint checking, only
without requiring execution for analysis.

-- 
Andrew Langmead


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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