[10519] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4111 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 30 11:06:55 1998

Date: Fri, 30 Oct 98 08:00:28 -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           Fri, 30 Oct 1998     Volume: 8 Number: 4111

Today's topics:
    Re: Almost Newbie Question. Passing %x and @x to a sub  dave@mag-sol.com
    Re: ANN: "pgrep" = perl grep (clay irving)
    Re: ANNOUNCE:  New Arrival <burt.adsit@gte.net>
        ATM network card question <izzya@nospam.please.notionssys.com>
        Dumping all input to a CGI <c960901@aix5.kbar.dtu.dk>
    Re: Easy Question: Rounding Numbers (Tad McClellan)
    Re: easy way to learn perl? grahams@wpds.com
    Re: eliminating duplicate lines (Hasan Diwan)
    Re: Forcing perl to garbage collect droby@copyright.com
        formatted read in perl <michaelr@lndn.tensor.pgs.com>
    Re: formatted read in perl (Sam Holden)
        Help with memory in Perl <rclark@adc.metrica.co.uk>
        Help: Mail , Mime (Jay)
        List of files to an array... <pete.donina@ketchum.com>
    Re: named arguments <jdporter@min.net>
        newbie needs help with cgi scipt <alpha@alphasys.net>
        newbie needs help with database cgi <alpha@alphasys.net>
    Re: Not to start a language war but.. <li-za.li@ubs.com>
    Re: Not to start a language war but.. <jdporter@min.net>
    Re: Not to start a language war but.. <jdporter@min.net>
    Re: Not to start a language war but.. <jdporter@min.net>
    Re: Not to start a language war but.. <jdporter@min.net>
    Re: Not to start a language war but.. (Andrew M. Langmead)
    Re: pass array to sub (Bart Lateur)
    Re: Perl & Y2K - booby trap code <jdporter@min.net>
    Re: Perl & Y2K - booby trap code <jdporter@min.net>
    Re: Perl exec can't re-write more than one arg? <perlguy@technologist.com>
    Re: Perl exec can't re-write more than one arg? (Sam Holden)
    Re: persistent variables ? (Bart Lateur)
    Re: Python fun <jdporter@min.net>
        Style Guides <arjan.huijzer@capgemini.nl>
        Syntax for use of "new" <bcurran@clariion.com>
    Re: Syntax for use of "new" <tchrist@mox.perl.com>
        Validate a re-formatted script (Melchisedech Bernd)
    Re: Validate a re-formatted script (Tad McClellan)
    Re: Very Large DBM file: Finding Number of keys (Bob Stewart)
    Re: Very Large DBM file: Finding Number of keys (Sam Holden)
    Re: Very Large DBM file: Finding Number of keys <merlyn@stonehenge.com>
        where can I find cgi script for hire <alpha@alphasys.net>
    Re: Why is perl better than shell scripting language? <jdporter@min.net>
    Re: Why is perl better than shell scripting language? <jdporter@min.net>
    Re: Win95 Script Mapping <perlguy@technologist.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 30 Oct 1998 10:21:35 GMT
From: dave@mag-sol.com
Subject: Re: Almost Newbie Question. Passing %x and @x to a sub in a module.
Message-Id: <71c3vd$ao$1@nnrp1.dejanews.com>

In article <363927FB.B207253E@interport.net>,
  Phillip Millman <millman@interport.net> wrote:
> I'm trying without success to do this
>
> $rc = &myFunc($x,\@y,\%z);
>
> sub myFunc {
> # How do I access those variables??

  my ($scalar, $arr_ref, $hash_ref) = @_;

  # You can then access the various parts of the array as
  $arr_ref->[0];

  # and the whole thing as
  @$arr_ref;

  # Similarly for the hash
  $hash_ref->{'key'};
  %$hash_ref;

> }
>
> I'm sure its somewhere in the documentation but I haven't been able to
> figure it out.

perldoc perlsub
perldoc perlref

hth,

Dave...

--
dave@mag-sol.com
London Perl M[ou]ngers: <http://london.pm.org/>
[Note Changed URL]

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


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

Date: 30 Oct 1998 10:18:26 -0500
From: clay@panix.com (clay irving)
Subject: Re: ANN: "pgrep" = perl grep
Message-Id: <71clc2$1ql@panix.com>

In <71agrf$23j$1@bsdti6.sdm.de> Steffen Beyer <sb@sdm.de> writes:

>Where is something comparable to The Perl 5 Module List for
>scripts?

Perl Reference?
http://reference.perl.com

-- 
clay irving
clay@panix.com
http://www.panix.com/~clay/


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

Date: 30 Oct 1998 14:45:22 GMT
From: Burt Adsit <burt.adsit@gte.net>
Subject: Re: ANNOUNCE:  New Arrival
Message-Id: <71cje2$mvc$0@205.138.137.51>

No, no, no. Not *sink*, warp. Time warp.

Tad McClellan wrote:
> 
> Daniel Grisinger (dgris@rand.dimensional.com) wrote:
> : Hannah Elizabeth Grisinger entered the world at
> : 5:45 am, 29 October 1998.  She weighed 6 lbs, 15 ozs.
> : and was 19 inches long.
> 
> : Mother and daughter are recuperating in the hospital,
> : father is delirious with joy :-).
> 
>    Sorry to see you leaving c.l.p.misc.
> 
>    I've enjoyed reading your postings.
> 
>    The Time Sink has been delivered  ;-)
> 
>    Congratulations!
> 
> --
>     Tad McClellan                          SGML Consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas

