[6555] in Perl-Users-Digest
Perl-Users Digest, Issue: 180 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 25 23:14:05 1997
Date: Tue, 25 Mar 97 20:00:23 -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 Tue, 25 Mar 1997 Volume: 8 Number: 180
Today's topics:
?Sort for all O/S's (Geoffrey Hebert)
Re: does open(FH, "pgm arg1 arg2") take only 1 arg? (Abigail)
Re: global my() variable used in foreach() loop loses i (Brian L. Matthews)
Re: global my() variable used in foreach() loop loses i (Scott Wimer)
interesting text formatting problem (Eric Litman)
Re: interesting text formatting problem <ltomlin@ucs.indiana.edu>
Need help CGI scripting HTML forms to email (Sheldon Rampton)
Re: Netscape Navigator 3.x <www@alien.claser.tno.it>
Re: On-line web page editor: Changing the directory a <tchrist@mox.perl.com>
perl regex optimization problem (Scott Wimer)
Re: Perl: case of? (Michael Fuhr)
Re: print "Content type: text/html\n\n"; <tchrist@mox.perl.com>
Re: print "Content type: text/html\n\n"; <dbenhur@egames.com>
Re: printing associative arrays in order (Brian L. Matthews)
QUESTION: rewriting a single line as several shorter li (Terrence M. Brannon)
reversing files?!?! (Ernesto Gianola)
Re: SIG{'CHLD'} problem with perl5.005_28 on Solaris 2. (Charles DeRykus)
suid perl script <root@eisa.p146.zaphod.rhein.de>
Re: term 'regular expressions' considered undesirable <vladimir@cs.ualberta.ca>
Re: term 'regular expressions' considered undesirable <vladimir@cs.ualberta.ca>
tied hash FETCH oddity (Thomas Andrews)
Re: Unix and ease of use (WAS: Who makes more ...) <tim@a-sis.com>
Re: Unix and ease of use (WAS: Who makes more ...) <tim@a-sis.com>
Re: Unixware 1.1.4 - Perl5.001m Protocol Not Supported <tchrist@mox.perl.com>
Re: What's a bad Perl book? (revjack@radix.net)
Re: When reversed<> used What is happening? <vladimir@cs.ualberta.ca>
Re: Who makes more $$ - Windows vs. Unix programmers? (Sometimes Brian)
Re: Who makes more $$ - Windows vs. Unix programmers? (Scott Norwood)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Mar 1997 01:43:27 GMT
From: soccer@microserve.net (Geoffrey Hebert)
Subject: ?Sort for all O/S's
Message-Id: <5h9u2a$ak4$1@news3.microserve.net>
I am writing a perl cross-reference script. The script will do a
complete directory. I do not know the size of the input.
I need to create an intermediate file to be sorted. I do this because
of potential memory problems. I could sort a hughe array, but how
large can an array be?
Because I want this to run anywhere perl code exists, how do I code a
machine/OS independent sort?
Currently I just do system() with a UNIX sort command.
Thanks
email to heberts@microserve.net
------------------------------
Date: Wed, 26 Mar 1997 00:34:06 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: does open(FH, "pgm arg1 arg2") take only 1 arg?
Message-Id: <E7MK8u.EsK@nonexistent.com>
On 25 Mar 1997 22:42:03 GMT, Joe McCaughan wrote in comp.lang.perl.misc:
++ Hi,
++
++ I cannot get the following construction to see more than 1 arg.
++ I'm using perl4.
Try upgrading to perl5.
++
++ open(JUNK, "start.pl $arg1 $arg2 |);
^ Where's the closing " ?
++
++ It sees $arg1 OK but nothing after it. I put print statements in
++ to make sure that the args were defined. This is a major
++ drawback for my work. If anyone has an idea (or work-around),
++ I'd appreciate it.
You *ALWAYS* check the return value of open. Try:
open (JUNK, "start.pl $arg1 $arg2 |") or die "Eeps: $!";
At least you will get a message that it fails, and most of the
time, it will tell you why it failed as well.
Abigail
------------------------------
Date: 25 Mar 1997 17:24:45 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: global my() variable used in foreach() loop loses its value
Message-Id: <5h9tst$crr$1@halcyon.com>
In article <5h9idg$9o0@shell1.cybercom.net>,
Ron Newman <rnewman@shell1.cybercom.net> wrote:
|I am using a global variable, declared my() at the top level, as
|the loop control variable in a "foreach" loop.
|Instead of getting the expected value of the variable, it instead
|finds the variable to be empty. Can anyone explain this?
Heavy sigh.
Yes, I can explain it, as can the perl manual pages, as can any perl
book worth reading, as can the FAQ, as can DejaNews (this has only
been discussed what, 7 or 8 times in the past month?).
Try some local resources before posting far and wide. Besides getting
the answer you want much faster, you'll also probably get some answers
you don't need today but will in the future.
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: Wed, 26 Mar 1997 00:22:25 GMT
From: scottw@earthlink.net (Scott Wimer)
Subject: Re: global my() variable used in foreach() loop loses its value
Message-Id: <33386b65.590322401@news.earthlink.net>
On 25 Mar 1997 17:08:48 -0500, rnewman@shell1.cybercom.net (Ron
Newman) wrote:
[Cc:ed to rnewman@shell1.cybercom.net ]
Ron,
my() variables are not visible to subroutines called from inside the
block they are in.
If what your after is making the script comile under use strict; then
do:
use vars qw(topic);
Then eliminate the my $topic; line.
regards,
scottwimer
Regards.
>Here's a Perl script whose behavior I don't understand at all.
>
>I am using a global variable, declared my() at the top level, as
>the loop control variable in a "foreach" loop. Inside the loop,
>I call a subroutine which access the global variable. Instead
>of getting the expected value of the variable, it instead finds
>the variable to be empty. Why?
>
>***** The perl script ********
>
>#!/usr/local/bin/perl -w
>
>use strict;
>my $topic;
>
>main();
>
>sub main {
> my @topics = ("first", "second", "third", "fourth");
> foreach $topic (@topics) {
> print "In loop: topic is $topic\n";
> subroutine();
> }
>}
>
>
>sub subroutine {
> print "In subroutine: topic is $topic\n";
>}
>
>******* The output **********
>
>In loop: topic is first
>Use of uninitialized value at /tmp/foo.pl line 18.
>In subroutine: topic is
>In loop: topic is second
>Use of uninitialized value at /tmp/foo.pl line 18.
>In subroutine: topic is
>In loop: topic is third
>Use of uninitialized value at /tmp/foo.pl line 18.
>In subroutine: topic is
>In loop: topic is fourth
>Use of uninitialized value at /tmp/foo.pl line 18.
>In subroutine: topic is
>
>****** end of output *******
>
>If I remove these two lines:
>
> use strict;
> my $topic;
>
>the program behaves properly:
>
>In loop: topic is first
>In subroutine: topic is first
>In loop: topic is second
>In subroutine: topic is second
>In loop: topic is third
>In subroutine: topic is third
>In loop: topic is fourth
>In subroutine: topic is fourth
>
>Can anyone explain this?
>
>
>--
>Ron Newman rnewman@cybercom.net
>Web: http://www.cybercom.net/~rnewman/home.html
------------------------------
Date: 26 Mar 1997 02:32:49 GMT
From: elitman@viaduct.com (Eric Litman)
Subject: interesting text formatting problem
Message-Id: <5ha1sh$6ic@news4.digex.net>
I have a rather interesting text formatting problem to solve. I have an
application in which I need to strip HTML from a document to deliver
it via email as plain text. When simply removing (<.+?>), I'm left with
large, blank areas in the paragraphs where the HTML tags once were.
What I'd like to do is remove the HTML codes while retaining the
original paragraph "shape" (i.e. formatted to 75 columns).
Perl formats *almost* work, but they break down when dealing with line-by-line
lists of items like this:
This is the first list item
This is the second, slightly longer, list item
This is the third, longer than the first two, list item
Has anyone solved this problem with a reasonably generic approach?
--
Eric A. Litman Viaduct Technologies, Inc. Bethesda, MD
CEO http://www.viaduct.com (301) 493-0220
digital cellular (PCS) info: http://www.celltalk.com
------------------------------
Date: Tue, 25 Mar 1997 22:02:56 -0500
From: Jay Tomlin <ltomlin@ucs.indiana.edu>
Subject: Re: interesting text formatting problem
Message-Id: <Pine.HPP.3.91.970325215641.13945A-100000@ezinfo.ucs.indiana.edu>
If you're using a Unix flavored server with lynx installed (and if you
don't think it would bring the server to its knees to do this), you could
try the handy -dump flag with lynx:
print `/usr/bin/lynx -dump http://perl.com`;
Obviously, not recommended if you anticipate tons of hits, but fine for
an occasional splurge.
-jay
----------
Jay Tomlin
Office of Overseas Study, Indiana University
http://ezinfo.ucs.indiana.edu/~ltomlin
"When it speaks of music, language is lame." --George Steiner
On 26 Mar 1997, Eric Litman wrote:
> I have a rather interesting text formatting problem to solve. I have an
> application in which I need to strip HTML from a document to deliver
> it via email as plain text. When simply removing (<.+?>), I'm left with
> large, blank areas in the paragraphs where the HTML tags once were.
>
> What I'd like to do is remove the HTML codes while retaining the
> original paragraph "shape" (i.e. formatted to 75 columns).
>
> Perl formats *almost* work, but they break down when dealing with line-by-line
> lists of items like this:
>
> This is the first list item
> This is the second, slightly longer, list item
> This is the third, longer than the first two, list item
>
> Has anyone solved this problem with a reasonably generic approach?
>
> --
> Eric A. Litman Viaduct Technologies, Inc. Bethesda, MD
> CEO http://www.viaduct.com (301) 493-0220
> digital cellular (PCS) info: http://www.celltalk.com
>
>
------------------------------
Date: Tue, 25 Mar 1997 21:23:28 -0500
From: sheldon@execpc.com (Sheldon Rampton)
Subject: Need help CGI scripting HTML forms to email
Message-Id: <sheldon-2503972123280001@galaan-7.execpc.com>
Hi, I'm about to attempt writing my first CGI script in Perl and am hoping
someone can help me shortcut the learning curve. I've been learning Perl
itself using MacPerl and have written a number of scripts that run
successfully on my laptop. I've created a form in HTML and gotten the web
page to work properly from my internet account. Now I want to create a
script that will take the information posted from the form, clean it up a
bit, and email the result back to me. The problem is, I can't figure out
how to make Perl send email. I've bought two books on Perl and one on CGI
scripting in Perl, and none of them seems to give any examples of how to
do this. Can someone help me out, by (1) telling me to where to look up
the information I need, or (2) emailing me a few lines of sample code?
How, for example, would I write a script to send email from
"sheldon@execpc.com" to "srampton@aol.com" with "Hello, world" in the
Subject line and a simple paragraph of text in the message body? If
someone can explain how I do this much, I think I can figure out the rest.
Post responses here, and if you please, forward them to my email address:
sheldon@execpc.com
Thanks!
------------------------------
Date: Tue, 25 Mar 1997 18:58:37 -0800
From: Luis Ontanon <www@alien.claser.tno.it>
Subject: Re: Netscape Navigator 3.x
Message-Id: <333890DD.7AF7@alien.claser.tno.it>
Scott Reed wrote:
>
> I am currently working on an NT system that uses Perl with
> ActiveWare's Perl for Win32. I can get the script to work
> properly under IE 3.0. When I use Netscape's Navigator, it tries
> to use a helper app to respond to the perl script because it has
> a .pl extension. I tried to remove the references of the .pl
> files in Navigator through a file in the Navigator directory and
> the Win 95 registry. Does anyone know how I can get around this?
> I didn't buy Navigator so I don't have support from Netscape.
> Also, I have to use the .pl extension because it is required from
> Perl for Win32. Help!!
You can convert the perl script ino a .bat file using the perl2bat batch
script distributed with activeware's perl distribution so by invoking
just the name with no extention it will do.
------------------------------
Date: 26 Mar 1997 02:33:33 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: On-line web page editor: Changing the directory a file is written to?
Message-Id: <5ha1tt$hq8$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Tom Phoenix <rootbeer@teleport.com> writes:
:Check out perlfunc(1), which has several helpful Perl operators and
:examples.
No, Tom: perlfunc has functions, perlop has operators. (Ok, I know we
put -X in perlfunc. Nonetheless...) These two aren't the same, except
in a sick and supergeeky kind of way that no one understands.
In the following expression:
$a = f($x) + g($y);
The operators are "+" and "=", whereas the functions are f() and g().
I realize you can blur the distinction, but that serves only to confuse
people. Don't call print or chomp operators. Call them functions.
Things like "eq" and "++" are operators. And "<STDIN>" is not an operator
at all. At most, it's an operation, where "<>" is the circumfix operator
and STDIN its operand.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
But you have to allow a little for the desire to evangelize when you
think you have good news.
--Larry Wall in <1992Aug26.184221.29627@netlabs.com>
------------------------------
Date: Wed, 26 Mar 1997 00:17:02 GMT
From: scottw@earthlink.net (Scott Wimer)
Subject: perl regex optimization problem
Message-Id: <333869a8.589877023@news.earthlink.net>
Hi.
I'm working on a module Text::StringParse that is a suplement of sorts
to the Text::ParseWords module. It accepts any regex for both the
quote and delimiter strings. However, I want to avoid doing a billion
regex recompilations on the pattern which doesn't change.
The problem is, when I use the /o flag I can't coerce the bloody thing
into matching.
This is a long post, i've included the output of perl -v, perl -V and
the script itself. Any advice on why I can't set the /o flag
(specifically when i'm looking for the begining or end of a quoted
block) would be greatly appriciated.
Thanks,
scottwimer
perl -v:
chevy:/home/scottw/scripts/library> perl -v
This is perl, version 5.003 with DEBUGGING EMBED
built under solaris at Oct 24 1996 12:24:16
+ suidperl security patch
Copyright 1987-1996, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.
chevy:/home/scottw/scripts/library>
perl -V:
chevy:/home/scottw/scripts/library> perl -V
Summary of my perl5 (5.0 patchlevel 3 subversion 0) configuration:
Platform:
osname=solaris, osver=2.5, archname=sun4-solaris
uname='sunos chevy 5.5 generic sun4c sparc sunw,sun_4_75 '
hint=recommended, useposix=true, d_sigaction=define
Compiler:
cc='gcc', optimize='-O', gccversion=2.7.2
cppflags='-I/opt/gnu/include -DDEBUGGING'
ccflags ='-I/opt/gnu/include -DDEBUGGING'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=15
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib -L/opt/gnu/lib'
libpth=/usr/local/lib /opt/gnu/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
libc=/lib/libc.so, so=so
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
cccdlflags='-fpic', lddlflags='-G -L/usr/local/lib -L/opt/gnu/lib'
@INC: /usr/local/lib/perl5/sun4-solaris/5.003 /usr/local/lib/perl5
/usr/local/li
b/perl5/site_perl/sun4-solaris /usr/local/lib/perl5/site_perl .
chevy:/home/scottw/scripts/library>
And now the script itself:
# StringParse.pm - Perl module for parsing text that needs to be split
but
# may contain quoted text which contains the split regex. This
provides a
# means to parse such text and preserve the protections that were
intended by
# the person writing the stuff down.
# This is somewhat like the Text::ParseWords module that comes
standard with
# the Perl 5 distribution, but doesn't have what I consider to be some
of its
# limitations. It accepts any arbitrary string as the delimiter(can
even be
# a regex) and any arbitrary string (can also be a regex) as the
quoting chars
# as opposed to only working with |"| and |'| quoted strings. Of
course, these
# benefits are not without tradeoffs, it runs slower than
Text::ParseWords does.
# Oh well, win some, lose some.
#
# usage:
# use StringParse;
# $string_ref=\@strings; # setup reference to @strings array
#
@{$array_ref}=StringParse($string_ref,$seperator,$quote_pattern,$keep);
#
# NOTE: that you are handing it a reference to an array, not the array
itself
# this should make it execute a little faster.
# ALSO, the value returned is a reference to an array of the parsed
strings,
# not the parsed strings themselves. This also is for speed reasons.
#
################################################################################
# by Scott Wimer scottw@earthlink.net
# Copyright 1997 by Scott Wimer
# This was written for EarthLink Network, Inc. but they aren't liable
for its
# use. If it blows away your data or kicks your cat, it's your fault,
not
# EarthLink Network, Inc.'s or mine.
# scottwimer
################################################################################
### take care of all the package overhead stuff
package Text::StringParse;
require 5.000;
use Carp;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(StringParse);
###
### Insert POD Documentation here
###
### the StringParse routine
##- Here's a brief description of the methodology used to handle the
parsing.
##- Each element of the array we were handed is checked to see if
there are
##- any $quote_pattern in them, or if there are any |\|'s to protect
individual
##- characters. If there isn't any reason to do anything more than
simply
##- break the string apart on $seperator occurances, no point in
spending time
##- processing it.
##-
##- If a string contains quote characters, well, that's where we earn
our money.
##- If we reach the end of a string and are still in a quoted section,
then
##- complain about an imbalanced quote; spit out the string to help
the user
##- find the error.
##-
##- The first three(3) argument are mandatory, the final is optional
sub StringParse ($$$;$) {
#use strict; # for debugging purposes only, slows down
execution
### get stuff from @_ , i.e., our paramaters
return (0) unless (scalar(@_)>=2);
my @strings =@{$_[0]} if $_[0];
$Text::StringParse::sep =$_[1] if $_[1];
$Text::StringParse::quote =$_[2] if $_[2];
my $keep =$_[3] if $_[3];
###
### return null if we were called with an empty @strings
unless (@strings)
{
return(0);
}
###
### here is where we do some speed tweaking
##- The problem I'm faced with is this. I'm doing a boatload of regex
searches
##- in here, on either $quote or $sep, an they don't change throughout
##- this routine. BUT, if somebody calls this routine twice from the
same
##- script with different $quote or $sep strings, then my /regex/o
optimization
##- attmepts flunk. So, I use the method below to try to improve the
speed
##- with which this routine executes.
##- check to see if $quote or $sep is different
##- if different, (and its not the first time we were called)
##- set up a must succeed dummy match and eval{} it to recompile the
REGEX and
##- then go on about our business.
if ($Text::StringParse::times_through)
{
# print "DEBUG:okay, we were called again, check for different
patterns\n";
# we've been called before, check to see if the patterns are
different
unless ($quote eq $Text::StringParse::prev_quote)
{
# print "DEBUG:different \$quote pattern\n";
# setup dummy match for $quote and eval{} it
eval '$quote=~/$quote/o';
# don't do anything otherwise
}
unless ($sep eq $Text::StringParse::prev_sep)
{
# print "DEBUG:different \$sep pattern\n";
# setup dummy match for $sep and eval{} it
eval '$sep=~/$sep/o';
# don't do anything otherwise
}
}
###
### prepare to be called to battle again in the future
$Text::StringParse::times_through++;
$Text::StringParse::prev_quote =$quote; # just incase we're called
again
$Text::StringParse::prev_sep =$sep; # just incase we're called
again
###
### now go through each line in @strings
##- as we get a(n) chunk/element split, stuff it onto the @output
array
my ($string,$ct,@this_element,@output);
foreach $string (@strings)
{
if ($string !~/$sep/o)
{
### string doesn't contain a seperator string, stuff it into output
# print "DEBUG:no_sep:$string\n";
if (!$keep)
{
# print "DEBUG:not keeping $quote\n\n";
$string=~s/^$quote//;
$string=~s/$quote$//;
}
push @output,$string;
next;
###
}
### now walk down each string, and keep quotes if the $keep is set
my ($i,$block,$slash); # define some variable & flags we'll
be using
for ($i=0;$i<=length($string);$i++)
{
# print "*",substr($string,$i,1),"*\n";
if ($slash)
{
# slash protection is on, turn it off, push this value onto
@this_element
# print "DEBUG:end slash\n";
$this_element[$ct++]=substr($string,$i,1);
$slash=0;
next;
}
if (substr($string,$i,1) eq '\\')
{
# begin slash protection
# print "DEBUG:begin slash\n";
$this_element[$ct++]=substr($string,$i,1);
$slash=1;
next;
}
if ($block)
{
### inside of a quote protected block
if (substr($string,$i,1) =~/$quote/)
{
### end of a quote protected block
##- keep the $quote if $keep is set
# print substr($string,$i,1);
# print "\nDEBUG:end quote\n";
$this_element[$ct++]=substr($string,$i,1) if $keep;
$block=0;
next;
###
}
# just another char in a quote protected block
# print "+";
# print substr($string,$i,1);
$this_element[$ct++]=substr($string,$i,1);
next;
}
###
if (substr($string,$i,1) =~ /$quote/) # not recompiled, won't match
'/'
{
### begining of a quote protected block
# print "DEBUG:begin quote\n";
# print substr($string,$i,1);
$this_element[$ct++]=substr($string,$i,1) if $keep;
$block=1;
next;
###
}
if (substr($string,$i,1) =~/$sep/o)
{
### end of this_element, push @this_element onto @output
# print "DEBUG:element end\n\n";
my $this_element=join "",@this_element;
push @output,$this_element;
$ct=0;
@this_element=();
next;
###
}
### just regular unquoted text, jam it in as well
$this_element[$ct++]=substr($string,$i,1);
}
### check for unbalanced quotes
carp ("unbalanced quote --> $string\n") if $block;
###
### push @this_element onto @output, cause we're done with this
string
my $this_element=join "",@this_element;
push @output,$this_element;
@this_element=();
###
###
}
###
return @output;
}
###
1; # make sure we evaluate as true
--------------
--
Scott Wimer
scottw@earthlink.net
Just another computer geek
------------------------------
Date: 25 Mar 1997 18:04:39 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Perl: case of?
Message-Id: <5h9sn7$r7u@nova.dimensional.com>
[ cc to author ]
Matthew Grady <mgrady@nortel.ca> writes:
>Does anyone know if Perl has the equivalent of a "case of" control
>structure? If so, is it the same as in C?
Yes, several :-) Take a look at the perlsyn manual page for
some of the variations.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 26 Mar 1997 01:27:19 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: print "Content type: text/html\n\n";
Message-Id: <5h9u1n$e9f$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Brian Lorraine <lorraine@ait.nrl.navy.mil> writes:
:This one always gets me. I'm writting a perl counter script. Here's the
:actual code:
:I can get the rest of the program to work, but check it out at:
:"http://www.ait.nrl.navy.mil/cgi-bin/lorraine/testcgi.pl"
:It won't show the output as an html document. Is there an EXACT place I
:have to shove that "print "Content type: text/html\n\n";" line and the
:rest of it to get it to work??
:--------------------------------------------------------------
:Brian "the BrAiN" Lorraine lorraine@ait.nrl.navy.mil
Brian, O Brain, this is not a CGI group. Didn't you realize that? Also,
you forgot locks. And counters are a stoopid waste (and wrong as well).
Go read the FAQ.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like
reading a suicide note -- three days too late."
--Tom Christiansen <tchrist@mox.perl.com>
------------------------------
Date: Tue, 25 Mar 1997 17:15:07 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Brian Lorraine <lorraine@ait.nrl.navy.mil>
Subject: Re: print "Content type: text/html\n\n";
Message-Id: <3338789B.6DD6@egames.com>
[mail&post]
Brian Lorraine wrote:
> print "Content type: text/html\n\n";
^ you want a dash here.
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: 25 Mar 1997 17:19:10 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: printing associative arrays in order
Message-Id: <5h9tie$cns$1@halcyon.com>
In article <33381DDB.41C6@gaia.umbc.edu>,
Ishwarya Rao <irao1@gaia.umbc.edu> wrote:
|I was wondering if there is a one line command to print the elements
|of an associative array in the order in which it was created
perl doesn't have the slightest idea the order keys are added to a hash.
If you want to be able to access elements in the order they're added,
you'll have to maintain that information yourself, for instance with
an array:
push @array, $key unless exists $hash{$key};
$hash{$key} = $data;
then print it with:
foreach (@array)
{
print $hash{$_}, "\n";
}
or have a second hash to maintain the order, or use a compound key
that lets you sort in created order, or make each hash value a
two element array with one element being the data and the other
an indicator of the creation order, or ...
The point is, you'll have to maintain creation order yourself.
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: 25 Mar 1997 17:15:07 -0800
From: brannon@kappa.usc.edu (Terrence M. Brannon)
To: brannon@rana
Subject: QUESTION: rewriting a single line as several shorter lines
Message-Id: <ysiz913bmp2p.fsf@kappa.usc.edu>
I have a string containing a total of 100 digits which are either a 1
or 0 sep'd by a single space in between them. I want to write this
string to a file in which each line contains $lineLength number of
digits, where $lineLength <= 16;
How can I do this in Perl?
--
terrence brannon brannon@rana.usc.edu fax:213-740-5687 home:213-737-5096
2677 Ellendale Place #206, LA, CA 90007 /o)\ neuralcomplab:213-740-3397
http://rana.usc.edu:8376/~brannon \(o/ brainsimlab:213-740-6995
------------------------------
Date: 26 Mar 1997 02:57:42 GMT
From: netog@cs.bu.edu (Ernesto Gianola)
Subject: reversing files?!?!
Message-Id: <5ha3b6$j3d@news.bu.edu>
To reverse a file use GNU tac!
Ernesto
------------------------------
Date: Tue, 25 Mar 1997 23:44:47 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: SIG{'CHLD'} problem with perl5.005_28 on Solaris 2.5
Message-Id: <E7MHyp.2Ar@bcstec.ca.boeing.com>
In article <5h6ac1$q54@mozo.cc.purdue.edu>,
Wendy Lin <af5@quest.cc.purdue.edu> wrote:
>I built a version for AIX systems and have not had problems. But when
>the following script ran on Solaris, children became <defunct>.
>
>First the script:
>
> #!/usr/local/bin/perl -w
>
> $SIG{'CHLD'} = 'IGNORE';
>
> # Things work if I have my own signal handler!
> #$SIG{'CHLD'} = \&myHandler;
>
> print "I am the parent with pid $$\n";
> if(!fork()) {
> print "I am child #1 with pid $$\n";
> print "Child #1 Exiting\n";
> exit;
> }
> if(!fork()) {
> print "I am child #2 with pid $$\n";
> print "Child #2 Exiting\n";
> exit;
> }
> print "\nWaiting 1 Second...\n";
> sleep(2);
> print "Running `ps -g $$'\n\n";
> system("ps -g $$");
> print "\n";
>
>
> sub myHandler
> {
> wait;
> }
>
Wendy,
On a Solaris 5.5.1 system, I noticed that the defunct processes
vanished a couple of seconds after the script exited. I wonder
if "system" call reaping of the children perhaps had something
to do with it? Anyway, very strange, but then Solaris is quite
strange :)
As a "workaround", forking another process to look at the process
table eliminated even these short-lived zombies.
if (!fork) {
system "ps", "-g", "$$";
exit;
}
Regards,
--
Charles DeRykus
ced@carios2.ca.boeing.com
------------------------------
Date: 25 Mar 1997 21:26:53 +0100
From: root <root@eisa.p146.zaphod.rhein.de>
Subject: suid perl script
Message-Id: <d8sn4t0y.fsf@eisa.p146.zaphod.rhein.de>
how do i use suid perl scripts.
i have found
suidperl -v
This is perl, version 5.003 with EMBED
built under linux at Aug 21 1996 13:01:33
+ suidperl security patch
ls -l suidperl
-rws--x--x 1 root root 488672 Aug 21 1996 suidperl*
ok , suidperl seems to exist. but how do i use it??
i guess i had to rewrite the perl script with a starting line like
#!/usr/bin/suidperl
but again the script chmoded to 4711 complains with
Can't do setuid
thanks for help
--
Jvrg Jenderek phone: + 49 228 232028 email:joerg_jenderek@zaphod.rhein.de
Quirinstra_e 9 fax : + 49 228 234755 email:joerg_jenderek@T-online.de
53129 Bonn Germany www :http://home.t-online.de/home/joerg_jenderek
------------------------------
Date: 25 Mar 1997 18:33:49 -0700
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <ompvwnv3lu.fsf@tees.cs.ualberta.ca>
In article <JFRIEDL.97Mar24014305@tubby.nff.ncl.omron.co.jp> jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey) writes:
> |> Now the second one needs no backtracking:
> |> find an 'a' or fail;
> The "or fail" is, by definition, backtracking.
Why do you say so? Eg /a/ will fail on "b", and I don't see how it could
possibly backtrack.
> |> > /^a[^b]*?b[^c]*?c/
> |> This one won't need backtracking indeed.
> Sure it does... when the [^b] fails, it can backtrack to the ``gee, because
> of the * I didn't really need to attempt [^b]
When would the [^b] fail? I read teh above thus: check that the first char is
a, then gobble up all ^b's, check that there is a next char (it would be b),
gobble up all ^c's, check for a c.
> in common practice, an ``NFA'' is usually endowed with a much more
> expressive language.
What do you mean by "more expressive in common practice"? If exactly the same
languages (regular ones) are recognized by both NFAs and DFAs, which is more
expressive? You can't make a distinction unless you also consider execution
time etc.
> To a DFA (awk, lex, etc.), /a|and/ and /and|a/ and /a(nd?)/ are *exactly*
> the same.
Ok (though you seem to have a typo in the last one).
> Yet they're quite different with Perl and the majority of regex engines out
> there.
>From an implementation point of view? So what? We were talking about the math
term "regular language" and whether perl regexps implement those or more or
less. The first two regexps specify the same language (set of strings) in
either formal langauges or perl (unless the perl implementation is wrong).
> |> The greedy/non-greedy |> distinction doesn't come into play here at all.
> If they're the same, then so are /.*/ and /.*?/, and if the target string
> has any [non-newline] characters they're guaranteed to be different.
They match THE SAME SET OF STRINGS, though they pick up the match differently.
Both specify a regular language.
------------------------------
Date: 25 Mar 1997 19:04:56 -0700
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
Subject: Re: term 'regular expressions' considered undesirable
Message-Id: <omohc7v25z.fsf@tees.cs.ualberta.ca>
In article <5h8i9o$fhc@samba.rahul.net> c.c.eiftj@33.usenet.us.com (Rahul Dhesi) writes:
> CLAIM: /^a.*b.*c/ (greedy) and /^a.*?b.*?c/ (nongreedy) both match the
>
> RESPONSE: what if the input stream is not entirely matched by either? Then,
> in normal perl code operation, we may end up matching different substrings
> of the input stream by the two patterns. Thus it's incorrect to say that
> both match the same strings
It's quite correct to say so: /$re1/ and /$re2/ will return 1 for the same set
of values of $_.
> COMMENT: Perl and similar pattern matching has one of two goals:
> (a) either deciding whether an entire input string is matched by a given
> pattern,
Right. But regular languages only have this goal.
> or (b) searching the input string for some substring that is
> matched by a given pattern.
If you claim that something does not specify a regular language, and if you
use the term in its mathematical sense, you have to stick with (a).
> Therefore blindly extending the concepts of language grammars to pattern
> matching will lead to much confusion.
No, blindly using the term "regular expression" in its math sense without
conforming to what Chomsky and Kleene used it for is what leads to confusion.
> CLAIM: /^a.*?b.*?c/ (nongreedy) and /^a.*b.*c/ (greedy) can be
> implemented with exactly the same finite state machine.
>
> RESPONSE:
Before I consider your response, let me reiterate my argument. Both the above
regexps require a string that starts with a and has a prefix also containing b
and c. Thus your "sawa, sawb" FA works for the second regexp too. It is true
that it would match the "wrong" c (not the last possible one), but this
doesn't matter. Because FA's *cannot specify matches*, it can only say whether
the string matched or not. At least the output-less FAs that are used in
regular language thory.
BTW there's a moot point in the definition of greedy *. How exactly should
this be maximized? Does the first .* take precedence over the second .*? Eg
for the string abbc, is
a .* b .* c a better match than a .* b .* c ?
a b b c a b b c
> The greedy /^a.*b.*c/ cannot be implemented with a finite
> state machine.
Well, how do you expect the FA to report the matches? If you want it to say "I
matched the b from the regexp" as soon as it's seen the correct b, then
obviously it can't do that, because this depends on whether there are more b's
(and c's0 in the input.
> CLAIM: Anything that is generated by a regular language is a regular
> expression.
> RESPONSE: Only if you remain within the spirit of regular languages
But certainly you should remain within this spirit. Otherwise what's the THIRD
sense (neither formal languages nor perl) in which you're using the term?
> As soon as you start looking for any *substring* in the input stream that is
> in the regular language, you are misusing the terminology.
Right ;-) Formal regular languages are not concerned with the way something
matches, only with whether it matches.
> CLAIMS: "How a matcher is implemented (backtracking etc) has no bearing
> on the language it recognizes"
Now an example showing that non-greedy matching may require backtracking:
"abbc" =~ /a.*?b[^b]c/ The .*? will first match "" but then it will have to
reconsider and match the first b.
------------------------------
Date: 25 Mar 1997 19:05:25 -0800
From: thomaso@shell3.ba.best.com (Thomas Andrews)
Subject: tied hash FETCH oddity
Message-Id: <5ha3pl$ms6@shell3.ba.best.com>
I have a tied hash, %domains, which does one thing if I
say:
(*) Package::function($domains{$name});
and another thing when it does:
(**) Package::function($dummy=$domains{$name});
My tied hash returns objects of a fixed type, and Package::function
expects an object of that specific type. (*), for some reason,
fails, because it doesn't get an object of the correct type.
(**) works, however.
I'm using Perl 5.001n, so maybe this is just an oddity in that
version of the language?
Other information:
Platform: Solaris 2.5
Package::function is actually a builtin we've compiled
into perl, so the problem could possibly be in there.
Any help would be appreciated. Thanks. I've played with
contexts (scalar vs array) and have not succeeded there...
--
==
Thomas Andrews thomaso@best.com http://www.best.com/~thomaso/
"Harry Truman's a goddamn liar. No
pidgeon ever lit on my head." - Senator Sam Rayburn
------------------------------
Date: 25 Mar 1997 20:51:39 GMT
From: "Tim Behrendsen" <tim@a-sis.com>
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <01bc395e$3c0375a0$87ee6fce@timpent.a-sis.com>
Hugh A. L. Dempsey <dempseyh@pinn.net> wrote in article <33376EA3.3C06@pinn.net>...
> > Tim Behrendsen wrote:
>
> > Do you think he is going to put something
> > into Linux that he wouldn't put into his commercial baby?
> >
> > --
> > ==========================================================================
> > | Tim Behrendsen (tim@a-sis.com) | http://www.cerfnet.com/~timb |
> > | "Judge all, and be prepared to be judged by all." |
> > ==========================================================================
>
> Why, yes, I do. In his commercial baby, he is directed by the
> "pointy-haired
> boss" and must do what the management team wants, rather than what he
> thinks
> is right. This frustration will be relieved by by putting "the right
> code" into
> linux.
In my experience, the best programmers do the "Right Thing" on
whatever project they are doing, and don't think in terms of
petty "conspiratorial" thinking like this.
In any case, if Linux happened to have some nifty feature that a
commercial Unix doesn't have (hasn't happened yet to the best of
my knowledge, but that's beside the point), then the market will
demand it of the commercial Unixes. Even Mr. Pointy-Haired-Boss
understands meeting market demands before (or after, whatever)
the competition does.
--
==========================================================================
| Tim Behrendsen (tim@a-sis.com) | http://www.cerfnet.com/~timb |
| "Judge all, and be prepared to be judged by all." |
==========================================================================
------------------------------
Date: 25 Mar 1997 21:17:26 GMT
From: "Tim Behrendsen" <tim@a-sis.com>
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <01bc3961$d5867120$87ee6fce@timpent.a-sis.com>
Eric Bohlman <ebohlman@netcom.com> wrote in article <ebohlmanE7LKDq.3FJ@netcom.com>...
> Tim Behrendsen (tim@a-sis.com) wrote:
>
> : Indeed, which is why it will never be dominant (note I did
> : *NOT* say successful, which is a different thing). Microsoft
> : et al have an incentive of fundamental survivability, and
> : Linux does not. Commercial operating systems will always be
> : a few steps ahead of free operating systems, simply because
> : they have to be to survive, and that is a much more powerful
> : incentive than some guy working part time on some part of
> : the operating system, particularly when that same guy is
> : probably working on a commercial O/S in order to put the kids
> : through college. Do you think he is going to put something
> : into Linux that he wouldn't put into his commercial baby?
>
> Quite possibly yes, because the "commercial baby" isn't his, it's his
> boss's, and his boss's reasons for deciding what does/doesn't get put in
> may very well be motivated by office politics (perhaps the feature that
> the developer thinks would enhance the product's survival is being
> strongly advocated by another manager who's competing with the
> developer's boss for a possible promotion, so putting the feature in
> would increase the promotability of the boss's rival).
The best programmers that I know don't think in terms of financial
ownership of a product, they think in terms of "My Project", and
take pride in what they do.
> Or the software
> may be released before it's completely ready because missing a deadline
> would adversely affect the company's stock price, even though a premature
> release would lead to increased support expenses in later quarters. Or a
> simple change may require a month's worth of signature-getting, so the
> developer doesn't bother to implement it.
Maybe the boss is a spy for a competing company, and is only
at the company to sabatoge the product. Maybe he is really a
frustrated hardware engineer, and is taking his revenge on the
world. Maybe his wife secretly wants to have a farm, so she
sneaks in and destroys the computers and backups.
Your point?
Of course, your point is irrelevent because we are talking about
the mass market, not an individual company. Any individual
company can do anything, but it's competition that causes self-
correction of these statistical anomolies. A company's
fundamental motivation is surivivability in the marketplace,
and this is always at odds with human fallibility.
> Now this doesn't necessarily imply the opposite of what you were saying,
> that free software is going to be of inherently better quality than
> commercial software, but it does imply that the actual comparison is a
> lot closer than you make it out to be.
I have no doubt that free software will be continue to be
successful, in the sense that it will provide a useful purpose.
It just will always be behind the commercial market (except
perhaps for short, temporary ebbs and flows), and will never
achieve dominance.
> Another consideration is that in many cases the market for free software
> consists of those who are going to use it hands-on while the market for
> commercial software consists of those who make the purchasing decisions
> for their company, and in many cases those decisions are made with little
> input from the actual users. Thus a large commercial software firm may
> not feel it worthwhile to invest much in development that doesn't create
> something that impresses computer-illiterate managers, even if that
> development would enhance the usability of the software. This acts to
> reduce the disparity in practically available resources between the free
> software developer and the commercial software developer.
Perhaps, but this is a small effect in the scheme of things.
Companies that have this effect dominate the corporate structure
do not survive for long.
> Now in some areas, commercial software is definitely going to have an
> advantage over free software; mass-market consumer software is going to be
> one of those, because the software marketing process is much more
> important than the software development process in determining success in
> that sort of market; what goes on the box is more important than what goes
> in the box.
Marketing is important, no question about it, but it's much less
important than most (particularly anti-Microsoft people) think.
Far more important to people is standardization and the ability
to run the applications that they are used to, and what everyone
else has.
Example: OS/2. The marketing stank, but that's not what killed
OS/2. Lack of 100% compatibility killed OS/2. In the beginning,
OS/2 got a *lot* press coverage, and computer magazine coverage.
It never made any market penetration because "Joe Blow" doesn't
understand how/where/when the incompabilities were going to bite
him in the butt, so it's too much of a PITA to deal with.
Of course, Apple is going to make the same mistake, *again*,
when the come out with Rhapsody which is (probably) not going
to be 100% Win32 compatible. It is dead before it is even
written. When will they learn? The public doesn't give a crap
about technical superiority, they care about getting work done
with a minimum of hassle. And incompatibility is the #1 most
major hassle.
--
==========================================================================
| Tim Behrendsen (tim@a-sis.com) | http://www.cerfnet.com/~timb |
| "Judge all, and be prepared to be judged by all." |
==========================================================================
------------------------------
Date: 26 Mar 1997 02:08:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Unixware 1.1.4 - Perl5.001m Protocol Not Supported
Message-Id: <5ha0en$hq8$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
"John Kaminski" <john@execnet.net> writes:
:I am using at Script the uses the chat2.pl perl library with a Unixware
:1.1.4 system. My compile of perl5.001m was sucessful. When I execute this
:Perl fragment I get a protocol not supported.
Look in the FAQ. Search for "chat2" and for "procol not supported".
The faq is at http://www.perl.com/perl/faq/
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
There ain't nothin' in this world that's worth being a snot over.
--Larry Wall in <1992Aug19.041614.6963@netlabs.com>
------------------------------
Date: Wed, 26 Mar 1997 03:15:21 GMT
From: revjack@radix.net (revjack@radix.net)
Subject: Re: What's a bad Perl book?
Message-Id: <33439363.11156695@news1.radix.net>
Keywords: Hexapodia as the key insight
Previously, Eric Bohlman at OMS Development wrote:
: (Seriously, has anyone done any research on whether Perl is easier to
: learn as a first or subsequent language, and if the latter, which first
: languages make it easier and which make it harder? I sometimes think my
: C background has sometimes gotten in the way of my learning certain
: aspects of Perl.)
Some are born to Perl, others have it thrust upon them. I am in the
latter category - hired as an HTML grunt, I was quickly required to
produce [you-know-what] scripts, and am now in the process of
constructing a back-end web database. My background in linear non-OOP
languages like BASIC probably shows. I strongly suspect that I am
repeatedly guilty of reinventing the wheel, but I'm too embarrassed to
talk about it.
_________________
revjack@radix.net
------------------------------
Date: 25 Mar 1997 19:07:46 -0700
From: Vladimir Alexiev <vladimir@cs.ualberta.ca>
To: soccer@microserve.net (Geoffrey Hebert)
Subject: Re: When reversed<> used What is happening?
Message-Id: <omn2rrv219.fsf@tees.cs.ualberta.ca>
In article <5h73gc$r97$1@news3.microserve.net> soccer@microserve.net (Geoffrey Hebert) writes:
> Is the software/hardware smart enough to position the readhead at the
> end of the file and actually read block by block backwards?
No. <> slurps thw whole file into memory (into an array) and then reverse
works in memory.
> Or is this just a software trick to read in the whole file and then
> present it to the script backwards?
Perl as a whole is a trick. What's bad with that?
------------------------------
Date: Tue, 25 Mar 1997 18:05:22 GMT
From: brianm@ricochet.net (Sometimes Brian)
Subject: Re: Who makes more $$ - Windows vs. Unix programmers?
Message-Id: <33381387.3243540@news.ricochet.net>
On Sat, 22 Mar 1997 22:32:12 -0600, Marion Evans
<marion.evans@wcom.com> wrote:
>Novell treated Unix with same reverance as WordPerfect alright
>Noorda's sucksessor Frankenstein sold Unix and UnixWare to Sun
>Even still the Unix - Sun deal was done bout a year before the
>WP - Corel deal.
Actually, SCO bought Unix from Novell, and currently own the Unix
system. I don't think that Sun owns Unix at all.
Brian Moffet
brianm@ricochet.net Brian D. Moffet
Be careful believing what I say, I have been known to be
wrong before.
------------------------------
Date: 26 Mar 1997 02:14:50 GMT
From: snorwood@balloon.ml.org (Scott Norwood)
Subject: Re: Who makes more $$ - Windows vs. Unix programmers?
Message-Id: <5ha0qq$ceu4@wombat.wm.edu>
In article <33381387.3243540@news.ricochet.net>,
Sometimes Brian <brianm@ricochet.net> wrote:
>
>Actually, SCO bought Unix from Novell, and currently own the Unix
>system. I don't think that Sun owns Unix at all.
Sun doesn't own UNIX, but they did purchase the right to use the name
and (I believe) some source) for forever, as of a couple of years ago
(not sure on details...check a good UNIX book for more information).
--
<html><head><title>Down with HTML news postings!</title></head><body>
<h1><blink>If this line blinks, then it's time to get a newsreader that
doesn't encourage HTML news posting! There are many that are better
than Netscape or IE; try trn!</blink></h1></body></html>
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 180
*************************************