[18846] in Perl-Users-Digest
Perl-Users Digest, Issue: 1014 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 29 18:05:52 2001
Date: Tue, 29 May 2001 15:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991173914-v10-i1014@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 29 May 2001 Volume: 10 Number: 1014
Today's topics:
Re: END{} and tempfiles <ilya@math.ohio-state.edu>
Re: exec script w/require & headers (BUCK NAKED1)
Re: hash array <ren@tivoli.com>
HTML Output from .pl? <nein@no.com>
IPC:Shareable vs mod_perl ipcs not dying (Konstantinos Agouros)
Is it possible in Perl?? <shino_korah@yahoo.com>
manipulating HUGE amounts of text <todd@designsouth.net>
Re: Perl Community Stars (?) <sgkay@btinternet.com>
Re: question about the UNIX commands in perl script (Roanld)
read and solve arithmetic strings <rpowell@dal.asp.ti.com>
Re: read and solve arithmetic strings <joe+usenet@sunstarsys.com>
Re: The FlakeyMind/Bryce Jacobs FAQ (v0.1) <NOtwiner@atcableinet.you'llco.seeuk>
Re: url parsing <todd@designsouth.net>
Re: url parsing <buggs@geekmail.de>
Re: url parsing <lmoran@wtsg.com>
Re: Variables and Precedence <todd@designsouth.net>
Re: Variables and Precedence <iltzu@sci.invalid>
Re: Variables and Precedence <todd@designsouth.net>
What does this perl line mean? <smehrabi@cisco.com>
Re: What does this perl line mean? <todd@designsouth.net>
Re: What does this perl line mean? (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 May 2001 20:09:18 +0000 (UTC)
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: END{} and tempfiles
Message-Id: <9f0vle$24v5$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Abigail
<abigail@foad.org>], who wrote in article <slrn9h7gl5.efq.abigail@tsathoggua.rlyeh.net>:
> $$ Will not work on most of the systems.
> Irrelevant.
> It will work on Solaris, the system the OP uses.
Sorry, did not mean her yet.
Ilya
------------------------------
Date: Tue, 29 May 2001 12:46:20 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: exec script w/require & headers
Message-Id: <29874-3B13E06C-220@storefull-242.iap.bryant.webtv.net>
FWIW... the file "pcount.pl" doesn't call out any headers or
content-type. I guess the file that I call "pcount.pl" from ("bna.pl")
is throwing them in. Probably because I use cgi.pm in "bna.pl".
--Dennis
------------------------------
Date: 29 May 2001 14:27:47 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: hash array
Message-Id: <m366ek7y6k.fsf@dhcp9-172.support.tivoli.com>
On Sat, 26 May 2001, gisle@ActiveState.com wrote:
> mjd@plover.com (Mark Jason Dominus) writes:
>
>> In article <ndAP6.70962$I5.15872424@news1.rdc1.tn.home.com>,
>> Todd Smith <todd@designsouth.net> wrote:
>> >How do you ask a hash how big it used to be?
>>
>> Devel::Peek, perhaps.
>
> You can also get that number with code like this:
>
> $size = do { local $hash{x} = 1; (split "/", %hash)[1] };
This has the side effect of leaving "x" around as a key in %hash. The
value is gone, because of the local, but the key is still there.
Actually, something strange seems to happen as a result of that
"local". The key survives the block even if it is explicitly deleted
within the block. I assume the "restore the old value" aspect of
"local" is (re-)creating the key upon exit of the block.
#!/usr/bin/perl
use strict;
use warnings;
my %hash;
{ local $hash{x} = 1; delete $hash{x} };
print "After localized delete: ", keys %hash, "\n";
{ $hash{x} = 1; delete $hash{x} };
print "After non-localized delete: ", keys %hash, "\n";
__END__
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 29 May 2001 16:25:12 -0400
From: negative nein <nein@no.com>
Subject: HTML Output from .pl?
Message-Id: <u718ht445k79pgblpd159qj5bpae3aj3f4@4ax.com>
Hi,
I'm a total newbie to perl...with that said, I'm having allot of
trouble tryng to get this to print html (or even to a .txt file).
This is the htmlsub prog. from Perl Cookbook. Basically, it changes
whatver word you specify in a .html file to a user defined word.
My question is, what do I have to add to get this to print to an html
file...?
thanks.
m.
#!/usr/bin/perl -w
#make substituions in text of html filez
sub usage { die "Usage: $0 <from> <to> <file>...\n" }
my $from = shift or usage;
my $to = shift or usage;
usage unless @ARGV;
#Build the HTML::Filter Subclass to do the substituting
package MyFilter;
require HTML::Filter;
@ISA=qw(HTML::Filter);
use HTML::Entities qw(decode_entities encode_entities);
sub text {
my $self = shift;
my $text = decode_entities($_[0]);
$text =~ s/\Q$from/$to/go;
$self->SUPER::text(encode_entities($text));
}
package main;
foreach (@ARGV) {
MyFilter->new->parse_file($_);
}
------------------------------
Date: 29 May 2001 21:25:44 +0200
From: elwood@news.agouros.de (Konstantinos Agouros)
Subject: IPC:Shareable vs mod_perl ipcs not dying
Message-Id: <elwood.991164106@news.agouros.de>
Hi,
I created a small server that shares an array via IPC::Shareable. There are
two CGI-Scripts called with the mod_perl-Handler from apache that use this
array. One of these erases elements from the shared array with something
like
@SHARED_ARRAY = grep ($_ != $element_to_destroy), @SHARED_ARRAY. This is
enclosed by a shlock/shunlock.
The whole stuff is working (meaning after the cgi the element is missing),
but I see a growing number of shared memory segments and semaphores (I take
it the tie allocates on of each).
At the end of the script I do an untie but I am not really sure that is enough.
Anybody has an opinion since ipcrm'ing gets a little annoying.
Konstantin
--
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elwood@agouros.de
Otkerstr. 28, 81547 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not sustain the forming of the cosmos." B'Elana Torres
------------------------------
Date: Tue, 29 May 2001 14:20:59 -0700
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Is it possible in Perl??
Message-Id: <9f13rs$ktq@news.or.intel.com>
Hi,
I'm trying to lock a file. My file is in network (NFS) so I cannot use
flock
I'm using fcntl
This is my code
open(FD,"a.txt");
fcntl(FD,&F_SETLK,LOCK_EX) or die "Can't lock ::$!\n";
copy("a.txt","b.txt");
fcntl(FD,&F_SETLK,LOCK_UN);
close(FD);
when I run this code it says
Can't lock:: bad address
Please help
------------------------------
Date: Tue, 29 May 2001 21:50:15 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: manipulating HUGE amounts of text
Message-Id: <rQUQ6.84273$I5.19967477@news1.rdc1.tn.home.com>
If I wanted to play with files (tar files maybe) that were gigabytes in
size, and I wanted to look for patterns in the text and rearrange columns
and rows, what would be the best way to represent the data in my program,
considering that I (probably) wouldn't want an array with a billion
elements?
------------------------------
Date: Tue, 29 May 2001 22:42:19 +0100
From: "Steve Kay" <sgkay@btinternet.com>
Subject: Re: Perl Community Stars (?)
Message-Id: <9f157l$boq$1@plutonium.btinternet.com>
Lou,
Don't think it's just a Perl thing : jahhaj@bigfoot.com could be classified
as a star of the comp.lang.c++ newsgroup (about 100 postings in the past
week).
And if we expand the scope a little beyond purely language newsgroups, then
surely Casper Dik is worth nominating in the comp.unix.solaris newsgroup.
Steve
"Lou Moran" <lmoran@wtsg.com> wrote in message
news:gp77htg4qja5irh0eube3359j953ti75qo@4ax.com...
> --I have noticed that Perl seems to have "famous" people.
[snip]
> --Are there other famous programmers in other languages or is this a
> "Perl Thing"?
------------------------------
Date: 29 May 2001 13:51:27 -0700
From: ronaldh@sina.com (Roanld)
Subject: Re: question about the UNIX commands in perl script
Message-Id: <aafb219c.0105291251.50fcd65b@posting.google.com>
Thank you, ALL
I am still quite new to Perl. Yes, Perl's powerful and provide multi-way to solve problem.
It's good to have this practice to know it.
cheers,
Ronald
------------------------------
Date: Tue, 29 May 2001 15:56:17 -0500
From: Russell Powell <rpowell@dal.asp.ti.com>
Subject: read and solve arithmetic strings
Message-Id: <3B140CF1.B4D1BE68@dal.asp.ti.com>
--------------B202A2D86891BA9B3B7DD02B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Given a text file containing simple arithmetic equations such as
A = 'B*C' B = '1' C = '2'
Is there a simple method to read these lines and solve for A ?
--
sincerely,
,,,
(o o)
/==============ooO=====(_)=====Ooo===========\
| Russell Powell - Compiler Memory Designer |
| Texas Instruments |
| E-MAIL: rpowell@dal.asp.ti.com |
| ph: (214) 480-1196 |
| |
| .ooo0 0ooo. |
| ( ) ( ) |
\================\ (=========) /=============/
\_) (_/
--------------B202A2D86891BA9B3B7DD02B
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Given a text file containing simple arithmetic equations such as
<br> A = 'B*C' B = '1' C = '2'
<p>Is there a simple method to read these lines and solve for A ?
<br>
<pre>--
sincerely,
,,,
(o o)
/==============ooO=====(_)=====Ooo===========\
| Russell Powell - Compiler Memory Designer |
| Texas Instruments |
| E-MAIL: rpowell@dal.asp.ti.com |
| ph: (214) 480-1196 |
| |
| .ooo0 0ooo. |
| ( ) ( ) |
\================\ (=========) /=============/
\_) (_/</pre>
</html>
--------------B202A2D86891BA9B3B7DD02B--
------------------------------
Date: 29 May 2001 17:57:51 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: read and solve arithmetic strings
Message-Id: <m3y9rfom1s.fsf@mumonkan.sunstarsys.com>
Russell Powell <rpowell@dal.asp.ti.com> writes:
> Given a text file containing simple arithmetic equations such as
> A = 'B*C' B = '1' C = '2'
>
> Is there a simple method to read these lines and solve for A ?
Sounds like homework to me. Oh well- as long as your equations
are pretty simple (i.e. triangular), this might work for you:
% cat try.pl
#!/usr/bin/perl -wlp
1 while s/ \b([A-z])\b (.*) \1 \s*=\s* '(.*?)' /($3)$2$1='$3'/x;
/ ([A-z]) \s*=\s* '(.*?)' /x or die "Can't parse '$_' ";
print "$1=", eval $2;
__END__
% ./try.pl
A = 'B*C' B = 'C' C = '4'
A=16
A = '((4))*(4)' B='(4)' C='4'
A = 'B*C+D' B='C*D' C='D' D='9'
A=738
A = '(((9))*(9))*((9))+(9)' B='((9))*(9)' C='(9)' D='9'
A = 'B*C' B = '1' C = '2'
A=2
A = '(1)*(2)' B='1' C='2'
HTH
--
Joe Schaefer "I must have a prodigious quantity of mind; it takes me as much
as a week sometimes to make it up."
--Mark Twain
------------------------------
Date: Tue, 29 May 2001 19:36:09 GMT
From: "Chris Twiner" <NOtwiner@atcableinet.you'llco.seeuk>
Subject: Re: The FlakeyMind/Bryce Jacobs FAQ (v0.1)
Message-Id: <JSSQ6.2346$zb7.351439@news1.cableinet.net>
Thaddeus L Olczyk <olczyk@interaccess.com> wrote in message
news:3b1bd57d.558879812@nntp.interaccess.com...
> Cross posted the first time to comp.lang.perl.misc so that
<snipped all the stuff Thaddues said>
Look I've let off at topmind in a short sweet statement. It may have been
appropriate on a personal basis but it was wrong in the NG's it maid me too
close to a troll for comfort.
Although I don't like the trolly know it all attitude of either Topmind or
Godzilla!, sending out a post like this sends a very clear picture that you
aren't doing anything nobler than they.
It doesn't do anyone any favours.
Chris
------------------------------
Date: Tue, 29 May 2001 18:08:57 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: url parsing
Message-Id: <ZARQ6.83808$I5.19848890@news1.rdc1.tn.home.com>
"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:991134054.9998@itz.pp.sci.fi...
> In article <slrn9h5s7m.la0.abigail@tsathoggua.rlyeh.net>, Abigail wrote:
> >Craig Berry (cberry@cinenet.net) wrote on MMDCCCXXIV September MCMXCIII
> >in <URL:news:tgtetvhqvn182d@corp.supernews.com>:
> >`` Ilmari Karonen (iltzu@sci.invalid) wrote:
> >`` :
> >`` : $url =~
/^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/s
> >`` : or die "Invalid URL: $url\n";
> >``
> >`` So a valid url can contain newlines practically anywhere?
> >
> >No.
> >The "or die" part is utterly silly.
>
> Right. My mistake.
>
> I'd say the fundamental problem was that I wrote "Invalid URL" without
> realizing that it might be taken as an implication that anything matched
> by that regexp is valid, which is of course completely wrong.
>
> Besides, isn't that regexp guaranteed to match any string as long as the
> /s modifier is there? *smacks forehead* I plead lack of sleep.
>
Why not just ping it to see if it's valid or not?
------------------------------
Date: Tue, 29 May 2001 20:17:24 +0200
From: buggs <buggs@geekmail.de>
Subject: Re: url parsing
Message-Id: <9f0p0u$1cj$00$2@news.t-online.com>
Todd Smith wrote:
--snip--
>
> Why not just ping it to see if it's valid or not?
>
ping www.microsoft.com
Buggs
------------------------------
Date: Tue, 29 May 2001 16:20:00 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: url parsing
Message-Id: <p218htosq8pbtcfegg4abvpgdergt11vek@4ax.com>
On Tue, 29 May 2001 20:17:24 +0200, buggs <buggs@geekmail.de> wrote
wonderful things about sparkplugs:
>Todd Smith wrote:
>
>--snip--
>>
>> Why not just ping it to see if it's valid or not?
>>
>
>ping www.microsoft.com
that's a pretty good reason.
--
BSOD? In my day we didn't have 0000FF!
lmoran@wtsg.com
------------------------------
Date: Tue, 29 May 2001 18:06:30 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Variables and Precedence
Message-Id: <GyRQ6.83803$I5.19847640@news1.rdc1.tn.home.com>
<Gordon.Haverland@gov.ab.ca> wrote in message
news:3b13d78e.19886755@news.gov.ab.ca...
> Or, at least I think that's the subject. I'm trying to puzzle out why
> a perl CGI script is giving me errors. Anyway, at one point the
> script is printing
>
> print "Location: ${URI}\n";
>
> To my way of thinking, isn't ${URI} the same as $URI ??? It's only
> this one variable which seems to be written this way. Thanks for any
> light you might shed on this.
>
> Gord
>
You don't need the curly braces in a string like that. And the Location
header needs 3 newlines.
print "Location: $URI\n\n\n";
------------------------------
Date: 29 May 2001 20:10:34 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Variables and Precedence
Message-Id: <991166625.16388@itz.pp.sci.fi>
In article <GyRQ6.83803$I5.19847640@news1.rdc1.tn.home.com>, Todd Smith wrote:
>
>You don't need the curly braces in a string like that. And the Location
>header needs 3 newlines.
>
>print "Location: $URI\n\n\n";
What on earth is this newline mania? The "Location:" header line is
indeed a line, and, like all lines, it needs exactly one newline to
terminate it. No more, no less. Just one.
You also need to print one blank line after all the header lines. Often
that is done by simply appending an extra newline after the last header
line, but that can be misleading as we've seen.
_Three_ newlines, however, makes no sense at all.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Tue, 29 May 2001 21:54:01 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: Variables and Precedence
Message-Id: <ZTUQ6.84275$I5.19970762@news1.rdc1.tn.home.com>
"Ilmari Karonen" <iltzu@sci.invalid> wrote in message
news:991166625.16388@itz.pp.sci.fi...
> In article <GyRQ6.83803$I5.19847640@news1.rdc1.tn.home.com>, Todd Smith
wrote:
> >
> >You don't need the curly braces in a string like that. And the Location
> >header needs 3 newlines.
> >
> >print "Location: $URI\n\n\n";
>
> What on earth is this newline mania? The "Location:" header line is
> indeed a line, and, like all lines, it needs exactly one newline to
> terminate it. No more, no less. Just one.
>
> You also need to print one blank line after all the header lines. Often
> that is done by simply appending an extra newline after the last header
> line, but that can be misleading as we've seen.
>
> _Three_ newlines, however, makes no sense at all.
>
> --
I'd always put 2 after the content-type, and I thought you had to put 3
after the location line. I know one was to end the line and one was to end
the headers, but I had to use 3 to get Location: to work the first time I
did it. I don't know why. Oh well.
------------------------------
Date: Tue, 29 May 2001 16:12:27 -0400
From: "Sultan Mehrabi" <smehrabi@cisco.com>
Subject: What does this perl line mean?
Message-Id: <991167173.333383@sj-nntpcache-3>
I was reading over a script someone else wrote and saw this line. I can't
seem to figure out what it means.
I know the hashes but what's our exactly?
Is this a list of hashes?
our (%console_svr, %console_port, %checkout);
Thanks in advance for your help.
-Sultan
------------------------------
Date: Tue, 29 May 2001 21:42:55 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: What does this perl line mean?
Message-Id: <zJUQ6.84256$I5.19958172@news1.rdc1.tn.home.com>
"Sultan Mehrabi" <smehrabi@cisco.com> wrote in message
news:991167173.333383@sj-nntpcache-3...
> I was reading over a script someone else wrote and saw this line. I can't
> seem to figure out what it means.
> I know the hashes but what's our exactly?
> Is this a list of hashes?
>
> our (%console_svr, %console_port, %checkout);
>
> Thanks in advance for your help.
> -Sultan
>
man perlfunc
/\bour
our EXPR
An `our' declares the listed variables to be valid globals
within the enclosing block, file, or `eval'. That is, it
has the same scoping rules as a "my" declaration, but does
not create a local variable. If more than one value is
listed, the list must be placed in parentheses. The `our'
declaration has no semantic effect unless "use strict vars"
is in effect, in which case it lets you use the declared
global variable without qualifying it with a package name.
(But only within the lexical scope of the `our' declaration.
In this it differs from "use vars", which is package
scoped.)
An `our' declaration declares a global variable that will be
visible across its entire lexical scope, even across package
boundaries. The package in which the variable is entered is
determined at the point of the declaration, not at the point
of use. This means the following behavior holds:
package Foo;
our $bar; # declares $Foo::bar for rest of
lexical scope
$bar = 20;
package Bar;
print $bar; # prints 20
Multiple `our' declarations in the same lexical scope are
allowed if they are in different packages. If they happened
to be in the same package, Perl will emit warnings if you
have asked for them.
use warnings;
package Foo;
our $bar; # declares $Foo::bar for rest of
lexical scope
$bar = 20;
package Bar;
our $bar = 30; # declares $Bar::bar for rest of
lexical scope
print $bar; # prints 30
our $bar; # emits warning
------------------------------
Date: Tue, 29 May 2001 16:55:29 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: What does this perl line mean?
Message-Id: <slrn9h8361.5ce.tadmc@tadmc26.august.net>
Sultan Mehrabi <smehrabi@cisco.com> wrote:
>I was reading over a script someone else wrote
You were reading a Perl 5.6 script someone else wrote.
>and saw this line. I can't
>seem to figure out what it means.
>I know the hashes but what's our exactly?
A new scoping method that was introduced with version 5.6.
perldoc -f our
If you have 5.6.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 1014
***************************************