[7724] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1350 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 20 19:07:33 1997

Date: Thu, 20 Nov 97 16:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 20 Nov 1997     Volume: 8 Number: 1350

Today's topics:
     Re: "perl aware" vi editor? (Martien Verbruggen)
     Re: ^D not working (brian d foy)
     Re: Accept ("Interrupted system call") (Gerben Wierda)
     Re: An elegant solution wanted for removing .. in path (Tushar Samant)
     Re: Another s/// question (Juergen Heinzl)
     Re: Another s/// question <jczech@NOSPAM.ablecom.net>
     Re: Another s/// question (brian d foy)
     Re: Another s/// question <tycage@infi.net>
     Re: Another s/// question (brian d foy)
     Re: Can Perl dial the phone? (Bryan Miller)
     Re: date (brian d foy)
     Re: Error 500 on server??? (Martien Verbruggen)
     Re: Extracting key-value pairs from HTML FORM text (Jan Ivar Pladsen)
     Re: File test operators do not work as advertised!! (brian d foy)
     Re: Help: What dir am I in <msa@cynet.net>
     Re: How To Test if number is ODD or EVEN? (Ken Fox)
     Re: ignore above... (Martien Verbruggen)
     Intermediary compiled perl? (Gerben Wierda)
     Re: Is there a sendmail utility for MIIS/NT (Neil Briscoe)
     Re: max size of cookie? <dboorstein@ixl.com>
     Re: Perl Source Formatter <rpsavage@ozemail.com.au>
     Pipes and Shared Memory naveen_rajavasireddy@acml.com
     Re: Please help with user log (brian d foy)
     Re: Q: How many elements in a %HASH ? (Gerben Wierda)
     Re: Q: How many elements in a %HASH ? (brian d foy)
     Regexps question <a15d@unb.ca>
     Re: Regexps question (brian d foy)
     Re: s/// Question <jefpin@bergen.org>
     Re: Schplitz v1.1 rets@meta3.com
     Re: Split (brian d foy)
     Unable to locate DLL marek@cmic.ca
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 20 Nov 1997 21:59:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: "perl aware" vi editor?
Message-Id: <652brd$1e5$1@comdyn.comdyn.com.au>

>>well, that's a shame. nvi is a much better piece of work.

Please, please please,

not another religious 'my editor is better than your editor' war.
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Webmaster www.tradingpost.com.au    | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: Thu, 20 Nov 1997 17:58:29 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: ^D not working
Message-Id: <comdog-ya02408000R2011971758290001@news.panix.com>

In article <652a63$9mi$1@gamera.albany.net>, "Skip Egley" <egley@albany.net> wrote:

>@array = <STDIN>;
>
>and perl will keep stuffing array with lines from standard input until a ^D
>(Control-D). Mine doesn't work. The ^D simply prints a weird character on
>the screen. It doesn't interrupt the receiving of data from standard input.
>Am I doing this right? Is there something wrong with my version of perl? I
>downloaded the latest one for Win95, I believe it was 5.004_02.

^D is a Unix sort of thing.  perhaps that other OS has a different key?  how
do you normally signal the end of input?

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 19 Nov 1997 08:21:44 GMT
From: G.C.Th.Wierda@AWT.nl (Gerben Wierda)
Subject: Re: Accept ("Interrupted system call")
Message-Id: <EJvwK8.ByI@AWT.NL>

You have to put the accept in a loop, catch the signals and make sure that 
after the signal handling the accept is restarted. So, a way to do it is as 
follows (forking server):

sub REAPER {
    $waitedpid = wait;
    $SIG{CHLD} = \&REAPER;  # loathe sysV
    syslog 'info', "Parent: reaped $waitedpid" . ($? ? " with exit $?\n" : 
"\n");
}

$SIG{TERM} = \&catch_int;
$SIG{INT} = \&catch_int;
$SIG{USR1} = \&catch_int;
$SIG{USR2} = \&catch_int;
$SIG{CHLD} = \&REAPER;

while (1) { &mainLoop } # Double endless loop..., if you really want to be 
robust

sub mainLoop {
    for ($waitedpid = 0;
	 ($paddr = accept( CLIENT, SERVER)) || $waitedpid;
	 $waitedpid = 0, close CLIENT)
    {
	next if $waitedpid and not $paddr; # E.g. on interruped system call
	my ($clientPort, $iaddr) = sockaddr_in( $paddr);
	my $name = gethostbyaddr( $iaddr, AF_INET);

	syslog 'info', "Connection from $name [" . inet_ntoa( $iaddr) .
	    "] at port $clientPort";

	my $pid;
	if (not defined($pid = fork)) {
	    # I am the parent, but forking failed
	    syslog 'alert', "Parent: Cannot fork: $!";
	    next;
	}
	elsif ($pid) {
	    # I am the parent
	    syslog 'debug', "Parent: begat $pid";
	    next;
	}
	else {
	    # else I am the child, $pid == 0
	    # do something useful here
	    exit; # Everything went fine
	}
    }
    syslog 'debug', "Left loop (e.g. on any signal but the expected ones)";
}

