[12510] in Perl-Users-Digest
Perl-Users Digest, Issue: 6110 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 23 15:07:24 1999
Date: Wed, 23 Jun 99 12:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 23 Jun 1999 Volume: 8 Number: 6110
Today's topics:
A foreach question photoguy@my-deja.com
Re: A foreach question <troyknight@troyknight.eurobell.co.uk>
Re: Apache + Perl <cassell@mail.cor.epa.gov>
Re: Beginner Perl Question <cassell@mail.cor.epa.gov>
Re: Comparing two associative arrays (Abigail)
Re: Comparing two associative arrays (Andrew Allen)
Re: Cooperating processes... (Andrew Allen)
Re: Cooperating processes... <tchrist@mox.perl.com>
Re: Cooperating processes... <djbell@wdsec.com>
Re: Cooperating processes... <portboy@home.com>
Re: deleting whitespace (Marc Bissonnette)
Re: Does Perl have a future? (Filip M. Gieszczykiewicz)
Re: extracting <jed@moose.chem.yale.edu>
Re: extracting (Sean McAfee)
Re: extracting (Larry Rosler)
Re: FAQ 1.8: How does Perl compare with other languages <cassell@mail.cor.epa.gov>
Re: Help Excel functions to Perl Code <cassell@mail.cor.epa.gov>
Re: inheriting Class Data (Abigail)
Module Path Problem <fishers@lister.acm.wwu.edu>
Re: Module Path Problem <craig@mathworks.com>
Re: Needle in a hash/list... (Tad McClellan)
Re: Newbie - Perl books - which to get? <cassell@mail.cor.epa.gov>
Re: NT - Server Up time <davidk@netscape.com>
Re: NT - Server Up time <djbell@wdsec.com>
Re: NT - Server Up time <bjornsvensson@geocities.com>
perl 5.005_3 on hp/ux 10.20 <jnich@pdd.att.com>
Perl Alphanumeric Sort? doug_johnston@my-deja.com
Re: Perl and Personal Web Server (Win98) <cassell@mail.cor.epa.gov>
Perl in Win32 <spud200@earthlink.net>
Re: Statistics for comp.lang.perl.misc <cassell@mail.cor.epa.gov>
Re: Statistics for comp.lang.perl.misc <tchrist@mox.perl.com>
Re: Summing an array <aqumsieh@matrox.com>
towards relational DB in perl ... <jed@moose.chem.yale.edu>
Re: towards relational DB in perl ... <jcreed@cyclone.jprc.com>
Re: towards relational DB in perl ... <garethr@cre.canon.co.uk>
URI:_generic Error <russconway@NOSPAMmindspring.com>
use strict question <mike@innercite.com>
Re: use strict question <craig@mathworks.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 23 Jun 1999 18:21:33 GMT
From: photoguy@my-deja.com
Subject: A foreach question
Message-Id: <7kr8iv$ebn$1@nnrp1.deja.com>
Greetings,
I'm reading a text file into an array, then using foreach to loop
through the array looking for a specific pattern. Once I find the
pattern I want to look at the next element in the array to check for 2
other patterns. Sample below:
open (FILENAME, "somefile");
@file_lines = FILENAME;
foreach $file_line (@file_lines)
{
# check for first pattern
# if matched, increment the element $file_line points to
# check for patterns in $file_line
}
My question is if I increment the element that $file_line is pointing
to, will that effect the 'foreach' sequencing? (i.e. the next time
through the loop after incrementing $file_line to say 2), will foreach
return element 2 or 3 of @file_lines?
ps, I only have 3 weeks of Perl experience & I apologize if this seems
like a easy problem.
Thanks,
Doug
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 23 Jun 1999 19:53:50 +0100
From: "Troy Knight" <troyknight@troyknight.eurobell.co.uk>
Subject: Re: A foreach question
Message-Id: <7kra9n$2f6$1@aub.eurobell.net>
The loop will carry on as normal!
<photoguy@my-deja.com> wrote in message news:7kr8iv$ebn$1@nnrp1.deja.com...
> Greetings,
>
> I'm reading a text file into an array, then using foreach to loop
> through the array looking for a specific pattern. Once I find the
> pattern I want to look at the next element in the array to check for 2
> other patterns. Sample below:
>
> open (FILENAME, "somefile");
> @file_lines = FILENAME;
>
> foreach $file_line (@file_lines)
> {
> # check for first pattern
> # if matched, increment the element $file_line points to
>
> # check for patterns in $file_line
> }
>
> My question is if I increment the element that $file_line is pointing
> to, will that effect the 'foreach' sequencing? (i.e. the next time
> through the loop after incrementing $file_line to say 2), will foreach
> return element 2 or 3 of @file_lines?
>
> ps, I only have 3 weeks of Perl experience & I apologize if this seems
> like a easy problem.
>
> Thanks,
> Doug
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
------------------------------
Date: Wed, 23 Jun 1999 11:52:57 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Apache + Perl
Message-Id: <37712D09.AE5B8C7E@mail.cor.epa.gov>
Jay Flahertry wrote:
> Jason Reed wrote:
> > And don't forget! Next week!
> >
> > PERL VS. CGI!
> >
> Which one will be wearing the mask and cape and have a really obnoxious
> manager? ;-)
More to the point, which one will have the sexy blonde in the
tight miniskirt? :-)
> Take care of your shoes...jay
> fty@utk.edu
"Shoes for industry! Shoes for the dead! Hi, I'm Joe Beet..."
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 23 Jun 1999 11:08:13 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Beginner Perl Question
Message-Id: <3771228D.9D7E905F@mail.cor.epa.gov>
Abigail wrote:
> [snip]
> Fun. Run your program on Solaris 2.6. Now, upgrade to Solaris 7.
> See things change.
>
> Unix is a twisty little maze of tools, all different.
Especially in Slowlaris. Who got together and said, "Let's
leave the interfaces as similar as possible, but *then* we'll
change the constants for socket programming! It'll be a riot!"
David, who has a big job running on Slowlaris 2.5 this moment...
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 23 Jun 1999 10:56:08 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Comparing two associative arrays
Message-Id: <slrn7n20sg.k1b.abigail@alexandra.delanet.com>
Vinayak P DAs (vinayak@india.ti.com) wrote on MMCXXII September MCMXCIII
in <URL:news:sy5r9n35on6.fsf@india.ti.com>:
__
__ Is there any such operations which will compare key , value pairs for
__ two associative arrays directly.
No.
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 23 Jun 1999 17:20:29 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Comparing two associative arrays
Message-Id: <7kr50t$nc6$1@fcnews.fc.hp.com>
Vinayak P DAs (vinayak@india.ti.com) wrote:
: Hi,
: Wanted to know if there is any way to directly compare two hashes.
: What I want to do is
: if ( %hash1 == %hash2 ){
: ..... do something
: }
"@{[%hash1]}" eq "@{[%hash2]}"
almost works (but can you explain why?). The exception is:
%hash1=("a b" => "c")
%hash2=("a" => "b c")
Setting $" to something not occuring in either hash will fix that.
Andrew
------------------------------
Date: 23 Jun 1999 17:26:44 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Cooperating processes...
Message-Id: <7kr5ck$nc6$2@fcnews.fc.hp.com>
Mitch (portboy@home.com) wrote:
: I have two process running that need to know when each other changes a
: certain variable. However, this variable (we'll call it $foo) is both
: local to each process, however, if one changes there $foo variable,
: the other process needs to know about it. How can I do this?
perldoc perlipc
Tie::Watch might also be useful
Andrew
------------------------------
Date: 23 Jun 1999 11:44:43 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Cooperating processes...
Message-Id: <37711d0b@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
portboy@home.com (Mitch) writes:
:I have two process running that need to know when each other changes a
:certain variable. However, this variable (we'll call it $foo) is both
:local to each process, however, if one changes there $foo variable,
:the other process needs to know about it. How can I do this?
#!/usr/bin/perl
# sharetest - test shared variables across forks
use IPC::Shareable;
$handle = tie $buffer, 'IPC::Shareable', undef, { destroy => 1 };
$SIG{INT} = sub { die "$$ dying\n" };
for (1 .. 10) {
unless ($child = fork) { # i'm the child
die "cannot fork: $!" unless defined $child;
squabble();
exit;
}
push @kids, $child; # in case we care about their pids
}
while (1) {
print "Buffer is $buffer\n";
sleep 1;
}
die "Not reached";
sub squabble {
my $i = 0;
while (1) {
next if $buffer =~ /^$$\b/o;
$handle->shlock();
$i++;
$buffer = "$$ $i";
$handle->shunlock();
}
}
But I wouldn't do that, really. I'd use some more normal
kind of IPC.
--tom
--
Real programmers can write assembly code in any language. :-)
--Larry Wall in <8571@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Wed, 23 Jun 1999 13:37:36 -0400
From: "Daniel Bell" <djbell@wdsec.com>
Subject: Re: Cooperating processes...
Message-Id: <7kr676$is2$1@sulu.wdsec.com>
If I was in UNIX, I would send a signal to the other process which would
notify it to watch for a change. If I was in NT, I would break down and
write the info it to a temporary directory (which is probably what you're
doing until you can find something better to do). I actually have to
communicate between two Perl processes, one on Linux, and one on an NT box.
The best way I found to do it is to send a file back and forth between the
two whenever a change is made- it works great and it takes no time to write.
> I have two process running that need to know when each other changes a
> certain variable. However, this variable (we'll call it $foo) is both
> local to each process, however, if one changes there $foo variable,
> the other process needs to know about it. How can I do this?
------------------------------
Date: Wed, 23 Jun 1999 18:51:39 GMT
From: Mitch <portboy@home.com>
Subject: Re: Cooperating processes...
Message-Id: <3770BCDB.8CA5DB2F@home.com>
Daniel Bell wrote:
> If I was in UNIX, I would send a signal to the other process which would
> notify it to watch for a change. If I was in NT, I would break down and
> write the info it to a temporary directory (which is probably what you're
> doing until you can find something better to do). I actually have to
> communicate between two Perl processes, one on Linux, and one on an NT box.
> The best way I found to do it is to send a file back and forth between the
> two whenever a change is made- it works great and it takes no time to write.
Thanks all for the reply!!! However, these processes will not be forked. The
two processes that need to need to know when one changes a local variable are
both started separately. So, let's say that you start both processes:
perl5 foo.pl
perl5 foo2.pl
Both processes have a variable called $foo which each will manipulate
internally. So, let's say that process foo2 changes its $foo to "whatever"
($foo = "whatever"). Then, somehow process foo, needs to know that process foo2
changes its $foo variable to "whatever".
Can I do it this way?
.mitch
------------------------------
Date: Wed, 23 Jun 1999 18:34:42 GMT
From: dragnet@internalysis.com (Marc Bissonnette)
Subject: Re: deleting whitespace
Message-Id: <6N9c3.19580$5a.24993@news20.bellglobal.com>
In article <P9Ub3.3018$I72.384814@nnrp1.ptd.net>, tfiedler@ptd.net says...
>
>how do i delete whitespace or for what its worth any junk on a line?
>
$line =~ s/ //;
--
----------------------------
Marc Bissonnette
InternAlysis
Corporate Internet Research and Results!
http://www.internalysis.com
------------------------------
Date: 23 Jun 1999 17:04:01 GMT
From: fmgst+@pitt.edu (Filip M. Gieszczykiewicz)
Subject: Re: Does Perl have a future?
Message-Id: <7kr421$b92$1@usenet01.srv.cis.pitt.edu>
In Article <brian-ya02408000R2306990942260001@news.panix.com>, through puissant locution, brian@pm.org (brian d foy) soliloquized:
>In article <Pine.GSO.4.02A.9906221735570.1698-100000@user2.teleport.com>, Tom Phoenix <rootbeer@redcat.com> posted:
[snip]
>memory is not that expensive. :) it's not really a fair statement
>because that memory is going to be used by the CGI scripts too,
>even though not continously. i forget where i saw this adage:
>
> free memory is wasted memory
[snip]
Prolly the linux FAQ about memory usage. My "free" ram hovers around 3.5MB
free while buffers are 30MB, shared ~50MB, and cache ~50MB... out of 128MB.
"free memory" is really wasted... I like it used for cache especially :-)
--
Filip "I'll buy a vowel" Gieszczykiewicz | http://www.repairfaq.org/
Always and everything for the better!
Now exploring whatever, life, and the meaning of it all... and 'not' :-)
------------------------------
Date: Wed, 23 Jun 1999 14:20:18 -0400
From: john gehman <jed@moose.chem.yale.edu>
Subject: Re: extracting
Message-Id: <37712562.7B9C7889@moose.chem.yale.edu>
Brian Pontz wrote:
> Hello,
> How would I extract "/test/" (without the quotes and slashes) and
> "Testing" without the quotes and put them in a variable from a line
> like this.
>
> <A HREF="/test/">Testing </A>Whatever</H3>
> I had something like this but I cant get it to work right.
>
> /$\<A HREF="\/(.*)"\/\>(.*)\<\/A(.*)>(.*)<(.*)>/
> $first=$1;
> second=$2;
>
> Thanks
> Brian Pontz
$j = "<A HREF=\"/test/\">Testing <\/A\>Whatever</H3>";
# the \ mark I've inserted before the internal quotes were necessary
just for properly
# setting the variable -- If you pick up the line from another file via
something like
# $j = <HTMLFILE>
# the quotes don't spoil anything.
$j =~ /<A HREF="\/(.*)\/"\>(.*)\<\/A\>(.*)\<(.*)\>/;
$first=$1;
$second=$2;
$third=$3;
$fourth=$4;
print "$first\n";
print "$second\n";
print "$third\n";
print "$fourth\n";
------------------------------
Date: Wed, 23 Jun 1999 18:40:55 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: extracting
Message-Id: <XS9c3.105$I55.5756@news.itd.umich.edu>
In article <37710f5e.8807785@news2.channel1.com>,
Brian Pontz <pontz@channel1.com> wrote:
>How would I extract "/test/" (without the quotes and slashes) and
>"Testing" without the quotes and put them in a variable from a line
>like this.
><A HREF="/test/">Testing </A>Whatever</H3>
Like this:
$str = '<A HREF="/test/">Testing </A>Whatever</H3>';
MyParser->new->parse($str)->eof;
print "$$_[0]: $$_[1]\n" foreach @tag;
BEGIN {
package MyParser;
require HTML::Parser;
@ISA = 'HTML::Parser';
sub start { $_[1] eq "a" and ($href = $_[2]{href}) =~ tr|/||d, $text = ""; }
sub end { $_[1] eq "a" and push(@::tag, [$href, $text]), $href = "" }
sub text { $href and $text .= $_[1] }
}
> I had something like this but I cant get it to work right.
>/$\<A HREF="\/(.*)"\/\>(.*)\<\/A(.*)>(.*)<(.*)>/
See perlfaq9 on the dangers of using regular expressions to process HTML.
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: Wed, 23 Jun 1999 11:50:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: extracting
Message-Id: <MPG.11dacc50e0be1520989c32@nntp.hpl.hp.com>
In article <37712562.7B9C7889@moose.chem.yale.edu> on Wed, 23 Jun 1999
14:20:18 -0400, john gehman <jed@moose.chem.yale.edu> says...
...
> $j = "<A HREF=\"/test/\">Testing <\/A\>Whatever</H3>";
>
> # the \ mark I've inserted before the internal quotes were necessary
> just for properly
> # setting the variable -- If you pick up the line from another file via
> something like
> # $j = <HTMLFILE>
> # the quotes don't spoil anything.
Then use qq{} instead of outer double-quotes. Too many backslashes,
Herr Mozart!
> $j =~ /<A HREF="\/(.*)\/"\>(.*)\<\/A\>(.*)\<(.*)\>/;
> $first=$1;
> $second=$2;
> $third=$3;
> $fourth=$4;
That is all so hard to write and to read. And you backslash '<' and '>'
for no apparent reason. Too many backslashes, Herr Mozart!
How about this:
my ($first, $second, $third, $fourth) =~
m%<A\s+HREF="/(.*?)/">(.*?)</A>(.*?)<(.*?)>%is;
Not a backslash in sight. However, I non-greedied the regex to make it
useful with more than one such tag in the string. I also added the /i
and /s modifiers, because HTML is case-insensitive and line-insensitive.
You could/should replace the named variables by an array.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 23 Jun 1999 11:33:48 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: Tom and Gnat <perlfaq-suggestions@perl.com>
Subject: Re: FAQ 1.8: How does Perl compare with other languages like Java, Python, REXX, Scheme, or Tcl?
Message-Id: <3771288C.120B78FD@mail.cor.epa.gov>
[cc sent to perlfaq-suggestions]
Tom Christiansen wrote:
> [snip]
> Probably the best thing to do is try to write equivalent code to do
> a set of tasks.
However, you should be aware of the difficulty involved in doing so
in order to 'compare' one language to another. You can compare
your effectiveness in Language A vs. that in Language B, but that is
not the same as comparing the effectiveness of the two languages in
solving your problem. If you are skilled in Language A and still
learning Language B, it is almost inevitable that your code in
Language A will be more efficient than your code in Language B, and
hence your Language-A code is more likely to be fast and robust.
This does not mean that someone else would not have written a
significantly faster, more robust solution in Language B.
> These languages have their own newsgroups in which
> you can learn about (but hopefully not argue about) them.
>
> Some comparison documents can be found at
> http://language.perl.com/versus/ if you really can't stop yourself.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 23 Jun 1999 11:50:30 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Help Excel functions to Perl Code
Message-Id: <37712C76.581943F4@mail.cor.epa.gov>
Simmo wrote:
>
> Hi,
Howdy,
> Has anyone any experience of creating Perl scripts that replicate Excel
> functions or know of any resource which provides some help? Found a
You'll probably want to look into the Win32::OLE module which
runs quite nicely with ActiveState Perl (on win32, of course).
> spreadsheet::excel module but am not able to install on the server due to
> security restrictions.
Do you mean that you can't upload any modules at all? Or that
you can't install modules in the @INC directories? There is a
difference. The FAQ tells you how to put modules in your own
space and then access them.
If your sysadmin isn't being cooperative, try being nicer to
him/her/it first. Pizza and beer [*good* pizza and *really*
good beer] has been known to work wonders. If your sysadmin
doesn't want either, then suspect he/she has been replaced
by aliens.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 23 Jun 1999 10:22:34 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: inheriting Class Data
Message-Id: <slrn7n1uti.k1b.abigail@alexandra.delanet.com>
Tom Christiansen (tchrist@mox.perl.com) wrote on MMCXXII September
MCMXCIII in <URL:news:3770c7da@cs.colorado.edu>:
()
() Did you read perltootc? Pick a layout format:
()
() http://language.perl.com/misc/perltootc.pod
() http://language.perl.com/misc/perltootc.man
() http://language.perl.com/misc/perltootc.ps
() http://language.perl.com/misc/perltootc.html
() http://language.perl.com/misc/perltootc.text
What? No Word format?
Abigail *ducking*
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 23 Jun 1999 10:59:57 -0700
From: Shane Fisher <fishers@lister.acm.wwu.edu>
Subject: Module Path Problem
Message-Id: <Pine.BSF.4.05.9906231053250.12031-100000@lister.acm.wwu.edu>
Greetings,
There is a problem with the perl script I'm piping to from procmail.
When I run it from my home directory (./myscript < sample_message) it
works fine, but when I try to run it from any other directory (or
procmail), it reports that it can't find the module it uses (both the main
script and the module reside directly under my home directory). So now I
have to figure out how to get the script to "see" the included module
(using the "use module" syntax). I've tried appendeding "-IP
path/to/my/module" to the "#!" line in the perl script, but that appears
to cause the perl interpreter to try and compile the "sample_message" when
I run "./myscript < sample_message."
So I suppose the simple question I'm asking is where do I need to put
modules in relation to the main script that uses them in order for them to
be seen universally (from wherever they're ran) so that they will be
included properly? Like I said, both the script and the module currently
live in the same directory, my $home.
Thanks for any help!
Regards,
Shane
=========================================================================
Shane M. Fisher
CS Major, Western Washington University
E-Mail: fishers@acm.wwu.edu, smfisher@gte.net
Web: http://www.acm.wwu.edu/fishers
=========================================================================
------------------------------
Date: Wed, 23 Jun 1999 14:50:55 -0400
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: Module Path Problem
Message-Id: <37712C8F.135BCFD7@mathworks.com>
Shane Fisher wrote:
> So I suppose the simple question I'm asking is where do I need to put
> modules in relation to the main script that uses them in order for them to
> be seen universally (from wherever they're ran) so that they will be
> included properly? Like I said, both the script and the module currently
> live in the same directory, my $home.
The beginning of your script should look like:
#!/usr/local/bin/perl
BEGIN {
push(@INC,<SOME_DIR>);
}
where <SOME_DIR> is the actual name of a directory.
Craig
------------------------------
Date: Wed, 23 Jun 1999 08:06:41 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Needle in a hash/list...
Message-Id: <hkiqk7.u82.ln@magna.metronet.com>
Mitch (portboy@home.com) wrote:
: How can I find a value in a hash/list. So, if my hash/list is
: coke sucks:major bites:forever rules:dominates # the :'s are part of
: each element. So $hash{coke}[0] -> sucks:major
: how, do i go through the hash/list and find rules or rules:dominates?
my @rules = grep(/^rules:/, @{$hash{coke}});
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 23 Jun 1999 10:35:54 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Newbie - Perl books - which to get?
Message-Id: <37711AFA.B02E9A46@mail.cor.epa.gov>
Andy wrote:
[Note: I'm moving your comment to *after* its prequel, since
that's the way people read Usenet. Good snippage, though...]
> Eric Bohlman wrote in message ...
> [my snip of Eric's advice]
>
> How about for win32 systems?
> I've already purchased the Lizard book.
> Any comments on this one. It's still being shipped as of this message.
Excellent choice. The gecko book (it's a 'wall' gecko - get it?)
is a good translation from the unix world to the win32 world.
In fact, you should buy everything that has one or more of
these names on it:
Larry Wall
Randal Schwartz
Tom Christiansen
Lincoln Stein
Do *not* buy any book which is for 'Dummies', or which promises
to teach you something in K days. I don't think Randal Himself
could teach the average newbie all of Perl in 7 days and have
that person be a fully functional Perl programmer. Similarly,
I doubt the tag team of Kernighan and Ritchie could teach
some newbie to be a *good* C programmer in 7 days.
Anyone can teach a newbie to be a *lousy* programmer in K days.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 23 Jun 1999 10:09:50 -0700
From: dave keefer <davidk@netscape.com>
To: mirak63@yahoo.com
Subject: Re: NT - Server Up time
Message-Id: <377114DE.E3866AED@netscape.com>
c:\net server statistics
i think.
mirak63@yahoo.com wrote:
> Hello,
>
> Is there a way in Perl to be able to determine the time
> and date that an NT server came up?
>
> Thanks,
> Karim Wall
------------------------------
Date: Wed, 23 Jun 1999 13:21:16 -0400
From: "Daniel Bell" <djbell@wdsec.com>
Subject: Re: NT - Server Up time
Message-Id: <7kr58i$ig4$1@sulu.wdsec.com>
Check the last modified (or accessed) date of PAGEFILE.SYS. Since the
paging file is always opened, the date will be thast time the machine came
up successfully. The difference between this time and the current time is
the number you're looking for.
Daniel Bell
> Is there a way in Perl to be able to determine the time
> and date that an NT server came up?
------------------------------
Date: Wed, 23 Jun 1999 20:41:11 +0200
From: Bjorn Svensson <bjornsvensson@geocities.com>
Subject: Re: NT - Server Up time
Message-Id: <37712A47.90FD7B66@geocities.com>
mirak63@yahoo.com wrote:
> Is there a way in Perl to be able to determine the time
> and date that an NT server came up?
Yes,
uptime.pl
by Milivoj Ivkovic <mi@alma.ch>
#########################################################################
#########################################################################
#! perl -w
# use strict; # eval doesn't work with use strict !?
# see POD documentation at end
=head1 NAME
uptime.pl - Uptime for Windows. Version 0.23.
=cut
$^O eq "MSWin32" || die "Sorry, this works only on Windows for now\n";
my $max_results = 5; # if we have to use tick counts
my $VERSION = 0.23;
my $debug = $ENV{'QUERY_STRING'} || $ARGV[0];
print "$0 version $VERSION\n" if $debug;
print "Debug mode on\n" if $debug;
print "Perl version $]\n" if $debug;
BEGIN {
# HTTP headers if needed
local $^W = 0;
print "$ENV{'SERVER_PROTOCOL'}/200 OK\n" if $ENV{'PERLXS'} eq
"PerlIS";
print "Content-type text/plain\n\n" if $ENV{'SERVER_PROTOCOL'};
}
my ($several, @uptimes);
if (Win32::IsWinNT()) {
print "Windows NT\n\n" if $debug;
push @uptimes, (&event_log || &tick_counts);
print "eval error: $@\n" if $@ && $debug;
}
else {
print "Windows 9x\n\n" if $debug;
push @uptimes, (&system_da0 || &tick_counts);
}
sub tick_counts {
print "Counting ticks\n" if $debug;
my @ticks;
my $ticks = Win32::GetTickCount() > 0
? Win32::GetTickCount()
: Win32::GetTickCount() + 2**32;
my $seconds = $ticks/1000;
for (1..$max_results-1) {
push @ticks, time()-$seconds;
$seconds += 2**32/1000;
}
return @ticks, time()-$seconds;
}
sub system_da0 {
my $file = "$ENV{'WINDIR'}\\system.da0";
print "Checking $file\n" if $debug;
my $stat = (stat $file)[9];
print "Could not stat $file ($!)\n" if $debug && !$stat;
return $stat || undef;
}
sub event_log {
my $result = eval '
use Win32::EventLog;
my ($EventLog, $first, $count, $event, %data);
Win32::EventLog::Open($EventLog , "System", "") || die ("EventLog
Open() failed");
$EventLog->GetOldest($first) || die ("EventLog GetOldest() failed");
$EventLog->GetNumber($count) || die ("EventLog GetNumber() failed");
print "Event log first=$first, count=$count\n" if $debug;
$EventLog->Read((EVENTLOG_SEEK_READ |
EVENTLOG_BACKWARDS_READ),$first+$count,$event);
for $i (0 .. $first+$count-1) {
$EventLog->Read((EVENTLOG_SEQUENTIAL_READ|EVENTLOG_BACKWARDS_READ),0,$event)
|| die ("EventLog Read() failed at event $i");
%data = %{$event};
$data{"EventID"} = $data{"EventID"} & 0xffff;
next unless $data{"EventID"} == 6005;
print "Found event 6005\n" if $debug;
return $data{"TimeGenerated"};
print "This script is broken: it should never reach this line\n";
}
return undef;
';
if ($@) {
print "Eval error: $@\n";
return undef;
}
else {
return $result;
}
}
$several = @uptimes - 1;
foreach (@uptimes) {
print "up ", &time2days($_), " (since ", scalar localtime($_), ")\n";
print "or:\n" if $several;
}
print "... but who would believe that anyway?...\n" if $several;
sub time2days {
print "converting $_[0]\n" if $debug;
my $days = (time() - $_[0])/(24*60*60);
my $hours = ($days - int($days)) * 24;
my $minutes = ($hours - int($hours)) * 60;
my $day_st = $days >= 2 ? 'days' : 'day';
return sprintf("%0d $day_st %02d:%02d", $days, $hours, $minutes);
}
__END__
=head1 SYNOPSIS
perl uptime.pl [debug]
=head1 DESCRIPTION
Report machine uptime on Windows systems.
This script attempts to report the system uptime in a way similar
to the Unix uptime command. It only reports uptime, not users or
load statistics.
On NT it uses the event log. The event log service itself writes an
entry to it when it starts (ID 6005).
On Win9x it gets the create time of the system.da0 file (the
system.dat
backup file which is recreated at system start).
If eihter of these methods fail for any reason, it uses the system
tick counts.
Since these can only hold about 47 days, it returns a list of possible
uptimes, limited to C<$max_results> (5 by default). (Have you ever
seen
a Windows system up for more than 200 days? :-) If yes, set
C<$max_results> to a higher value).
The script can be used in CGI. It will print the needed headers
automatically.
=head1 OPTIONS
If given any argument (at the command line or as a CGI argument), it
is
considered as a 'debug' or 'verbose' option, and additional stuff is
printed.
=head1 FEATURES (aka BUGS)
On NT, the uptime will be wrong if you restarted the event log
service.
If you have a low limit on your event log file size or logged events,
and
your system has been up for a long time, the event may not be
available
anymore. The script will then use tick counts.
On Win9x, the uptime will be wrong if the create time of your
system.da0 file
is not the same as when your system booted. I don't see what could
cause this
unless you overwrite the file, but there may be special cases. Let me
know if
you find any.
Not tested on Win98.
=head1 SCRIPT CATEGORIES
Win32
=head1 OSNAMES
MSWin32
=head1 AUTHOR
Milivoj Ivkovic <mi@alma.ch>. Others welcome to extend it to more
operating systems which don't have an uptime command.
=head1 COPYRIGHT
Copyright Milivoj Ivkovic, 1999. Same license as Perl itself.
=cut
#########################################################################
#########################################################################
======================================================
Bjvrn Svensson bjornsvensson@geocities.com
======================================================
------------------------------
Date: Wed, 23 Jun 1999 12:07:29 -0400
From: Jim Nicholson <jnich@pdd.att.com>
Subject: perl 5.005_3 on hp/ux 10.20
Message-Id: <37710641.9ECBA841@pdd.att.com>
I'm trying to build the latest stable perl on a 715 with 10.20 installed
(using the hp-supplied ANSI compiler, not the k&r one). Make dies in the
miniperl tests with the following:
cc -L/usr/local/lib -o miniperl miniperlmain.o libperl.a -lnsl_s
-lndbm -ldld -lm -lc -lndir -lcrypt
./miniperl -w -Ilib -MExporter -e 0 || make minitest
./miniperl configpm tmp
*** Termination signal 132
Stop.
Has anyone succeeded in getting a perl more recent than 5.004 to compile
under HP/UX?
- Jim Nicholson
jnich@att.com
------------------------------
Date: Wed, 23 Jun 1999 17:46:38 GMT
From: doug_johnston@my-deja.com
Subject: Perl Alphanumeric Sort?
Message-Id: <7kr6hq$df8$1@nnrp1.deja.com>
Ok, here's my problem:
I'm looking to do a sort on an array that
contains data somewhat like this -
@letter_nums = ("A4","A2","A1","A3");
I use the following code to sort it into a temp
array for later processing -
@temp1 = sort by_values (@letter_nums);
sub by_values
{
($a cmp $b)
}
It's a little more complex than that, but
basically it works whenever I want to sort only
numbers or letters, but when sorting this, it
doesn't seem to work. I would expect @temp1 to
contain ("A1","A2","A3","A4") after the sort, but
it ends up being just the same as it was when it
went in. This just doesn't make sense to me so
I'm hoping someonw else out there has experienced
this and can help me. Thanks
Doug Johnston
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Wed, 23 Jun 1999 10:53:16 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Perl and Personal Web Server (Win98)
Message-Id: <37711F0C.7E7D6E02@mail.cor.epa.gov>
Richard H wrote:
>
> seems to be PWS day today :-)
>
> ive a page http://www.rhclc.freeserve.co.uk/demos/pws.html
^^^^^
Oops. The poster will need to change 'demos' to 'demo' without
the 's' if he wants to reach that URL.
> with some instructions and a copied script which <could> do it for you.
> usual disclaimers for distributing somebody elses code!!
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 23 Jun 1999 10:06:26 -0700
From: "Spud" <spud200@earthlink.net>
Subject: Perl in Win32
Message-Id: <7kr47n$a39$1@holly.prod.itd.earthlink.net>
For some reason when I try to execute my perl programs in Windows a black
DOS-like screen comes up for a second and then dissappears. I'm running
ActivePerl 517. Help, please!
Thank you
------------------------------
Date: Wed, 23 Jun 1999 11:03:52 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <37712188.C15A1B67@mail.cor.epa.gov>
Abigail wrote:
> [snip]
> Could someone tell what they are using the OCR listing for? Does it show
Does it have anything other than entertainment value? Who is using
Greg's weekly posting to assess content ration, instead of doing it
real-time?
> who are posting FAQs, or something like that? I don't think FAQs are
> original content, but Gregs little program thinks they are. Why doesn't
> anyone get upset about that, yet they waste long threads about quoting
> prefixes?
Because everyone's scared of Tom? I dunno. I think that the FAQ and
perlfunc posts shouldn't be included. But I don't care enough one way
or the other. Just as I am only interested in your quoting style to
see what new creative doodads you have to offer.
Is someone really worried that their rightful place in history as
The Master Of OCR is going to be jeopardized by your quoting style?
I doubt it. The 'quoting prefixes' issue seems like more of a fun way
to toss around thoughts on regexen and text parsing.
But then, what do I know...
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 23 Jun 1999 12:07:22 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <3771225a@cs.colorado.edu>
In comp.lang.perl.misc,
David Cassell <cassell@mail.cor.epa.gov> writes:
:Because everyone's scared of Tom? I dunno. I think that the FAQ and
:perlfunc posts shouldn't be included.
They aren't.
--tom
--
"The Internet is like a town that leaves its streets unmarked on the
principle that people who don't already know don't belong"
- James Glieck
------------------------------
Date: Wed, 23 Jun 1999 11:01:22 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Summing an array
Message-Id: <x3yg13jc666.fsf@tigre.matrox.com>
James Stewart <james@britlinks.co.uk> writes:
> Just wondering how to find the sum of all the elements of an array. A
> look through the FAQs doesn't yield an answer. I guess I could do it with
> a loop, but I'm guessing there's a more elegant solution.
sub sum_array {
my $sum = shift;
my @ary = @_;
$sum += shift @ary;
return $sum unless @ary;
sum_array($sum, @ary);
}
@x = qw/1 2 3 4 5/;
$x = sum_array(0, @x);
;-)
Ala
------------------------------
Date: Wed, 23 Jun 1999 13:59:53 -0400
From: john gehman <jed@moose.chem.yale.edu>
Subject: towards relational DB in perl ...
Message-Id: <37712098.D5C0C8AF@moose.chem.yale.edu>
# This may be trivial, but I sure can't find the answer --
# Consider a multidimensional hash such as
$example{"red"}{"chevy"} = 1;
$example{"red"}{"ford"} = 2;
$example{"blue"}{"chevy"} = 3;
$example{"blue"}{"dodge"}= 4;
$example{"green"}{"ford"} = 5;
# the values are irrelevant to the question ...
# now, if I want to print all of the first dimensions
# keys, I of course write
print keys %example;
print "\n";
# If I want to print the second dimension's keys which
# have a common first-dimension string, I write
print keys %{ $example{red} };
print "\n";
# Now, I would love to be able to select all those first
# dimension keys that have the second dimension in common.
# My first inclination is to seek some wildcard or globbing
# character to fill the first dimension, such as
# print keys %{ $example{*}{chevy} }; # where I'd hope to get
redblue
# Of course, I can kludge a solution with
foreach $ex ( keys %example ) {
@list = keys %{ $example{$ex} };
foreach $r (@list) {
if ( $r =~ /chevy/ ) {
print "$ex\n";
}
}
}
# But my gut tells me there must be a more elegant
# solution (i.e. single statement). After all,
# these keys are just references to the address where
# the actual information (value data) is, There
# shouldn't be anything magical about the dimension
# in which a particular key exists, other than its position
# in the "ordered list" of keys.
# Is Perl secretly writing a list that resides in the namespace
# with 1st-dimension keys, e.g. @example = qw(red blue green),
# and then subsequent lists for higher dimensions,
# e.g. @{ $example{red} } = qw(chevy ford), such that
# when prompted for `keys` it just dumps the list elements?
#
# If so, I suppose the only way out is to overtly
# create the reverse lists as I did above, but I hope there
# exists a more elegant solution
#
# Many thanks to anybody who can enlighten me.
#
---------------------------------------------------------
john gehman
email: jed@moose.chem.yale.edu
"Once in a while, you get shown the light
In the strangest of places, when you look
at it right."
--GD
------------------------------
Date: 23 Jun 1999 14:05:07 -0400
From: Jason Reed <jcreed@cyclone.jprc.com>
Subject: Re: towards relational DB in perl ...
Message-Id: <a1k8su23os.fsf@cyclone.jprc.com>
john gehman <jed@moose.chem.yale.edu> writes:
> # Now, I would love to be able to select all those first
> # dimension keys that have the second dimension in common.
OWTDI:
print grep { exists $example{$_}{chevy} } keys %example;
perldoc -f grep
---Jason
------------------------------
Date: Wed, 23 Jun 1999 18:20:49 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: towards relational DB in perl ...
Message-Id: <si1zf2dbi6.fsf@cre.canon.co.uk>
John Gehman <jed@moose.chem.yale.edu> wrote:
> towards relational DB in perl
If you need a relational database, use one. Perl does not pretend to
offer the same features as a good RDBMS.
> Now, I would love to be able to select all those first dimension keys
> that have [a particular value for] the second dimension.
grep { exists $hash{$_}{'value'} } keys %hash
--
Gareth Rees
------------------------------
Date: Wed, 23 Jun 1999 11:55:51 -0400
From: "Russ Conway" <russconway@NOSPAMmindspring.com>
Subject: URI:_generic Error
Message-Id: <7kqvr7$ifk$1@nntp8.atl.mindspring.net>
I've been trying run the following code segment::
# Create request object
$objRequest = new HTTP::Request('GET', $sURL);
# Pass request to server and get response object
$objResponse = $objUserAgent->request($objRequest, $sOutputFile);
The last statement generates an error:
Can't locate object method "host_port" via package "URI::_generic" at
C:/Perl/site/lib/URI/WithBase.pm line 41.
I've been trying to figure out what is causing the error, but haven't had
any luck so far. Is this a problem with the version of URI that I am using
(v1.02)? I'm still somewhat new at working with Perl modules so any help
would be appreciated.
TIA
(remove NOSPAM from my address to respond via e-mail)
------------------------------
Date: Wed, 23 Jun 1999 11:39:46 -0700
From: Mike Machado <mike@innercite.com>
Subject: use strict question
Message-Id: <377129F1.6D36D6E5@innercite.com>
I am trying to use a scalar as a subroutine name while I have use strict
on and I keep getting the error:
Can't use string ("mysub") as a subroutine ref while "strict refs" in
use at testing.pl line 5
Here is the code
#!/usr/bin/perl
use strict;
my $sub = "mysub";
&$sub;
sub mysub {
print "hello this does not work while use strict is on\n";
}
How can I get this to work while still having 'use strict' on?
--
Mike Machado
mike@innercite.com
InnerCite
Network Specialist
------------------------------
Date: Wed, 23 Jun 1999 14:57:02 -0400
From: Craig Ciquera <craig@mathworks.com>
Subject: Re: use strict question
Message-Id: <37712DFD.7BF14EAC@mathworks.com>
Mike Machado wrote:
> Can't use string ("mysub") as a subroutine ref while "strict refs" in
> use at testing.pl line 5
>
Only hard references are allowed while using strict.
For example:
#!/usr/local/bin/perl -w
use strict;
my $sub = \&mysub;
&$sub;
sub mysub {
print "hello WILL work while use strict is on\n";
}
__END__
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 6110
**************************************