[23287] in Perl-Users-Digest
Perl-Users Digest, Issue: 5507 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 15 18:05:44 2003
Date: Mon, 15 Sep 2003 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 15 Sep 2003 Volume: 10 Number: 5507
Today's topics:
Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
Re: "between" function equivalent in Perl? <skuo@mtwhitney.nsc.com>
Re: "between" function equivalent in Perl? <sagittaur@ftml.net>
CGI: Help with "loading" message while processing. (corky)
Crypt::SSLeay <ama@PW.CA>
Re: Crypt::SSLeay <minceme@start.no>
Re: Crypt::SSLeay <ak+usenet@freeshell.org>
Re: Crypt::SSLeay <minceme@start.no>
different proxies and multiple requests in LWP::Paralle (Zeke Koos)
Re: importing a hash from package (Tad McClellan)
Re: kill command in a perl script <tzz@lifelogs.com>
Re: Maddening bug: Why do quotes fix it? <emschwar@pobox.com>
Re: Newbie Help with Hashes (James Bonanno)
Re: Newbie Help with Hashes (Tad McClellan)
Newbie Question: Could someone show me how to implement <Borniac_1@hotmail.com>
Re: Newbie Question: Could someone show me how to imple <ak+usenet@freeshell.org>
Re: Perl DBMS (Daniel R. Tobias)
Re: Problem with xml parser <bart.lateur@pandora.be>
Re: recognising a special character inside [^] (Tad McClellan)
Re: shutdown or reboot computer <abigail@abigail.nl>
Re: Subroutine as a new Task <abigail@abigail.nl>
Re: Tring to kill my kids, but they are stuborn little <eric@dmcontact.com>
Re: Tring to kill my kids, but they are stuborn little <eric@dmcontact.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 15 Sep 2003 12:08:14 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bk52nl$7g6$1@lumberjack.rand.org>
"Tad McClellan" <tadmc@augustmail.com> wrote:
> Alexandra <sagittaur@ftml.net> wrote:
>
> > I've since discovered the count
> > function.
>
>
> What is the count function?
Um, something from my imagination? I had misinterpreted the variable name in
the following text.
=== copied from perldata pod ===
List assignment in scalar context returns the number of elements produced by
the expression on the right side of the assignment:
$x = (($foo,$bar) = (3,2,1)); # set $x to 3, not 2
$x = (($foo,$bar) = f()); # set $x to f()'s return count
This is handy when you want to do a list assignment in a Boolean context,
because most list functions return a null list when finished, which when
assigned produces a 0, which is interpreted as FALSE.
It's also the source of a useful idiom for executing a function or
performing an operation in list context and then counting the number of
return values, by assigning to an empty list and then using that assignment
in scalar context. For example, this code:
$count = () = $string =~ /\d+/g;
will place into $count the number of digit groups found in $string. This
happens because the pattern match is in list context (since it is being
assigned to the empty list), and will therefore return a list of all
matching parts of the string. The list assignment in scalar context will
translate that into the number of elements (here, the number of times the
pattern matched) and assign that to $count. Note that simply using
$count = $string =~ /\d+/g;
would not have worked, since a pattern match in scalar context will only
return true or false, rather than a count of matches.
=== end paste ===
However, I still could not get the following to return $count as a value of
3, $count returned a value of 1:
#! /usr/bin/perl -s
#use strict;
#use warnings;
$mystring = ('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz
server2=user1 @');
$count = () = $mystring =~ /=(.*?)\s/;
print $count;
Also, when I included the 'use strict' and 'use warnings' statements I
received the following output messages and don't understand how to resolve
them. Any insight?
Can't locate warnings.pm in @INC (@INC contains:
/usr/lib/perl5/5.00502/sun4-solaris /usr/lib/perl5/5.00502
/usr/lib/perl5/site_perl/5.005/sun4-solaris /usr/lib/perl5/site_perl/5.005
.) at test.pl line 3.
BEGIN failed--compilation aborted at test.pl line 3.
Global symbol "$mystring" requires explicit package name at test.pl line 6.
Global symbol "$count" requires explicit package name at test.pl line 7.
Execution of test.pl aborted due to compilation errors.
A posting guideline question:
This thread originated with my question about a between function equivalent
in Perl but has since evolved to this question on list count evaluation.
Would it be proper to have renamed this post subject line to something like
"List counts <was: Re: "between" function equivalent in Perl?>" or is it
preferred by this group to keep all related posts under the original
discussion thread?
Much thanks,
Alexandra
------------------------------
Date: Mon, 15 Sep 2003 12:10:33 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bk52rg$7g7$1@lumberjack.rand.org>
"Tad McClellan" <tadmc@augustmail.com> wrote:
> Alexandra <sagittaur@ftml.net> wrote:
(My apologies for the untimely reply as I was taking some time to read up
more.)
> > Would it be accurate to
>
> No.
>
> > assume that most Perl expressions/functions will evaluate "at large" and
>
> They have 2 different behaviors.
>
> If called in a scalar context, they do one thing.
>
> If called in a list context, they do something else.
>
> They are often "related" things, but that is convention rather
> than requirement. They could do wildly different unconnected
> things, such as send an email in scalar context and return
> the contents of a database table in list context.
Ok, I see now my generalizations were inaccurate and that context does
determine how operators *and* functions evaluate, even though "certain
operators know
which context they are in". (Programming Perl, p45) It goes on to say: "In
computer lingo, the functions are 'overloaded' on the type of their return
value. But it's a very simple kind of overloading, based only on the
distinction between singular and plural values, and nothing else."
Before, I was reading this to mean that in most cases only the variable type
(scalar or list) determines the context in which the expression evaluates.
> It is up to the author of the function to decide what it is that
> their function will do in each context. (So you cannot use the
> function intelligently without reading the functions' docs.)
It seems a bit of a paradigm shift from languages such as VB, where
declarations are used to determine object classes and variable datatypes.
Functions in many cases are tied to object classes and variable datatype
declarations; I was trying to make a connection between this convention with
determining context in Perl.
Not to get mired in semantics with this, but working with Perl seems to
require a shift in approach: Perl statements are more compressed, and a lot
more can happen on one line than in other programming languages. (I'm sure
this could be debated, too. I'm merely trying to breach the disconnect I was
having here in approaching the Perl language as a whole. Still much reading
to do...)
> > then look to "format" (for lack of a better term) the return value
depending
> > on the context of the assignment variable or operand?
> ^^^^^^^^^^
>
> You should have left that word out. Context matters for operators
> other than assignment as well.
I see that a little better now. It's incorrect to assume context is
restricted to or solely determined by the assignment operator.
> > I read somewhere that you do not have to declare variables in Perl, you
just
> > use them.
>
> Right (but not recommended, other than in one-liners).
>
> > Getting a grasp on contexts, even a tiny one, explains now how
> > that can work.
>
> No it doesn't.
>
> Context has nothing whatsoever to do with either of Perl's two
> systems of variables.
>
> If you can explain why you think context relates to declaring (or not)
> variables, then perhaps we can help fix the misunderstanding.
I believe I was trying to apply my previous experience with object-oriented
languages to use as a framework for understanding Perl. I'm under the
impression now, after this discussion, that many of the same principles do
apply (object declarations, datatype assignment, determining evaluation
context) but they are more compressed in Perl syntax. I feel that coming up
with an example at this point would only serve to waste your time before I
read up more and can phrase clear questions with specific examples (such as
the question in the other post in this thread), but I very much appreciate
your willingness to help and explain.
Also, I appreciate your indulging me in this discussion as I realize it is
beneath the level of most everyone in this group. While I'm still in a bit
over my head
here, I believe I'm getting on track, if slowly, thanks to you and all
who've replied in this string.
Alexandra
------------------------------
Date: Mon, 15 Sep 2003 12:56:15 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <Pine.GSO.4.21.0309151250060.8992-100000@mtwhitney.nsc.com>
On Mon, 15 Sep 2003, Alexandra wrote:
(snipped)
>
> However, I still could not get the following to return $count as a value of
> 3, $count returned a value of 1:
>
> #! /usr/bin/perl -s
> #use strict;
> #use warnings;
Why the '-s' on the shebang line? Perhaps you meant '-w'?
> $mystring = ('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz
> server2=user1 @');
A scalar from list assignment? The assigns the last item in the list
to the scalar. Perhaps you meant to use a quote operator?
my $mystring = q('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz server2=user1 @');
> $count = () = $mystring =~ /=(.*?)\s/;
> print $count;
And here, for counting the number of matches, I guess you meant to
use global matches:
my $count = () = $mystring =~ /=(.*?)\s/g; # note the /g modifier
print $count;
> Also, when I included the 'use strict' and 'use warnings'
> statements I received the following output messages and don't
> understand how to resolve them. Any insight?
strict.pm ought to be okay -- warnings.pm was introduced in version 5.6.
--
Hope this helps,
Steven
------------------------------
Date: Mon, 15 Sep 2003 14:21:46 -0700
From: "Alexandra" <sagittaur@ftml.net>
Subject: Re: "between" function equivalent in Perl?
Message-Id: <bk5ahi$921$1@lumberjack.rand.org>
"Steven Kuo" <skuo@mtwhitney.nsc.com> wrote:
> On Mon, 15 Sep 2003, Alexandra wrote:
>
> (snipped)
> >
> > However, I still could not get the following to return $count as a value
of
> > 3, $count returned a value of 1:
> >
> > #! /usr/bin/perl -s
> > #use strict;
> > #use warnings;
>
>
> Why the '-s' on the shebang line? Perhaps you meant '-w'?
The '-s' I included because of an internal convention here where I work. I'm
not sure if it's still necessary or perhaps obsolete (some of this code is
more than 6 years old). Previously I had tried the '-w' switch (instead and
in addition to) but received the 'Can't locate warnings.pm in @INC' as with
the 'use warnings' statement. (However, the code below works fine now.)
> > $mystring = ('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz
> > server2=user1 @');
>
>
> A scalar from list assignment? The assigns the last item in the list
> to the scalar. Perhaps you meant to use a quote operator?
>
> my $mystring = q('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz
server2=user1 @');
rrrg. yes. :)
> > $count = () = $mystring =~ /=(.*?)\s/;
> > print $count;
>
> And here, for counting the number of matches, I guess you meant to
> use global matches:
>
> my $count = () = $mystring =~ /=(.*?)\s/g; # note the /g modifier
> print $count;
Huh. I did experiment with including the global modifier to return all
matching parts, but still received a return value of 1 (I assume due to my
list assignment issue).
> > Also, when I included the 'use strict' and 'use warnings'
> > statements I received the following output messages and don't
> > understand how to resolve them. Any insight?
>
> strict.pm ought to be okay -- warnings.pm was introduced in version 5.6.
Thanks for the help! This statement worked perfectly:
#! /usr/rand/bin/perl -ws
#use warnings; #running Perl version 5.00502
use strict;
my $stringvar = q('xxx server1=user1 @', 'yyy server1=user2 @', 'zzz
server2=user1 @');
my $count = () = $stringvar =~ /=(.*?)\s/g;
print $count;
Alexandra
------------------------------
Date: 15 Sep 2003 13:49:40 -0700
From: twistdpair@hotmail.com (corky)
Subject: CGI: Help with "loading" message while processing.
Message-Id: <e2d5abce.0309151249.792a8e06@posting.google.com>
Using Perl 5.6.0. I need to temporarily show a message while I process
in the background. The process calls an OLE component which sets a
value in the user's cookie.
The DisplaySecSubmit sub calls my "please wait" page which is static.
The GetSecureModels sub runs the OLE process and sets the cookie.
The DisplaySubmit sub displays a new page which uses the cookie which
was just set.
Here is where it starts:
elsif ($FORM{'FUNC'} eq 'DISP_SEC_SUBMIT')
{&RightViolation($CREATE_RIGHT) if (($createRight == 0) &&
($a_createRight == 0));
&DisplaySecSubmit();
&GetSecureModels();
&DisplaySubmit();
}
use Win32::OLE;
use DBI;
use DBD::ODBC;
sub GetSecureModels{
if (length($trainedOn) < 1){
$dbh = DBI->connect("dbi:ODBC:support", exsu, exsupwd)|| die "Can't
connect !!: $DBI::errstr";
$dbh -> {RaiseError} = 1;
$stmt = "SELECT DISTINCT CTI_MODEL, MODEL FROM MODEL_LOOKUP WHERE
STATUS = 'ACTIVE' AND CLASS_FAMILY IN (SELECT DISTINCT FAMILY FROM
MODEL_FAMILY) ORDER BY MODEL;";
$sth = $dbh->prepare($stmt)|| die "Error on prepare $DBI::errstr";
$sth->execute()|| die "Error on Execute $DBI::errstr";
while (@row = $sth->fetchrow_array) {
my $server = Win32::OLE->new('auth.caller','Quit');
$server->{Model} = $row[0];
$server->{NSSGID} = $userID;
my $trainstat = $server->{Verify};
if ($trainstat ne -1 ) {
push @trainedOn , $row[1];
}
}
$trainedOn = join ',', @trainedOn;
print "Content-type: text/html; charset=utf-8\n";
&SetCompressedCookies('MODELS','trainedOn', $trainedOn);
print "\n";
}
}
sub DisplaySecSubmit{
&set_submit_strings();
&EchoFile($HTML_PATH, "traincheck.htm");
}
My problem is that it seems as though each individual CGI call will
only return a single page of output. For example, I show my "please
wait" message while I'm processing and when processing is done the
results are appended to the "please wait" message instead of replacing
it.
Another problem is that the cookie stuff shows in the browser too.
Is there any way to flush or start with a clear screen? Can I run the
process on a different thread? Can I use refreshes to handle this? Or
should I use a combination of approaches?
I only use Perl once a year or so as necessary, and as a consequence
this may be a simple problem with a simple answer, so please forgive
me.
Thanks in advance for any help,
Corky
------------------------------
Date: Mon, 15 Sep 2003 16:13:38 -0400
From: "A. Ma" <ama@PW.CA>
Subject: Crypt::SSLeay
Message-Id: <bk56hv$er71@shark.pwgsc.gc.ca>
I am tryping to get Crypt::SSLeay to run under Windows. From CPAN, the
documentation says that Activestate has a compiled version available
already. Yet I cannot locate it when I went to Activestate. Does anyone know
where I can find one? (The documentation from CPAN implied that compiling
the module yourself is very problematic. That's why they suggested getting
the PPM version from Activestate.)
------------------------------
Date: Mon, 15 Sep 2003 21:04:29 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: Crypt::SSLeay
Message-Id: <bk59gp$t3q$1@troll.powertech.no>
A. Ma <ama@PW.CA> wrote:
> I am tryping to get Crypt::SSLeay to run under Windows. From CPAN, the
> documentation says that Activestate has a compiled version available
> already. Yet I cannot locate it when I went to Activestate. Does anyone know
> where I can find one? (The documentation from CPAN implied that compiling
> the module yourself is very problematic. That's why they suggested getting
> the PPM version from Activestate.)
http://ppm.activestate.com
Cheers,
--
Vlad
------------------------------
Date: Mon, 15 Sep 2003 21:20:39 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Crypt::SSLeay
Message-Id: <slrnbmcb96.r0i.ak+usenet@vinland.freeshell.org>
In article <bk59gp$t3q$1@troll.powertech.no>, Vlad Tepes wrote:
> A. Ma <ama@PW.CA> wrote:
[cut]
>> where I can find one? (The documentation from CPAN implied that compiling
>> the module yourself is very problematic. That's why they suggested getting
>> the PPM version from Activestate.)
>
> http://ppm.activestate.com
I had a quick look around there and yes, the build status says
that Crypt::SSLeay does build on Windows, but their pages
contains no link to any package. Maybe it's just me who is
unfamiliar with the packaging system they use (I'm a Unix guy).
Hopefully A. Ma is able to make more use of the site than I did.
--
Andreas Kähäri
------------------------------
Date: Mon, 15 Sep 2003 21:50:37 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: Crypt::SSLeay
Message-Id: <bk5c7d$u3d$1@troll.powertech.no>
Andreas Kahari <ak+usenet@freeshell.org> wrote:
> In article <bk59gp$t3q$1@troll.powertech.no>, Vlad Tepes wrote:
>> A. Ma <ama@PW.CA> wrote:
> [cut]
>>> where I can find one? (The documentation from CPAN implied that compiling
>>> the module yourself is very problematic. That's why they suggested getting
>>> the PPM version from Activestate.)
>>
>> http://ppm.activestate.com
>
> I had a quick look around there and yes, the build status says
> that Crypt::SSLeay does build on Windows, but their pages
> contains no link to any package. Maybe it's just me who is
> unfamiliar with the packaging system they use (I'm a Unix guy).
> Hopefully A. Ma is able to make more use of the site than I did.
I've never used Activestates packaging system, but I think most people
install the packages with ppm rather than downloading from the website
with a browser. Something like this might work:
ppm install Crypt-SSLeay.ppd
( I'm not sure of the syntax, check the docs for ppm. )
--
Vlad
------------------------------
Date: 15 Sep 2003 12:53:10 -0700
From: zekekoos@softhome.net (Zeke Koos)
Subject: different proxies and multiple requests in LWP::Parallel
Message-Id: <e579120b.0309151153.4e9236e@posting.google.com>
I've written the following script to verify a list of proxies in a
seperate file. It works fine except that I can't get LWP::Parallel to
use different proxies for each request. As it is now when I call
$ua->wait(20), the last proxy in list is used for every request in the
queue. If anyone has a solution please help me out here.
thanks
Koos
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;
use LWP::Parallel::UserAgent;
open(IN, './proxies.txt') or die "Could not open filename:";
my @proxies = <IN>;
chomp @proxies;
close(IN);
print "Content-type: text/html\n\n";
print "Start test:<br />";
my $ua = LWP::Parallel::UserAgent->new();
for (my $i = 0; $i < @proxies; $i++) {
tt("http://192.168.0.1/",$proxies[$i]);
};
my $entries = $ua->wait(20);
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
print "Answer for '",$res->request->url, "' was \t", $res->code,":
",
$res->message,"\n<br />";
}
print "end";
sub tt {
my ($url,$proxy) = @_;
$ua->max_hosts(25);
$ua->agent('Mozilla/4.5');
$ua->proxy('http', 'http://'.$proxy);
my $req = HTTP::Request->new('GET', $url);
$ua->register ($req);
}
------------------------------
Date: Mon, 15 Sep 2003 15:26:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: importing a hash from package
Message-Id: <slrnbmc83f.1td.tadmc@magna.augustmail.com>
Jeff Thies <cyberjeff@sprintmail.com> wrote:
> Steve Grazzini wrote:
>> The difference is between lexical (my) variables, which you can't
>> use outside the scope where they were declared, and package variables,
>> which are global.
>>
>> You can use our() to declare package variables.
>>
>> our %HASH; # %VARIABLES::HASH
>>
>> Is that what you were after?
>
> Yes,
Then see also:
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 15 Sep 2003 14:30:43 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: kill command in a perl script
Message-Id: <4noexlewfg.fsf@lockgroove.bwh.harvard.edu>
On 15 Sep 2003, skang@leaguedata.com wrote:
> I just started learning Perl and I am trying to do followings;
>
> ps -ef | grep java >pidfile
> In pidfile, there are 3 PIDs for weblogic processes.
>
> root 1769 1758 TS 0 0 17:55:26 vt02 44:38
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms512m
> -Xmx512m -Dweb
> root 27464 27453 TS 29 0 09:15:55 vt04 91:55
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms1024m
> -Xmx1024m -Dw
> root 27533 27522 TS 49 0 09:21:45 vt03 2:35
> /opt/java2-1.3.1/bin/./../bin/x86at/native_threads/java -Xms32m
> -Xmx200m -Dwebl
>
> What I want is get the largest PID which is 27533 in this case, and
> then kill -3 the PID.
Use Proc:ProcessTable from CPAN.
<offtopic>
I should warn you that the "largest" PID is meaningless - new
processes do not necessarily have larger PIDs than older processes on
any OS I have used, including Linux. You should find a better way to
discover the process you want to kill. You could use the daemontools
package, for instance.
</offtopic>
Ted
------------------------------
Date: Mon, 15 Sep 2003 14:00:06 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Maddening bug: Why do quotes fix it?
Message-Id: <eton0d5x1o9.fsf@wormtongue.emschwar>
James Willmore <jwillmore@cyberia.com> writes:
> On Sun, 14 Sep 2003 13:36:46 -0700
> Arvin Portlock <apollock11@hotmail.com> wrote:
> <snip>
>> I'm using ADO via Win32::OLE. I didn't even know you could use ADO
>> in the DBI module! That would be very useful.
>
> Yes, yes there is a DBD::ADO module for use with DBI.
Even better than using quote() explicitly is using a prepare-execute
pair, which automatically quotes things for you:
my $sth = $dbh->prepare("select * from users where userid=?");
my $rc = $sth->execute($userid);
For more information, see the DBI and DBD docs for your database.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 15 Sep 2003 12:42:23 -0700
From: jamesb7us@yahoo.com (James Bonanno)
Subject: Re: Newbie Help with Hashes
Message-Id: <3869c28a.0309151142.67cdb400@posting.google.com>
mooseshoes <mooseshoes@gmx.net> wrote in message news:<Sg89b.185$vv3.15572138@newssvr14.news.prodigy.com>...
> <snip>
>
> What I really want to do is to be able to have
> > "irregular" numbers of subprojects under each project, and gracefully
> > handle them with my code. For example, if Project1 contained a
> > subdirectory "Excel" in addition to Visio,Word,Schematic, and Verilog,
> > I'd like the program to be able to handle that rather than having a
> > "fixed number" of subprojects. My code is shown below, where the my
> > %row hash is the problem. I want to be able to make proj1, proj2,
> > proj3 a "dynamic size". I'm a newbie at perl, please forgive my
> > approach if another is clearly more obvious.
>
> <<< It appears that you may be in need of data strucure with an extra
> dimension. Consider using an HoAoA so you can have varying numbers of
> items per project. The best way to think of this data structure is a "hash
> whose value references an array which references a second array." That
> should help you add and extract items from it. Be sure to check out
> various helpful perldocs on data structures and references.
>
> Moose
====> Thanks Moose. I will look at the problem using the HoAoA approach. Kind
Regards, James
------------------------------
Date: Mon, 15 Sep 2003 15:41:45 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie Help with Hashes
Message-Id: <slrnbmc909.1td.tadmc@magna.augustmail.com>
James Bonanno <jamesb7us@yahoo.com> wrote:
> use File::Find::Rule;
> use HTML::Template;
You are missing these:
use strict;
use warnings;
> @projects_to_display = &dirscan_root("$root");
Three different mistakes all folded in to a single line of code.
Impressive! :-)
my @projects_to_display = dirscan_root($root);
Declare your variables (use strict will _require_ you to do so).
Don't use ampersand on function calls (see perlsub.pod for what
that form of function call does).
perldoc -q vars
What's wrong with always quoting "$vars"?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 15 Sep 2003 18:27:21 GMT
From: Borniac <Borniac_1@hotmail.com>
Subject: Newbie Question: Could someone show me how to implement options
Message-Id: <150920032028070159%Borniac_1@hotmail.com>
thanks,
Borniac
------------------------------
Date: Mon, 15 Sep 2003 18:57:57 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Newbie Question: Could someone show me how to implement options
Message-Id: <slrnbmc2tk.r0i.ak+usenet@vinland.freeshell.org>
In article <150920032028070159%Borniac_1@hotmail.com>, Borniac wrote:
> thanks,
> Borniac
Please don't put the question in the subject only...
Untested:
#!/usr/bin/perl -w
use strict;
use warnings;
use Getopt::Std;
my %opts;
if (!getopts("hn:", \%opts) || (defined(%opts{h}) && $opts{h})) {
die "Usage: $0 -h | -n name\n";
}
if (defined($opts{n})) {
print "Hi $opts{n}!\n";
}
print "(Done)\n";
Given -h: Will print usage info and die.
Given -n name: Will print "Hi <name>!".
See "perldoc Getopt::Std".
--
Andreas Kähäri
------------------------------
Date: 15 Sep 2003 11:38:04 -0700
From: dan@tobias.name (Daniel R. Tobias)
Subject: Re: Perl DBMS
Message-Id: <aab17256.0309151038.33bedc5@posting.google.com>
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message news:<Pine.LNX.4.53.0309131850380.4388@lxplus078.cern.ch>...
> I don't agree. Most MS software that's meant to get anywhere close to
> the Internet is rubbish for many different reasons, and I've no
> intention of "accommodating to" its misbehaviour, but putting the
> cursor in the right place for starting to snip quotage isn't one of
> them.
Putting the signature block *above* the quoted material, however, and
putting in a lengthy header block at the top of the quote instead of a
concise attribution line, are indications that trimming the quotes and
replying below them were *not* what MS's programmers were expecting
users to do upon beginning a reply with its top-placed cursor.
--
Dan
------------------------------
Date: Mon, 15 Sep 2003 21:57:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Problem with xml parser
Message-Id: <8occmv4iqgfdkkq13jltortmg2e6m7qaql@4ax.com>
debraj wrote:
>Couldn't open encmap windows-1252.enc:
>No such file or directory
> at /lib/perl5/site_perl/5.8.0/sun4-solaris-thread-multi/XML/Parser.pm
>line 185
>
>Can anyone suggest, why I am getting this ?The path to the above
>Parser.pm exists .
Yes, but not the file"windows-1252.enc".
Hmm... I have it here, under the name "cp1252.enc". I'm not sure I
didn't create it myself.
There are at least two ways you can create such a file. The data source,
in any way, is the text files under
<http://unicode.org/Public/MAPPINGS/>, for this particular file (which
describes the standard Windows character set) is
<http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT>.
The official way to create it, as you can see here:
<http://search.cpan.org/src/MSERGEANT/XML-Parser-2.34/Parser/Encodings/README>
is to use a script that comes with the module XML::Encoding on CPAN,
<http://search.cpan.org/author/COOPERCL/XML-Encoding-1.01/>
The second way is slightly more manual, it is by using a script I wrote
years ago and which you can find here:
<http://bumppo.net/lists/macperl-modules/2000/04/msg00017.html>
Wow. History repeats itself. :)
--
Bart.
------------------------------
Date: Mon, 15 Sep 2003 15:37:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: recognising a special character inside [^]
Message-Id: <slrnbmc8ni.1td.tadmc@magna.augustmail.com>
Jason Quek <qjason@cyberway.com.sg> wrote:
> $string = '1|2';
vertical bars are special in a regex, you must backslash them
if you want a literal one:
my $string = '1\|2';
> I believe the problem lies with ([^\|]*).
Nope.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Sep 2003 20:56:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: shutdown or reboot computer
Message-Id: <slrnbmc9rn.cji.abigail@alexandra.abigail.nl>
Jochen Friedmann (jochen.friedmann2@de.bosch.com) wrote on MMMDCLXVII
September MCMXCIII in <URL:news:bk48ef$e0k$1@ns2.fe.internet.bosch.com>:
__ Oh, sorry
__
__ the OS is Win2000 or WinnNT
Oh, fastest way to shutdown Win2000 from Perl that I know is:
print "\t\t\b\b\b\b\b\b\b\b\b\b\b\b" while 1;
Although this might be fixed with some patch.
Abigail
--
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
------------------------------
Date: 15 Sep 2003 20:59:54 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Subroutine as a new Task
Message-Id: <slrnbmca2a.cji.abigail@alexandra.abigail.nl>
Jochen Friedmann (jochen.friedmann2@de.bosch.com) wrote on MMMDCLXVII
September MCMXCIII in <URL:news:bk48o4$ea4$1@ns2.fe.internet.bosch.com>:
"" Hello,
""
"" how can I start a soubroutine as a new task.
"" The main script should run on until the end is reached.
"" But the subroutine should run in another task where I can work with it.
"" OS: Win200,WinNT
The traditional way of doing this is using fork(). Which for quite some
time, has been available for the Windows platform as well.
perldoc -f fork
perldoc perlipc
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: Mon, 15 Sep 2003 18:15:36 GMT
From: bob <eric@dmcontact.com>
Subject: Re: Tring to kill my kids, but they are stuborn little bastards!
Message-Id: <3F6601C9.90207@dmcontact.com>
Hi,
I think I see that happening, and know you are right, but this doesn't
seem to matter.
#while (my $connection = $listen_socket->accept()) {
while (1) {
my $connection = $listen_socket->accept() or do {
next if $!{EINTR};
last;
};
Sorry if I am being clueless, but I have done a lot of reading and
working at this, but I seem to keep getting it wrong.
Here is a sample run, with what I write to my log file:
secure# ./franken_socket.pl &
[1] 7186
secure# PID: 7186
ARGV:
[Server ./franken_socket.pl accepting clients]
secure# telnet localhost 1081
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Command?who
root ttyp0 Sep 11 10:51 (24.68.221.164)
root ttyp1 Sep 11 10:52 (24.68.221.164)
root ttyp2 Sep 11 11:23 (24.68.221.164)
Command?quit
Connection closed by foreign host.
[1] + Done ./franken_socket.pl
Log file cotains:
./franken_socket.pl 7194: got - CHLD
at Mon Sep 15 05:49:55 2003
I got forked
./franken_socket.pl 7186: begat 7194 at Mon Sep 15 05:49:54 2003
begat 7194
./franken_socket.pl 7186: got - CHLD
at Mon Sep 15 05:49:58 2003
./franken_socket.pl 7186: main 7194 -- reaped 1 at Mon Sep 15 05:49:58 2003
reaped 1
This is what I am running above:
#!/usr/bin/perl -w
## new frankenstein!
use strict;
use POSIX ();
use POSIX 'WNOHANG';
use Errno;
use IO::Socket;
use FindBin ();
use File::Basename ();
use File::Spec::Functions;
use Net::hostent;
use Carp;
$|=1;
my $pid;
open (DIED, ">>/var/log/daemon_log") or warn "$!";
sub logmsg { print DIED "$0 $$: @_ at ", scalar localtime, "\n" }
my $listen_socket = IO::Socket::INET->new(LocalPort => 1081,
LocalAddr => '127.0.0.1',
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1 )
or die "can make a tcp server on port 1080 $!";
# make the daemon cross-platform, so exec always calls the script
# itself with the right path, no matter how the script was invoked.
my $script = File::Basename::basename($0);
my $SELF = catfile $FindBin::Bin, $script;
# POSIX unmasks the sigprocmask properly
my $sigset = POSIX::SigSet->new();
my $action = POSIX::SigAction->new('sigHUP_handler',
$sigset,
&POSIX::SA_NODEFER);
my $action_alrm = POSIX::SigAction->new('sigALRM_handler',
$sigset,
&POSIX::SA_NODEFER);
POSIX::sigaction(&POSIX::SIGHUP, $action);
POSIX::sigaction(&POSIX::SIGALRM, $action_alrm);
sub sigHUP_handler {
print "got SIGHUP\n";
exec($SELF, @ARGV) or die "Couldn't restart: $!\n";
}
sub sigALRM_handler {
print "got ALARM timeout\n";
}
$SIG{CHLD} = \&REAPER_NEW;
sub REAPER {
$SIG{CHLD} = \&REAPER; # loathe sysV
my $waitedpid = wait;
logmsg "reaped $waitedpid" . ($? ? " with exit $?" : '');
}
sub REAPER_NEW {
logmsg "got - @_\n";
my $wpid = undef;
while ($wpid = waitpid(-1,WNOHANG)>0) {
logmsg "main $pid -- reaped $wpid" . ($? ? " with exit $?" :
'');
print DIED "reaped $wpid" . ($? ? " with exit $?" : '');
}
}
print "PID: $$\n";
print "ARGV: @ARGV\n";
print "[Server $0 accepting clients]\n";
#while (my $connection = $listen_socket->accept()) {
while (1) {
my $connection = $listen_socket->accept() or do {
next if $!{EINTR};
last;
};
$connection->autoflush(1); ## missing seemed to cause client
problem, but not telnet
if (!defined($pid = fork)) {
logmsg "cannot fork: $!";
}elsif ($pid) {
logmsg "begat $pid";
print DIED "begat $pid\n";
}else{
# else i'm the child -- go spawn
print $connection "Command?";
while ( <$connection> ){
my $return_value = undef;
if (/quit|exit/i) { last; }
elsif (/closeme/i ) {$connection->close(); }
elsif (/date|time/i) { printf $connection "%s\n", scalar
localtime; exit(0); }
elsif (/who/i ) { print $connection `who 2>&1`;}
elsif (/dienow/i ) { alarm 2; exit(0); }
elsif (/dieT/i ) { die; }
print $connection "Command?";
print DIED "I got forked\n"; }
exit(0);
} ## end while <$connection>
} ## end else
close ($listen_socket);
Steve Grazzini wrote:
> bob <eric@dmcontact.com> wrote:
>
>>This one, works, but when I exit the whole thing including the
>>parent die!
>> $SIG{CHLD} = \&REAPER_NEW;
>>
>> while (my $connection = $listen_socket->accept()) {
>
>
> I already told you why this is happening.
>
> When the child exits, SIGCHLD will interrupt the accept() system
> call. Perl 5.8 installs %SIG handlers without SA_RESTART, and so
> accept() fails when interrupted. (And then the parent falls out
> of its loop and exits.)
>
------------------------------
Date: Mon, 15 Sep 2003 19:05:41 GMT
From: bob <eric@dmcontact.com>
Subject: Re: Tring to kill my kids, but they are stuborn little bastards!
Message-Id: <3F660D7A.6050709@dmcontact.com>
Hi,
I just wanted to confirm, this exact code does work prefectly in Perl
5.6. So Steve, you are certainly correct. I just don't know how to fix
it in 5.8.
Thanks,
Eric
bob wrote:
> Hi,
>
> I think I see that happening, and know you are right, but this doesn't
> seem to matter.
>
> #while (my $connection = $listen_socket->accept()) {
> while (1) {
> my $connection = $listen_socket->accept() or do {
> next if $!{EINTR};
> last;
> };
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5507
***************************************