sub catch_int {
    my $signame = shift;
    exit if ($signame =~ /(INT|TERM)/o);
    if ($signame eq 'USR1') {
	&syslog_level( ++$opt_verbose);
    }
    if ($signame eq 'USR2') {
	&syslog_level( --$opt_verbose);
    }
    # Reinstall for SysV
    $SIG{$signame} = \&catch_int;
    $waitedpid = 1; # Fool main loop
}

If an interrupt TERM, or INT or USR1 etc is given, the function catch_int is 
called. This one exits on INT and TERM and handles verbose setting on USR1 
and USR2. This is a forking server so we also handle SIGCHLD (finishing 
children) and clear their remains with a wait (otherwise you get socalled 
'zombie' processes') and we do not want to wait in the main loop as we want 
to start accepting connections immediately after having split of a child to 
handle it.

Yours,

---
Gerben Wierda,

Stafmedewerker Adviesraad voor het Wetenschaps- en Technologiebeleid.
Staff member Advisory Council for Science and Technology Policy
Javastraat 42, 2585 AP, Den Haag/The Hague, The Netherlands
Tel (+31) 70 3639922	Fax (+31) 70 3608992
http://www.AWT.nl/prive/wierda/

The fox knows many things, but the hedgehog knows one big thing.

"History may not repeat itself, but it does rhyme a lot."
  - Mark Twain



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

Date: 20 Nov 1997 17:39:38 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: An elegant solution wanted for removing .. in path
Message-Id: <652hnq$5ca@shoga.wwa.com>

cboget@apdi.net writes:
>Please forgive me for asking (I'm a newbie),
>but what does the above do?  I do not understand.


	s#/+#/#g; $_ = "/$_/";       #"sentinels"
	1 while s#/[^/]+/\.\./#/#;
	chop($_ = substr($_,1));     #or something like that


First, the middle line has already been explained by Tad. But
just for completeness: the substitution operator is looking for
a pattern like:

	/dir/../

anywhere in the path, and replacing it with just a "/". (That's
what was wanted, getting rid of redundant things like going into
dir and coming back upstairs.)

The "1 while <the substitution>" means: do the substitution, and
if it succeeds try it again. (You will have to look at the man
pages to see why that's the effect of "1 while ..."). So, there
will be no such pattern in the path once the statement is executed.


Now the statements before and after are trying to sweat it to the
max: s#/+#/#g turns anything like "a////b" into "a/b". Then you
slap on a "/" before and after the path -- the reason is, you
would like to deal with something like a/b/c/.. and turn it into
a/b, but the substitution pattern won't catch that.

After we are done we need to get rid of the "sentinel" /s on the
left and right. The last line does that -- maybe in an offensively
ugly way, but you get used it after a while. $_ = substr($_,1)
gets rid of the first "/" and the chop removes the last "/".
Once again the man pages will tell you why.



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

Date: 20 Nov 1997 22:20:19 GMT
From: juergen@unicorn.noris.de (Juergen Heinzl)
Subject: Re: Another s/// question
Message-Id: <slrn679e7l.64.juergen@unicorn.noris.de>

In article <6527gg$5v8$1@usenet85.supernews.com>, Vaughn Fox wrote:
>hi all
>
>I'm new with Perl and am trying to replace an empty space in a variable with
>a "?" and haven't had much luck with the following:
>
>$variable =~ s/ /?/gi;

even you do not need the i here it should work. Could it be that your space
is a tab ? Either here / / or in $variable. If you've the vi try set list,
so tabs are displayed as ^I.

Bye, Juergen

-- 
\ Real name     : Juergen Heinzl     \       no flames      /
 \ EMail Private : unicorn@noris.de   \ send money instead /
  \ Phone Private : +49 0911-4501186   \                  /


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

Date: Thu, 20 Nov 1997 14:27:50 -0800
From: J <jczech@NOSPAM.ablecom.net>
Subject: Re: Another s/// question
Message-Id: <3474B966.15FB@NOSPAM.ablecom.net>

Vaughn Fox wrote:
> 
> hi all
> 
> I'm new with Perl and am trying to replace an empty space in a variable with
> a "?" and haven't had much luck with the following:
> 
> $variable =~ s/ /?/gi;
> 
> am I on the right track, or is there another way I should go about this?
> 
> Thanks
> 
> Vaughn

The question mark is a special character in regular expressions, so you
have to escape it with a backslash.

should be: 

$variable =~ s/ /\?/g;

also, since you're not substituting the '?' for a character, you can
drop the "i" at the end to do case insensitive matching.

*J


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

Date: Thu, 20 Nov 1997 17:38:29 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Another s/// question
Message-Id: <comdog-ya02408000R2011971738290001@news.panix.com>

In article <6527gg$5v8$1@usenet85.supernews.com>, "Vaughn Fox" <vfox@nbnet.nb.ca> wrote:

>I'm new with Perl and am trying to replace an empty space in a variable with
>a "?" and haven't had much luck with the following:
>
>$variable =~ s/ /?/gi;
>
>am I on the right track, or is there another way I should go about this?

for simple one-to-one replacements, go with the tr/// thingy:

   #!/usr/bin/perl

   $variable = 'just another new york perl hacker';

   $variable =~ tr/ /?/;

   print "$variable\n";

   __END__

   just?another?new?york?perl?hacker

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 20 Nov 1997 17:30:44 -0500
From: Ty Cage Warren <tycage@infi.net>
Subject: Re: Another s/// question
Message-Id: <3474BA14.77240D28@infi.net>

Vaughn Fox wrote:
> 
> hi all
> 
> I'm new with Perl and am trying to replace an empty space in a variable with
> a "?" and haven't had much luck with the following:
> 
> $variable =~ s/ /?/gi;
> 
> am I on the right track, or is there another way I should go about this?
> 
> Thanks
> 
> Vaughn


$variable =~ s/[\t ]/?/g;

worked for me.  You don't need the i since space doesn't have a case
anyway.  I though about using \s instead of [\t ] but it would replace a
newline
as well.

If you want multiple spaces/tabs replaced with one ? make it

$variable =~ s/[\t ]+/?/g;

Hope this helps,
  Ty

+---+
Ty Cage Warren                                           tycage@infi.net
Systems Engineer                                                 InfiNet
The Web Site of Love: http://tazer.engrs.infi.net/mst3k/
PGP Public Key: http://tazer.engrs.infi.net/~tycage/pgpkey.html
PGP Fingerprint: FF C1 28 CA 80 B5 31 78  B1 24 2E 8C AB DA FB D2
------------->Never invoke anything bigger than your head.<-------------


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

Date: Thu, 20 Nov 1997 17:50:30 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Another s/// question
Message-Id: <comdog-ya02408000R2011971750300001@news.panix.com>

In article <3474B966.15FB@NOSPAM.ablecom.net>, J <jczech@NOSPAM.ablecom.net> wrote:

>Vaughn Fox wrote:

>> $variable =~ s/ /?/gi;

>The question mark is a special character in regular expressions, so you
>have to escape it with a backslash.
>
>should be: 
>
>$variable =~ s/ /\?/g;

no need for the slash - the replacement text is not a pattern.  it
works equally as well when escaped though, but leads to leaning
toothpick syndrome.

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 20 Nov 1997 22:24:06 GMT
From: millerb@millerb.fc.hp.com (Bryan Miller)
Subject: Re: Can Perl dial the phone?
Message-Id: <652da6$pi0@fcnews.fc.hp.com>

S (se@primenet.com) wrote:
: Could someone please point me to more info/howto/module for getting
: perl to dial a phone line. 

: I need to do this for Win95, NT4.0, and Linux

: Thanks,
: shawn

---
Only if you give it treats first and say "Good Perl".



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

Date: Thu, 20 Nov 1997 17:51:49 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: date
Message-Id: <comdog-ya02408000R2011971751490001@news.panix.com>

In article <3474ABE1.18164626@healtheon.com>, Indu Bingham <indu@healtheon.com> wrote:

>Anyone know how I could get a script to get a date range for a week.
>
>For example I have a week 46 and I would like to get the the begin date
>of the week 46 and the end date.


CPAN [1] has many nifty Date modules.

[1] 
Comprehensive Perl Archive Network
find one near you at <URL:http://www.perl.com>

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 20 Nov 1997 22:33:38 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Error 500 on server???
Message-Id: <652ds2$1il$1@comdyn.comdyn.com.au>

In article <3472F583.69758B94@dds.nl>,
	Michiel van Leening <mivale@dds.nl> writes:

> I see what others haven't seen: you did a chmod +x script

I think we all saw that :)

> That means you're on a Unix machine, which in turn means that the script
> (probably) fails because it contains CRLF instead of only LF.

Possible.

[some possible fixes deleted]

The best fix would probably be to make sure you ftp your script in
ASCII mode, if this is the cause of the grief.

> If you're using a reasonably new version of vim try the following
> commands (one after the other, <Enter> = press Enter key)
> 
>:set notextmode<Enter>

Just as an aside, if you're using one of the new vim alpha's after I
think 5.0n or so, use

:set ff=unix

Martien

-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | I'm just very selective about what I
Commercial Dynamics Pty. Ltd.       | accept as reality - Calvin
NSW, Australia                      | 


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

Date: 20 Nov 1997 22:19:05 GMT
From: pladsen@ra.pvv.ntnu.no (Jan Ivar Pladsen)
Subject: Re: Extracting key-value pairs from HTML FORM text
Message-Id: <slrn679dkl.itv.pladsen@ra.pvv.ntnu.no>

On Tue, 18 Nov 1997 13:46:46 -0800, Chris Schoenfeld <chris@ixlabs.com> wrote:
>Now I want to access the key-value pairs of the FORM elements without

Use CGI.pm 
Take a look at CPAN

Good luck.

-- 
------------------------------------------------------------------------
Jan Ivar Pladsen                             http://www.pvv.org/~pladsen
------------------------------------------------------------------------




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

Date: Thu, 20 Nov 1997 17:29:02 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: File test operators do not work as advertised!!
Message-Id: <comdog-ya02408000R2011971729020001@news.panix.com>

In article <19971120210001.QAA18755@ladder01.news.aol.com>, daveisdead@aol.com (DaveIsDead) wrote:

>As far as I can figure
>
>opendir DIR, '/home/foo';
>@dirs = grep -d, readdir DIR;
>
>should load up @dirs with all of the directories in /home/foo, without the full
>path name.  However, the only items in @dirs are '.' & '..' after this call,

all of these work for me on Solaris 2.5 and MacOS8, both with Perl5.004

   #!/usr/bin/perl -w

   opendir DIR, '/export/home/brian' or die "$!\n";
   #Mac:   opendir DIR, `cwd` or die "$!\n";
   #@dirs  = grep { -d $_ } readdir DIR;
   #@dirs  = grep  -d $_, readdir DIR;
   @dirs  = grep  -d, readdir DIR;
   closedir DIR;

   $" = "\n\t";

   print "--Directories--\n\t@dirs\n";

   __END__

you might want to try other syntax rather than opeing pipes and doing a
lot of work :)

>although 'foo' clearly has subdirs.  I'm running Perl 5.004 under AIX 4.1.?. 
>I've tried both Bash & csh, thinking this might help - it didn't.  I've also
>noticed that this doesn't work on NT or MacPerl.

i wasn't able to reproduce this problem under the latest MacPerl.  which
version are you using?

>There are also problems with the other file test operators.  -f seems to work,
>-r returns seemingly arbitrary results.  -T seems to always evaluate false,
>except once in a long while.

perhaps you could provide more information about these other cases, such
as if -T fails on a system that has something other than text files, or if
you tested -r with different real and effective uid combinations?

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 20 Nov 1997 17:19:37 -0500
From: "Matthew S. Ayres" <msa@cynet.net>
Subject: Re: Help: What dir am I in
Message-Id: <Pine.GSO.3.96.971120171753.25572A-100000@home2.cynet.net>

On Thu, 20 Nov 1997, David J. Boyd wrote:

# How does one go about determine what directory I am from perl?  Where the
# directory script is?

i think you want the value of the current directory, based on what i
read...which you can find with the environmental variable PWD
($ENV{'PWD'})

matthew


-----------------------------------------------------------
|                          |                              |
|   Matthew S. Ayres       |    Technical Supervisor      |
|   msa@cynet.net          |    Majordomo Listmanager     |
|   listmaster@cynet.net   |    Webmaster                 |
|   webmaster@cynet.net    |    Cynet, Inc.               |
|                          |                              |
-----------------------------------------------------------



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

Date: 20 Nov 1997 23:23:07 GMT
From: fox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: How To Test if number is ODD or EVEN?
Message-Id: <652gor$8r33@eccws1.dearborn.ford.com>

jay@dixonssurgical.co.uk (Jay Dixon) writes:
> I want to test if a variable is Odd (or Even)

As inspired by abigail:

perl -wle 'print "Even" if (1 x shift) =~ /^(1+?)\1$/'

> Any suggestions will be much appreciated.

*Please* don't use this approach in your code though... :)

- Ken

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: 20 Nov 1997 22:45:39 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: ignore above...
Message-Id: <652eij$1il$2@comdyn.comdyn.com.au>

In article <64udtd$3tg$1@newton.pacific.net.sg>,
	"winston khoo" <flare@mindless.com> writes:
> i got the perismission done....but i still encounter this error when i
> submit my form :(

Please read the doumentation that is specifically written for these
sorts of questions:

ftp://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html

> anything wrong wiff the script file?

I don't know. I can't read uuencoded stuff, and I am not going to go
through the trouble of decoding it for you. Sorry.

> or my web server doesn't support scripting?

Ask your ISP. Not us.

> 500 Server Error
> 
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
> 
> Please contact the server administrator, flare@mindless.com and inform them
> of the time the error occurred , and anything you might have done that may
> have caused the error.
> Error: HTTPd: malformed header from script
> /usr/local/etc/httpd/htdocs/infofax/cgi/Webimport.cgi

See what it says up here? 'contact the server administrator'. 

Besides, questions about server problems are not a perl issue. Ask
them in one of the comp.infosystems.www.* groups, please.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd.       | thing but mean your mother.
NSW, Australia                      | 


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

Date: Tue, 18 Nov 1997 08:47:45 GMT
From: G.C.Th.Wierda@AWT.nl (Gerben Wierda)
Subject: Intermediary compiled perl?
Message-Id: <EJu33L.6ny@AWT.NL>

I know someone is working on a perl compiler. I was wondering something else, 
namely: is it possible to store the result of perl *after* perl compiles your 
script, but before perl starts executing it (a sort of perl bytecode)?

---
Gerben Wierda,

Stafmedewerker Adviesraad voor het Wetenschaps- en Technologiebeleid.
Staff member Advisory Council for Science and Technology Policy
Javastraat 42, 2585 AP, Den Haag/The Hague, The Netherlands
Tel (+31) 70 3639922	Fax (+31) 70 3608992
http://www.AWT.nl/prive/wierda/

The fox knows many things, but the hedgehog knows one big thing.

"Use the word 'cybernetics,' Norbert, because nobody knows what it
means.  This will always put you at an advantage in arguments."
 - Claude Shannon (the Father of Information Theory) in a letter to
   Norbert Weiner of M.I.T., in the 40's.  (Wiener's book _Cybernetics_ was 
published in 1961.)



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

Date: 20 Nov 1997 22:23:27 GMT
From: neilb@zetnet.co.uk (Neil Briscoe)
Subject: Re: Is there a sendmail utility for MIIS/NT
Message-Id: <memo.19971120222327.46057C@skep.compulink.co.uk.cix.co.uk>

In article <34740DEF.5957@thames.com>, david@thames.com (David Rayner)
wrote:

> We debug our cgi's on our NT/MIIS intranet before uploading them to
> the web, I can simulate everything except piping information
> to sendmail is there a utility or work around for NT???
>
> $mailprog = '/usr/lib/sendmail';
>

Well, you can simulate even that.  Buy a port of Unix Sendmail to NT.  Try
the Metainfo product.

Unfortunately, you now have to buy it from Metainfo's UK distributor - who
will sell it to you at the same amount of pounds as Metainfo charge
dollars.

If this annoys you - let Metainfo know.  We used to sell the product at a
valid exchange rate - but now we have to buy at this ridiculous price less
discount, and have no choice.

Let Metainfo know that this policy will price their products out of the
market - and perhaps they'll get a clue.

Regards
Neil



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

Date: Thu, 20 Nov 1997 17:37:13 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: max size of cookie?
Message-Id: <3474BB99.A0EBA60B@ixl.com>

Bart Lateur wrote:
> 
> Eli the Bearded <usenet-tag@qz.little-neck.ny.us> wrote:
> 
> >kim slack <kas5670@vaxb.isc.rit.edu> wrote:
> >> How much data can you fit in a cookie?  Geoff
> >
> >What kind of cookie? I saw a great shortbread recipe the other day,
> >but is is off-topic here.
> 
> Maybe it's a Chinese fortune cookie. That would alow for, eh..., one
> tiny piece of paper. How many bytes is that?

It ususally takes me two. But it really depends on how many bits it
breaks into.

Dan


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

Date: Fri, 21 Nov 1997 09:20:36 +1000
From: Ron Savage <rpsavage@ozemail.com.au>
Subject: Re: Perl Source Formatter
Message-Id: <3474C5C4.75BD@ozemail.com.au>

Bill Dorin wrote:
> 
> Anyone point me to a perl source formatter similar to lint?  Sorry if this has been a previous
> topic.
> 
> bill@lanl.gov

Here be Untested Code...

#!/usr/gnu/bin/perl

# 'pb' Perl Beautifier

# Written by P. Lutus Ashland, Oregon lutusp@arachnoid.com 5/20/96

# This script processes Perl scripts, cleans up and indents, like cb does for C

# Be careful with this script - it accepts wildcards and processes every text file
# that meets the wildcard criteria. This could be a catastrophe in the hands of the unwary.

$tabstring = "  "; # You may place any tab-stop characters you want here

if($ARGV[0] eq "") {
  print "usage: file1 file2 etc. or wildcards (replaces originals in place)\n";
}
else {
  foreach $filename (@ARGV) {
    if(-T $filename) {
      &process($filename);
    }
  }
}

sub process {
  $fn = $_[0];
  undef $/; # so we can grab the entire file at once
  undef @infa; # prevent left-overs
  print STDERR "$fn";
  open (INFILE,$fn);
  @infa = split(/\n/,<INFILE>);
  close INFILE;
  
  $/ = "\n"; # restore default
  
  open (OUTFILE,">$fn");
  $tabtotal = 0;
  for (@infa) {
    
    s/^\s*(.*?)\s*$/$1/; # strip leading and trailing spaces
    
    $a = $_; # copy original string
    $q = $a; # i plan to modify this copy for testing
    $q =~ s/\\\#//g; # remove escaped comment tokens
    $q =~ s/\#.*?$//g; # remove Perl-style comments
    $q =~ s{/\*.*?\*/} []gsx; # remove C-style comments
    $q =~ s/\\\{//g; # remove escaped left  braces
    $q =~ s/\\\}//g; # remove escaped right braces
    $q =~ s/\\\(//g; # remove escaped left  parentheses
    $q =~ s/\\\)//g; # remove escaped right parentheses
    
    $q =~ s/\'.*?\'//g; # remove single-quoted lines
    
# now the remaining braces/parentheses should be structural
    
    $delta = -($q =~ s/\}/\}/g); # subtract closing braces
    $delta += ($q =~ s/\{/\{/g); # add opening braces
    
    $delta -= ($q =~ s/\)/\)/g); # subtract closing parens
    $delta += ($q =~ s/\(/\(/g); # add opening parens
    
    $tabtotal += ($delta < 0)?$delta:0; # subtract closing braces/parentheses
    
    $i = ($tabtotal > 0)?$tabtotal:0; # create tab index
    
    $tabtotal += ($delta>0)?$delta:0; # add opening braces/parentheses for next print
    
    if(substr($a,0,1) ne "#") { # don't tab comments
      print OUTFILE $tabstring x $i; # "tab" out to position
    }
    
    print OUTFILE "$a\n"; # print original line
  } # -- for (@infa)
  
  close OUTFILE;
  
  if($tabtotal != 0) {
    print STDERR " Indentation error: $tabtotal\n";
  }
  else {
    print STDERR "\n";
  }
} # sub process

-- 
Cheers,
Ron Savage
Office: savage.ron.rs@bhp.com.au
Home (preferred): rpsavage@ozemail.com.au


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

Date: Thu, 20 Nov 1997 16:51:24 -0600
From: naveen_rajavasireddy@acml.com
Subject: Pipes and Shared Memory
Message-Id: <880065712.28193@dejanews.com>

# foo_1.pl
$key = shmget(0,2000,0777);
open (INPUT, "foo_2.pl $key |");
while($in =<INPUT>)
{
shmwrite($key,$in,0,60);
sleep 10;
}
shmctl($key,0,0);

#foo_2.pl
$key = shift @ARGV;
open(JUNK,"> junk.txt");
$msg = "Test";
print $msg; # This will send to foo_1 process
sleep 10;
shmread($key,$buf,0,60);
print JUNK $key, " Message from shared mem ", $buf;
close JUNK;

After I execution of foo_1.pl is complete, I expect to junk.txt to contain
the message retrieved by shmread but it is empty? Any tips as to what I am
doing wrong. Thank you.

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Thu, 20 Nov 1997 17:55:48 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Please help with user log
Message-Id: <comdog-ya02408000R2011971755480001@news.panix.com>

In article <651jjq$m29$1@news.securenet.net>, fox@securenet.net (Pearl Fox) wrote:

>I have this user log file on my webpage to log the users.  However I
>would like to exclude my own entry when visiting my page.  How would I
>do this?  

before you let your script open files and so on, check to see that the
user is not you.  how you do this can vary, but let's assume that you 
have a development machine with a fixed IP number and your server isn't
doing hostname lookups:

   #somewhere near the top.  supply your IP
   exit if $ENV{'REMOTE_HOST'} eq 'aaa.bbb.ccc.ddd';

if your situation is a bit different, just salt that test to taste :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 19 Nov 1997 09:39:09 GMT
From: G.C.Th.Wierda@AWT.nl (Gerben Wierda)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <EJw059.CCr@AWT.NL>

aml@world.std.com (Andrew M. Langmead) wrote:
>As for which is faster or slower:
>
>use Benchmark;
>
>%TEST = map { $_, $_ } 'a' .. 'z';
>timethese (100000, {
>  use_keys => q($n = keys %TEST;),
>  use_loop => q($n=0;while(($k,$v) = each %TEST) {$n++}),
>  use_array => q(@TEST=%TEST; $n=@TEST/2)
>});

A clear winner (perl5):

Benchmark: timing 100000 iterations of use_array, use_keys, use_loop...
 use_array: 171 secs (129.28 usr  0.67 sys = 129.95 cpu)
  use_keys:  1 secs ( 0.53 usr  0.02 sys =  0.55 cpu)
  use_loop: 164 secs (143.39 usr  0.48 sys = 143.88 cpu)

So:

sub size_hash {
	# Pass reference to hash
	# don't use while inside another each loop!
	my $hashref = shift;
	my $n;
	$n=0;
	while (($k,$v) = each %$hashref) {
		$n++;
	}
	return $n;
}

Usage:
	$hash_size = &size_hash( \%TEST);

Well, couldn't we get a 'sizeof' operator in Perl for these kind of 
operations?

---
Gerben Wierda,

Stafmedewerker Adviesraad voor het Wetenschaps- en Technologiebeleid.
Staff member Advisory Council for Science and Technology Policy
Javastraat 42, 2585 AP, Den Haag/The Hague, The Netherlands
Tel (+31) 70 3639922	Fax (+31) 70 3608992
http://www.AWT.nl/prive/wierda/

The fox knows many things, but the hedgehog knows one big thing.

"There are no bad haircuts in cyberspace." 
  - Dave Barry



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

Date: Thu, 20 Nov 1997 18:50:01 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <comdog-ya02408000R2011971850010001@news.panix.com>

In article <EJw059.CCr@AWT.NL>, G.C.Th.Wierda@AWT.nl (Gerben Wierda) wrote:

>aml@world.std.com (Andrew M. Langmead) wrote:

>>timethese (100000, {
>>  use_keys => q($n = keys %TEST;),
>>  use_loop => q($n=0;while(($k,$v) = each %TEST) {$n++}),
>>  use_array => q(@TEST=%TEST; $n=@TEST/2)
>>});

>Benchmark: timing 100000 iterations of use_array, use_keys, use_loop...
> use_array: 171 secs (129.28 usr  0.67 sys = 129.95 cpu)
>  use_keys:  1 secs ( 0.53 usr  0.02 sys =  0.55 cpu)
>  use_loop: 164 secs (143.39 usr  0.48 sys = 143.88 cpu)

>So:

>sub size_hash {

>}



perhaps i'm missing the point of your post.  the use of keys in the
scalar context is almost 200 times faster than the other methods, but
you suggest a loop subroutine.  why?

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 20 Nov 1997 18:08:19 -0400
From: ASHFIELD  M <a15d@unb.ca>
Subject: Regexps question
Message-Id: <Pine.SOL.3.96.971120180048.10622A-100000@sol.sun.csd.unb.ca>

Hi, Sorry if this is a newbie question but I've been looking through
documentation and have seen nothing that might help me...
My problem is the following, given an html file with a tag for <author> I
want to extract what is between the tags into a variable named author.
This is very simple, however, I may have multiple authors, and it may span
several lines, for example:

<author> authorname1</author><author> authorname2 \n </author>\n
<author> authorname3</author>

Now, the code I have to do this is simply:
$/=undef;
open(HTMLFILE, "$file2") || die "COuldn't open $file2 !";
	while(<HTMLFILE>){
		if (/<AUTHOR>(.*)<\/AUTHOR>/si) { push (@authors, $1)}
	}

The problem is, this code only generates one author scalar, instead of 3.
I assume it's reading the opening tag for the first author and the closing
tag for the third, and putting everything in between into one scalar. 
I guess the problem is to figure out a way to make it stop scanning after
it finds the first closing tag.
Hopefully this doesn't sound very confusing, because I 've blown an entird
afternoon on this while looking through documentation and I could really
use a hand, preferably by email


Thanks for your time,

Matt
a15d@unb.ca



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

Date: Thu, 20 Nov 1997 18:06:12 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Regexps question
Message-Id: <comdog-ya02408000R2011971806120001@news.panix.com>

In article <Pine.SOL.3.96.971120180048.10622A-100000@sol.sun.csd.unb.ca>, ASHFIELD  M <a15d@unb.ca> wrote:

><author> authorname1</author><author> authorname2 \n </author>\n
><author> authorname3</author>
>
>Now, the code I have to do this is simply:
>$/=undef;
>open(HTMLFILE, "$file2") || die "COuldn't open $file2 !";
>        while(<HTMLFILE>){
>                if (/<AUTHOR>(.*)<\/AUTHOR>/si) { push (@authors, $1)}
>        }

your regexp is being greedy - add a non greedy thingy (the ?) to it:

   #!/usr/bin/perl
   
   $_ =<<'HERE';
   <author> authorname1</author><author> authorname2 </author>
   <author> authorname3</author>
   HERE
   
   #
   @authors = ( m| <AUTHOR>(.*?)</AUTHOR> |xgsi );
   
   $" = "\n"; print "@authors\n";
   
   __END__
    authorname1
    authorname2 
    authorname3

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 20 Nov 1997 17:46:28 -0500
From: TechMaster Pinyan <jefpin@bergen.org>
To: Paul Plowman <paulp@jumper.mcc.ac.uk>
Subject: Re: s/// Question
Message-Id: <Pine.SGI.3.95.971120174443.25653B-100000@vangogh.bergen.org>

On Thu, 20 Nov 1997, Paul Plowman wrote:
>
>Is there any way of using the result of a match in the match itself? For 
>instance, if you want to search for a capital letter, followed by a 
>number, followed by the same letter. Could you do something like:
>
>$test =~ s/([A-Z])[0-9]$1/whatever/g;

Almost, but there are two different kinds of backreferences, \ and $.
The correct line should be:
	$test =~ s/([A-Z])[0-9]\1/whatever/g;

\1 is used in the lefthand-side, $1 is used on the righthand-side.

----------------
| "WYSIWYG?  More like WUSSIWYG... Text Editors Rule!!!"
| 	- Jeff Pinyan
----------------
Jeff Pinyan | http://users.bergen.org/~jefpin | jefpin@bergen.org
webXS - the new eZine for WebProgrammers! TechMaster@bergen.org
Visit us @ http://users.bergen.org/~jefpin/webXS
*NEW* techie@rocko.linuxbox.com | techmaster@mindless.com *NEW*
** I can be found on #perl on irc.ais.net as jpinyan **

- geek code -
GCS/IT d- s>+: a--- C+>++ UAIS+>$ P+++$>++++ L E--->---- W++$
N++ !o K--? w>+ !O M>- V-- PS PE+ !Y !PGP t+ !5 X+ R tv+ b>+
DI+++ D+>++ G>++ e- h- r y? 



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

Date: Thu, 20 Nov 1997 16:51:44 -0600
From: rets@meta3.com
To: comdog@computerdog.com
Subject: Re: Schplitz v1.1
Message-Id: <880065950.28503@dejanews.com>

This is the patch for Schplitz.

Replace

=> my $a = 'Craig Davis|cdavis\@cnp.net';

with

=> my $a = "Craig Davis|cdavis\@cnp.net";

or

=> my $a = 'Craig Davis|cdavis@cnp.net';


Final script as follows:

#!/usr/bin/perl5 -w

# Schplitz v1.1
# Special thanks to
#
# brian d foy
#
# for pointing out
#
# d problem
#
# Copyright(C) 1997 Kenneth A. Holm III
# All rights reserved
#
# See Licensing Info at http://www.metamall.com/rets/license.html
# If you find this script useful please send lots of money to
# Ken Holm
# POB 97536
# Jackson, MS 39288-7536
# rets@meta3.com

        # Lets declare our variables
my ($user_name, $user_email, $userdomain);

        # Lets define the string with which we're working
my $a = 'Craig Davis|cdavis@cnp.net';

# You can replace the above line with the following.
# As far as I can tell, this is a preference and does
# not affect such a trivial script much (at all)

# my $a = "Craig Davis|cdavis\@cnp.net";

        # Split $a using / or @
($user_name, $user_email, $userdomain) = split(/\||\@/, $a);

        # Print for posterity.
print "[$user_name][$user_email][$userdomain]\n\n";

        # You are ever in one's debt.
exit;

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Thu, 20 Nov 1997 17:35:40 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Split
Message-Id: <comdog-ya02408000R2011971735400001@news.panix.com>

In article <880059462.21308@dejanews.com>, rets@meta3.com wrote:

>#!/usr/bin/perl5 -w
>
># Schplitz
># Copyright(C) 1997 Kenneth A. Holm III
># All rights reserved
>#
># See Licensing Info at http://www.metamall.com/rets/license.html
># If you find this script useful please send lots of money to
># Ken Holm
># POB 97536
># Jackson, MS 39288-7536
># rets@meta3.com
>
>        # Lets declare our variables
>my ($user_name, $user_email, $userdomain);
>
>        # Lets define the string with which we're working
>my $a = 'Craig Davis|cdavis\@cnp.net';
>
>        # Split $a using / or @
>($user_name, $user_email, $userdomain) = split(/\||\@/, $a);
>
>        # Print for posterity.
>print "[$user_name][$user_email][$userdomain]\n\n";
>
>        # You are ever in one's debt.
>exit;


so what happened when you tested this script?  i got:

   [Craig Davis][cdavis\][cnp.net]

this seemed strange to me. didn't it seem strange to you?  perhaps
you'd like to provide a patch to fix the obvious bug in your
software?

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Fri, 21 Nov 1997 02:00:44 GMT
From: marek@cmic.ca
Subject: Unable to locate DLL
Message-Id: <3474e98d.31608000@nntp.uunet.ca>

Hi there,

I wrote some CGI script, by means of CGI.pm and perl5.004_02 from
WinNT. It used DBI package from communication with ORACLE too. When I
tested it from command line, all work properly. But when I try to run
this script from HTTP server some error issued.

Unable to Locate DLL
 The dynamic link library OCIW32.dll could not be found in specified
path C:\PERL\.........

Is it path valid for DynaLoader??
How can I change this path??

Thanks,

Marek
---------
marek@cmic.ca


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

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

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