[22864] in Perl-Users-Digest
Perl-Users Digest, Issue: 5085 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 6 21:05:52 2003
Date: Fri, 6 Jun 2003 18:05:12 -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 Fri, 6 Jun 2003 Volume: 10 Number: 5085
Today's topics:
Re: and if I killed this programmer *I'd* go to jail.. (Daniel Berger)
Re: ANSI NT W2K <kalinabears@hdc.com.au>
bareword complaints in if statement <abc@nowhere.com>
Re: bareword complaints in if statement <goedicke@goedsole.com>
Re: bareword complaints in if statement <abuse@sgrail.org>
Re: bareword complaints in if statement <abc@nowhere.com>
Re: bareword complaints in if statement <michael.p.broida@boeing.com>
Calling dll's from perl <shtil@attbi.com>
Re: Calling dll's from perl <kalinabears@hdc.com.au>
Re: Changing form output (Steve)
Re: Changing form output <emschwar@pobox.com>
Converting numerical character references to Unicode <apollock11@hotmail.com>
Re: Converting numerical character references to Unicod <noreply@gunnar.cc>
Critique my code - need a bit of help (Perl for Win32) (Jason B)
Re: Critique my code - need a bit of help (Perl for Win <noreply@gunnar.cc>
Re: Critique my code - need a bit of help (Perl for Win <noreply@sympatico.ca>
Re: Critique my code - need a bit of help (Perl for Win <noreply@gunnar.cc>
Re: Daemon Script n' system() function - for gurus: Ran (Carlton Brown)
Generate second child after a while (Jessie)
Re: getting the date for "last Wednesday" <usenet@dwall.fastmail.fm>
Help with XML::Simple <jgbdif@yahoo.com>
Re: Help with XML::Simple <cpryce@pryce.nospam.net>
Re: Help with XML::Simple <goedicke@goedsole.com>
Re: Help with XML::Simple <brian@bluecoat93.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Jun 2003 15:04:46 -0700
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: and if I killed this programmer *I'd* go to jail..
Message-Id: <6e613a32.0306061404.3c20ce84@posting.google.com>
genericax@hotmail.com (Sara) wrote in message news:<776e0325.0306050958.319bfc19@posting.google.com>...
> This is one of the less ugly examples what I've inherited from my
> "ancestral" programmers here. I think he must have had a C-to-Perl
> script he ran to produce his Perl Code..
>
> 805: for($i=0;$i<=$#g_INFO;$i++){
> 806: if($g_INFO[$i][$x_ID] ne $id){ next; }
> 807: @tmp1 = split(/;/,$g_INFO[$i][$_TEXT]);
> 808: for($j=0;$j<=$#tmp1;$j++){
> 809: $tmp1[$j] =~ s/^(\s)*//g;
> 810: @tmp2 = split(/,/,$tmp1[$j]);
> 811: if($tmp2[0] == $level){ return "$tmp2[1]"; }
>
> I'll be in rehab before this project is though.. ACK....
>
> Gx
I dunno how much it'll help with your project as a whole, but there's
always perltidy. Might cut down your time in rehab, if not keep you
out of it. :)
http://perltidy.sourceforge.net
Regards,
Dan
------------------------------
Date: Sat, 7 Jun 2003 10:38:04 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: ANSI NT W2K
Message-Id: <3ee13516$0$30685@echo-01.iinet.net.au>
"Carsten L." <clandos@gmx.de> wrote in message
news:3ee05f76$0$10140$4d4ebb8e@read.news.de.uu.net...
> I try to make my output more colourful. But with Windows NT / 2000 I cant
> use the ansi function described in the perl (5.6.1) documentation. I
always
> get the control sequence "?[1;34mThis text is bold blue."
>
> Thanks for your help
> carsten
>
Afaik this won't work in a cmd.exe shell.
It will work if you load ansi.sys and run in a command.com shell - but you
may not want to run in that shell. It's the *last* shell I would want to use
:-)
It might also run in a bash shell if you wanted to install one and try
........ dunno .......
Cheers,
Rob
------------------------------
Date: Fri, 06 Jun 2003 23:16:25 GMT
From: ktom <abc@nowhere.com>
Subject: bareword complaints in if statement
Message-Id: <3EE120C9.5030402@nowhere.com>
i have the simple if statement that barfs with the 'bareword' error
message.. "Bareword "l200" not allowed while "strict subs" in use at.."
this doesn't work as it is expected("1200" is not 1200)
if( ( $testNum >= 100 ) && ( $testNum <= "l200" ) ) {
this generates the bareword error
if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
this works just fine
if( $testNum >= 100 ) {
how do i get this to suck up the number 1200??
thanks.. kevint
------------------------------
Date: Fri, 06 Jun 2003 23:20:47 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: bareword complaints in if statement
Message-Id: <m3adcux06q.fsf@mail.goedsole.com>
Daer Kevint -
ktom <abc@nowhere.com> writes:
> this generates the bareword error
> if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
Something else must be going on; can you paste a bigger snippet of
your code (all is often good) for our perusal.
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
Good management involves five activities:
o Facilitate your staff's efforts by removing organizational
impediments.
o Identify each staff member's strengths and goals
and veer their responsibilities towards them.
o Assign responsibility with commensurate authority.
o Set realistic expectations in your customers.
o Evangelize your services.
- William Goedicke
------------------------------
Date: Fri, 06 Jun 2003 23:25:37 GMT
From: derek / nul <abuse@sgrail.org>
Subject: Re: bareword complaints in if statement
Message-Id: <om82evsobef95pd66gdhmqffvam5m60m6f@4ax.com>
On Fri, 06 Jun 2003 23:16:25 GMT, ktom <abc@nowhere.com> wrote:
>i have the simple if statement that barfs with the 'bareword' error
>message.. "Bareword "l200" not allowed while "strict subs" in use at.."
>
>this doesn't work as it is expected("1200" is not 1200)
> if( ( $testNum >= 100 ) && ( $testNum <= "l200" ) ) {
^^^^^^^^ that's not 1200
>
>this generates the bareword error
> if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
>
>this works just fine
> if( $testNum >= 100 ) {
>
>how do i get this to suck up the number 1200??
>
>thanks.. kevint
------------------------------
Date: Fri, 06 Jun 2003 23:27:53 GMT
From: ktom <abc@nowhere.com>
Subject: Re: bareword complaints in if statement
Message-Id: <3EE1233C.8020206@nowhere.com>
ktom wrote:
> i have the simple if statement that barfs with the 'bareword' error
> message.. "Bareword "l200" not allowed while "strict subs" in use at.."
>
> this doesn't work as it is expected("1200" is not 1200)
> if( ( $testNum >= 100 ) && ( $testNum <= "l200" ) ) {
>
> this generates the bareword error
> if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
>
> this works just fine
> if( $testNum >= 100 ) {
>
> how do i get this to suck up the number 1200??
>
> thanks.. kevint
>
UGH!! typo the 1200 is really l(like letter l)200 it is fixed...
sorry
------------------------------
Date: Fri, 6 Jun 2003 23:50:55 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: bareword complaints in if statement
Message-Id: <3EE128DF.D88A35B9@boeing.com>
ktom wrote:
>
> i have the simple if statement that barfs with the 'bareword' error
> message.. "Bareword "l200" not allowed while "strict subs" in use at.."
>
> this doesn't work as it is expected("1200" is not 1200)
> if( ( $testNum >= 100 ) && ( $testNum <= "l200" ) ) {
>
> this generates the bareword error
> if( ( $testNum >= 100 ) && ( $testNum <= l200 ) ) {
>
> this works just fine
> if( $testNum >= 100 ) {
>
> how do i get this to suck up the number 1200??
Make sure that's not a lowercase letter L followed by 200.
<grin> That would make it a bareword. Depending on your
display font, the difference between "1" and "l" is not
always obvious. In fact, those two look identical to me
in this newsreader's default compose font.
Also make sure there's no other (unprintable) character in
there. I suggest deleting the entire line and retyping it
from scratch. You might already have tried that, but ...
One other possibility:
my $temp = 1200; #Again watch out for lowercase "L"
if (....... $testnum <= $temp )...
Mike
------------------------------
Date: Fri, 06 Jun 2003 20:13:43 GMT
From: "Yuri Shtil" <shtil@attbi.com>
Subject: Calling dll's from perl
Message-Id: <XB6Ea.43588$d51.98376@sccrnsc01>
Hi folks
The Win32::Api module provides a capability to load and call exported
functions from a DLL file.
I want to call a DLL that was produced with C#.
My questions are:
- is it possible to do and how
- in general how one knows what functions a DLL has available and what
their prototypes are ?
Thank you
Yuri.
------------------------------
Date: Sat, 7 Jun 2003 10:30:27 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Calling dll's from perl
Message-Id: <3ee1334d$0$30682@echo-01.iinet.net.au>
"Yuri Shtil" <shtil@attbi.com> wrote in message
news:XB6Ea.43588$d51.98376@sccrnsc01...
> Hi folks
>
> The Win32::Api module provides a capability to load and call exported
> functions from a DLL file.
> I want to call a DLL that was produced with C#.
>
> My questions are:
>
> - is it possible to do and how
Yes, there's no special requirement - except that the dll functions have to
use the _stdcall calling convention. If the dll wasn't built using this
convention then you won't be able to access the exported functions with
Win32::API.
> - in general how one knows what functions a DLL has available and what
> their prototypes are ?
>
The exported functions would be listed in the '.exp' file. To determine
their prototypes you would need to look at the source (or the
documentation).
If all you have is the actual dll (and no other files/documentation) then it
would be difficult to get the access you desire.
If you have any necessary header ('.h') files and the static lib ('.lib')
file other options would be to use Inline::C or to write an XS module. (You
would also need a C compiler.)
Cheers,
Rob
------------------------------
Date: 6 Jun 2003 16:13:38 -0700
From: techadmin@shaw.ca (Steve)
Subject: Re: Changing form output
Message-Id: <2e27f51a.0306061513.205acd58@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<bbphsj$c86ip$1@ID-184292.news.dfncis.de>...
> Steve wrote:
> > Gunnar, bored are you?
>
> This is how I read your question:
>
> "I downloaded this free script. It doesn't quite satisfy my needs, and
> I'm not interested in learning Perl, so could somebody modify the
> script for free?"
>
> Such questions do make me bored, and I don't want to see them in this
> group. To prevent such reactions, you'd better show that you have
> really tried yourself before posting.
>
> / Gunnar
Who gave you the right to decide what gets asked in this forum? Self
proclaimed are you?
Read the question like I wrote it, a simple question to a simple
problem.
And for your information, through help from this forum, I have made a
couple of changes to the code already so that it meets my needs. Sorry
that my knowledge of perl, or code in general, is not to your
liking.....
After reading through some of your other replies I see that this is
nothing personel as you seem to apply your higher than mighty attitude
to others as well.
------------------------------
Date: 06 Jun 2003 17:27:43 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Changing form output
Message-Id: <etobrxass5s.fsf@wormtongue.emschwar>
techadmin@shaw.ca (Steve) writes:
> Who gave you the right to decide what gets asked in this forum? Self
> proclaimed are you?
No, in fact he's being rather polite. You come across as demanding
someone else solve your problem, without showing any evidence you've
tried yourself. That may or may not be true, but it's how you appear,
and that's not the sort of attitude this newsgroup likes very much.
> Read the question like I wrote it, a simple question to a simple
> problem.
Perhaps you should read the Posting Guidelines to this newsgroup,
which are posted here regularly. If you don't see them on your
newsgroup, please read them online at
<URL:http://mail.augustmail.com/~tadmc/clpmisc.shtml>. Specifically,
see the "Provide enough information" section.
> And for your information, through help from this forum, I have made a
> couple of changes to the code already so that it meets my needs. Sorry
> that my knowledge of perl, or code in general, is not to your
> liking.....
It's not a matter of "liking". It's a matter of your posting,
demanding others do your work for you, without showing that you've
made any effort yourself. Some few people will go ahead and help
anyway, but they quickly get burnt out on helping others who show no
signs of trying to do the work themselves first.
> After reading through some of your other replies I see that this is
> nothing personel as you seem to apply your higher than mighty attitude
> to others as well.
*sigh* Tell ya what, why don't you hang out on clpm for a few months
and see how many people post messages like yours, and see how many of
them just want someone else to write them some code without their
having to invest anything in it. It's not certain that your situation
is like that, but it shows all the signs of being that way. Perhaps
if you were a tad less defensive, and took a clear look at how others
see you, you might see how to present yourself in a more favourable
light.
-=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: Fri, 06 Jun 2003 15:31:10 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Converting numerical character references to Unicode
Message-Id: <bbr4nh$9us$1@agate.berkeley.edu>
Say I'm given a hexadecimal numerical character reference:
"©". How can I turn this into the equivalent unicode
character: "©"? It's not in XML or HTML data so I can't
use a parser. Something like print "\x{00A9}"; only works
at compile time, it doesn't take a variable as an argument.
I couldn't figure out how to do it using chr() as the
documentation suggests. Any help would be appreciated.
------------------------------
Date: Sat, 07 Jun 2003 01:43:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Converting numerical character references to Unicode
Message-Id: <bbr903$cfr86$1@ID-184292.news.dfncis.de>
Arvin Portlock wrote:
> Say I'm given a hexadecimal numerical character reference:
> "©". How can I turn this into the equivalent unicode
> character: "©"? It's not in XML or HTML data so I can't
> use a parser. Something like print "\x{00A9}"; only works
> at compile time, it doesn't take a variable as an argument.
> I couldn't figure out how to do it using chr() as the
> documentation suggests. Any help would be appreciated.
One idea:
my $string = '©';
print chr oct $1 if $string =~ /&#(\w+);/;
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 6 Jun 2003 15:20:43 -0700
From: jbunsto@toronto.ca (Jason B)
Subject: Critique my code - need a bit of help (Perl for Win32)
Message-Id: <1ec8e5e.0306061420.59619936@posting.google.com>
I have to rollout a shortcut update to several dozen WinNT/Win2k
workstations. We are going through a server migration and are looking
to replace all desktop shortcuts (*.lnk) that have targets that are in
the INC convention:
IE:
Desktop Path \Administrator\Desktop
LinkName \file.lnk
Arguments <none>
Target \\server\directoryA\directoryB\File.doc
Working Directory \\server\directoryA\directoryB\
Icon File C:\somefile.exe
Icon Index 12
We are using the WinNT resource kit tool Shortcut.exe to perform this
maneuovre.
What I want help with is the setup of our script...I want to be able
to swap out the various link names and targets for other link names
and targets as we need to so that we can push many different NT
shortcuts as needed.
The following script takes a text file, named "computers.txt" and
parses every line for the workstation name (hostname) and from there
we get an output if needed (shortcut attribute dumped to a local file
for instance). It has been modified to UPDATE a given shorcut
("file.lnk") file by name only, but it's not working. this is where my
lack of knowledge is getting me stuck. Does anyone have any general
suggestions as to where I go from here, or some help with fixing this?
Thanks in advance everyone - I'm getting my feet wet here so I hope I
haven't asked too much of the roving help here.
Jason B
=========start================
#!C:\Perl\bin\perl.exe
################################################################################
#
#
# makeshortcut.pl
#
#
#
################################################################################
# UDS.pl - ver1.03.2002
# ----------------------
# This script extracts computer configurations from either machines
by a given computer list text file
#
# Syntax:
# perl makeshortcut.pl [ Computer List File ]
#
# Examples:
# perl makeshortcut.pl computers.txt
#
#
#======================================#
# Module to be imported #
#======================================#
use Win32;
use win32::Registry;
use Win32::TieRegistry( Delimiter=>"/" );
use Win32::NetAdmin;
use POSIX;
#==============================================================================#
# Programs - Only works for Class C subnet or individual destop
#
#==============================================================================#
unless (@ARGV)
{
print<<"eof";
##############################################################################
#
#
# Perl Script for scanning workstations over network.
#
#
#
# Syntax: perl makeshortcut.pl [ Computer List File ]
#
#
#
# Examples:
#
# perl uds.pl computers Retrieve all workstations in
computers.txt #
#
#
##############################################################################
eof
die 'Syntax Incorrect. Goodbye';
}
foreach (@ARGV)
{
my $HostName=$ARGV[0];
open FH_NAME, "$_.txt";
@HostID=<FH_NAME>;
close FH_NAME;
$Delimiter = "\t";
open FH_REPORT, ">C:\\Temp\\$_-Shortcut.txt";
print FH_REPORT "Workstation\tLinkName\tArguments\tTarget\tWorking
Directory\tIcon File\tIcon Index\tUser Profile Desktop Path\n";
# Go through Each workstation by first testing existence of the
workstation,
# and connect to its registry if found
$Total = @HostID;
$Current = 0;
foreach $Machine (@HostID)
{
my ($LM, $hkey);
my @SIDs=();
$Current ++;
chomp($Machine);
$Machine =~ tr/a-z/A-Z/;
print "\n$Current\/$Total\tWorking on '$Machine' ... ";
my @Ping = `PING -n 1 $Machine`;
#if (grep { /Request timed out./ } @Ping)
if (!grep { /Reply/ } @Ping)
{
print STDERR "\t! Failed to PING it.\n";
print FH_REPORT "\? $Machine\t! Failed to PING it.\n";
next; # Skip this Machine since failed to ping it
}
my ($hkey, $DataType, $Ver, $ProfileDir);
if (!$HKEY_LOCAL_MACHINE->Connect($Machine, $LM))
{
print STDERR "\t! Failed to connect to the registry.\n";
print FH_REPORT "\? $Machine\t! Failed to connect to the
registry.\n";
next; # Skip this IP Address since the workstation's registry can't
be accessed
}
# -- Check out the Windows NT version to determine the profile
directory --
$RegistryKey = "SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\ProfileList";
$LM->Open($RegistryKey, $hkey) || die "Error: ProfileList";
$hkey->GetKeys(\@SIDs);
foreach $SID (@SIDs)
{
next if (!grep {/S-1-5-21/} $SID);
$RegistryKey .= "\\";
$RegistryKey .= $SID;
#print "$RegistryKey\n";
$LM->Open($RegistryKey, $hkey) || die;
$hkey->QueryValueEx('ProfileImagePath', $DataType, $ProfilePath) ||
die;
$ProfileDir = "\\\\$Machine\\C\$\\Winnt\\Profiles" if (grep
{/Profiles/} $ProfilePath);
$ProfileDir = "\\\\$Machine\\C\$\\Docume~1" if (grep
{/Documents/} $ProfilePath);
last;
}
#$LM->close();
#$hkey->close();
$Path_Desktop = $ProfileDir."\\ALLUSE~1\\Desktop\\";
#print "$Path_Desktop\n";
my $LinkName = $Path_Desktop."IBMS.lnk";
`shortcut.exe -f -t "c:\\ibms\\csdc\\amanda4.1\\iprod.bat" -n
"$LinkName" -i "c:\\ibms\\csdc\\amanda4.1\\ibmsprod.ico" -d
"c:\\ibms\\csdc\\amanda4.1"`;
$Path_Link =$Path_Desktop."*.LNK";
@Dir = `DIR $Path_Link /A /B`;
foreach $LinkName (@Dir)
{
chomp($LinkName);
#print "$LinkName\n";
$LinkName_Path = $Path_Desktop.$LinkName;
#print "$LinkName_Path\n";
@Shortcut = `SHORTCUT -n "$LinkName_Path" -u all`;
print FH_REPORT $Machine.$Delimiter;
foreach $ShortcutLine (@Shortcut)
{
chomp($ShortcutLine);
print FH_REPORT $ShortcutLine;
print FH_REPORT $Delimiter;
}
print FH_REPORT $Path_Desktop;
print FH_REPORT "\n";
}
print STDERR "OK";
}
close FH_REPORT;
}
------------------------------
Date: Sat, 07 Jun 2003 00:32:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Critique my code - need a bit of help (Perl for Win32)
Message-Id: <bbr4qo$co2is$1@ID-184292.news.dfncis.de>
Jason B wrote:
> The following script takes ... but it's not working. this is where
> my lack of knowledge is getting me stuck. Does anyone have any
> general suggestions as to where I go from here, or some help with
> fixing this?
The obvious general suggestion would be to ask Perl to tell you why
"it's not working" by using
use strict;
use warnings;
and study the resulting messages in the error log.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 06 Jun 2003 19:51:07 -0400
From: Jason Bunston <noreply@sympatico.ca>
Subject: Re: Critique my code - need a bit of help (Perl for Win32)
Message-Id: <BB06A12B.1123A%noreply@sympatico.ca>
Thanks kindly Gunnar,
I'm certain the best advice will be the most obvious to the veteran coders
here.
I appreciate every bit of advice,
Jason Bunston
On 6/6/03 6:32 PM, in article bbr4qo$co2is$1@ID-184292.news.dfncis.de,
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote:
> Jason B wrote:
>> The following script takes ... but it's not working. this is where
>> my lack of knowledge is getting me stuck. Does anyone have any
>> general suggestions as to where I go from here, or some help with
>> fixing this?
>
> The obvious general suggestion would be to ask Perl to tell you why
> "it's not working" by using
>
> use strict;
> use warnings;
>
> and study the resulting messages in the error log.
>
> / Gunnar
------------------------------
Date: Sat, 07 Jun 2003 02:18:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Critique my code - need a bit of help (Perl for Win32)
Message-Id: <bbrb0l$cgbai$1@ID-184292.news.dfncis.de>
Jason Bunston wrote:
> Gunnar Hjalmarsson wrote:
>> The obvious general suggestion would be to ask Perl to tell you
>> why "it's not working" by using
>>
>> use strict;
>> use warnings;
>>
>> and study the resulting messages in the error log.
>
> I'm certain the best advice will be the most obvious to the veteran
> coders here.
>
> I appreciate every bit of advice,
Uhm.. Maybe I'm misunderstanding you now, Jason, but are you saying
that using strictures and warnings is just for veteran coders? It's
not. It's even more important for beginners like you and me.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 6 Jun 2003 13:32:50 -0700
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Daemon Script n' system() function - for gurus: Randal L. Schwartz, Larry Wall, Joseph N. Hall, and others
Message-Id: <aa611a32.0306061232.31570f7d@posting.google.com>
eulerpereira@hotmail.com (Euler) wrote in message news:<f94db63e.0306042100.2fc2f75e@posting.google.com>...
> hey folks,
>
> Please helpe-me, i wrote the following script - daemon perl script,
> but when i try execute system( 'system_command' ) function from
> daemon, the return code ( $? ) from system() is -1. The same happens
> when i try use quotation `system_command` or exec( 'system_command' ).
Long story short - Don't mix system() and SIGCHLD handlers containing
waitpid() unless you really know what you're doing. If you really
feel like you need to handle SIGCHLD with waitpid(), consider using
open() instead of system(). Or, you could override your SIGCHLD
handler to DEFAULT immediately before you call system().
The code you posted is runnable if you eliminate any of the following:
the system() call (consider using open() instead)
the waitpid() call
the SIGCHLD handler (without waitpid() it does nothing anyway)
Short story long - system() doesn't need our help in reaping child
processes, it handles them in its own special way (specifically, it
defers the SIGCHLD from the shell command and therefore discards the
exit code from "ls"). By the time your signal handler catches the
SIGCHLD the exit code is gone, so waitpid must exit with -1. It is not
system() that sets $? to -1 like you thought, this is actually being
done by waitpid().
You don't have to be a guru to know this, you just need little
experience with PERL's occasionally unexpected signal-handling
behavior.
-Carlton
PS A little more free advice - for reasons similar to those described
above, don't expect consistent results if you mix sleep() and alarm().
------------------------------
Date: 6 Jun 2003 16:18:03 -0700
From: gj_chen12@yahoo.com (Jessie)
Subject: Generate second child after a while
Message-Id: <ba2e921e.0306061518.48887f4@posting.google.com>
I am developing a multiple process application. There are totally two
children generated. The requirement is the child#1 start immediately
after program run. But the child#2 starts after a period of time like
1 minute after the first child starts. Which command I should use to
ask Child#2 wait for 1 minute? I have tried ask it to sleep, but seems
it doesn't work.
Thanks.
Jessie
------------------------------
Date: Sat, 07 Jun 2003 00:03:34 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: getting the date for "last Wednesday"
Message-Id: <Xns9392CC0D224FEdkwwashere@216.168.3.30>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
[using Date::Manip to find the date of "last Wednesday";
>
> It [Date::Manip] may also be more correct.
>
> In the presence of DST, there are days that are shorter than 24 hours
> (in local time). In your original solution you are stepping back by 24
> hour intervals, so you may skip the day you are looking for if you
> are unlucky. You would then get the Wednesday a week earlier.
I belatedly realized that there is an FAQ entry directly relevant that I
had forgotten about:
perldoc -q yesterday
------------------------------
Date: Fri, 06 Jun 2003 21:19:51 GMT
From: "Jonah Bishop" <jgbdif@yahoo.com>
Subject: Help with XML::Simple
Message-Id: <Xz7Ea.83369$jp.1482541@twister.southeast.rr.com>
I'm trying to parse an XML file that has the following format:
<phonebook>
<developers>
<person id="asmith">
<fullname>Angela Smith</fullname>
<phone>1-2345</phone>
<email>asmith@somewhere.com</email>
</person>
<person id="bbrown">
<fullname>Billy Brown</fullname>
<phone>4-5678</phone>
<email>bbrown@somewhere.else.com</email>
</person>
</developers>
</phonebook>
In trying parse this XML file, I am using the XML::Simple parser and the
following perl code:
my $parser = XML::Simple->new();
my $doc = $parser->XMLin($BluePagesFilename);
foreach my $id (keys (%{$doc->{developers}->{person}}))
{
print "ID: $id,Phone: $id->{$phone}\n";
}
As you can see, I'd simply like to print each person's ID value and then
their phone. But the phone number portion is not appearing correctly. I may
be assuming too much when I think that $id can "point" to the fields
underneath it. How can I go about accessing the three fields ("fullname",
"phone" and "email") that are beneath each person's "id" value? What I'm
doing just doesn't work...
Thanks,
Jonah
------------------------------
Date: Fri, 06 Jun 2003 21:55:40 GMT
From: cp <cpryce@pryce.nospam.net>
Subject: Re: Help with XML::Simple
Message-Id: <060620031655392968%cpryce@pryce.nospam.net>
In article <Xz7Ea.83369$jp.1482541@twister.southeast.rr.com>, Jonah
Bishop <jgbdif@yahoo.com> wrote:
> I'm trying to parse an XML file that has the following format:
>
> <phonebook>
> <developers>
> <person id="asmith">
> <fullname>Angela Smith</fullname>
> <phone>1-2345</phone>
> <email>asmith@somewhere.com</email>
> </person>
> <person id="bbrown">
> <fullname>Billy Brown</fullname>
> <phone>4-5678</phone>
> <email>bbrown@somewhere.else.com</email>
> </person>
> </developers>
> </phonebook>
>
> In trying parse this XML file, I am using the XML::Simple parser and the
> following perl code:
>
> my $parser = XML::Simple->new();
> my $doc = $parser->XMLin($BluePagesFilename);
> foreach my $id (keys (%{$doc->{developers}->{person}}))
> {
> print "ID: $id,Phone: $id->{$phone}\n";
> }
>
> As you can see, I'd simply like to print each person's ID value and then
> their phone. But the phone number portion is not appearing correctly. I may
> be assuming too much when I think that $id can "point" to the fields
> underneath it. How can I go about accessing the three fields ("fullname",
> "phone" and "email") that are beneath each person's "id" value? What I'm
> doing just doesn't work..
Use Data::Dumper and examine the structure of $doc.
Use Data::Dupmer;
print Dumper( $doc );
developers is the second level of the HOH structure. And $id is a
scalar value set to the each key, not a hash. Your loop should be:
foreach my $id (keys (%{ $doc->{phonebook}{developers}{person} } ))
{
print "ID: $id,
Phone: $doc->{phonebook}{developers}{person}{ $id }{phone}\n
E-mail: $doc->{phonebook}{developers}{person}{ $id }{email}\n";
}
Although if that is your real
You can review Perl's references structures in perldoc perldsc.
--
cp
------------------------------
Date: Fri, 06 Jun 2003 22:04:34 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Help with XML::Simple
Message-Id: <m3llwex3pq.fsf@mail.goedsole.com>
Dear Jonah -
Finally, a coding question I can competently answer.
"Jonah Bishop" <jgbdif@yahoo.com> writes:
> foreach my $id (keys (%{$doc->{developers}->{person}}))
> {
> print "ID: $id,Phone: $id->{$phone}\n";
> }
while ( my ( $id, $pers_href ) = each( %{$doc->{developers}{person}} ) )
{
print "ID: $id,Phone: $pers_href->{phone}\n";
}
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
It's noon somewhere.
- Moko
------------------------------
Date: Fri, 06 Jun 2003 18:52:06 -0400
From: Brian Landers <brian@bluecoat93.org>
Subject: Re: Help with XML::Simple
Message-Id: <BB069356.375E%brian@bluecoat93.org>
> my $parser = XML::Simple->new();
> my $doc = $parser->XMLin($BluePagesFilename);
> foreach my $id (keys (%{$doc->{developers}->{person}}))
> {
> print "ID: $id,Phone: $id->{$phone}\n";
> }
>
> As you can see, I'd simply like to print each person's ID value and then
> their phone. But the phone number portion is not appearing correctly. I may
> be assuming too much when I think that $id can "point" to the fields
> underneath it. How can I go about accessing the three fields ("fullname",
> "phone" and "email") that are beneath each person's "id" value? What I'm
> doing just doesn't work...
Data::Dumper is often your best friend when dealing with XML::Simple. Stick
a 'use Data::Dumper; print Dumper( $doc ); exit' in there after you parse
the document and look at the data structure that results. That should give
you some clues as to how to access the data.
*B
------------------------------
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 5085
***************************************