-- 
Burt Adsit
http://www.featurefarm.com
lat n43.10' lon w86.2'
"Spam is an amusing artifact of our connectivity."


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

Date: Fri, 30 Oct 1998 08:22:04 -0600
From: "Izzy Aala" <izzya@nospam.please.notionssys.com>
Subject: ATM network card question
Message-Id: <71chu7$hn7$1@eve.enteract.com>

Hi,

I am about to start a project where I am going to connect two ATM interface
cards to the same computer with a crossover UTP cable (for
simulation/development purposes) running Windows NT.  My question to the
group is, could I use Perl to do the job of communicating between the two
cards?  In other words, would I be able to send out an ATM packet out one
card and receive it from the other?

Thanks in advance,

Izzya@notionssys.com






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

Date: Fri, 30 Oct 1998 14:40:18 +0100
From: Morten <c960901@aix5.kbar.dtu.dk>
Subject: Dumping all input to a CGI
Message-Id: <Pine.A41.3.95.981030143659.20506B-100000@aix5.kbar.dtu.dk>


Hi

I can understand that use of CGI.pm is encouraged. Well, the server
I need to put my scripts on has some early version of Perl 5 that
doesn't seem to support this, instead I use require("cgi-lib.pl");

When such libraries/modules are used, is there a way to still 
check all the data that is sent to the script? Like when you
use read(STDIN,$buffer,... you can write the buffer to a file
"as is". I need to look at all the input to the script, something is
rotten somewhere and I'm lost.

Thanks

Morten



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

Date: Fri, 30 Oct 1998 08:59:40 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <s8kc17.g8u.ln@flash.net>

Tad McClellan (tadmc@flash.net) wrote:
: Alistair Calder (webmaster@topproducer.com) wrote:


: : I read through the manpages for both, but I got nothing out of how to format
: : variable $example so that it will round like this: xx.x 


:    printf "%4.2f\n", $_;  # min field width of 4, 2 decimal places


   Duh... Make that:

     printf "%4.1f\n", $_;  # min field width of 4, 1 decimal place


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


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

Date: Fri, 30 Oct 1998 15:10:43 GMT
From: grahams@wpds.com
Subject: Re: easy way to learn perl?
Message-Id: <71cktj$naf$1@nnrp1.dejanews.com>

In article <3638c49c.0@d2o204.telia.com>,
  "Bibliotek" <olavskolen.bibliotek@hl.telia.no> wrote:
> is it any web sites wher newbies can learn peral eas`?
> whgat is stronges off java script and perl sdscript
>
>

One thing that helped me when I was learning (sorry - starting to learn Perl)
was ActiveState's Perl Debugger which you can try out for a month free of
charge - the book 'Learning Perl' by Randal Schwarz is very good too.

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


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

Date: 30 Oct 1998 14:04:54 GMT
From: hdiwan@diwanh.stu.rpi.edu (Hasan Diwan)
Subject: Re: eliminating duplicate lines
Message-Id: <71ch26$vr0$1@newsfeeds.rpi.edu>

westi@leland.stanford.edu wrote:
>I am trying to open a webserverlog file and read in all the data to a new
>file The problem I'm having is eliminating all of the lines which are
>duplicates. If anyone could give me a few tips, I would really appreciate
>it.

Just have the old lines piped to STDERR and the new ones sent to your file 
handle.
-- 
Hasan Diwan


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

Date: Fri, 30 Oct 1998 14:49:44 GMT
From: droby@copyright.com
Subject: Re: Forcing perl to garbage collect
Message-Id: <71cjm8$ktm$1@nnrp1.dejanews.com>

In article <715fu9$dae$1@mathserv.mps.ohio-state.edu>,
  ilya@math.ohio-state.edu (Ilya Zakharevich) wrote:
> [A complimentary Cc of this posting was sent to
> <droby@copyright.com>],
> who wrote in article <715bvq$hhc$1@nnrp1.dejanews.com>:
> > > > I was curious too, so I tried it.  No go.  In fact, it shows up twice
with
> > or
> > > > without the clearing attempt.  If you substitute $i = 'abc123' for $i =
`cat
> > > > z.in`, it reduces to one, so I guess one of them is a temporary copy
created
> > > > by the ``.
> > >
> > > Correct.  Temporaries are not touched (until reused, or interpreter
> > > dies).  But even if reused or forgotten, the string buffer is just
> > > free()ed or realloc()ed, which does not guarantie anything.
> > >
> > > > It might be that the s/./\0/g clears it but creates another
> > > > temporary copy in the process.
> > >
> > > No, it should not.  An optimization should be triggered, and no new
> > > memory is going to be allocated.
> > >
> >
> > Well then.  Something's holding onto the value.  At least in Perl5.00401.
>
> Yes.  But you correctly (IMO) determined who: the temporary of ``.
>

No.  There's another copy somewhere.  As noted in the previous message,
eliminating the `` leaves one copy.

--
Don Roby
droby@copyright.com

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


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

Date: Fri, 30 Oct 1998 12:21:30 +0000
From: Michael Renshaw <michaelr@lndn.tensor.pgs.com>
Subject: formatted read in perl
Message-Id: <3639AF4A.2008@lndn.tensor.pgs.com>

does anyone know how to emulate a formatted read from C eg. fscanf
in perl. I normally use split but i have a file where one column
is right up against another column so split will treat these as one
but if i had a formatted read between column numbers this would be
OK. perhaps i can use split with a format string ???

any ideas ?

thanx

Mike


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

Date: 30 Oct 1998 12:51:08 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: formatted read in perl
Message-Id: <slrn73jdhs.6lk.sholden@pgrad.cs.usyd.edu.au>

On Fri, 30 Oct 1998 12:21:30 +0000, Michael Renshaw
	<michaelr@lndn.tensor.pgs.com> wrote:
>does anyone know how to emulate a formatted read from C eg. fscanf
>in perl. 

The unpack function...

perldoc -f unpack
perldoc -f pack (for the format encoding information)

-- 
Sam

People get annoyed when you try to debug them.
	--Larry Wall


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

Date: Fri, 30 Oct 1998 10:07:29 -0000
From: "Rob Clark" <rclark@adc.metrica.co.uk>
Subject: Help with memory in Perl
Message-Id: <909742053.12937.0.nnrp-05.c246a7ae@news.demon.co.uk>

Hi everyone,

Sorry if this has been asked before or is in a FAQ.

I've got a program that runs fine with small inputs but falls over with a
135mb core file when run under greater loads. I'm assuming that what we have
here is a memory leak of some sort.

I didn't write the code so I'm not in a good position to debug it without
help. What I'd like to know is whether there is a way I can see how Perl's
internal usage of memory is going as the program executes and maybe track
down the part that is causing the problem. Also anything that can flag data
that is not being reused by the garbage collector for whatever reasons would
be an enormous help.

Many thanks for any suggestions

Rob





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

Date: Fri, 30 Oct 1998 15:46:54 +0000
From: "Jhirley (Jay) Fonte" <JFonte@TNetC.Net>
Subject: Help: Mail , Mime
Message-Id: <3639DF6E.6A0AF4D3@TNetC.Net>

I am trying to send out an HTML form from a perl script, using good old
plain mail , ie  # mail $emailaddress -s $subject  < file..  ,,,
contents of file below.  Now what I get is the text listed below,  but
if edit the message before reading it and remove the blank line after
subject I get HTML.. How can I not send that blank line.  .


Please Give a guy a hand , or an Faq , even a URL

Thanks

-Jay



file
______________________________________________________________________
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
<TABLE BORDER COLS=1 WIDTH="100%" NOSAVE >
<TR>
<TD>test</TD>
</TR>
</TABLE>
</HTML>

______________________________________________________________________
Message As Text
______________________________________________________________________

Sender: jfonte
Message-ID: <3639D614.3F5D901D@TNetC.Net>
Date: Fri, 30 Oct 1998 15:07:00 +0000
From: "Jhirley (Jay) Fonte" <JFonte@TNetC.Net>
Organization: http://www.TNetC.Net
X-Mailer: Mozilla 4.04 [en] (X11; I; Linux 2.0.35 i686)
MIME-Version: 1.0
To: jfonte@tnetc.net
Subject: (no subject)
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
&nbsp;
<TABLE BORDER COLS=2 WIDTH="100%" NOSAVE >
<TR>
<TD>test</TD>

<TD>test</TD>
</TR>
</TABLE>
&nbsp;</HTML>

______________________________________________________________________
Message As HTML
______________________________________________________________________
 Sender: jfonte
Message-ID: <3639D614.3F5D901D@TNetC.Net>
Date: Fri, 30 Oct 1998 15:07:00 +0000
From: "Jhirley (Jay) Fonte" <JFonte@TNetC.Net>
Organization: http://www.TNetC.Net
X-Mailer: Mozilla 4.04 [en] (X11; I; Linux 2.0.35 i686)
MIME-Version: 1.0
To: jfonte@tnetc.net
Subject: (no subject)
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
&nbsp;
<TABLE BORDER COLS=2 WIDTH="100%" NOSAVE >
<TR>
<TD>test</TD>

<TD>test</TD>
</TR>
</TABLE>
&nbsp;</HTML>






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

Date: Fri, 30 Oct 1998 09:55:41 -0500
From: Pete Donina <pete.donina@ketchum.com>
Subject: List of files to an array...
Message-Id: <3639D36D.B4D6AAB5@ketchum.com>

I am lookling for an easy way to get a directory structure (path and
filename) into an array.  I can do with a FOR loop and a GLOB but, it
seems kind of slow.  I'm using Perl 5 on NT.


Thanks.



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

Date: Fri, 30 Oct 1998 09:45:48 -0500
From: John Porter <jdporter@min.net>
Subject: Re: named arguments
Message-Id: <3639D11C.F69B686C@min.net>

Jason Orendorff wrote:
> 
> > Unless you are like me, and write functions that can accept a
> > myriad of named arguments.
> >
> > $result = some_function  parameter1 => value1,
> >                          parameter2 => value2,
> >                          parameter3 => value3,
> >                          parameter4 => value4;
> 
> This type of syntax might be annoying in Perl; I guess that's one
> reason Perl doesn't have it. 

It would be annoying IFF Perl didn't have it.
But it does, so it isn't.


> I bet it's more fun to write that function in Python 

More generally, I bet it's more fun to write that function in a language
one knows.


> (since Python has named arguments as an actual language feature.)

I'm not sure what that buys you, when the language already supports
dictionaries/hashes as first-class objects.

John Porter


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

Date: Fri, 30 Oct 1998 09:48:05 -0500
From: E-Mail Transponder <alpha@alphasys.net>
Subject: newbie needs help with cgi scipt
Message-Id: <3639D1A5.E3DD9391@alphasys.net>

--Ooops forgot to send message here it is:

Can anyone help, I am very new to Perl5 and CGI scripting.

We need a script that outputs selected database information.

I hope this explain what we are trying to do:

We are a long distance calling card company and would like to offer
on-line service to our clientele
(both existing clients and new).

When someone purchase a calling card, what they are actually purchasing
is an authorized number
code that can found on the back of the card (the cards come in different
monetary denominations
such as $5, $10, $20, etc.).  What we would like to do is have a way of
putting some this number
into a database (that we can modify on our end), so that when some
purchase calling cards that they
will receive an authorized code for each of quantity cards they
purchased.


     i.e.: a client purchases five $10 calling cards and one $20 calling
card, at the end of his
     transaction they would receive six authorized codes (that
corresponds to actual calling card
     that we would send out to them later).


Since we can not have any client with the same authorized codes, each
result must be different.
Additionally we have way of tracking which codes been given out (either
by e-mail or additional html
page storage).

We are on a WIN95 platform later to uploaded to a NT server.

Because we are behind in our timeframe we would consider just paying for
the script but prefer to write it ourself so that we can make adjustment
when needed.

I would appreciate any help.

--Janice




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

Date: Fri, 30 Oct 1998 09:45:45 -0500
From: E-Mail Transponder <alpha@alphasys.net>
Subject: newbie needs help with database cgi
Message-Id: <3639D118.7300FF35@alphasys.net>





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

Date: Fri, 30 Oct 1998 13:37:00 +0100
From: LIN Li <li-za.li@ubs.com>
Subject: Re: Not to start a language war but..
Message-Id: <3639B2EC.848D8898@ubs.com>

Just curious, can someone show me how to create all these routines for a
class using another routine in Python? (Do you need these things for a
Python class at all?) Code similar to these should never happen in a
highlevel __Elegant__ language like Python. The result may persue me to
use python (JPython) for my next big project.

Thanks.

Lin

Walter Tice USG wrote:
> 
 In article <718rsc$ctn$1@client3.news.psi.net> abigail@fnx.com writes:
 >Zenin (zenin@bawdycaste.org) wrote on MDCCCLXXXV September MCMXCIII in
 ><URL:news:909623452.948196@thrush.omix.com>:
 >++ Dave Kirby <dkirby@bigfoot.com> wrote:
 >++
 >++     From my current (blagh) Java project:
 >++
 >++     public StringBuffer append (boolean bool)   {
extractStringBuffer().append (bool); type = STRING; return string; }
 >++     public StringBuffer append (char     ch)    {
_extractStringBuffer().append (ch);   type = STRING; return string; }
 >++     public StringBuffer append (int     num)    {
_extractStringBuffer().append (num);  type = STRING; return string; }
 >++     public StringBuffer append (long    num)    {
_extractStringBuffer().append (num);  type = STRING; return string; }
 >++     public StringBuffer append (float   num)    {
_extractStringBuffer().append (num);  type = STRING; return string; }
 >++     public StringBuffer append (double  num)    {
_extractStringBuffer().append (num);  type = STRING; return string; }
 >++     public StringBuffer append (Object  obj)    {
_extractStringBuffer().append (obj);  type = STRING; return string; }
 >++     public StringBuffer append (String  str)    {
_extractStringBuffer().append (str);  type = STRING; return string; }
 >++     public StringBuffer append (char[]  data)   {
_extractStringBuffer().append (data); type = STRING; return string; }


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

Date: Fri, 30 Oct 1998 09:49:21 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Not to start a language war but..
Message-Id: <3639D1F1.EDB0192A@min.net>

Zenin wrote:
> 
> John Porter <jdporter@min.net> wrote:
> :   sub Widget::new { bless {} }
> 
> Since the object is now blessed into package main::, it will never
> search @Widget::ISA to find Frob or borrow any of Frob's methods.

Actually I didn't mean to focus on the semantics of constructors;
but to show how the 'package' word is not necessary to get Perl
objects.

John Porter


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

Date: Fri, 30 Oct 1998 09:54:01 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Not to start a language war but..
Message-Id: <3639D309.264873E@min.net>

[ comp.lang.python removed.]

Zenin wrote:
> 
> BTW, would you happen to have copies of the source for versions
> 1, 2, and 3?  I'd like to have them around for such historical
> testing.

They're archived somewhere on the net; I recently downloaded
version 1 to try out.  Unfortunately it died a grodious death
during the early stages of compilation.  Maybe my compiler doesn't
support Pure, Original, Authentic K&R C.

John Porter


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

Date: Fri, 30 Oct 1998 09:55:58 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Not to start a language war but..
Message-Id: <3639D37E.22E794C2@min.net>

Austin Schutz wrote:
> 
> perl -ne 's/#.*//g;print';

Shouldn't that be

	perl -pe 's/#.*//g'

???

John Porter


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

Date: Fri, 30 Oct 1998 10:12:24 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Not to start a language war but..
Message-Id: <3639D758.FF19EE4D@min.net>

Uri Guttman wrote:
> 
> even though i can make my editor wider than 80 columns i fnd that is a
> good width to keep for reading and writing anything including code. long
> code lines even when visible and not wrapped are annoying to me to read.

That is a good point, and reminds of the fact that newspapers long ago
discovered that reading speed is higher for narrower columns (to a point,
I assume).  Too much horizontal eye motion is difficult|stressful|slow.

John Porter


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

Date: Fri, 30 Oct 1998 15:16:19 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Not to start a language war but..
Message-Id: <F1nBr7.MDw@world.std.com>

gorilla@elaine.drink.com (Alan Barclay) writes:

>Therefore I deduce that perl has had exceptions since day 1, or at least
>at the patch level I have (perl v1.0.1.3 Patch level 10).

I remember once looking around various comp.sources.unix archives for
older versions of perl one of the patches for perl1 said something
like "I finally found a reason to want an eval function".

Ok, so I searched around a bit and found
<URL:ftp://ftp.uu.net/usenet/comp.sources.unix/voluem13/perl/patches6-10.Z>
and found this descritption included in patch #8.

>Subject: perl 1.0 patch #8
>Message-ID: <1174@devvax.JPL.NASA.GOV>
>Date: 28 Jan 88 19:44:05 GMT
>[other headers deleted]
>Description:
>	I didn't add an eval operator to the original perl because
>	I hadn't thought of any good uses for it.  Recently I thought
>	of some.  Along with creating the eval operator, this patch
>	introduces a symbolic debugger for perl scripts, which makes
>	use of eval to interpret some debugging commands.  Having eval
>	also lets me emulate awk's FOO=bar command line behavior with
>	a line such as the one a2p now inserts at the beginning of
>	translated scripts.

So eval hasn't been in there since "day 1", but awfully close.



-- 
Andrew Langmead


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

Date: Fri, 30 Oct 1998 13:26:39 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: pass array to sub
Message-Id: <363da6b1.14289288@news.ping.be>

Randal Schwartz wrote:

>Typing optimization:
>
>  join " ", @foo
>
>is easier typed as
>
>  "@foo"

Note that the result depends on the special variable $" (default is a
space).

Actually, Randal, I KNOW you know that, but any newbies stumbling over
this thread, might not. They do now. :-)

	Bart.


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

Date: Fri, 30 Oct 1998 10:16:38 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <3639D856.D3E4BA6A@min.net>

Zenin wrote:
> 
> John Porter <jdporter@min.net> wrote:
>         >snip<
> : There can be no reason to use => in a construction like
> :       push @array => $item
> : other than sheer (attempted) cuteness.
> 
> Same for:
> 
>   bless $self => 'Class';

No, that's NOT the same.  At least in this case, the arrow kinda
makes sense: your blessing the object into the class.
With the push, and various other cases, the arrow simply makes
no sense at all, even if the code executes as indended.


> Or how about:
>   $HashObject->addElement ($name => $value);

What's wrong with that?  That is the definitive canonical
example (IMHO) of when to use =>.

-- 
John "Throbblefoot" Porter

Please Don't "Courtesy CC" me.
I read this newsgroup fanatically.  You know that!
("Emailed only" is fine, though.)

"The people at the Grey Hotel
  Are either aged or unwell." -- EG


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

Date: Fri, 30 Oct 1998 10:18:18 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <3639D8BA.E6B13D32@min.net>

Matt Knecht wrote:
> 
> John Porter <jdporter@min.net> wrote:
> >There can be no reason to use => in a construction like
> >
> >       push @array => $item
> >
> >other than sheer (attempted) cuteness.
> 
> Besides, 'push @array => $item' looks backwards to me. ... 

Gee, you're quick.  That was my entire point.
It is misguided to try to use => anywhere and everywhere 
it can possibly be used.

-- 
John "Throbblefoot" Porter

Please Don't "Courtesy CC" me.
I read this newsgroup fanatically.  You know that!
("Emailed only" is fine, though.)

"The people at the Grey Hotel
  Are either aged or unwell." -- EG


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

Date: Fri, 30 Oct 1998 12:31:43 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: Perl exec can't re-write more than one arg?
Message-Id: <3639B1AF.E142A781@technologist.com>

Sam,

I don't know if you want your program to exit, but with the "exec"
function in Perl that is exactly what happens.  Exec runs the specified
program and NEVER returns.

If you want to stay in your Perl program, take a look at the "system"
command or the back-ticks `` or even qx

Good luck!
Brent
-- 
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: 30 Oct 1998 13:02:02 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Perl exec can't re-write more than one arg?
Message-Id: <slrn73je6a.6lk.sholden@pgrad.cs.usyd.edu.au>

On Fri, 30 Oct 1998 12:31:43 GMT, Brent Michalski
	<perlguy@technologist.com> wrote:
>Sam,
>
>I don't know if you want your program to exit, but with the "exec"
>function in Perl that is exactly what happens.  Exec runs the specified
>program and NEVER returns.

If you read the subject then maybe that was what the original poster asked
for... 

I assume if the original poster wanted system they would have asked for
system, if not then they will discover the problem the first time they
test their script, and most probably know the solution anyway.

>
>If you want to stay in your Perl program, take a look at the "system"
>command or the back-ticks `` or even qx

You forgot to mention fork...

-- 
Sam

So I did some research. On the Web, of course. Big mistake...
	--Larry Wall


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

Date: Fri, 30 Oct 1998 11:22:03 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: persistent variables ?
Message-Id: <36399988.10920133@news.ping.be>

_Paul Coleman wrote:

>Is there a way to have persistent variables (or information) across Web
>Pages?

Now that all the commotion has settled down a bit, I'll take a stab at a
possible solution. :-)

I'll be brief on the CGI side.

First, try adding some more data in the URL, as if the script's name was
a mere directory. Try looking at your environment variables on the CGI
side, and see if you can get it there. Especially watch out for
$ENV{PATH_INFO}. If you're lucky, the extra data in the URL should be
there.

If that works, you must generate a unique session ID, and the first
time, redirect the browser to the URL with this session ID appended.

That's all for CGI. Now the Perl side.

I wouyld stay away from "real" dB's, unless they can actually be kept
running in the background. They'd take forever to start up.

You can try out the Data::Dumper module, but I wouldn't use it for
"real" work. It's not very fast for frequently run code, and it's not
too taint safe. You're writing code in a *data* file, and execute it
next time? ANY hacker can overwrite that data file -- it needs to be
world writable -- with his own Perl code, and next time this code will
be executed. Urgh.

My solution is a simple text, tab delimited, data file, one per session.

I'd create a special directory for sessions, and create small data files
in this sessions directory. A session ID is valid if the equivalent
session file exists. (The file may have a slightly different name than
the session ID). Either delete older session files, or check for the
file's age as well.

You don't really want to store ALL the variables, do you? So, put
everything you want to keep in a hash. I called mine %session. Save the
hash in the session file, and read it back next time.

Here is simple code that does this, using a tab delimited text file. The
most difficult part of the code is related to the file locking; I hope I
got it right. :-)

  sub sessionValues {
	my($sessionfile) = @_;
	-e $sessionfile && -M $sessionfile < 4/24 or return (); 
	# under 4 hours
	my %session;
	local($/) = "\n";
	local(*SESSION);
	open(SESSION,$sessionfile) or return ();
	flock(SESSION,2);
	my %session = map { split/\t/,$_,2 } <SESSION>;
	close SESSION;		
	return (%session, file => $sessionfile );
	# this returns at least one key in the hash,
	# to distinguish it from the errorcase ().
  }

Saving the data is even simpler:

  sub saveSession {
	my($sessionfile,%session) = @_;
	local(*SESSION);
	open(SESSION,"+>>$sessionfile") or return undef;
	flock(SESSION,2); seek SESSION,0,0; truncate $sessionfile,0;
	local($\,$,) = ("\n","\t");
	foreach (sort keys %session) {
		print $_,$session{$_};
	}
	close SESSION;
	return 1;
  }


The limitation with this code, is that you can only save scalars, not
arrays or hashes, and that the values can not contain newlines. (Note
that tabs are maintained.)

Both limitations can be worked around. Actually needed tabs, in real
data is very rare. Therefore, you can save hashes and arrays by
splitting the scalar value on tabs. (Watch out for odd numbers of fields
for hashes.) This still has the limitation that key names for scalars,
hashes and arrays must be unique.

If you need it, you can encode actual tabs, newlines and backspaces by
replacing them with the strings '\t', '\n' and a double backslash (to
distinguish a tab from the string '\t'):

	my %replace = ( "\t" => '\t', "\n" => '\n',
		"\\" => "\\\\");
	s/([\t\n\\])/$replace{$1}/g;

and back:

	my %replace = ( 't' => "\t", 'n' => "\n",
		"\\" => "\\");
	s/\\([\\tn])/$replace{$1}/g;


For more inspiration on CGI-related Perl solutions, see Randal Schwartz'
WebTechniques columns:
<http://www.stonehenge.com/merlyn/WebTechniques/>. You could, for
example, create a http daemon; see the Eliza example ("Doctor is IN").

See Column 4 for code related to file locking. I need that probably more
than you do. ;-)

HTH,
Bart.


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

Date: Fri, 30 Oct 1998 10:22:57 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Python fun
Message-Id: <3639D9D1.25849137@min.net>

Michael P. Reilly wrote:
> 
> One difference that I see is that the Perl version yields a one
> dimensional array, where the Python version returns a matrix.  I'm not
> sure if the one dimensional array was deliberate.  It's been a long
> time since my linear algegra days, but I think the cartesian product
> should result in a matrix, no?

Well, I didn't put that much deep thought into the contract of this
function :-)    Sure, I could have had the perl version do that.

But, imho, when you come to this point, it's really time to start 
scrounging for a library that already implements matrix math!

John Porter


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

Date: Fri, 30 Oct 1998 16:47:33 +0100
From: "Arjan Huijzer" <arjan.huijzer@capgemini.nl>
Subject: Style Guides
Message-Id: <71cn2m$fk1$1@thunderstorm.netnews.de>

Currently I am reworking some Perl Scripts so they are more readable. I have
read the Style Guide contained in the Perl Documentation, but was wondering
if there are more such documents. Could someone point me to relevant
material.

Thanx.

Arjan Huijzer




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

Date: 30 Oct 1998 09:35:29 -0500
From: Bill Mills-Curran <bcurran@clariion.com>
Subject: Syntax for use of "new"
Message-Id: <jluyapynmmm.fsf@pent584.i-did-not-set--mail-host-address--so-shoot-me>

I remember a suggestion that the following syntax should not be used:

$obj = new SomeClass;

Instead, some (obscure) problem could be avoided by this syntax:

$obj = SomeClass->new;

Does anyone remember the reasoning behind this suggestion?  I seem to
remember that the perl parser could make an error with the first use,
under some circumstances.

TIA,
Bill


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

Date: 30 Oct 1998 15:32:52 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Syntax for use of "new"
Message-Id: <71cm74$mv1$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Bill Mills-Curran <bcurran@clariion.com> writes:
:I remember a suggestion that the following syntax should not be used:
:
:$obj = new SomeClass;
:
:Instead, some (obscure) problem could be avoided by this syntax:
:
:$obj = SomeClass->new;
:
:Does anyone remember the reasoning behind this suggestion?  I seem to
:remember that the perl parser could make an error with the first use,
:under some circumstances.

::::Alpha.pm::::
    package Alpha;
    sub new {
	print "I am alpha new\n";
	return bless {}, shift;
    } 
    1;

::::Beta.pm::::
    package Beta;
    require "Alpha.pm";
    sub new {
	print "I am beta new\n";
	return bless {}, shift;
    } 
    sub old {
	print "I am beta old, want alpha new\n";
	return new Alpha;
    } 
    1;

::::testit:::::
    require "Alpha.pm";
    require "Beta.pm";
    $x = new Beta;
    $y = old Beta;
    $z = new Alpha;

Running testit produces

    I am beta new
    I am beta old, want alpha new
    I am beta new
    I am alpha new

The assignment to $x called the right thing.  Fine.

The assignment to $z called the right thing.  Fine.

The assignment to $y, however, did *not* call the right thing.  It first
called Beta::old, which in turn then called Alpha::new("Alpha") but
it fact, called Beta::new("Alpha").  That's wrong.  It would have been
find if you had had Beta::old return Alpha->new instead, it would have
been fine all along.  This is a bug that would take you a long time to
figure out.  So let's just never go down that path, ok?

--tom
-- 
The hardest thing in the world to understand is the income tax.
                --Albert Einstein


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

Date: 30 Oct 1998 11:22:08 +0100
From: melchi@kalium.HL.Siemens.DE (Melchisedech Bernd)
Subject: Validate a re-formatted script
Message-Id: <71c40g$h2t@kalium.HL.Siemens.DE>


I'm planning to re-format an existing perl source code of ~ 2000 LOC.
The idea is to format it properly according to K&R indendation style.

1.) Are there some 'beautifiers' around to do this job automatically?

2.) Is there a possibility to validate that the pre and post source code
     are identical (some intermediate or 'compiled' format?)

Thanks 


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

Date: Fri, 30 Oct 1998 09:44:03 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Validate a re-formatted script
Message-Id: <3smc17.jdu.ln@flash.net>

Melchisedech Bernd (melchi@kalium.HL.Siemens.DE) wrote:

: I'm planning to re-format an existing perl source code of ~ 2000 LOC.
: The idea is to format it properly according to K&R indendation style.


   So, the only changes will be the adding/subtracting of whitespace?


: 1.) Are there some 'beautifiers' around to do this job automatically?


   A search of c.l.p.misc for 'beautifier' finds 800 hits at
   http://www.dejanews.com


: 2.) Is there a possibility to validate that the pre and post source code
:      are identical (some intermediate or 'compiled' format?)


   If the answer to my question at the top is "yes", then you can
   delete all whitespace from both versions and compare them.

   Doesn't really validate, but better than nothing.


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


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

Date: Fri, 30 Oct 1998 13:09:05 GMT
From: rstewart@vmirror.com (Bob Stewart)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <3639b795.3309358@news.digex.net>

Thanks! Talk about a quick response!

I wasn't averse to using the keys function, but had also read warnings
about it and tried it once with bad results, but I think I took it to
an array and THEN got the scalar length.

I tested the folowing each twice on an array with about 100,000 keys
with all the values about the length of an IP. Here are the times:


$num_keys = keys %LINES;

8.04u   0.48s   0:12.19   69.8%
7.87u   0.45s   0:11.00   75.6%

$num_keys = scalar keys %LINES;

8.02u   0.57s   0:12.69   67.6%
7.85u   0.52s   0:12.30   68.0%

There was a lot of stuff going on in this machine at the time, so I
guess the small variation is probably due to other processes on the
CPU?

Thanks again,

Bob Stewart

rstewart@vmirror.com




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

Date: 30 Oct 1998 13:20:27 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <slrn73jf8q.72e.sholden@pgrad.cs.usyd.edu.au>

On Fri, 30 Oct 1998 13:09:05 GMT, Bob Stewart <rstewart@vmirror.com> wrote:
>Thanks! Talk about a quick response!
>
>I wasn't averse to using the keys function, but had also read warnings
>about it and tried it once with bad results, but I think I took it to
>an array and THEN got the scalar length.
>
>I tested the folowing each twice on an array with about 100,000 keys
>with all the values about the length of an IP. Here are the times:
>
>
>$num_keys = keys %LINES;
>
>8.04u   0.48s   0:12.19   69.8%
>7.87u   0.45s   0:11.00   75.6%
>
>$num_keys = scalar keys %LINES;
>
>8.02u   0.57s   0:12.69   67.6%
>7.85u   0.52s   0:12.30   68.0%
>
>There was a lot of stuff going on in this machine at the time, so I
>guess the small variation is probably due to other processes on the
>CPU?

I doubt the time the programs took to run was even slightly influenced by
the extracted single statements (building the hash probably took all the
time)...

use Benchmark;
$key="aaaabbbbccccddd";
for (1...1000000)
{
        $hash{$key++}++;
}

timethese(1000000, {
        "keys" => sub {$count = keys %hash}
        });
 
Benchmark: timing 1000000 iterations of keys...
      keys: 11 wallclock secs (10.39 usr +  0.00 sys = 10.39 CPU)

approx 0.00001 seconds on my machine to execute keys %hash with a hash
of 1 million keys...

-- 
Sam

There's no such thing as a simple cache bug.
	--Rob Pike


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

Date: Fri, 30 Oct 1998 15:45:36 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Very Large DBM file: Finding Number of keys
Message-Id: <8ck91iqciu.fsf@gadget.cscaper.com>

>>>>> "Bob" == Bob Stewart <rstewart@vmirror.com> writes:

Bob> $num_keys = keys %LINES;

Bob> 8.04u   0.48s   0:12.19   69.8%
Bob> 7.87u   0.45s   0:11.00   75.6%

Bob> $num_keys = scalar keys %LINES;

Bob> 8.02u   0.57s   0:12.69   67.6%
Bob> 7.85u   0.52s   0:12.30   68.0%

These are *precisely* the same thing.  "scalar" is not a function.  It
does nothing.  It does not have an opcode.  It does not have a runtime
speed.  It's merely a piece of syntax that says "use the scalar
definition of the following expression even if we might possibly be in
a list context".  But since you were *already* in a scalar context
($num_keys = ...), there's really nothing to force.

Just another guy who is far too tired of seeing needless "scalar"s,

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Fri, 30 Oct 1998 09:53:35 -0500
From: E-Mail Transponder <alpha@alphasys.net>
Subject: where can I find cgi script for hire
Message-Id: <3639D2EF.1CFE282A@alphasys.net>

Hi,

Does any know of a good cgi script writer that I can hire to write a
script for me?

--Janice



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

Date: Fri, 30 Oct 1998 10:26:04 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Why is perl better than shell scripting language?
Message-Id: <3639DA8C.EE40EC25@min.net>

Brand Hilton wrote:
> 
> This is the primary reason I switched from TCL to Perl for GUI apps.
> 
> Jeez, hope I didn't just start another language war.

Not to worry.  I'm sure the lone Tcl guy out there doesn't have a
meaningful response to this allegation.

-- 
John "Throbblefoot" Porter

Please Don't "Courtesy CC" me.
I read this newsgroup fanatically.  You know that!
("Emailed only" is fine, though.)

"The people at the Grey Hotel
  Are either aged or unwell." -- EG


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

Date: Fri, 30 Oct 1998 10:36:56 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Why is perl better than shell scripting language?
Message-Id: <3639DD18.9CB63C91@min.net>

yong wrote:
> 
> Could you care to give an example to illustrate your point? I thought perl -c
> was equivalent to csh -n, only that C shell (or Bourne, Korn) usually gives
> simple, generic and therefore useless error messages.

Glad to.

	#!/usr/bin/csh

	echo    "Rebuilding database"
	rm      $DB_FILES/*
	blargh  $DATASOURCE $DB_FILES
	echo    "Done"

Output:

	Rebuilding database
	blargh: Command not found

And of course, csh -n indicates no errors.

-- 
John "Throbblefoot" Porter

Please Don't "Courtesy CC" me.
I read this newsgroup fanatically.  You know that!
("Emailed only" is fine, though.)

"The people at the Grey Hotel
  Are either aged or unwell." -- EG


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

Date: Fri, 30 Oct 1998 12:51:16 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: Win95 Script Mapping
Message-Id: <3639B644.9ACA5C1A@technologist.com>

edit scriptname.bat
 @echo off
 perl scriptname.pl
save batch file

to run:
 scriptname

You even save yourself from having to type the .pl each time!

I know this was kind of a smart-assed answer, sorry ;-)  I don't think
'95 handles file associations the same way NT does - which is why you
are having problems...

Good luck,
Brent
-- 
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

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

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