[22850] in Perl-Users-Digest
Perl-Users Digest, Issue: 5071 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 00:05:58 2003
Date: Tue, 3 Jun 2003 21:05:10 -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 Tue, 3 Jun 2003 Volume: 10 Number: 5071
Today's topics:
Re: Accounting File Help <kha@rogers.com>
capturing output of executed system command <bensonl@stanford.edu>
Re: capturing output of executed system command (Sam Holden)
Re: capturing output of executed system command (Sam Holden)
Re: capturing output of executed system command <news2@earthsong.null.free-online.co.uk>
Re: capturing output of executed system command <grazz@pobox.com>
Re: capturing output of executed system command <news2@earthsong.null.free-online.co.uk>
formatting my output (slash)
Re: formatting my output (Sam Holden)
getting the date for "last Wednesday" <usenet@dwall.fastmail.fm>
Re: getting the date for "last Wednesday" <cpryce@pryce.nospam.net>
Re: getting the date for "last Wednesday" <heaney@cablespeed.com>
Re: Help: Sort HOH by value? (entropy123)
LWP and HTTP protocol (Chacrint Charinthorn)
Re: LWP and HTTP protocol (Sam Holden)
Re: LWP and HTTP protocol <mgjv@tradingpost.com.au>
Re: n-gram for words <spam@thecouch.homeip.net>
Re: n-gram for words (slash)
newbie: simple question <dhou@removethisrohan.sdsu.edu>
Re: newbie: simple question (Sam Holden)
Re: newbie: simple question <dhou@rohan.sdsu.edu>
Re: Passing Hash To Subroutine Question (Tad McClellan)
Perl Daemon and inittab <goodcall__1@hotmail.com>
Re: Perl Daemon and inittab <news2@earthsong.null.free-online.co.uk>
perlmagick - can't get opacity to work when compositing <news2@earthsong.null.free-online.co.uk>
Re: Q about assignments for unmatched regex <ben.goldberg@hotpop.com>
Re: Reference types <penny1482@attbi.com>
Re: Remove first character in a string? <jurgenex@hotmail.com>
Replacing users password input with asterisks (Steven Danna)
Re: Replacing users password input with asterisks <kalinabears@hdc.com.au>
Re: simple script error <mgjv@tradingpost.com.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 04 Jun 2003 02:30:47 GMT
From: Kien Ha <kha@rogers.com>
Subject: Re: Accounting File Help
Message-Id: <3EDD59D7.DAAC4071@rogers.com>
Matt wrote:
>
> > > Can someone give me shove in the right direction with this?
> >
> >
> > See above.
>
> Thanks! Thats a good shove.
>
> Matt
Hopefully by now you've already given it a try.
#!/usr/bin/perl -w
use strict;
use constant ENTRIES => 3; # change this accordingly
my %dbase;
while ( <DATA> ) {
chomp;
my( $username, @data ) = split /[ ,]+/ => $_;
for ( @data ) {
push @{ $dbase{$username}{dataset} }, $_;
$dbase{$username}{total} += $_;
if ( @{ $dbase{$username}{dataset} } > ENTRIES ) {
my $old_value = shift @{ $dbase{$username}{dataset} };
$dbase{$username}{total} -= $old_value;
}
}
}
for ( sort keys %dbase ) {
delete $dbase{$_}, next unless $dbase{$_}{total};
print "$_ ", join(", ", @{ $dbase{$_}{dataset} } ),
"\ttotal = $dbase{$_}{total}\n";
}
__DATA__
george 50, 901, 30
tom 47, 250, 1110
tom 1220, 1330
nobody 100, -100, 0
somebody 10, 100, 2000, 500, 30
--
Kien
------------------------------
Date: Tue, 3 Jun 2003 17:33:24 -0700
From: benson limketkai <bensonl@stanford.edu>
Subject: capturing output of executed system command
Message-Id: <Pine.GSO.4.44.0306031732340.14587-100000@elaine6.Stanford.EDU>
suppose i have:
system 'ps'
how can i redirect the output into an array?
thanks,
benson
------------------------------
Date: 4 Jun 2003 00:57:56 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: capturing output of executed system command
Message-Id: <slrnbdqh0k.7d8.sholden@flexal.cs.usyd.edu.au>
On Tue, 3 Jun 2003 17:33:24 -0700,
benson limketkai <bensonl@stanford.edu> wrote:
> suppose i have:
>
> system 'ps'
>
> how can i redirect the output into an array?
You could try reading the documentation for the function you are using.
Possibly the bit that says "This is _not_ want you want to use to capture the
output from a cooment, for that you should use..." will be useful to read.
And of course before asking a question, checking the FAQ is the polite thing
to do:
perlfaq8:
Why can't I get the output of a command with system()?
--
Sam Holden
------------------------------
Date: 4 Jun 2003 00:59:26 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: capturing output of executed system command
Message-Id: <slrnbdqh3e.7d8.sholden@flexal.cs.usyd.edu.au>
On 4 Jun 2003 00:57:56 GMT, Sam Holden <sholden@flexal.cs.usyd.edu.au> wrote:
>
> Possibly the bit that says "This is _not_ want you want to use to capture the
> output from a cooment, for that you should use..." will be useful to read.
^^^^^^^
Now that's quite a typo :)
--
Sam Holden
------------------------------
Date: Wed, 04 Jun 2003 01:07:09 +0000
From: Andy Baxter <news2@earthsong.null.free-online.co.uk>
Subject: Re: capturing output of executed system command
Message-Id: <bbjgnv$2so$1@news5.svr.pol.co.uk>
benson limketkai wrote:
> suppose i have:
>
> system 'ps'
>
> how can i redirect the output into an array?
>
> thanks,
> benson
This code should do it (adapt as needed.)
#!/usr/bin/perl
$ps=`ps`; # capture output of 'ps'
print $ps ."\n"; # print output as a string.
@ps=split /\n/,$ps; # split into an array
$lc=0;
foreach $line (@ps) {
$lc++; # line count just to show that the string _has_ been split.
print "$lc: $line\n"; # print one line from the array.
};
The important bits are the `ps` in backticks - if you put any system
command in backticks, the resulting expression will evaluate as the
_output_ of that command (not exit code as with 'system'). Also the 'split
/\n/,$ps' which means split the string $ps into an array with one element
for each line of the string (splitting on the newline character). You
should be able to figure out how to split the individual lines into fields
using the same command. There might be a module to do this more robustly -
have a look on CPAN.
andy.
--
--------------------------
remove ' n - u - l - l ' to email me.
------------------------------
Date: Wed, 04 Jun 2003 03:16:38 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: capturing output of executed system command
Message-Id: <qwdDa.44624$fT5.18272@nwrdny01.gnilink.net>
Andy Baxter <news2@earthsong.null.free-online.co.uk> wrote:
> benson limketkai wrote:
>
>> system 'ps'
>>
>> how can i redirect the output into an array?
[ snip sig, etc ]
> $ps=`ps`; # capture output of 'ps'
> print $ps ."\n"; # print output as a string.
> @ps=split /\n/,$ps; # split into an array
You're making this harder than it needs to be:
my @ps = `ps`;
--
Steve
------------------------------
Date: Wed, 04 Jun 2003 03:36:24 +0000
From: Andy Baxter <news2@earthsong.null.free-online.co.uk>
Subject: Re: capturing output of executed system command
Message-Id: <bbjpfp$fv7$1@news7.svr.pol.co.uk>
thanks. didn't know you could do this.
andy.
Steve Grazzini wrote:
> Andy Baxter <news2@earthsong.null.free-online.co.uk> wrote:
>> benson limketkai wrote:
>>
>>> system 'ps'
>>>
>>> how can i redirect the output into an array?
>
> [ snip sig, etc ]
>
>> $ps=`ps`; # capture output of 'ps'
>> print $ps ."\n"; # print output as a string.
>> @ps=split /\n/,$ps; # split into an array
>
> You're making this harder than it needs to be:
>
> my @ps = `ps`;
>
--
--------------------------
remove ' n - u - l - l ' to email me.
------------------------------
Date: 3 Jun 2003 18:01:19 -0700
From: satishi@gwu.edu (slash)
Subject: formatting my output
Message-Id: <30fe9f1e.0306031701.ef1ea76@posting.google.com>
hi,
i am new to perl.
following is the output i get:
* * * * united
* * * united states
* * united states patent
* united states patent april
united states patent april 16
states patent april 16 2002
patent april 16 2002 method
april 16 2002 method apparatus
16 2002 method apparatus performing
2002 method apparatus performing variable
for the following code:
undef $/;
@stack=("*\t", "*\t", "*\t", "*\t", "*\t");
@words = split /\W+/, <> ;
foreach $word (@words) {
chomp($word);
shift(@stack);
push @stack, $word;
printf "@stack\n";
};
how can i format it better so the file is a little more readable.
thanks in advance,
satish
------------------------------
Date: 4 Jun 2003 01:16:18 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: formatting my output
Message-Id: <slrnbdqi32.7ki.sholden@flexal.cs.usyd.edu.au>
On 3 Jun 2003 18:01:19 -0700, slash <satishi@gwu.edu> wrote:
> hi,
> i am new to perl.
> following is the output i get:
>
> * * * * united
> * * * united states
> * * united states patent
> * united states patent april
> united states patent april 16
> states patent april 16 2002
> patent april 16 2002 method
> april 16 2002 method apparatus
> 16 2002 method apparatus performing
> 2002 method apparatus performing variable
>
>
> for the following code:
> undef $/;
>
> @stack=("*\t", "*\t", "*\t", "*\t", "*\t");
> @words = split /\W+/, <> ;
>
> foreach $word (@words) {
>
> chomp($word);
That chomp is useless since "\n" is matched by \W and hence won't
be in any of the elements in @words.
> shift(@stack);
> push @stack, $word;
>
> printf "@stack\n";
printf join("\t", @stack), "\n";
Plus taking the tabs out of the * strings would make it easier to see
the individual words.
Alternatively if you find the letter 'e' to be unsightly you could try
$word=~tr/eE/33/;
near the start of the for loop.
> how can i format it better so the file is a little more readable.
Defining what 'readable' means in this context would help.
--
Sam Holden
------------------------------
Date: Wed, 04 Jun 2003 01:37:35 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: getting the date for "last Wednesday"
Message-Id: <Xns938FDBFCA519Edkwwashere@216.168.3.30>
I need a function that will return the calendar date for Wednesday of
last week. If the current day of the week is Wednesday, I want last
week's date. All I need is year, month, and day.
Here's the function I wrote:
sub get_last_wed {
my $usetime = time();
my $weekday = 0; # as long as it's not 3 (Wed)
my @date;
while ($weekday != 3) { # 3=Wed (0=Sun)
$usetime -= 24*60*60;
($weekday, @date) = (localtime $usetime)[6,5,4,3];
}
return $date[0]+1900, $date[1]+1, $date[2]; # Year,Month,Day
}
It returns just what I want, but in my opinion it's a bit ugly. Should
I try to make it "prettier", or just go ahead and use it? It doesn't
really *matter*, but I or whoever has to maintain this years down the
road might appreciate it.
By the way, execution speed is not an issue. I wouldn't want it to take
more than, say, 0.1 sec, but other than that I don't care. It's far
faster than that already.
--
David Wall
------------------------------
Date: Wed, 04 Jun 2003 02:06:12 GMT
From: cp <cpryce@pryce.nospam.net>
Subject: Re: getting the date for "last Wednesday"
Message-Id: <030620032106120934%cpryce@pryce.nospam.net>
In article <Xns938FDBFCA519Edkwwashere@216.168.3.30>, David K. Wall
<usenet@dwall.fastmail.fm> wrote:
> I need a function that will return the calendar date for Wednesday of
> last week. If the current day of the week is Wednesday, I want last
> week's date. All I need is year, month, and day.
>
> Here's the function I wrote:
[snip code]
>
> By the way, execution speed is not an issue. I wouldn't want it to take
> more than, say, 0.1 sec, but other than that I don't care. It's far
> faster than that already.
IFIRC Date::Manip will do some of those calculations for you. If speed
is not an issue, it might be worth investigating.
cp
------------------------------
Date: 03 Jun 2003 23:13:54 -0400
From: "Tim Heaney" <heaney@cablespeed.com>
Subject: Re: getting the date for "last Wednesday"
Message-Id: <87isrmpma5.fsf@mrbun.watterson>
"David K. Wall" <usenet@dwall.fastmail.fm> writes:
> I need a function that will return the calendar date for Wednesday of
> last week. If the current day of the week is Wednesday, I want last
> week's date. All I need is year, month, and day.
I think I might use Date::Calc. In fact, borrowing from recipe 9 on
the Date::Calc man page
http://search.cpan.org/author/STBEY/Date-Calc-5.3/Calc.pod#9_
I think something like this
use Date::Calc qw( Today Day_of_Week Add_Delta_Days );
sub get_last_wed {
my @today = Today;
my $current_dow = Day_of_Week(@today);
my $searching_dow = 3; # Wednesday
my @prev;
if ( $current_dow > $searching_dow) {
@prev = Add_Delta_Days(@today, $searching_dow - $current_dow);
} else {
@prev = Add_Delta_Days(@today, $searching_dow - $current_dow - 7);
}
return @prev;
}
might do it.
Tim
------------------------------
Date: 3 Jun 2003 18:21:15 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Re: Help: Sort HOH by value?
Message-Id: <90cdce37.0306031721.3577f58d@posting.google.com>
>
> I emphasize this not because your usage confuses me, but because I've
> seen your usage confuse you several times.
>
Xho,
This saying should be carved onto a piece of wood and that wood hung on my wall :).
Thanks for the advice, I'll give it a spin.
entropy
------------------------------
Date: 3 Jun 2003 19:40:25 -0700
From: chacrint@hotmail.com (Chacrint Charinthorn)
Subject: LWP and HTTP protocol
Message-Id: <bfe227db.0306031840.dfca197@posting.google.com>
What HTTP protocol does the lastest LWP version support?
HTTP/1.1 or HTTP/1.0
if it supports both, how can I "POST /script.cgi HTTP/1.0"?
thanks for any comment,
chacrint
------------------------------
Date: 4 Jun 2003 02:54:26 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: LWP and HTTP protocol
Message-Id: <slrnbdqnr2.8rv.sholden@flexal.cs.usyd.edu.au>
On 3 Jun 2003 19:40:25 -0700, Chacrint Charinthorn <chacrint@hotmail.com> wrote:
> What HTTP protocol does the lastest LWP version support?
> HTTP/1.1 or HTTP/1.0
> if it supports both, how can I "POST /script.cgi HTTP/1.0"?
>
> thanks for any comment,
By reading the documentation that comes with LWP.
Of particular interest may be the bit that starts:
"Enable the old HTTP/1.0 protocol driver..."
--
Sam Holden
------------------------------
Date: Wed, 04 Jun 2003 02:54:43 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: LWP and HTTP protocol
Message-Id: <slrnbdqnrj.1lr.mgjv@verbruggen.comdyn.com.au>
On 3 Jun 2003 19:40:25 -0700,
Chacrint Charinthorn <chacrint@hotmail.com> wrote:
> What HTTP protocol does the lastest LWP version support?
> HTTP/1.1 or HTTP/1.0
You should read the documentation. The main LWP documentation page
answers this question:
$ perldoc LWP
> if it supports both, how can I "POST /script.cgi HTTP/1.0"?
The same document explains that there is an environment variable that
controls this. Whether there are other ways to force the use of the
1.0 protocol driver I don't know off-hand. I've never cared.
I'd say you should probably study the documentation for LWP::UserAgent
and LWP::Protocol to find out if there's a way there. Maybe all you
need to do is switch off keep_alive.
Why do you care? What seems to be your problem if you don't try
anything specific and just let the module do what it thinks is best? I
believe it'll do whichever the remote server supports.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
Trading Post Australia | the world - Franz Kafka
|
------------------------------
Date: Tue, 03 Jun 2003 18:16:04 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: n-gram for words
Message-Id: <E69Da.49602$Z83.442811@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
slash wrote:
> I have been fiddling with this problem for a while and desperately
> need some help. Linguistic applications frequently call for examining
> linguitic units in a particular context. I am trying to do an n-gram
> for word forms with a fixed context width. For example, by viewing all
> sequences of three word forms in a text, like this --
>
> "by viewing all"
> "viewing all sequences"
> "all sequences of"
> "sequences of three"
> "of three word"
> "three word forms"
> "word forms in"
> "forms in a"
> "in a text"
>
> you might be able to spot some clear patterns once you have a critical
> mass of text at your disposal. I have seen lots of examples of
> character realted n-grams but none for a complete word, where concepts
> can be extracted given a fixed context width.
>
> I am also new to perl so am very overwhelmed by the non-intuitive
> syntax. I have been able to write a small script that generates a text
> file consisting of tokens (- stop words). How can I generate something
> like this?
>
>
> * * * * united
> * * * united states
> * * united states patent
> * united states patent april
> united states patent april 16
> states patent april 16 2002
> patent april 16 2002 method
> april 16 2002 method apparatus
>
> Any suggestions would be greatly appreciated.
>
> Slash
Here's one way to do it:
#
# Define the data and config:
#
$data = "united states patent april 16 2002 method apparatus";
$maxperline = 5;
#
# Split the data into an array, one word per element
#
@words = split(/\s+/, $data);
#
# Loop from 0 to the last element id of the array, name the loop variable $to
#
for $to (0..$#words) {
#
# For each iteration of the loop, we'll print out a line consisting of
# $maxperline elements. The last element printed will be $to's id
# So on the first line, we'll only print element 0, on the second line, 0 and 1
# This is done by printing the elements from $to-$maxperline+1 till $to
# However, in the early values of $to, $to-$maxperline+1 would produce a negative
# number which would loop backwards around the array. To avoid that, we run
# that mini loop through a map that traps negative numbers and replaces them
# with a "*", otherwise replaces the element with the corresponding word from the
# @words array
#
print join("\t", map {$_ < 0 ? "*" : $words[$_] } ($to-$maxperline+1..$to)), "\n";
}
Best of luck.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+3R4neS99pGMif6wRAuWmAKC2GJxWjCrLb2kNYi565KCBhfsTkQCg31y5
aHg/oi7Esy3A7qCpcS5FIyA=
=qwgF
-----END PGP SIGNATURE-----
------------------------------
Date: 3 Jun 2003 18:16:54 -0700
From: satishi@gwu.edu (slash)
Subject: Re: n-gram for words
Message-Id: <30fe9f1e.0306031716.2056e409@posting.google.com>
Dear All,
This is a little silly but I wanted to express myself regardless.
This was my first Usenet experience and I must say your helpful
responses totally made the day. Who says altruism is a virtue of the
past?
Anyway, I did not realize how simple the problem was so I was able to
figure it out myself by a simple stack like implementation. Thanks for
all your help! I truly appreciate it.
Slash
tiltonj@erols.com (Jay Tilton) wrote in message news:<3edd152e.180382865@news.erols.com>...
> satishi@gwu.edu (slash) wrote:
>
> : I am trying to do an n-gram
> : for word forms with a fixed context width. For example, by viewing all
>
> [snip]
>
> : How can I generate something like this?
> :
> : * * * * united
> : * * * united states
> : * * united states patent
> : * united states patent april
> : united states patent april 16
> : states patent april 16 2002
> : patent april 16 2002 method
> : april 16 2002 method apparatus
>
> #!perl
> use warnings;
> use strict;
>
> $_ = 'united states patent april 16 2002 method apparatus';
> my $n = 5;
>
> my @words = ( ('*') x ($n-1), split );
> $" = "\t";
> while( @words >= $n ) {
> print "@words[0..$n-1]\n";
> shift @words;
> }
------------------------------
Date: 4 Jun 2003 01:05:51 GMT
From: hou <dhou@removethisrohan.sdsu.edu>
Subject: newbie: simple question
Message-Id: <bbjglf$f3d$1@gondor.sdsu.edu>
Hello everyone,
I am learning Perl and I am tring some examples in the book I bought.
But I don't understand the following warning message.
Script started on Tue Jun 03 17:58:22 200
rohan:1:ch2[89]% cat number2.plx
#!/usr/bin/perl
use warnings
print 255, "\n";
print 0377, "\n";
print 0b11111111, "\n";
print 0xFF, "\n";
rohan:1:ch2[90]% perl number2.plx
255
unknown warnings category '1' at number2.plx line 3
BEGIN failed--compilation aborted at number2.plx line 3.
rohan:1:ch2[91]% exit
rohan:1:ch2[92]%
script done on Tue Jun 03 17:58:52 200
I don't know what's wrong with the code.
If I comment out the "use warnings"( the author recommend to use it),
it works just fine( printing four "255" ).
Thank you very much
Dean
------------------------------
Date: 4 Jun 2003 01:18:04 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: newbie: simple question
Message-Id: <slrnbdqi6c.7ki.sholden@flexal.cs.usyd.edu.au>
On 4 Jun 2003 01:05:51 GMT, hou <dhou@removethisrohan.sdsu.edu> wrote:
> Hello everyone,
> I am learning Perl and I am tring some examples in the book I bought.
> But I don't understand the following warning message.
>
> Script started on Tue Jun 03 17:58:22 200
> rohan:1:ch2[89]% cat number2.plx
> #!/usr/bin/perl
> use warnings
> print 255, "\n";
> print 0377, "\n";
> print 0b11111111, "\n";
> print 0xFF, "\n";
>
> rohan:1:ch2[90]% perl number2.plx
> 255
> unknown warnings category '1' at number2.plx line 3
> BEGIN failed--compilation aborted at number2.plx line 3.
> rohan:1:ch2[91]% exit
> rohan:1:ch2[92]%
> script done on Tue Jun 03 17:58:52 200
>
> I don't know what's wrong with the code.
You are missing a semicolon after "use warnings".
--
Sam Holden
------------------------------
Date: 4 Jun 2003 01:33:01 GMT
From: hou <dhou@rohan.sdsu.edu>
Subject: Re: newbie: simple question
Message-Id: <bbji8d$fol$1@gondor.sdsu.edu>
Sam Holden <sholden@flexal.cs.usyd.edu.au> wrote:
>> I don't know what's wrong with the code.
> You are missing a semicolon after "use warnings".
> --
> Sam Holden
Thank you very much, Mr. Holden
Dean
------------------------------
Date: Tue, 3 Jun 2003 17:15:56 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Passing Hash To Subroutine Question
Message-Id: <slrnbdq7gs.i65.tadmc@magna.augustmail.com>
mooseshoes <mooseshoes@gmx.net> wrote:
> Some supplemental assistance is requested -
You can request such assistance by putting this at the top of your program:
use strict;
> %sub_master_keyword_list = %$mkwl_ref;
^^^^^^^
> print $sub_master_record_list{$tempvalue};
^^^^^^
One of these things is not like the other, one of these
things just isn't the same...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 04 Jun 2003 01:57:04 GMT
From: "Jack D." <goodcall__1@hotmail.com>
Subject: Perl Daemon and inittab
Message-Id: <QlcDa.6348$QF2.1666995@news2.telusplanet.net>
I want to have a program running as a daemon. (Linux RH7.2) So I daemonize using
the subroutine as shown at:
http://webreference.com/perl/tutorial/9/3.html
I want this running all the time, so I put the perl command as a 'respawn' in
the inittab. The problem is that I get a "respawning too rapidly" error and I
get about 10 of these running. I assume it has something to do with the fork and
exit (which will respawn another program). I even tried wrapping the perlscript
within a shell script to no avail.
So, the questions are:
1. Am I doing this wrong?
2. If yes, what should I be doing instead?
--
Jack D.
Remove '__' from address if replying by e-mail.
------------------------------
Date: Wed, 04 Jun 2003 02:23:49 +0000
From: Andy Baxter <news2@earthsong.null.free-online.co.uk>
Subject: Re: Perl Daemon and inittab
Message-Id: <bbjl9h$slr$1@newsg1.svr.pol.co.uk>
Jack D. wrote:
> I want to have a program running as a daemon. (Linux RH7.2) So I daemonize
> using the subroutine as shown at:
>
> http://webreference.com/perl/tutorial/9/3.html
>
> I want this running all the time, so I put the perl command as a 'respawn'
> in the inittab. The problem is that I get a "respawning too rapidly" error
> and I get about 10 of these running. I assume it has something to do with
> the fork and exit (which will respawn another program). I even tried
> wrapping the perlscript within a shell script to no avail.
>
> So, the questions are:
>
> 1. Am I doing this wrong?
> 2. If yes, what should I be doing instead?
>
> --
> Jack D.
> Remove '__' from address if replying by e-mail.
Don't know much about perl forks, but I'd have thought you'd be better
starting it from a script in /etc/init.d rather than inittab. On debian
there's a script called '/etc/init.d/skeleton' which you can copy and
modify to start and stop your daemon with. Then make links to the (renamed)
init.d script in the /etc/rcX.d directories to start or stop your daemon at
different runlevels. On the other hand, Red Hat may use a different init
system to debian.
--
--------------------------
remove ' n - u - l - l ' to email me.
------------------------------
Date: Wed, 04 Jun 2003 00:10:53 +0000
From: Andy Baxter <news2@earthsong.null.free-online.co.uk>
Subject: perlmagick - can't get opacity to work when compositing
Message-Id: <bbjdee$h2j$1@newsg2.svr.pol.co.uk>
I've been writing a program using imagemagick which makes animated tiled
background gifs of lots of objects falling (originally to make a snow
effect but it could be anything). I'd like to have them all rendered in
different random opacities over the background to get a layered effect, but
I can't get the opacity function to work in Image->composite.
I've reproduced the error/bug in the following code.
#!/usr/bin/perl -w
use strict;
use Image::Magick;
# Simulate background picture... :)
my $image1 = Image::Magick->new;
$image1->Set(size=>'100x100');
$image1->ReadImage('xc:orange');
# overlaid image
my $image2 = Image::Magick->new;
$image2->ReadImage('testopaq.png');
# Make composite image of background and a 50 % transparent image.
$image1->Composite(compose=>'over', image=>$image2, x=>0, y=>0,
opacity=>50);
$image1->Display;
exit 0;
testopaq.png is a black stripe and a white stripe on a transparent
background.
with opacity=0 or not stated, it does the normal 'over' overlay, with
transparent areas untouched, but with opacity >0, testopaq.png is overlaid
with a black background and no effect on opacity. The transparent areas of
testopaq.png end up black.
when i use the 'dissolve' option instead of 'over', nothing happens at all,
for any value of opacity. (just a plain orange background).
using ImageMagick 5.5.5 and perl 5.6.1
--
--------------------------
remove ' n - u - l - l ' to email me.
------------------------------
Date: Tue, 03 Jun 2003 21:13:56 -0400
From: Benjamin Goldberg <ben.goldberg@hotpop.com>
Subject: Re: Q about assignments for unmatched regex
Message-Id: <3EDD47D4.719A0130@hotpop.com>
Michael Powe wrote:
>
> hello,
>
> i am looping through a file matching lines to a regex. however, some
> lines don't return a match. so, i have something like this:
>
> while (<FH>) {
>
> my ($one,$two,$three,$four,$five,$six);
>
> ($one,$two,$three,$four,$five,$six) = ($_ =~ /$re/);
You do realize that these lines can be combined, into:
my ($one,$two,$three,$four,$five,$six) = /$re/;
>
> ...
>
> }
>
> the question is, what goes into $one ... $six when the $re does not
> match anything in the line?
When a regular expression match is performed in list context, and it
fails, then it will return an empty list. Thus, $one..$six will all
contain undef.
> i would like to catch this condition when it occurs.
A list assignment, in scalar context, is the number of items assigned.
So if $re succeeds, the expression (my(...) = /$re/) will have a true
value in scalar context, and if $re fails, it will have a false value in
scalar context.
Thus, you can write:
if( my ($one,$two,$three,$four,$five,$six) = /$re/ ) {
# match succeeded.
} else {
# match failed. Note that $one..$six will now contain
# undef.
}
Note if there are *no* capturing parens in $re, and the match succeeds,
then a "1" will get assigned to $one, and undefs to $two...$six. You'll
still end up in the "match succeeded" branch, but $one won't contain
what you might expect.
> i thought it might be undef or an empty string, but if so, i don't
> seem to have the right handle on how to detect that. how can i check
> for the condition, so as to use the results only when the vars contain
> matched values?
>
> i tried if(defined($one)){ ... } and if ($one ne ""){ ... }. duds
> both.
Hmm... what's in $re and in $_? If your capturing parens are in
different "|" branches from each other, then the match can succeed but
result in $1 being undef. E.g., consider:
my ($x, $y) = "12345" =~ /(0)|(1)/;
This sets $x to undef, and $y to "1".
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Tue, 03 Jun 2003 22:15:09 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: Reference types
Message-Id: <N59Da.822447$OV.778055@rwcrnsc54>
> I'm doing my nut trying to distinguish between references to anonymous
> and named data elements i.e. given a sub which takes a reference,
> can/should the sub be able to determine whether the reference is to
> named or anonymous data.
>
I'm not guru, even sort of a newbie, but I have not found (or maybe too dumb
to notice) any distinction (at least that mattered to me).
My suggestion, is have a one line sub, that passes the arg to Data::Dumper
and print, and call it twice passing both to it to see what happens, eg,
use Data::Dumper;
blah ...blah...blah
print Dumper(arg1);
print Dumper(arg2);
Dick Penny
------------------------------
Date: Wed, 04 Jun 2003 03:35:11 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Remove first character in a string?
Message-Id: <PNdDa.13740$JW6.3938@nwrddc02.gnilink.net>
Koos Pol wrote:
>> Jon Rogers wrote:
>>> Is there an easy way of removing the first character of a string?
>
> chip() should make a fine opposite to chop()
> I find myself removing a first char regularly.
Well, you could always do
#pseudo-code! you need to get the return values and default operands
right
reverse; chop; reverse;
But I doubt that this will be faster than substr.
jue
------------------------------
Date: 3 Jun 2003 16:08:53 -0700
From: MissingWords@hotmail.com (Steven Danna)
Subject: Replacing users password input with asterisks
Message-Id: <e78d8c5a.0306031508.5100988f@posting.google.com>
I am currently creating a program which keeps track of a runners
millage. The program is meant to be used by multiple people, so I
have created simple password protection of user names.
However, I do not want the users input to be shown while they are
typing in their passwords. I did a 'perldoc -q password' and am
currently using the Term::ReadKey module like it sugests. (Actually, I
first used the system() routine, but decided I wanted something more
portable.) However, I would still like the user to be able to see how
many characters he or she has entered(or backspaced). Preferably the
users input would echo onto the screen as asterisks, or any other
symbolic character(# or ~ perhaps).
I have already done some searching on this and everything I find
seems to point to the two methods I already discussed or the use of
the POSIX module. I read the documentation for POSIX and do not
understand how it can be used to accomplish this.
Here is part of my script if you would like to see what I am already
doing:
#!perl
use strict;
use Term::ReadKey;
my ($menu_choice,$runner,$password,$password2,$goal, $deadline, $desc,
$date, $miles, %RUNNER);
print "====================\n";
print "| Run Logger 0.1\n";
print "| Created by Steven Danna\n";
&login;
&show_menu;
sub login{
print "\n Enter User Name(new users type 'new'):";
chomp($runner = <STDIN>);
if($runner ne "new" && $runner ne "\'new\'"){
print " Enter User Pass:";
ReadMode('noecho');
chomp($password=ReadLine(0));
ReadMode('restore');
}
&login_check;
}
sub login_check{
if($runner eq "new" || $runner eq "\'new\'"){
$menu_choice="new";
&menu_parser;
}
elsif(! dbmopen(%RUNNER, "${runner}_profile", undef)){
print " User does not exsist!";
&login;
}
elsif(crypt($password, $RUNNER{'Password'}) ne
$RUNNER{'Password'}){
print " INVALID PASSWORD";
&login;
}
}
------------------------------
Date: Wed, 4 Jun 2003 12:20:51 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Replacing users password input with asterisks
Message-Id: <3edd58a6$0$21274@echo-01.iinet.net.au>
"Steven Danna" <MissingWords@hotmail.com> wrote in message
<snip>
> However, I would still like the user to be able to see how
> many characters he or she has entered(or backspaced). Preferably the
> users input would echo onto the screen as asterisks, or any other
> symbolic character(# or ~ perhaps).
>
<snip>
Just some ideas on how you can approach this:
#!perl -w
use strict;
use Term::ReadKey;
my $pwd = mask_pwd();
print "\n", length($pwd), "\n", $pwd, "\n";
##############################
sub mask_pwd {
my $password = '';
my $key;
print "Enter password\n";
while(1) {
while(not defined($key = ReadKey(-1))) {};
if(ord($key) != 13) { # ie not "Enter"
if(ord($key) == 8) { # ie "Backspace"
print "\r", "\0" x length($password);
chop($password);
print "\r", "*" x length($password);
}
else {
$password .= $key;
print "*";
}
}
else {last}
}
return $password;
}
__END__
Cheers,
Rob
------------------------------
Date: Wed, 04 Jun 2003 01:24:35 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: simple script error
Message-Id: <slrnbdqiij.1lr.mgjv@verbruggen.comdyn.com.au>
On 3 Jun 2003 05:40:01 -0700,
Jerry Maguire <jamesbond_422@hotmail.com> wrote:
> Hi,
> Can anyone look at the following script and let me know the resolution
> to the error:
There are many things wrong. Some related to Perl problems, some
related to understanding of tools and protocols. There is simply too
much wrong to come up with a fix for what you submit.
> #!/usr/bin/perl
no warnings, and no strictures. Two big problems that you should
rectify before posting code again to this group. People do not like
doing the work of machines.
Also see
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.text
> ##
> $| = 1;
> $HOST1 = "foo.net";
> $HOST2 = "foo.com";
> $HOST_RESULT1 ="https://foo.net/$_";
> $HOST_RESULT2 = "https://foo.com/$_";
> $PORT = "443";
> $URLPAGE = "GET /";
> $TELNET = "/usr/bin/telnet $HOST1 443";
Why all the capitals for variable names? Is this a translation of a
shell script or so?
> #exec echo "$URLPAGE" |"$TELNET $HOST1 $PORT" |grep Connected;
> exec (echo $URLPAGE|$TELNET|grep "Connected to $HOST1") 1<&2 ;
exec executes the program and _never returns_.
Also, this is not how exec works, and you should be quoting strings.
That redirection also doesn't work (even for shells it would be in the
wrong spot). Read the docuemntation on exec in the perlfunc
documentation. You should probably also learn some Perl.
Also, this is not how telnet works. If you want to use external
programs, you will have to use soemthing that is aware of how the HTTP
protocol works (lynx, wget, curl), ro you will have to implement the
protocol exchange yourself over telnet. Simply piping stuff in is not
going to work through.
If you write shell scripts, why are you getting Perl involved? As far
as I can tell, there is nothing at all in this thing (up to now) that
requires Perl, and a shell script is a much more natural way to do
what you're trying to do (at least, what I think you're trying to do).
Even in the case of a shell script, however, exec is not what you
want.
> if ( $? ne 0 ) {
> while ( <STDIN> ) {
> print "$HOST_RESULT2/$_";
Are you expecting that STDIN is now magically connected to that exec
above? Are you looking for fork and exec? Or are you maybe looking for
qx// (described in the perlop documention)?
> I am looking for a simple per script whihc cheks the url and if it is
> up then print a correct URL.
In that case, assuming you still want to use Perl, you should be using
the LWP modules (libwww), available from CPAN.
it could then be as simple as (extract from the LWP lwpcook
documentation):
perl -MLWP::Simple -e 'getprint "http://www.linpro.no/lwp/"'
Martien
--
|
Martien Verbruggen | Little girls, like butterflies, need no
Trading Post Australia | excuse - Lazarus Long
|
------------------------------
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 5071
***************************************