[9645] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3239 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 23 21:07:19 1998

Date: Thu, 23 Jul 98 18:00:28 -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           Thu, 23 Jul 1998     Volume: 8 Number: 3239

Today's topics:
        3c509 woes: Network card recommendations? spacy13@my-dejanews.com
    Re: @INC not working from within prog? <trobert@wpine.com>
    Re: @INC not working from within prog? (Martien Verbruggen)
        Can't shl_load a library (installing JPL on hp-ux) (Kevin Dee Sheely)
        changing default shell for system() <labrinid@cs.umd.edu>
    Re: comp.lang.perl.extreme <scribble@pobox.com>
    Re: delete while iterating over array ((null))
    Re: Dynamically creating graph images (Danny Aldham)
    Re: field (Andrew M. Langmead)
        Generating Win32 GUIDs in Perl ionFreeman@my-dejanews.com
    Re: How to access modem on NT ( terminal and ppp ). (Andrew M. Langmead)
    Re: How to delete files from perl <anandan_balaji@emicx.mentorg.com>
    Re: modifying a text file (courtesy)
    Re: modifying a text file <rick.delaney@shaw.wave.ca>
    Re: Multiple Key Sort (Andrew M. Langmead)
    Re: Need Perl Script/regexp/grep help, please... <rick.delaney@shaw.wave.ca>
    Re: parsing question <minich@globalnet.co.uk>
        perl as pseudocode <ghira@mistral.co.uk>
    Re: Perl Beautifier Home Page (Kai Henningsen)
    Re: Perl Beautifier Home Page (Kai Henningsen)
    Re: Perl Beautifier Home Page (Kai Henningsen)
        Returning values from a child process <cbero@uwyo.edu>
        Running one perl script from within another???? <casali@paymentsystems.org>
    Re: Running one perl script from within another???? (Kelly Hirano)
    Re: sendmail code (Martien Verbruggen)
        Slash vs backslash in nt vs 95? brianp_sheshunoff@my-dejanews.com
        STDOUT for Win32::Process ??? <jhempe@crossroute.com>
    Re: Sybperl script fails to exit after last line meadore@my-dejanews.com
    Re: temp directory for both unix and windows platform (Andrew M. Langmead)
        using s/// (Alexander Weaver)
    Re: Variable Interpolation (Andrew M. Langmead)
    Re: Web mail script endymion@my-dejanews.com
    Re: What's wrong? (Martien Verbruggen)
    Re: What's wrong? (Kai Henningsen)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 23 Jul 1998 22:41:55 GMT
From: spacy13@my-dejanews.com
Subject: 3c509 woes: Network card recommendations?
Message-Id: <6p8e7j$r0h$1@nnrp1.dejanews.com>

Hi,

I have a FreeBSD 2.2.6 box with a 3Com 509b network card.
Unfortunately it stops responding on high network load (known problem
with the ep0 driver. Is already in gnats. mbufs leak ?).
I saw this problem also in 2.1.6-RELEASE. Did anybody fix this problem yet?

Does anybody have recommendations which other ISA Ethernet card (10base-T)
runs reliably on FreeBSD even with high (very high!) network load?

Thanks a lot for any tips or recommendations
Bernhard

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 23 Jul 1998 18:31:59 -0400
From: Tom Robert <trobert@wpine.com>
Subject: Re: @INC not working from within prog?
Message-Id: <35B7B9DF.C020D4B7@wpine.com>

Man, my first post  in years, and it was just me being a bonehead!
Your "misinstallation" tipped me off.  My machine dual boots 95 and NT.
I originally installed PERL on 95.  Later from NT I simply added the the
bin directory to my path, which seemed to be all it needed at the time.

I just installed under NT and now everything works fine, without even
adding to or modifying @INC.  (I thought it was strange that it didn't
know where even the default libraries were kept!)

