[6481] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 106 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 12 23:17:20 1997

Date: Wed, 12 Mar 97 20:00:20 -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           Wed, 12 Mar 1997     Volume: 8 Number: 106

Today's topics:
     "my" all vars in eval() ?? <mkruse@shamu.netexpress.net>
     Re: a tricky regex (Tad McClellan)
     Re: Counter help me peez >:P (Tad McClellan)
     Re: Elegant way to strip spaces off the ^ and $ of a va <tchrist@mox.perl.com>
     Re: Elegant way to strip spaces off the ^ and $ of a va <wkuhn@uconect.net>
     Re: Elegant way to strip spaces off the ^ and $ of a va (Tad McClellan)
     Re: flock() problem <khera@kcilink.com>
     Re: flock() problem (Brendan O'Dea)
     getting system date on NT? (Chuck Wyatt)
     HELP: mirror.pl fails to execute (Terrence M. Brannon)
     Re: html embedding (Tad McClellan)
     Re: Installing Modules under Macperl & Getting the best (Paul J. Schinder)
     Re: matching whitespace? <powers@ml.com>
     Re: mathematically correct? <whall@oakhill.sps.mot.com>
     Re: newbie question: check if a number is in a list (Chip Salzenberg)
     Re: Perl FAQ part 8 of 0..9: System Interaction [Period <monnier@cs.yale.edu>
     Re: Please help with this Script. It's Cameron, not dia (Tad McClellan)
     Re: We have taken the Hassles out of the net (Tad McClellan)
     We've baffled tech support, now on to Usenet... <jman95@ix.NOSPAMnetcom.com>
     Re: We've baffled tech support, now on to Usenet... (Eric Bohlman)
     Re: What's a good Perl book? (David Tong)
     Re: Who makes more $$ - Windows vs. Unix programmers? <optimus@canit.se>
     Re: Why don't this helpful suggestions work? <roderick@argon.org>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 12 Mar 1997 21:08:09 GMT
From: Matt Kruse <mkruse@shamu.netexpress.net>
Subject: "my" all vars in eval() ??
Message-Id: <5g75vp$773@news1-alterdial.uu.net>

Let's say I want to get a perl expression from the user and execute it.  
But I don't want to have any variables in the eval() run into my own.  
What's the best way to do this?

I could do something like:
package temp;
eval(...);
package myownpackage;

But then the eval() is outside the original package, so the user must 
fully qualify every variable and know the name of the package that they 
want to pull values from, which I don't really want.

Isn't there just a way to clean up any variables created in the eval()??

-- 
Matt Kruse
mkruse@netexpress.net
http://www.netexpress.net/~mkruse/                  http://www.mkstats.com/
---------------------------------------------------------------------------
Unsolicited advertising of any type to this addresss will not be tolerated.


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

Date: Wed, 12 Mar 1997 17:07:50 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: a tricky regex
Message-Id: <60d7g5.bd4.ln@localhost>

Bryan Hart (bryan@eai.com) wrote:
: Sorry for asking such a question here, but I'm getting a bit stumped. 

This one had me going for a while too. I'm embarrassed at how much
time I spent on it, but I eventually found one that worked...


: I'm looking for a regex (or some other way) to remove whitespace from a
: string EXCEPT when the whitespace is enclosed in quotes("").

: Here's an example string:

: $Footer = { PullDown["New Issue"(AddNewIssue), "Help"(Help), "Issue
: Sticky"(StickyIssueAdd), "Link Sticky"(StickyLinkAdd)]; Motion;
: PullDown[ "Format 1"(Layout<1>), "Format 2"(Layout<2>), "Format
: 3"(Layout<3>), "Default"(Layout<0>)] }


As I'm yet only a lowly apprentice, it seems likely that the Master
will be able to improve upon it, but it will work in the mean time ;-)


------------
#!/usr/bin/perl -w

$_ = ' PullDown["New Issue"(AddNewIssue), "Help"(Help), "Issue
Sticky"(StickyIssueAdd), "Link Sticky"(StickyLinkAdd)]; Motion;
PullDown[ "Format 1"(Layout<1>), "Format 2"(Layout<2>), "Format
3"(Layout<3>), "Default"(Layout<0>)]
';

while ( m/(?:"[^"]+"|\s)/g ) {
   next if $& =~ /^"/;           # skip if double quote match
   $front = $`;                  # up to the part that matched
   s/\Q$front\E\s/$front/;       # delete whitespace
}

print;
------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Wed, 12 Mar 1997 18:34:08 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Counter help me peez >:P
Message-Id: <02i7g5.mn4.ln@localhost>

Brian Lorraine (lorraine@ait.nrl.navy.mil) wrote:
: Could someone help me with what is probably a simple perl problem? I'm
: working on a text counter that's rather simple. You can view it at:
: "www.ait.nrl.navy.mil/cgi-bin/lorraine/testcgi.pl"
: Anyhoo here is the actual perl code:
: ################################################
: #!/usr/bin/perl


Hey!  Where's every perl programmer's best friend?

What _is_ the perl programmer's best friend?

Why, that would be the -w switch to enable compiler warnings:

#!/usr/bin/perl -w
#               ^^  How ya doin ole friend?



: open(COUNTFILE, "testct");                 
: $numero = <COUNTFILE>;                     

: print "Content type: text/html\n\n";

: print "You are visitor number $numero\n" || print "Can't open the
: file\n";

: $numeronext = $numero + 1;              
: print COUNTFILE "$numeronext\n";         
: close(COUNTFILE);
: ################################################

: Yes, this script gives users read and execute permission and yes that
: "testct" countfile does give read and write permission to everyone. From
: what I can see this simple program SHOULD take the number already in
: there and print it out (which it does) and then takes that numbr, add
: one, and print that new number into the "testct" file (WHICH IS THE
: PROBLEM). It won't print to the file. I keep opening to check if it
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Maybe because you opened it for _input_?

You need to open it differently for output...

It may seem strange, but the answer for how to use open() for
output is described in the first paragraph of the open() part
of the free documentation that is included with the perl
distribution (perlfunc)...


: changed, but all I see in "testct" is a lonely "1". Would someone please
: offer some assistance :) ??? much more preferably by email but here in
: newsgroups if u want...
             ^^^^^^^^^


I want. 

Helping thousands of people at a time is something I'm willing 
to volunteer to do.

Individual help is billed at my usual rates  ;-)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 13 Mar 1997 01:12:01 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Elegant way to strip spaces off the ^ and $ of a variable containing a sentence.
Message-Id: <5g7k91$31j$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, asialive@best.com (Sherman Hsieh) writes:
:	I couldn't come up with an elegant way to strip off spaces
:(newline, tab or whatever) of a string. Does anyone have a good solution
:to this.
:
:Example:
:
:$variable = "	 jklsd jslkjsd   ";
:
:I want to strip off all the spaces before and after the string above so
:the resulting string should look like:
:
:$variable = "jklsd jslkjsd";

This is in the new faq.  Heck, it was in the old faq.

Go check out the recent posting of the faq, or the perl web page.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    That means I'll have to use $ans to suppress newlines now.  
    Life is ridiculous. 
        --Larry Wall in Configure from the perl distribution


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

Date: Wed, 12 Mar 1997 19:22:29 -0500
From: Bill Kuhn <wkuhn@uconect.net>
Subject: Re: Elegant way to strip spaces off the ^ and $ of a variable containing a sentence.
Message-Id: <332748C5.4EC1EF6B@uconect.net>

You can do it in one pass:

$variable =~ s/^\s+|\s+$/g ;

Hope this helps.

-Bill
-- 
Bill Kuhn
Chief Developer
Wired Markets, Inc.
http://www.buyersindex.com


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

Date: Wed, 12 Mar 1997 18:24:02 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Elegant way to strip spaces off the ^ and $ of a variable containing a sentence.
Message-Id: <2fh7g5.nl4.ln@localhost>

Les Peters (lpeters@aol.net) wrote:
: Sherman Hsieh wrote:

: > $variable = "    jklsd jslkjsd   ";
: > 
: > I want to strip off all the spaces before and after the string above so
: > the resulting string should look like:
: > 
: > $variable = "jklsd jslkjsd";

: Perhaps this?

: $var =~ s/^\s+(\S.*\S)\s+$/\1/;
                             ^^

You should be using the -w switch you know...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 12 Mar 1997 18:28:03 -0500
From: Vivek Khera <khera@kcilink.com>
Subject: Re: flock() problem
Message-Id: <x7d8t4snb0.fsf@kci.kciLink.com>

>>>>> "RS" == Randal Schwartz <merlyn@stonehenge.com> writes:

RS> Just consider flock(BLAH, 8) to NOT EXIST.

RS> (For those that want to know, the problem with releasing the lock
RS> first is that someone else can get the flock *before* your buffer
RS> flushes.  Ouch.)

Oh my... well, now I know what was causing those clashes in my
application...  Thanks oh so much for pointing this out!  I was
pulling out my hair for the last week on this!

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D.                Khera Communications, Inc.
Internet: khera@kciLink.com       Rockville, MD       +1-301-258-8292
PGP/MIME spoken here              http://www.kciLink.com/home/khera/


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

Date: 13 Mar 1997 01:15:41 GMT
From: bod@compusol.com.au (Brendan O'Dea)
Subject: Re: flock() problem
Message-Id: <5g7kft$dhl$1@diablo.compusol.com.au>

In article <8c7mjdi3yj.fsf@gadget.cscaper.com>,
Randal Schwartz  <merlyn@stonehenge.com> wrote:
>>>>>> "yili" == yili  <yili@cse.bridgeport.edu> writes:
>
>yili> flock(FH, $LOCK_UN);
>
>This is bad.  Never ever ever ever use flock(BLAH, 8).  Unless you
>really know what you are doing.  And even then, it'll be rare.
>Just close the filehandle.  It'll then flush the output buffer, close
>the fd, and release the lock implictly.
>
>Just consider flock(BLAH, 8) to NOT EXIST.

In which case the perlfunc manpage (for 5.003 anyway) should probably
be changed.  The flock example for does almost exactly what Yi Li
posted--effectively:

    flock F, 2;
    print F $data;
    flock F, 8;

While it is arguable that if the above is to be wrapped by open/close,
then the second flock can (and should) be dropped, is there really any
harm in using LOCK_UN if the second line was changed as follows?

    syswrite F, $data, length $data;

Regards,
-- 
Brendan O'Dea                                        bod@compusol.com.au
Compusol Pty. Limited                  (NSW, Australia)  +61 2 9809 0133


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

Date: Thu, 13 Mar 1997 03:25:02 GMT
From: cwyatt@cris.com (Chuck Wyatt)
Subject: getting system date on NT?
Message-Id: <332772aa.14256520@news.concentric.net>

Hello!

I'm familiar with how one might assign the system date to a variable
when programming Perl on a UNIX system.  

eg:
$date= `/bin/date "+%D %r"`;

However, it isn't clear to me how to do this in a Windows NT
environment.

eg:
$date= `c:\command\date`; 

doesn't cut it for me!  You end up with:
Current date is Wed 03-12-1997
Enter new date (mm-dd-yy):

 ...if you try to print $date!

Thanks for any suggestions.

Chuck Wyatt
cwyatt@cris.com
http://www.xensei.com/users/cwyatt/
Web Development and Implementation Services







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

Date: 12 Mar 1997 18:40:25 -0800
From: brannon@bufo.usc.edu (Terrence M. Brannon)
Subject: HELP: mirror.pl fails to execute
Message-Id: <ysiz209kqzu5.fsf@bufo.usc.edu>


I cannot get mirror to work. I made the suggested changes in
mirror.defaults and then invoked mirror as follows:

brannon@sand ~/install/scripts/perl/mirror : ls
CHANGES-since-2.1   do_unlinks          mirror.defaults     mm.man
README              ftp.pl              mirror.defaults~    mmin
README-URGENT       lsparse.pl          mirror.man          new-patches-by
README-VERY-URGENT  makefile            mirror.nightly      pkgs_to_mmin
TODO                mirror              mirror.pl           socket.ph
changelogs-rev1     mirror-.tar         mirror.pl~          socket.ph-solaris
chat2.pl            mirror-2.3.tar.gz   mirror.weather      support
dateconv.pl         mirror.cam          mm
brannon@sand ~/install/scripts/perl/mirror : uname -a
OSF1 sand V3.2 214 alpha
brannon@sand ~/install/scripts/perl/mirror : make mirror.tar
rev=`./mirror -v | perl -ane 'print "$F[2]\n";'`; echo ev; \
	tar cvf mirror-$rev.tar README README-URGENT README-VERY-URGENT CHANGES-since-2.1 TODO chat2.pl dateconv.pl do_unlinks ftp.pl lsparse.pl makefile mirror mirror.cam mirror.defaults mirror.man mirror.nightly mirror.pl mirror.weather socket.ph socket.ph-solaris mm mm.man pkgs_to_mmin mmin changelogs-rev1 support/cyber-patches support/lstest.pl new-patches-by
Final $ should be \$ or $name at ./mirror line 405, within string
syntax error at ./mirror line 405, near ", "^$2$""
Final $ should be \$ or $name at ./mirror line 410, within string
syntax error at ./mirror line 410, near ", "^$path$""
Execution of ./mirror aborted due to compilation errors.
brannon@sand ~/install/scripts/perl/mirror : 

-- 
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: Wed, 12 Mar 1997 18:47:12 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: html embedding
Message-Id: <gqi7g5.io4.ln@localhost>

Brian Lorraine (lorraine@ait.nrl.navy.mil) wrote:
: Quik Question... lets say I have a perl/cgi script that does the
                   ^^^^^^^^
: following print statement somewhere:
: #####
: print "<CENTER>Olah Taco</CENTER>; 
: #####

OK. "I have a perl/cgi script that does the
following print statement somewhere"          ;-)


: Is there a way I can take this html like output from this script and
: embed it into a part of another html document. For instance, If i have
: an html document where part of it says:
: #####
: <CENTER><B>You are visitor XXX</B></CENTER>
: #####
: Is there a way (without server side includes) that I can stick the
: output of that one script into where the XXX in this html document is?


Of course there is.


# UNTESTED

open(TMP, ">/tmp/brians_tmpfile") || 
   die "could not open '/tmp/brians_tmpfile'  $!";  # open output file
open(OTHER, "/path/to/other.html") || 
   die "could not open '/path/to/other.html'  $!";  # open input file

while (<OTHER>) {
   s#(<CENTER><B>You are visitor )XXX(</B></CENTER>)#$1<CENTER>Olah Taco</CENTER>$2#;
   print TMP;
}
close(OTHER);
close(TMP);
rename("/tmp/brians_tmpfile", "/path/to/other.html");



: thanks,

You're welcome, I guess.

I think you should read the docs a little more before resorting
to posting to thousands of computers around the entire World...


: peez respond by email if u can, or here if u really prefer >:)
                                          ^^^^^^^^^^^^^^^^^^

I really prefer.

Helping thousands of people at a time is something I'm willing to
volunteer for (notwithstanding that I am a Navy veteran, and am
well aquainted with the Never Again Volunteer Yourself acronym ;-).


Individual attention is billed at my usual rate, I gotta eat ya know ;-)


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Wed, 12 Mar 1997 19:51:02 -0500
From: schinder@leprss.gsfc.nasa.gov (Paul J. Schinder)
Subject: Re: Installing Modules under Macperl & Getting the best out of Makemaker
Message-Id: <schinder-1203971951030001@schinder.clark.net>

In article <332599EE.5E7E@no.spam>, geoff@no.spam.leeds.ac.uk wrote:

}  I feel compelled to ask a question about Macperl in this group because
}  I have been unable to get the answers I need from any FAQ, deja news or
}  the usual Macperl sources (which, sadly, appear to be slumbering).

You mean like the very active MacPerl mailing list?  Had you asked there,
you would have been answered.  Start up MacPerl, pull down the ? menu, and
you'll find the MacPerl homepage.  From there you can find some valuable
MacPerl links.

}  
}  My objective is to install the libwww modules(s). (To be honest, at this
}  stage, I would be pleased to receive guidance on installing any module).

<ftp://mors.gsfc.nasa.gov/pub/MacPerl/Scripts/libwww-perl-5.07.sit.hqx>. 
I've already done the work needed.  This archive includes libnet-1.04, but
not MD5 (MD5 is written in C, but you don't really need it).

}  
}  The biggest obstacle so far is the fact that Makemaker seems to crash
}  reliably on the Mac (this has been reported before).
}  
}  Even if Makemaker worked well, I would be left with a makefile, and the
}  Mac does not have a make.

Yes indeed.   The standard Perl installer should have been written in
platform neutral Perl.  It wasn't, and so we're stuck with trying to get
around a lack of make.  Personally what I usually do is install what I
want on my Sun workstation and then transfer the files to my Mac.  This
also gets around the problem that without make it's hard to Autosplit the
files that need Autosplitting.

The way I look at it, as soon as I can I'll be installing Rhapsody on my
Performa 6400.  Then, if rumors are correct, I'll have, or be able to get,
gcc and make.  So this type of problem should disappear in less than a
year.  Until then, forget about MakeMaker (unless you have MPW) and the
"standard" way of installing Perl modules.

}  
}  Perhaps installation on the Mac is intended to be done only using MPW
}  (tool).

Installation was apparently not intended to be done on anything but Unix
boxes.  Some modules can just be copied into the appropriate places in
@INC, but some take more serious work.

}  
}  Does anyone have any guidance, or could anyone point me in the right 
}  direction?
}  
}  Ben.

-- 
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@leprss.gsfc.nasa.gov


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

Date: 12 Mar 1997 14:55:53 -0500
From: "Brent B. Powers Swaps Programmer x2293" <powers@ml.com>
Subject: Re: matching whitespace?
Message-Id: <u02ohcoga0m.fsf@ml.com>

astroweb@astron (alex filippenko) writes:

 > i know i could look it up but i am 20min away from any perl book....sorry
 > 
 > how do I match an intederminate amount of whitespace... 
 > 
 > i thought... /' '.*/... but doesn't work.. 
 > 

I could answer, but I'm 20 Minutes away from any news reader :)

/\s/



-- 
Brent B. Powers               Merrill Lynch              powers@ml.com


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

Date: Wed, 12 Mar 1997 13:07:14 -0600
From: "J. Wayne Hall" <whall@oakhill.sps.mot.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: mathematically correct?
Message-Id: <3326FEE2.1785@oakhill.sps.mot.com>

This is a multi-part message in MIME format.

--------------28EF511269AE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Tom Phoenix wrote:
> 
> On Wed, 5 Mar 1997, Thomas A. Loser wrote:
> 
> >   The PERL (camel) book gives an example for selecting a random line
> > from a file of unknown length with a single pass through the file:
> 
> >   srand;
> >   rand($.) < 1 && ($it = $_) while <>;
> 
> As other posters have pointed out, this is mathematically correct in
> general. It can fail, though, for very large files because of the way in
> which rand() is implemented.
> 
> 

I was wondering about this, because I took someone's random
sig file script (the one that creates a named pipe and feeds
it random snippets) and did an overhaul.  At first, I just
made it do a format instead of just a snippet, and then
I added arguments for the snippet file and named pipe so that
other processes could use it, not just .signature and stuff.

Then I saw that my "randomness" wasn't so random.  Too often,
I saw the same ones come up.  I had a file that had about 300
snippets in it.

So, I changed it to slurp in the whole .signature_db file
into an array, and supplied a random snippet.  Then I
removed the snippet from the array.  When the array
was empty, I re-slurped in the .signature_db file.  That
way, I get every one exactly once (seems better to me than
exactly random), and then if I add more snippets to the
file, they're counted next time.

Obvious drawbacks:

  o  Memory is used all the time - not necessarily efficient.
  o  For some reason, pipe_draemon just dies.  About every
     month of uptime - it just disappears.  Don't know why.
  o  For some other reason, Netscape 3.01 Gold doesn't always
     read the named pipe.  50% of the time, it's blank
     However, everytime I do a cat .signature or a vi .signature
     or anything else, it reads 100% of the time.

Anyway, the script is attached. I'd love comments.

> 
> Hope this helps!
> 

Oh, it does... it does

 __________________________________________________________________
|  J. Wayne Hall  | whall@oakhill.sps.mot.com | Imaging & Storage  |
| Sys / Net Admin | RA2560@email.sps.mot.com  | CACTG, SPS, Austin |
|  Motorola, Inc. |                           |    512-891-3935    |
|------------------------------------------------------------------|
|  "I watched the Indy 500, and I was thinking that if they left   |
|   earlier they wouldn't have to go so fast." -- Steven Wright    |
 ------------------------------------------------------------------

--------------28EF511269AE
Content-Type: text/plain; charset=us-ascii; name="pipe_draemon"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="pipe_draemon"

#!/usr/moto/bin/perl -w
'di';
'ig00';
#
#
# Pipe Draemon
#
# J. Wayne Hall, 8/96
#
# $Id: pipe_draemon,v 1.1 1996/09/09 21:03:07 whall Exp whall $
#
#

sub get_snippets {
	local($SNIPS) = @_;
	$/ = "\n.\n";
	open(SNIPS,"$SNIPS") || die "$SNIPS: $!";
	chomp(@snippets = <SNIPS>);
	close(SNIPS);
	return @snippets;
} 

sub USAGE {
	print("Pipe Draemon v1.0, J. Wayne Hall\n\n");
	print("Usage: $0 [-d <database>] [-p <named pipe to create>] [-f <format to use>]\n");
	print(" <database>   = File of quotes, funny stuff, etc.\n");
	print("                default is ~/.signature_db\n");
	print("                Record separater is \'\\n.\\n\'\n");
	print(" <named pipe> = What named pipe you want\n");
	print("                default is ~/.signature\n");
	print(" <format>     = Format to use to print output\n");
	print("                default is random snippet on line by itself\n");
	print("\n");
	exit;
}

sub begin {
	$SNIPS = '.signature_db';
	$FIFO = '.signature';
	while (@ARGV) {
		$_ = shift(@ARGV);
		$_ =~ /^-d(.*)/      && ($SNIPS = ($1 ? $1 : shift(@ARGV)),next);
		$_ =~ /^-p(.*)/      && ($FIFO = ($1 ? $1 : shift(@ARGV)),next);
		$_ =~ /^-f(.*)/      && ($FORMAT = ($1 ? $1 : shift(@ARGV)),next);
		&USAGE;
	}
	$child = 0;
	my $snippet = "";
	@snippets = ();
	unless (-p $FIFO) {
		unlink $FIFO;
		print ("making file $FIFO\n");
		system('mknod', $FIFO, 'p') && die "$FIFO: $!";
	}  
	srand($$);
} 

sub END {
	unlink $FIFO if $child;
}


&begin;

# If user specified a customized format
if (defined($FORMAT)) {
	open(FORMATLOAD,"$FORMAT") || die "FORMATLOAD: $!";
	$format = "format FIFO = \n";
	while (<FORMATLOAD>) {
		next if /^format .* = \n/;
		last if /^\.\n/;
		$format .= $_;
	} 
	$format .= ".\n";
	close(FORMATLOAD);
	local $ = 0;
	eval $format;
	die $@ if $@;
} else {
	format FIFO =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$snippet
 .
}

if (fork) { wait; exit; }
if (fork) { exit; }
sleep 1 until getppid == 1;
$child = 1;
foreach (qw{INT TERM}) { $SIG{$_} = \&::END; }


while (1) {
	unless (@snippets) {
		@snippets = &get_snippets($SNIPS);
	}
	open(FIFO, "> $FIFO") || exit(1);
	$snippet = splice(@snippets, rand @snippets,1);
	write(FIFO);
	close FIFO;
	sleep 1;
}
############################################################

	# These next few lines are legal in both Perl and nroff.

 .00;					# finish .ig

'di            \" finish diversion-previous line must be blank
 .nr nl 0-1     \" fake up transition to first page again
 .nr % 0          \" start at page 1
'; __END__ ##### From here on it's a standard manual page #####

 .TH PIPE_DRAEMON 1 "September 9, 1996"
 .AT 3
 .SH NAME
pipe_draemon \- Named pipe w/ random snippet generator
 .SH SYNOPSIS
 .B pipe_draemon [\-d <database>] [\-f <format>] [\-p <named pipe>] 


 .SH DESCRIPTION
 .I Pipe_draemon
creates a named pipe (.signature by default) and daemon\-izes itself so that whenever something tries to read the pipe, it takes a random snippet from a database (.signature_db by default) and puts it into a user\-supplied format (snippet only by default).

To use in it's simplest form, follow these steps:

 .LP
 .RS
 .PD 0
 .TP 4
 .B o
Create a .signature_db in your home directory with neat sayings separated by "\\n.\\n".  (That's newline, ".", newline)
 .TP
 .B Example:
 .PD 0
 .TP 4
Exaggeration is a billion times worse than understatement.
 .
Headline:   Miners refuse to work after death
 .
[etc]
 .LP
 .RS
 .PD 0
 .TP 3
start pipe_draemon.  Whenever your program tries to read your .signature, it'll read a random snippet instead.

To use custom formats, do this:

Create a format file.  I'll use .signature_format as an example.  Make the format contain whatever you want, with the variable $snippet as the one line / multi lines with your snippet content.  Use PERL\-style formats, as such:

>>>> ^||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| <<<< ~~
     $snippet

The "^||||.." means take this many characters (word wrapped) and center them on this line, and then chop off what you used so as to break up each line.  

The "~~" means to dynamically create any number of lines it takes to use up the $snippet.  So, with this format, the bottom section will auto\-grow with the size of the snippet.

The ">>>>" and "<<<<" are just text symbols that will be printed

When you start pipe_draemon, be sure to specify "\-f .signature_format" so it'll know to use it as the format.

 .SH OPTIONS

\-d  Which database to take snippets from

\-p  What named pipe to create
    Default is .signature

\-f  What format to use for printing snippet
    Default is random snippet on line by itself, which
    looks like this:

^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$snippet

 .SH ENVIRONMENT
No environment variables are used.
 .SH FILES
 .signature
 .signature_db
 .SH AUTHOR
J. Wayne Hall  <RA2560@email.sps.mot.com>
 .SH "SEE ALSO"

Perl 5 Man Pages

 .SH ACKNOWLEDGEMENTS / ORIGIN

Thanx to Warren Hyde for his ideas and the original
signature daemon (sig_daemon)

Modifications from sig_daemon:

o  Uses user\-supplied formats in which to use a random snippet.
   This means you can make the output look however you want
   by following PERL\-style formats.  Use $snippet as the variable.

o  Snippets are read at the beginning of execution, and then
   re\-read as depleted.  Changes in snippet file are therefore
   recognized at next read\-in.  This also means that each
   snippet is used only once per # of snippets in file.  Results
   in more "randomness" in my opinion. (By definition, though it's
   actually less random.  Pfffftpht.)

o  Because the format, named pipe to create, and snippet file are
   user specified, you only need one program to do all of it.

 .SH FUTURE ENHANCEMENTS (you can help here if you wanna)

o  Keep the /n formatting in the original database in the format.


 .SH DIAGNOSTICS
If your format isn't working properly, look at your PERL\-styles.
In particular, if you're trying to put an "@" sign as text,
follow that line with "@" by itself, like this:

J. Wayne Hall, whall@oakhill.sps.mot.com
"@"
^||||||||||||||||||||||||||||||||||||||||||||||| ~~
$snippet

That way, the @ above isn't taken for a variable identifier


 .SH BUGS


--------------28EF511269AE--



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

Date: 12 Mar 1997 23:46:05 GMT
From: chip@rio.atlantic.net (Chip Salzenberg)
Subject: Re: newbie question: check if a number is in a list
Message-Id: <5g7f7t$8p@news.atlantic.net>

According to Dave@Thomases.com:
>On Thu, 06 Mar 1997 19:32:04 -0600, brz@hotmail.com <brz@hotmail.com> wrote:
>> Say I have a list of numbers {1, 2 ,4, 6, 9}
>OK, you have a list of numbers.

:-)

>> and I want to check if $a is in this list...
>> how do i do it?
>
>   if (grep($a, @list)) {
>      ...
>   }

That won't work.  You need 'grep($_ eq $a, @list)' or the version that
I find more readable, 'grep { $_ eq $a } @list'.
-- 
Chip Salzenberg     a.k.a.      <chip@atlantic.net>
      "Men of lofty genius are most active
       when they are doing the least work."
                          -- Leonardo da Vinci


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

Date: 12 Mar 1997 20:43:04 -0500
From: Stefan Monnier <monnier@cs.yale.edu>
Subject: Re: Perl FAQ part 8 of 0..9: System Interaction [Periodic Posting]
Message-Id: <5l913sftxz.fsf@tequila.systemsz.cs.yale.edu>

Stefan Monnier <monnier@cs.yale.edu> writes:
> Reminds me of a question:
> where should dynamically linked modules be put ? I created a
> /usr/local/lib/perl5 dir where I keep my perl modules, but if I set my
> PERL5LIB to /usr/local/lib/perl5, only /usr/local/lib/perl5 and
> /usr/local/lib/perl5/auto are searched for .so files, whereas I would much
> prefer to put the .so files at their "natural" place (in my case
> /usr/local/lib/perl5/i386-linux/5.003) but this requires me to add
> /usr/local/lib/perl5/i386-linux/5.003 to my PERL5LIB path, which seems ugly
> to me. What is the "normal" solution ?

I should precise that my perl is installed (per RedHat-4.0) in /usr rather 
than /usr/local, so that /usr/local/lib/perl5 is not automatically searched.
Also I don't have write access to /usr/lib/perl5, whereas I do have write
access to /usr/local/liberl5, so the situation is similar to the case where you
want to have your very own perl modules in ~/lib/perl5: where should the .pm go
(~/lib/perl5, it would seem), where should the .so go
(~/lib/perl5/i386-linux/5.003, it would seem) and what should PERL5LIB be set
to (~/lib/perl5 would look sensible to me) ?


        Stefan


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

Date: Wed, 12 Mar 1997 18:57:54 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Please help with this Script. It's Cameron, not diane.
Message-Id: <iej7g5.tq4.ln@localhost>

dianne cooper (cooper15@hsonline.net) wrote:
: Could somebody please help me with this portion of a script and tell me
: what part of it is for UNIX only. 

OK.

But I'm not gonna inspect 199 lines of code though...

Just try it and see if it works. If it doesn't, _then_ worry about
what's wrong (which may or may not be a Unix dependency)...



: I wan to to get to work on a Windows95
: OS. If you could, please tell me what I could do to change it. If this is 
: an impossible question, or I couldn't do it without rewriting it then don't
: kill yourselves trying to fighure the answer out. I downloaded the script,
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I don't think anyone has ever done this  ;-)


: And I'm just now trying to learn Perl. 


Well then. You should _immediately_ get the newly released Perl
FAQs (nine parts). You should also read the man pages that are
included with the perl distribution.

FAQ (part 8) says:

=head2 How can I capture STDERR from an external command?

There are three basic ways of running external commands:

    system $cmd;                # using system()
    $output = `$cmd`;           # using backticks (``)
    open (PIPE, "cmd |");       # using open()


So, a quick grep for 'system' and '`' (backtick) finds nothing.

A fgrep for '|' finds 5 lines, but none of them are in an open().

Looks good. Run it and see if it works...



[ snip an awful lot of code ]


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Wed, 12 Mar 1997 18:12:58 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: We have taken the Hassles out of the net
Message-Id: <aqg7g5.hk4.ln@localhost>

Nathan V. Patwardhan (nvp@shore.net) wrote:
: goextreme@hotmail.com wrote:


: :                  The Premiere Site on the Internet for EXTREME NET TOOLZ,

: I don't know about everyone else, but I'm hesitant to use something
: called "TOOLZ."  :-)


They spammed this all over too. I saw it three newsgroups, each
posted individually.

I'm hesitant to use _anything_ that's promoted by spammers.

I've added them of the list of places to avoid that I usually
provide to all of my clients.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 13 Mar 1997 02:33:48 GMT
From: "Jason Maggard" <jman95@ix.NOSPAMnetcom.com>
Subject: We've baffled tech support, now on to Usenet...
Message-Id: <01bc2f57$31fa9fe0$4eac20cc@graceland>

Howdy!!!!

	This program is a really simple thing, but I cannot get it to run on my
web server.  I use netcom, and all other scripts run fine.  Any input???? I
spent 2 hours with the Netcom hosting support kids, and they just finally
gave up with a resounding "Hmph, I dunno..."

Thanks, and come see us at ClaytorRE.com!
(There's always time for a cheesy plug.)

#Receptionist.pl ~ Jason Maggard
#! /usr/bin/local/perl5

#Where is that darn mail program??
$mailprog = '/usr/lib/bin/sendmail';

#And the mail is going where?
$recipient = 'office@claytorre.com';

read (STDIN, $buffer, $ENV{'content length"};
@pairs = split (/&/, $buffer);

foreach $pair (@pairs)
{
	($name, $value) = split (/=/, $pair);

	#Clean up that web garbage
	$value =~ tr/+/ /;
	$value =~ s/% ([a-fA-F0-9] [a-fA-F0-9]) /pack ("C", hex($1) /eg;
	$FORM{$name} = $value;
}

#Establish blank form behaviour
&blank_response unless $FORM{'Email'};

#Send and format mail
open (MAIL, "|$mailprog $recipient") || die "I can't seem to open
$mailprog!\n";
print MAIL "The following person has registered with us!\n";
print MAIL "----------------------------------------------\n";
print MAIL "Name:    $FORM{'Name:'}\n";
print MAIL "Address: $FORM{'Address:'}\n";
print MAIL "        
$FORM{'City:}"".""$FORM{'State:'}"".""$Form{'Zip:'}\n";
print MAIL "==============================================\n";
print MAIL "E-mail:  $FORM{'Email'}\n";
print MAIL "==============================================\n";
print MAIL "$FORM{'Name:'} had this to say...\n";
print MAIL "$FORM{'Comments'}\n";

close mail

#Insert HTML doc here for response using print tags



#--------------------------------------------------------
# subroutine blank_response
sub blank_response
{
	print "<center> <h1>";
	print "<p> You must include an E-mail Address in order to register. Please
re-enter your comments, or you may return to our <a
href="http://www.claytorre.com>homepage</a>.</p></center>";
	exit;
}
	 



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

Date: Thu, 13 Mar 1997 03:43:38 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: We've baffled tech support, now on to Usenet...
Message-Id: <ebohlmanE6yqCq.7v8@netcom.com>

Jason Maggard (jman95@ix.NOSPAMnetcom.com) wrote:
: 	This program is a really simple thing, but I cannot get it to run on my
: web server.  I use netcom, and all other scripts run fine.  Any input???? I
: spent 2 hours with the Netcom hosting support kids, and they just finally
: gave up with a resounding "Hmph, I dunno..."

[snip]
: #--------------------------------------------------------
: # subroutine blank_response

Just a nitpick here, but what's the point of a comment that merely echoes 
the code?

: sub blank_response
: {
: 	print "<center> <h1>";
: 	print "<p> You must include an E-mail Address in order to register. Please

              ^ opening quote

: re-enter your comments, or you may return to our <a
: href="http://www.claytorre.com>homepage</a>.</p></center>";

       ^ closing quote which isn't what you wanted         ^treated as 
opening quote

 : 	exit;
: }

Escape the quote with a backslash, use a single quote, or use some other 
quoting mechanism (a "here" style quote is ideal for this sort of thing).

Now if you were using cgi.pm, you'd have been able to test this from the 
command line, using the -w switch, and you'd have gotten a complaint 
about the mismatched quotes.
 


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

Date: 12 Mar 1997 22:57:46 GMT
From: dtong@lynx.dac.neu.edu (David Tong)
Subject: Re: What's a good Perl book?
Message-Id: <5g7cda$vtk@chaos.dac.neu.edu>

Hello,

Thanks to everyone who replied with their references. It was clear that
the O'Reiley books are the choices. I will also get the "Cross-platform Perl"
by Eric Johnson since I will work on multiple platforms. I am sure I will
come back here for more help from the kind and helpful people like you.

	Thank You
	David


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

Date: 12 Mar 97 16:17:41 +0100
From: Iggy Drougge <optimus@canit.se>
Subject: Re: Who makes more $$ - Windows vs. Unix programmers?
Message-Id: <1387.7010T977T2070@canit.se>

John Lockwood (johnl@calweb.com) skrev:
>"Terje A. Bergesen" <terjeber@eunet.spm-protect.no> wrote:

>>> Unix appeals more to me and is more advanced technically, but I am
>>> afraid that it is losing the market share to Windows 95.

>Unix is more advanced technically?  That's interesting.  The last time
>I installed a modem on Windows NT the OS found it for me.  The last
>time I tried it on Unix I read about the nine files one had to edit,
>then gave up.   It seems to me that Unix is losing market share
>precisely because end users never make the programmer's mistake of
>confusing technical advancement with obtuseness.

Why would your computer detect a modem for you? Do you mean it sent out "AT" on
the serial port and listened for "OK", or what? When I use modems, I just plug
them in into the appropriate sockets.
Granted, UNIX can be quite comlicated, but it still has the edge over NT in
really power-demanding niches.

--
    __/\________________ __ ______        _____________________________
    \/ /_  /\__  /\_  _// //     //\  /\ / ____________________________\
    / / / / __/ /  / / / // / / // / / // /          __   __
   / /_/ / / __/  / / / // / / // /_/ // /  alias | | _  | _  |__|
  /_____/ /_/    /_/ /_//_/\/_/ \_____\\ \        | |__| |__| .__|
________________________________________\ \        D r o u g g e
\_________________________________________/



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

Date: 12 Mar 1997 20:01:26 -0500
From: Roderick Schertler <roderick@argon.org>
To: cherold@pathfinder.com
Subject: Re: Why don't this helpful suggestions work?
Message-Id: <pzvi6wli8m.fsf@eeyore.ibcinc.com>

On Tue, 11 Mar 1997 12:54:54 +0000, Charles Herold <cherold@pathfinder.com> said:
> 
> [Using perl4,] I have this ugly set of if/else statements to set a
> particular array, and I want a neater way to do it.  This is the code
> that needs changing:
> 
>   if ($in{'op'} eq 'showcategory') {
>         %scheme = %scheme_showcategory;
>   } elsif ($in{'op'} eq 'showpage') {
>         %scheme = %scheme_showpage;
>   } elsif ($in{'op'} eq 'showbasket') {
>         %scheme = %scheme_showbasket;
>   } else {
>         %scheme = %scheme_default;
>   }
>   if(!%scheme) {
>         %scheme = %scheme_default;
>   }  

That code is fine.  You could clean up the formatting a little without
changing the algorithm, yielding

    if ($in{'op'} eq 'showcategory') {		%scheme = %scheme_showcategory;
    } elsif ($in{'op'} eq 'showpage') {		%scheme = %scheme_showpage;
    } elsif ($in{'op'} eq 'showbasket') {	%scheme = %scheme_showbasket;
    } else {					%scheme = %scheme_default;
    }

(you don't need the if(!%scheme) test) if you liked.

If you really wanted to make the hash selection programmatic you could
use type globs, like

    local(*scheme) = "scheme_$in{'op'}";
    *scheme = *scheme_default unless keys %scheme;

but I wouldn't recommend it, really.  This does work for both perl4 and
perl5, though.  If you want to understand it study the man page section
on "Passing by Reference," the symbol table part of the section on
"Packages" and the parts of the old FAQ which dealt with typeglobs.

> One response suggested something like this.  [...]
> 
> $scheme && (%scheme = %{scheme_.$in{'op'}}) || (%scheme = %scheme_default);

Systematically ignore anyone who tells you to write code like that.
That person is not worth listening to.  (Plus, you were right.  That
code requires perl5.)

-- 
Roderick Schertler
roderick@argon.org


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

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

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