>I've heard uncomplimentary things about that book.  This just provides one
>more piece of evidence that it's not a good Perl learning tool.  Note that
>the unshift method will work fine for 'require' but not for 'use' (unless
>you put the unshift in a BEGIN block, but then why not just do 'use
>lib'?).

In defense of the book, I just looked again and in the example it is
indeed doing a 'require' not a 'use'.  However the way the text reads
it does looks like a general method for modifying @INC.

Sorry for wasting this thread.  Thanks for your time.


Craig Berry wrote:

> Tom Robert (trobert@wpine.com) wrote:
> : Thanks for the advice.  What you say makes sense.
> : However when I insert the line (before other 'use' calls)
> :
> : use lib '/Perl/lib';
> :
> : It now generates a compile time error of:
> :
> : Can't locate lib.pm in @INC at myprog.pl line 2
>
> Oops.  What version of Perl are you running?  Do 'perl -v' to see.  Either
> you have a backlevel or a misinstalled Perl.  One way to tell which it is
> is to go to the Perl lib dir (if you know where that is, or should be) and
> check manually for the existence of lib.pm.  If it's there, your problem
> is a misinstallation.
>
> : The documentation I mention in my initial post came
> : from the book "teach yourself PERL in 21 days".
> : It even states to use "unshift" so that it's added to the
> : front of the search path as opposed to the end.
>
> I've heard uncomplimentary things about that book.  This just provides one
> more piece of evidence that it's not a good Perl learning tool.  Note that
> the unshift method will work fine for 'require' but not for 'use' (unless
> you put the unshift in a BEGIN block, but then why not just do 'use
> lib'?).
>
> ---------------------------------------------------------------------
>    |   Craig Berry - cberry@cinenet.net
>  --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
>    |      Member of The HTML Writers Guild: http://www.hwg.org/
>        "Every man and every woman is a star."





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

Date: 23 Jul 1998 23:23:58 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: @INC not working from within prog?
Message-Id: <6p8gme$lbv$2@nswpull.telstra.net>

In article <35B76315.E01EF45B@wpine.com>,
	Tom Robert <trobert@wpine.com> writes:
> Thanks for the advice.  What you say makes sense.
> However when I insert the line (before other 'use' calls)
> 
> use lib '/Perl/lib';
> 
> It now generates a compile time error of:
> 
> Can't locate lib.pm in @INC at myprog.pl line 2
> ...

Ah.. Maybe you're running some ancient perl version? What does perl -v
say? It should say 5.004_04. If not, you ought to upgrade.

> The documentation I mention in my initial post came
> from the book "teach yourself PERL in 21 days".

Hmm.. You might be interested in:
http://language.perl.com/critiques/index.html

You'll find that there are many much better, and especially more
modern books about perl.

> It even states to use "unshift" so that it's added to the
> front of the search path as opposed to the end.

It must have forgotten to mention that you have to include it in a
BEGIN block to make sure it gets done first. Or maybe the author
didn't know. Or maybe it's too old.

> I located the config.pm file.  Didn't seem trivial to make
> the changes apply.  That is it looks like I need to recompile
> PERL or use config.pm from within a program.

Judging by the error message that you got: you definitely need to
recompile perl. And you need to get a newer version :)

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Thu, 23 Jul 1998 22:31:02 GMT
From: sheely@misty.ca.boeing.com (Kevin Dee Sheely)
Subject: Can't shl_load a library (installing JPL on hp-ux)
Message-Id: <EwKJvq.51n@news.boeing.com>

I'm attempting to port the JPL (java/perl) toolkit over to a HP-UX 11.00
system.  I've built perl5.004_04 to use a shared library and using the
system malloc.  I've run in to a roadblock that I'm not sure how to
get around. When the Sample makefile does a 'perl -c Sample.pl' in order
to check the syntax, it produces:


/usr/lib/dld.sl: Can't shl_load() a library containing Thread Local Storage: /usr/lib/libpthread.1
/usr/lib/dld.sl: Exec format error
Can't load '/opt/perl_sh/lib/site_perl/9000/819-hpux/auto/JNI/JNI.sl' for module JNI: Exec format error at /opt/perl_sh/lib/9000/819-hpux/5.00404/DynaLoader.pm line 166.

 at /opt/jpl/perl/JPL/AutoLoader.pm line 53
BEGIN failed--compilation aborted at /opt/jpl/perl/JPL/AutoLoader.pm line 53.
BEGIN failed--compilation aborted at /opt/jpl/perl/JPL/Class.pm line 2.
BEGIN failed--compilation aborted at Sample.pl line 3.

--------------------
Sample.pl line 3 is use JPL::Class qw(java::lang::String);
Class.pm line 2 is use JPL::AutoLoader ();
AutoLoader.pm line 53 is use JNI;
DynaLoader.pm line 166 is my $libref = dl_load_file($file, $module->dl_load_flags)

I'm assuming the dl_load_file is trying to load libpthread which is where my
error is coming from.

There is a comment right before the call to 'dl_load_file' which states

# Many dynamic extension loading problems will appear to come from
# this section of code: XYZ failed at line 123 of DynaLoader.pm.
# Often these errors are actually occurring in the initialisation
# C code of the extension XS file. Perl reports the error as being
# in this perl code simply because this was the last perl code
# it executed.


Does anyone know of a way around this problem ?  

--
-----------------------------------------------------------------------
   Kevin Sheely                          Boeing Shared Services 
                                         P.O. Box 3707  m/s  7M-HC 
                                         Seattle,  WA.  98124-2207
                                         sheely@misty.ca.boeing.com 
-----------------------------------------------------------------------



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

Date: Thu, 23 Jul 1998 20:30:05 -0400
From: Alexandros Labrinidis <labrinid@cs.umd.edu>
Subject: changing default shell for system()
Message-Id: <35B7D58D.59E2@cs.umd.edu>

Hello all.

 I'd like to change the shell that system() spawns to execute its
arguments. For some reason, although $ENV{'SHELL'} is tcsh, perl
sticks with sh for system(). Any ideas? 

thanks a lot,
alex

PS: I am running Perl 5.004_04 on SunOS 5.5 (solaris).

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexandros Labrinidis,  Grad. student in Computer Science @ Univ of MD
 email: labrinid@cs.umd.edu   web page: http://www.cs.umd.edu/~labrinid


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

Date: 23 Jul 1998 19:55:48 -0500
From: Tushar Samant <scribble@pobox.com>
Subject: Re: comp.lang.perl.extreme
Message-Id: <6p8m2k$7t1@tekka.wwa.com>

gebis@albrecht.ecn.purdue.edu writes:
>PERL!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

syntax error at -e line 1, near "PERL!"



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

Date: 23 Jul 1998 22:36:53 GMT
From: mike@stok.co.uk ((null))
Subject: Re: delete while iterating over array
Message-Id: <6p8du5$f9s@news-central.tiac.net>

In article <35B72933.91DEAFD0@nortel.co.uk>,
F.Quednau <quednauf@nortel.co.uk> wrote:

>> I have an array where some keys are empty ( "" ). How do I do to delete them?
>> I understand that I can't use splice when iterating over the array.
>> 
>> Any suggestions?
>
>In the great spirit of TIMTOWTDI...
>
>@array = grep {$_} @array;
>
>Why? If element is not defined, it returns false, and the element is not
>taken.

Beware of the case where an element is the one character string '0' or
any other value perl considers false which isn't '':

  DB<1> @array = ('0', 0, '0.0', 0.0)

  DB<2> @array = grep {$_} @array

  DB<3> X array
@array = (
   0  0.0
)

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 23 Jul 1998 23:53:15 GMT
From: danny@lennon.postino.com (Danny Aldham)
Subject: Re: Dynamically creating graph images
Message-Id: <6p8idb$dph$1@lennon.postino.com>

X-Newsreader: TIN [version 1.2 PL2]

Greg Berigan (gberigan@cse.unl.edu) wrote:
: In comp.lang.javascript, carltjm@mail.auburn.edu (Joseph M Carlton) wrote:
: > I am using perl to fetch data from a database for a web project that I am 
: > working on. Now, I need to dynamically build a bar graph with this data.  
: > Someone told me that I could use javascript and somebody told me that I 
: > could do the whole thing in perl. I have not been able to find any 
: > information on this topic for either javascript or perl.  Could someone 
: > PLEASE direct me to a book or web page with information on this?  I am 
: > not limited to perl and javascript, so if anyone knows of a better way to 
: > do this.  I would be VERY appreciative.  Thanks in advance for your help.

: You can do bar graphs (scale images to the size of the needed bar) but
: line graphs and pie graphs are not possible since you can't create
: images on the fly (except B&W BMP images?).  If you need this
: functionality, you'll need either communication with a server which will
: create images on demand or use Java.

Take a look at GD and the GD modules. They allow color image generation
on the fly.

--
Danny Aldham             SCO Ace, MCSE, JAPH, DAD 
Field Service Manager    BCTel Systems Support
7000 Lougheed Hwy, Burnaby BC   (604) 444-8949


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

Date: Thu, 23 Jul 1998 23:41:45 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: field
Message-Id: <EwKn5L.4yK@world.std.com>

Kamran Iranpour <kamrani@ifi.uio.no> writes:

>I am looking for some function in perl that does the same
>thing as awk does, i.e. print only a field of a line.

You might want to take a look at the perltrap man page. It describes
some of the differences between what an awk programmer may expect from
perl and what perl actually does.

Perl does not split the input stream into fields implicitly, it
requires an explicit function to do so. The split function can perform
an action most similar to what awk does.

If you want to write "one-liners" similar to what people frequently do
with awk, you may want to take a look at the "-a" switch in the
perlrun man page.


> To be
>more specific I need to list all the machines belonging to
>a certain network, which I does with :
>exec('ypcat hosts.byaddr');

I think you want to use either a piped open, or backticks, probably
not system() and definitely not exec().


>And why can't I do :
>exec('ypcat hosts.byaddr | awk "{print $3}"');
>This does not work in my perl script, as if it just ignores the
>awk command.

Since exec() and system() pass their arguments to the shell (if there
is anything a shell may be interested in) the shell sees the "$3"
inside double quotes. Since the shell interpolates variables in double
quotes, it interpolates its variable $3. Since you probably don't have
an environment variable named 3, it gets replaced with nothing. That
makes the string passed to awk { print } which looks very similar to
if awk wasn't running at all.


So what you might be looking for, is something like this:

#!/usr/bin/perl -w

open HOSTS, 'ypcat hosts.byaddr |' or die "Can't run ypcat: $!\n";

while(<HOSTS>) {
  print( (split ' ')[2], "\n" );
}

close HOSTS or die "Error running ypcat: $!\n";
-- 
Andrew Langmead


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

Date: Thu, 23 Jul 1998 22:06:31 GMT
From: ionFreeman@my-dejanews.com
Subject: Generating Win32 GUIDs in Perl
Message-Id: <6p8c57$oa3$1@nnrp1.dejanews.com>

Hi!  I've got this really great perl script that moves text data into my SQL
server database using the Win32::ODBC module. However! Somebody replaced _my
database with the Access Upsizing tools, which apparently added a GUID
column. The GUIDs have to be unique.  Does anyone have an example of getting
a GUID in perl? Microsoft's knowledge base has a sample working from VB at
http://support.microsoft.com/support/kb/articles/q176/7/90.asp, and I'd like
to write something like that. Is there a man page on importing a dll someone
can point me to?  Thanks for your help! ion

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 23 Jul 1998 23:48:18 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: How to access modem on NT ( terminal and ppp ).
Message-Id: <EwKnGJ.7u7@world.std.com>

Meng Xiong <xiong@bigfoot.com> writes:

>Is there a module that I can use to establish a ppp connection and a
>direct dial in connection on Windows NT? Thanks for the help.

Microsoft has a Knowledge Base article on who to start up DUN (Dial Up
Networking) from the command line in Windows 95

<URL:http://support.microsoft.com/support/kb/articles/q145/7/40.asp>

can you do something similar in NT?


-- 
Andrew Langmead


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

Date: Thu, 23 Jul 1998 16:48:47 -0700
From: Anandan Balaji <anandan_balaji@emicx.mentorg.com>
Subject: Re: How to delete files from perl
Message-Id: <35B7CBDE.FA6B4409@emicx.mentorg.com>

To remove a file:

unlink   ( $filename );

To remove a directory

use File::Path;
rmtree ( $dir_name );

Neelam Saini wrote:

> Using perl on UNIX. How do I delete files from perl. I am creating the
> file using open <filename>
>
> Thanks






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

Date: 23 Jul 1998 23:08:04 GMT
From: Bob Shair (courtesy) <rmshair@delphi.itg.uiuc.edu>
Subject: Re: modifying a text file
Message-Id: <6p8fok$ov2$1@vixen.cso.uiuc.edu>

melspace@my-dejanews.com wrote:
> I am trying to figure out how to replace one line in a text file.  I have
> read perlfaq5, but I am still puzzled.	


Assuming that you want to replace a line, other than the last,
I suspect that you may be out of luck.  I haven't found a way
to do that without truncating the file at that point.

That's to say if your goal is:
Before				After
AAA				AAA
BBB				BBB
CCC				CCCnew
DDD				DDD

I'm as stumped as you... after writing CCCnew, line DDD vanishes.
-- 

Bob Shair                          rmshair@delphi.itg.uiuc.edu
Open Systems Specialist    	   Champaign, Illinois		   
/*  Opinions expressed are mine... go get your own!       */


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

Date: Fri, 24 Jul 1998 00:10:53 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: modifying a text file
Message-Id: <35B7D268.B0158578@shaw.wave.ca>

Bob Shair (courtesy) wrote:
> 
> melspace@my-dejanews.com wrote:
> > I am trying to figure out how to replace one line in a text file.  I 
> > have read perlfaq5, but I am still puzzled.
> 
> Assuming that you want to replace a line, other than the last,
> I suspect that you may be out of luck.  

Which part of the faq entry do _you_ find confusing?  If enough people
don't get it, perhaps it could be changed.

> I haven't found a way
> to do that without truncating the file at that point.
> 
> That's to say if your goal is:
> Before                          After
> AAA                             AAA
> BBB                             BBB
> CCC                             CCCnew
> DDD                             DDD
> 
> I'm as stumped as you... after writing CCCnew, line DDD vanishes.

With what kind of code?  Please, this stuff is trivial in Perl.  This
newsgroup has a lot of great info, but if you're new to Perl you'd do
better to start with something more structured, like Learning Perl.

Okay, one example for the above:
   perl -pi -e 's/CCC/CCCnew/' file

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


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

Date: Thu, 23 Jul 1998 22:48:10 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Multiple Key Sort
Message-Id: <EwKKoA.Mxy@world.std.com>

"F.Quednau" <quednauf@nortel.co.uk> writes:

>sub routine {
> my  @c1 = split '\*', $a;
> my  @c2 = split '\*', $b;
> my $aa = join ('', $c1[0], $c1[1]); 
> my $bb = join ('', $c2[0], $c2[1]);
> $aa <=> $bb;
>}

Do you realize how many times "routine" will be called?

I know you suggested that others would post "more elegant" answers,
but why answer a question that has been asked over and over again with
a solution known to be extrememly poor instead of pointing someone to
<URL:http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq4/
How_do_I_sort_an_aray_by_anyth.html> ?
-- 
Andrew Langmead


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

Date: Fri, 24 Jul 1998 00:21:06 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Need Perl Script/regexp/grep help, please...
Message-Id: <35B7D4D7.2EB0C0E6@shaw.wave.ca>

chrisabraham@my-dejanews.com wrote:
> 
> Gurus:
> 
> I have a grep question:
> 
> I have 300 pages of this kind of thing:
> 
[snip 300 pages]
> 
> Three hundred pages of this thing:
> 
[snip more of codeless problem description]

> 
> Any idea on how to do this?
> It all seems like there is not
> enough stuff to figure it out...
> even for GREP, regular
> expression, and PERL!
> 

perldoc perlfunc

There are more than enough functions in there to do this.  (Hint:  grep
isn't one of them).  Perhaps you could post the code that you have so
far?

> Any help would be pennies from heaven!
> 

If you want the gods to do all the work for you then you have to send
the pennies _to_ heaven.

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


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

Date: Thu, 23 Jul 1998 23:22:13 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: parsing question
Message-Id: <6p8d3s$ig4$1@heliodor.xara.net>

>1. you didn't check the return value of open().
>   you must *always* do that.  No but's.


I was in a rush; what can I say? IRL, I always do that but I
was trying to do this and must have overlooked it. Honest <g>

>2. unless you have some specific need to store the entire
>   input file in memory at once, it's better to while()
>   over it instead of foreach().  You'll notice the
>   difference as the files get larger.


The question asked about reading the entire record into a
string (well, an array's close enough ::ducks to avoid angry
Perl programmers::). So I read it all into the array.

>3. bizarre mixing of $_ and $indata.  $_ was sufficient for
>   the task.


I always name strings and arrays identical in foreach loops -
I get confused easily <g>

>4. you already did a split( /=/, $_, 2 ) when you did a
> if ( /=/ ) so use the results, rather than splitting again.


OK, so I should have used $' and $`

>5. superfluous quoting:
>>     $firstline = "$indata";


I always do that incase indata contains a semicolon.

>In summary:
>
> my $filename = "myfile.dat";
> open INF, "< $filename" or die "open $filename: $!";
>
> my $firstline;
> my %hash;
>
> while (<INF>) {
>   chomp;
>   if ( /^[MTWFS]/ ) {
>     $firstline = $_;
>     %hash = ();
>   }
>   elsif ( /=/ ) {
>     $hash{ $` }  = $';
>   }
>   # &c.
> }
>
> close INF;


They asked to have it read into an array though.

>6. But you don't cleanly handle the case where the last line
>   of input is the last "name = value" line of the last
>   record.


Is it? Oops, they should repeat the else routine once at the
end of the foreach loop.

>7. One should just use $/ for this kind of thing.


Obviously ?!?!?!? LOL!

OK, so there may have been a few problems but it answers
the question <g>

Martin




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

Date: 23 Jul 98 23:06:04 +0000
From: "Adam Atkinson" <ghira@mistral.co.uk>
Subject: perl as pseudocode
Message-Id: <2849.508T227T13862392@mistral.co.uk>

I occasionally have to give shortish talks to colleagues in which
I explain how to do something (e.g. Huffman coding or Monte carlo
simulation) and as well as explaining the algorithm I will show a program
in perl which actually DOES the thing in question.

Since my audience will not, generally, know perl, these programs
need to be working perl programs which look like pseudocode
rather than elegant/idiomatic perl. Of course, TMTOWTDI, so
perhaps I can do whatever I like. Also, I'm relatively new to Perl so I
probably wouldn't usually think of the elegant techniques anyway.

I've read FAQs and books, and this sort of issue doesn't seem
to be covered anywhere. I realise it's hard to say anything useful
about - what DO we assume the audience can understand? I'd say
"not regular expressions", but maybe in some unix environments
this would be unreasonable.

As an example, here is a program I have really used as part of a talk.

The only REAL reqirement was that it actually output correct answers.
Speed, elegance, idiomatic..um... ness? icity? and so on were entirely
by the by. After "doing what it's supposed to", my next requirement
is "more or less comprehensible to a relatively lay audience".
NB this particular program is not terribly important - but the "writing
perl for human consumption" issue interests me.

#huffman code script.
#argument is filename of symbol table

open(SYMBOLS,$ARGV[0]) || die "Can't find symbol table";

$i=0;
$entropy=0;
while (<SYMBOLS>) {
($symbol[$i],$prob{$i}) = split(/ /, $_);
chomp $prob{$i};
$p[$i]=$prob{$i};
$right[$i]=-1;
$left[$i]=-1;
$entropy-=$prob{$i}*log($prob{$i})/log(2);
$i++;
}

$symbols=$i;
$new=$symbols;
$end=$symbols-1;

#for ($i=0;$i<=$symbols;$i++) {
#$rank[$i]=$i;
#}

@sortedranks=sort symbol_sort keys %prob;

while ($end>0) {
$ult=$sortedranks[$end];
$penult=$sortedranks[$end-1];

$symbol[$new]=$new;
#$rank[$new]=$new;
$left[$new]=$penult;
$prob{$new}=$prob{$ult}+$prob{$penult};
delete $prob{$ult};
delete $prob{$penult};
$right[$new]=$ult;
$up[$penult]=$new;
$up[$ult]=$new;
$new++;
$end--;
@sortedranks=sort symbol_sort keys %prob;
}

for ($i=0;$i<$symbols;$i++) {
$j=$up[$i];
$k=$i;
while ($j!=undef) {
if ($k==$left[$j]) {
$string[$i]="0".$string[$i];
} else {
$string[$i]="1".$string[$i];
}
$k=$j;
$j=$up[$k];
}
}

print_table();

sub print_table {
$av_length=0;
for ($i=0;$i<$symbols;$i++) {
print "$symbol[$i] $p[$i] $string[$i]\n";
$av_length+=$p[$i]*length($string[$i]);
}

print "Bits per symbol theoretically = $entropy\n";
print "Average length of codes = $av_length\n";
$excess=$av_length/$entropy-1;
$excess=int($excess*10000+0.5)/100;
print "which is $excess% too much\n";

}

sub symbol_sort {
return $prob{$b}<=>$prob{$a};
}

-- 
Adam Atkinson (ghira@mistral.co.uk)
I never could get the hang of Thursdays



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

Date: 23 Jul 1998 22:19:00 +0200
From: kaih=6yQe9fpXw-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: Perl Beautifier Home Page
Message-Id: <6yQe9fpXw-B@khms.westfalen.de>

snowhare@devilbunnies.org (Snowhare)  wrote on 22.07.98 in <6p3lnl$l7f$1@supernews.com>:

> Feel free to suggest one. :) Honestly, the problem of generating
> every date in a year pretty much requires something like this
> somewhere. If you wanted to hide it, you could stuff it in an
> array after you built a single leap year calendar and a single
> non-leap year calendar. But that generation code would have the
> loops as well. I suppose you could put a loop around a call to
> 'gmtime' and add 86400 seconds each time around the loop if you
> were _really_ determined to avoid the nesting. But I really
> don't think that qualifies as 'elegant'. :)

Well, I do. Generating all days in a year _should_ just be a loop over the  
days and have the libraries care about calendar oddities. It's a question  
of code reuse.

Kai
-- 
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
  - Russ Allbery (rra@stanford.edu)


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

Date: 24 Jul 1998 00:03:00 +0200
From: kaih=6yUeA4qXw-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: Perl Beautifier Home Page
Message-Id: <6yUeA4qXw-B@khms.westfalen.de>

jdporter@min.net (John Porter)  wrote on 15.07.98 in <35ACFDB2.477B@min.net>:

> Nothing wrong with my logic, friend.  (Not here, anyway.)

I disagree. With the logic, that is, not necessarily with the result.

> What we have is problem of semantics.
> You say code which includes both perl4 and perl5 constructs can
> not be called perl code, even though there exists a program (named perl)
> which compiles and executes that code.
> I say such code can be called perl code -- and there are good
> reasons for saying it.   perl implements Perl, period.  It is a
> defining implementation.

If that were true, there could be no bugs in the perl implementation.  
After all, whatever the consequences of the bug, it would define the  
language, and thus be ok.

But that's obviously not how it works. Perl-the-implementation _can_ have  
bugs. Ergo, you're wrong.

Kai
-- 
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
  - Russ Allbery (rra@stanford.edu)


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

Date: 23 Jul 1998 23:56:00 +0200
From: kaih=6yQe9sLHw-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: Perl Beautifier Home Page
Message-Id: <6yQe9sLHw-B@khms.westfalen.de>

lr@hpl.hp.com (Larry Rosler)  wrote on 14.07.98 in <MPG.1015affeb7e5309989739@nntp.hpl.hp.com>:

> In article <6oh0l7$dav@mozo.cc.purdue.edu> on 15 Jul 1998 01:29:11 GMT,
> Michael J Gebis <gebis@albrecht.ecn.purdue.edu> says...

> >   `When I use a word,' Humpty Dumpty said in rather a scornful tone, `it
> >   means just what I choose it to mean -- neither more nor less.'
> >
> > Unfortunately, I can't tell if this quote is an argument for you or
> > for me.
>
> I can :-)  Dodgson was an expert in formal logic, and this statement is
> satirical.

Wasn't he a mathematician? If you replace "what I choose it to mean" with  
"what I explicitely define it to mean", you have standard mathematical  
practice.

Of course, the important part is actually doing the defining.


Kai
-- 
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
  - Russ Allbery (rra@stanford.edu)


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

Date: Thu, 23 Jul 1998 23:41:04 +0000
From: Chris Bero <cbero@uwyo.edu>
Subject: Returning values from a child process
Message-Id: <35B7CA10.BCDF5045@uwyo.edu>

Hello!

Not sure how lame this question is, but here goes.

If I have a parent process which forks to a child process and that child does
some kind of processing of a variable, is there a way to return the new value of
that variable to the parent process?  (my god, that was one sentence!)

I've been dorking around with the $SIG{CHLD} signal, but mostly I just set it to
IGNORE.

Any suggestions would be welcomed.  

Cheers,
Chris
___________________________________________________________.
 Christopher R. Bero                 Phone: (307)766-6195  |
 Head Geek,                            FAX: (307)766-2652  |
 Wyoming InfraRed Observatory       mailto:cbero@uwyo.edu  |
 University Wyoming                               Resume:  |
 P.O. Box 3905               http://kafka.uwyo.edu/resume  |
 Laramie, WY  82071-3905                                   |
-----------------------------------------------------------+


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

Date: Thu, 23 Jul 1998 18:28:14 -0400
From: Joseph Casali <casali@paymentsystems.org>
Subject: Running one perl script from within another????
Message-Id: <35B7B8FD.BC95E2F0@paymentsystems.org>

Is there any way to run a perl script within another perl script.  I'm
new at this, I needed to generate a number so that I could track form
responses.  I thought that the perfect way to do it was just use a
counter script.  Well, I don't know how to get the count variable into
the form response script. Kinda lost, I'd appreciate any help



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

Date: 23 Jul 1998 16:44:29 -0700
From: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: Running one perl script from within another????
Message-Id: <6p8hst$bt8@Xenon.Stanford.EDU>

In article <35B7B8FD.BC95E2F0@paymentsystems.org>,
Joseph Casali  <casali@paymentsystems.org> wrote:
>Is there any way to run a perl script within another perl script.  I'm
>new at this, I needed to generate a number so that I could track form
>responses.  I thought that the perfect way to do it was just use a
>counter script.  Well, I don't know how to get the count variable into
>the form response script. Kinda lost, I'd appreciate any help

well, how is the counter script going to get a count variable unless it is
always running? most likely it will read the counter from a file, right?
thus, can't yoru form response script read from the same file and you
eliminate the need for the counter script?
-- 
Kelly William Hirano	                    Stanford Athletics:
hirano@cs.stanford.edu	                 http://www.gostanford.com/
hirano@alumni.stanford.org      (WE) BEAT CAL (AGAIN)! 100th BIG GAME: 21-20


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

Date: 23 Jul 1998 23:32:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: sendmail code
Message-Id: <6p8h79$lbv$3@nswpull.telstra.net>

In article <6p74dq$j93$2@butterfly.hjsoft.com>,
	Matthew Flinchbaugh <matthew@nofear.hjsoft.com> writes:
> does anyone know what i can use in a code to make sendmail run the mail
> bomber with a oerl script

the oerl mail bomber self replicating fully object oriented y2k
compliant web oriented internet ready gui driven ActiveWaWa 64 bit
pre-emptive multitasking cappucino other managerial drivel tool kit.

Hope this helps.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Thu, 23 Jul 1998 22:57:37 GMT
From: brianp_sheshunoff@my-dejanews.com
Subject: Slash vs backslash in nt vs 95?
Message-Id: <6p8f51$rub$1@nnrp1.dejanews.com>

Hi,

I use the slash as the filespace delimiter in Perl scripts I run on NT. The
-M, -s, -d, and -f file tests work fine. When I try to run the same program
on 95, I get zero for age, and size and false for directoriness and fileness.
Changing from slash to escape (backslash) makes them work.

It looks as though I am going to have to rewrite large portions of my code to
use the ESCAPE SPECIAL CHARACTER in place of the normal slash as a path
separator. Am I overlooking another alternative?

Isn't Perl supposed to be portable? Is this a 95 bug? Can/should Perl
compensate for Bill's boneheaded idea of what a path separator should be?

Puzzled,

     Brian

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 23 Jul 1998 16:54:51 -0700
From: "John A. Hempe" <jhempe@crossroute.com>
Subject: STDOUT for Win32::Process ???
Message-Id: <35B7CD4B.CF1CA7CC@crossroute.com>

Greetings,

I'm trying to use Win32::Process::Create.  It works fine, but I'm having
trouble controlling the standard output of the process.  If I use
CREATE_NEW_CONSOLE, I get an MSDOS console with no scrollbars and the
output goes there.  If I use DETACHED_PROCESS, I see no output at all
and have no idea where it's going.  I'm on NT, but it might as well be
going to /dev/null.  :)

I'd like to find out where the standard out of the created process is
going; clearly it isn't to my Perl script's STDOUT.  I'd like to get
ahold of it so I can log it to a file and/or display it.

Thanks, and please reply to my private mailbox as well as to this group.

--John Hempe




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

Date: Thu, 23 Jul 1998 23:15:20 GMT
From: meadore@my-dejanews.com
Subject: Re: Sybperl script fails to exit after last line
Message-Id: <6p8g69$t5u$1@nnrp1.dejanews.com>

I upgraded the version of sybase open client to 11.1.1, re-built
sybperl, and my script seems to have stopped hanging.

I attached the dbx debugger to the running perl process and got the following
traceback (which made me think that it might be hung somewhere in sybase code
doing a ct_close)

(dbx) s

I/O possible/complete in ipd_close at 0xd0e94a14 ($t1)
0xd0e94a14 (ipd_close+0x30) 80410014          l   r2,0x14(r1)
(dbx) where
ipd_close(??, ??, ??, ??) at 0xd0e94a14
netp_close_poll(??) at 0xd0e92008
netg_process_request(??, ??) at 0xd0e91444
net_close(??, ??, ??, ??, ??, ??) at 0xd0e965a0
np_io_close(??, ??, ??) at 0xd0e9fc50
ct__tds_closeconn(??, ??, ??, ??) at 0xd0e9f2b0
ct_tds_close(??) at 0xd0e9f39c
ct__chkpt_close(??, ??, ??, ??) at 0xd0eb1664
ct__api_async_force_close(??, ??, ??, ??) at 0xd0e79634
ct__api_close(??, ??, ??) at 0xd0eb16cc
ct_close(??, ??) at 0xd0eb1850
unnamed block $b118, line 5562 in "CTlib.xs"
unnamed block $b117, line 5562 in "CTlib.xs"
XS_Sybase__CTlib_DESTROY(0x200a7ef0), line 5562 in "CTlib.xs"
Perl_pp_entersub() at 0x10032128
perl_call_sv() at 0x10013c58
Perl_sv_clear() at 0x1000949c
Perl_sv_free() at 0x10008a64
visit() at 0x1000257c
Perl_sv_clean_objs() at 0x1000987c
perl_destruct() at 0x10012f48
main() at 0x10000428
(dbx)


In article <6o01o2$24n$1@nnrp1.dejanews.com>,
  tonyprideaux@my-dejanews.com wrote:
> I've written a small Sybperl script which I run from Cron throughout the day.
> However, occasionally, after it has executed  the last lines in the script,
> the process goes into a cpu loop and has to be terminated with a kill -9. The
> last three lines are:  print LOG "Goodbye world!!\n";  close LOG;  exit 0;
>
> The print statement executes everytime so it is getting to the end.
>
> I'm running this on AIX 4.1.4 with Perl 5.004 and Sybperl 2. Has anyone got an
> idea as to why my script is sometimes looping when it should be exiting?
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 23 Jul 1998 22:30:31 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: temp directory for both unix and windows platform
Message-Id: <EwKJuv.Dqw@world.std.com>

mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:

>Anandan Balaji  <balaji@emicx.mentorg.com> wrote:
>>Hi,
>>
>>I am writing some perl scripts, which can run on both unix and
>>windows platform. Does any one have solution for how to take
>>care /tmp directory in the scripts?

>See IO::File::new_tmpfile or POSIX::tmpnam.

The last time I checked, the Windows ports of perl don't have a
POSIX.pm, but that was <URL:http://www.perl.com/CPAN//ports/win32/
Standard/x86/perl5.00402-bindist04-bc.zip>

has this changed?

-- 
Andrew Langmead


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

Date: Thu, 23 Jul 1998 23:54:19 GMT
From: weave005@bama.ua.edu (Alexander Weaver)
Subject: using s///
Message-Id: <35b7ca4c.100793836@news.ua.edu>

I've got a text file that I'm trying to do some things with that is
supposed to be comma-delimited, but there are also commas where they
aren't supposed to be.

Example record:

"3333","THIS COMMA,GETS IN THE WAY",444444,55555,33333

I would be perfectly happy to change the comma's inside quotation
marks into colons or some other character before treating the file as
a comma-delimited.  The desired output for the given example would be

"3333","THIS COMMA:GETS IN THE WAY",444444,55555,33333

All of the unneccessary commas will have a capital letter directly
before and directly after it.  So shouldn't I be able to use s/// to
search for that combination and change it?  How would that line of
code look?


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

Date: Thu, 23 Jul 1998 23:09:20 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Variable Interpolation
Message-Id: <EwKLnK.BD4@world.std.com>

tadmc@flash.net (Tad McClellan) writes:

>I expect it is because you could always interpolate scalar variables.

>So nobody _expected_ to get literal $ signs without escaping them.


>Then one day the p5p decided to change perl so that it would begin
>interpolating array variables too.

>But there were lots of programs out there that would break after
>such a change (since interpolation was not possible, programmers
>relied on getting their literal @ sign with no need to escape it).

Since the @ in front of arrays seems to have been added to version 2
of perl (from what I can tell of my FTP archeology search), I've
always guessed that that array interpolation into double quoted
strings happened then. (long before p5p, and I don't think the p2p
group had a membership geater than 1)

And since the initial scripts written in perl 0 have been reported to
be bug tracking reports distributed through a Usenet-like system, I'd
assume that there were lots of literal "@" in double quoted strings.

The real problem was that perl 4 parsed double quoted strings at
runtime, so it could check whether there had been an array defined by
that name. Perl 5 moved the parsing to compile time, so it can't tell
that a subroutine later in the file creates it.

-- 
Andrew Langmead


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

Date: Fri, 24 Jul 1998 00:08:52 GMT
From: endymion@my-dejanews.com
To: "Terry Cora" <TerryLCora@worldnet.att.net>
Subject: Re: Web mail script
Message-Id: <6p8jal$p4$1@nnrp1.dejanews.com>

In article <6p603t$nak@bgtnsc02.worldnet.att.net>,
  "Terry Cora" <TerryLCora@worldnet.att.net> wrote:
>
> I am looking for a web based e-mail script (ala hotmail) for a non profit
> geographic spacific church directory site.  Running a virtual server with a
> "catch all" e-mail system.  NetRoamer looks good, but they ignore my e-mails
> and do not provide demo to see if it will work on my server.  I installed
> MailMan, but it will only check the "catch all" box.
>
> Has anyone modified MailMan to to filter incoming messages and sort them
> into spacific user boxes with a web interface to allow new users to sign up?

We are working on this exact modification as an extension of the
Professional Edition of our MailMan product, as a means of providing
a one-stop "Free Mail" software solution, among other things.  Commercial
licenses for the professional edition will be $400 per server for an
unlimited number of users, and the as-of-yet unnamed one-stop free email
system will run $500 per server.  As a non-profit, this software would be
free for you to use, just like the Standard Edition of MailMan currently
is.  We are working out our engineering schedule right now to try to
determine a projected release date of this package, but our unofficial
projected initial beta release date right now is August 31.  Stop by
our site over the next couple of weeks if you are still interested,
http://www.endymion.com/products/mailman

Ryan Alyn Porter, President
Endymion Corporation
http://www.endymion.com

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 23 Jul 1998 23:14:30 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: What's wrong?
Message-Id: <6p8g4m$lbv$1@nswpull.telstra.net>

In article <35B74B45.2B19@min.net>,
	John Porter <jdporter@min.net> writes:
> Greg Bacon wrote:
>> 
>> ...or just use ./ex
> 
> Sure; or put . is before /usr/bin in your path.

Nonono.. This is not good advice, and it is also not topical for this
group. Go to Altavista, and read some of the stuff in comp.unix.misc
and comp.unix.shell to find out why.

It will 'help' for this problem, but it will start doing all kinds of
other bad things. I actually don't have . in my path at all.

> But better advice is to not name your programs the same as
> other programs!

Better, but not best.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 24 Jul 1998 00:47:00 +0200
From: kaih=6yUeANs1w-B@khms.westfalen.de (Kai Henningsen)
Subject: Re: What's wrong?
Message-Id: <6yUeANs1w-B@khms.westfalen.de>

merzky@physik.hu-berlin.de  wrote on 21.07.98 in <6p30ab$c1u$1@nnrp1.dejanews.com>:

> Anyway, ex does not explain Wilsons error message. This rather comes from
> the space in the first line, which prevents from calling perl at all. This
> actually seems to work on some systems/shells. Does anyone know who is
> interpreting this?

Under Linux, the kernel does, and it gets it right with as well as without  
the space, so that isn't it.

*How* is he running this script?

$ ./ex       # this should work
$ . ex       # this should give "print not found"


Kai
-- 
http://www.westfalen.de/private/khms/
"... by God I *KNOW* what this network is for, and you can't have it."
  - Russ Allbery (rra@stanford.edu)


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

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

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