[18522] in Perl-Users-Digest
Perl-Users Digest, Issue: 690 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 13 06:05:31 2001
Date: Fri, 13 Apr 2001 03:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <987156307-v10-i690@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 13 Apr 2001 Volume: 10 Number: 690
Today's topics:
Re: CGI.pm V. Here Docs . . . <webmaster@webdragon.unmunge.net>
Re: complaint about moderation of this group <gellyfish@gellyfish.com>
Re: how can I get a variable from Eval? (Tassilo v. Parseval)
Re: inheritance within one file? (Mark Jason Dominus)
It is still recursing <chris62vw@hotmail.com>
Re: Large File Help <krahnj@acm.org>
Re: Large File Help <gellyfish@gellyfish.com>
Re: perl hacker wanted <iltzu@sci.invalid>
Re: perl hacker wanted <iltzu@sci.invalid>
Re: Prefix-based IP address check <gellyfish@gellyfish.com>
RegEx novice <projectobjects@earthlink.net>
Re: Request <gellyfish@gellyfish.com>
Sorry, fixed <chris62vw@hotmail.com>
Re: Testing open ports <gellyfish@gellyfish.com>
Re: Warning Message (Gwyn Judd)
Re: Warning Message <chris62vw@hotmail.com>
Re: Warning Message (Tassilo v. Parseval)
Re: Warning Message <gellyfish@gellyfish.com>
Re: Warning Message <gellyfish@gellyfish.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Apr 2001 09:22:09 GMT
From: "Scott R. Godin" <webmaster@webdragon.unmunge.net>
Subject: Re: CGI.pm V. Here Docs . . .
Message-Id: <9b6gg1$qki$0@216.155.32.47>
In article <x7u23vnxrx.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
| AS> Oh? You have detected a new trend in clpm. Who, in particular,
| AS> would that be?
|
| yeah, we are all a bunch of shy wallflowers who never say a cross word
| at anyone. the whole perl community is so warm and loving. all posts
| here are welcomed equally and are all deserving of being read by all who
| wander in. newbie can learn perl from anyone they choose to learn from.
|
| :)
|
Gee I just feel SO warm and fuzzy and cuddly now. :-)
--
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw";
# ( damn spammers. *shakes fist* take a hint. =:P )
------------------------------
Date: 13 Apr 2001 07:24:58 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: complaint about moderation of this group
Message-Id: <9b69ka$8ip$1@plutonium.btinternet.com>
---Pete--- <bogus@erol.com> wrote:
>
> The Perl docs also left me with a similar impression
> because 133 of Perl files were related to CGI.
>
You mentioned this before and I really dont know what you are talking about.
Running :
find perl -type f -print | xargs grep -li cgi
on the latest source tree suggests that there are 81 files that contain the
string 'cgi' - doing it in case sensitive fashion indicates that there are
67 files that mention 'CGI' :
perl/Changes
perl/Changes5.004
perl/Changes5.005
perl/Changes5.6
perl/MANIFEST
perl/Porting/pumpkin.pod
perl/README.mpeix
perl/h2pl/eg/sys/ioctl.pl
perl/hints/machten.sh
perl/lib/CGI.pm
perl/lib/CGI/Apache.pm
perl/lib/CGI/Carp.pm
perl/lib/CGI/Cookie.pm
perl/lib/CGI/Fast.pm
perl/lib/CGI/Pretty.pm
perl/lib/CGI/Push.pm
perl/lib/CGI/Switch.pm
perl/lib/CGI/Util.pm
perl/lib/CGI/eg/clickable_image.cgi
perl/lib/CGI/eg/cookie.cgi
perl/lib/CGI/eg/crash.cgi
perl/lib/CGI/eg/customize.cgi
perl/lib/CGI/eg/diff_upload.cgi
perl/lib/CGI/eg/file_upload.cgi
perl/lib/CGI/eg/frameset.cgi
perl/lib/CGI/eg/index.html
perl/lib/CGI/eg/internal_links.cgi
perl/lib/CGI/eg/javascript.cgi
perl/lib/CGI/eg/monty.cgi
perl/lib/CGI/eg/multiple_forms.cgi
perl/lib/CGI/eg/nph-clock.cgi
perl/lib/CGI/eg/nph-multipart.cgi
perl/lib/CGI/eg/popup.cgi
perl/lib/CGI/eg/save_state.cgi
perl/lib/CGI/eg/tryit.cgi
perl/lib/CPAN.pm
perl/lib/File/Temp.pm
perl/lib/Pod/Html.pm
perl/pod/perl5004delta.pod
perl/pod/perl5005delta.pod
perl/pod/perldebtut.pod
perl/pod/perldiag.pod
perl/pod/perlebcdic.pod
perl/pod/perlfaq.pod
perl/pod/perlfaq1.pod
perl/pod/perlfaq2.pod
perl/pod/perlfaq3.pod
perl/pod/perlfaq9.pod
perl/pod/perlfunc.pod
perl/pod/perlipc.pod
perl/pod/perlmodlib.PL
perl/pod/perlmodlib.pod
perl/pod/perlrun.pod
perl/pod/perlsec.pod
perl/pod/perltoc.pod
perl/pod/roffitall
perl/pod/perl570delta.pod
perl/pod/perl571delta.pod
perl/t/lib/cgi-form.t
perl/t/lib/cgi-function.t
perl/t/lib/cgi-html.t
perl/t/lib/cgi-pretty.t
perl/t/lib/cgi-request.t
perl/t/lib/1_compile.t
perl/t/lib/cgi-esc.t
perl/vms/perlvms.pod
perl/utils/perlbug.PL
Now well more than half of those are the Module CGI itself, its examples
and its tests and only 17 are documentation, some are false positives
like the '$SIOCGIFADDR = 0xC020690D;' in ioctl.pl and so on. So where
*does* this figure of 133 come from ?
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: 13 Apr 2001 06:36:37 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: how can I get a variable from Eval?
Message-Id: <9b66pl$o74$1@nets3.rz.RWTH-Aachen.DE>
On Thu, 12 Apr 2001 17:15:34 -0400, Will S <waelhass@nortelnetworks.com> wrote:
>I have a structure like this
>
>@data = [
> ["name", "address", " age"
> ["dan", "190D ", " 26"
>
>];
>
>I used Dumper to put this in a file
>I used Dumper like this
>Dumper(\@data);
>
>then I did eval on the string I read from the file
>the file had the follwing
>$VAR1 = [
> [
> 'alpha',
> 'waelhass',
> 'assa'
> ],
> [
> 'gamma',
> 'wafa',
> 'M,T,W,TH,F,SAT,SUN'
> ],
> [
> 'delta',
> 'rana',
> ' T, W, TH'
> ],
> [
> 'delta1',
> 'rana',
> ' T, W, TH, S'
> ]
> ];
>how can I copy this evaluated variable into
>some thing like @mynewvariable
>
Try the following approach:
$d = Data::Dumper->new(\@data);
$string = $d->Dump;
@array = $d->Values;
The Values()-method should return you the original array. Dump() is actually
doing the same as evaluating the string.
Regards,
Tassilo
--
Operator, please trace this call and tell me where I am.
------------------------------
Date: Fri, 13 Apr 2001 04:23:47 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: inheritance within one file?
Message-Id: <3ad67f5b.2d9b$2f1@news.op.net>
In article <x7d7ahohx3.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
>i believe they manage both spaces.
Nope. They don't manage anything.
>if you put up a cpan module with internal class names that aren't
>below the file's name, i would hope they would disallow it.
Nope. They don't disallow anything. You can put porno pictures in
your CPAN directory if you want to.
>at least the author should be ashamed of that.
I disagree.
Fortunately, so does most of the rest of the world.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 12 Apr 2001 23:51:37 -0700
From: "Chris A." <chris62vw@hotmail.com>
Subject: It is still recursing
Message-Id: <tdd8g95rcl9e45@corp.supernews.com>
Walt;
I tried using the example that you showed me below and it still is
recursing. Any suggestions?
Thanks,
Chris A.
"Chris A." <chris62vw@hotmail.com> wrote in message
news:tdd63sa9joqn17@corp.supernews.com...
> Thanks Walt! You have provided MANY helpful hints and a great answer to
the
> question at hand. I have now learned how to use the perldoc more
> effectively.
>
> I just ran top and perl was taking up 12 megs of RAM!! The script has
only
> been running for two hours.
>
> A few questions...with while (1)
>
> is while testing the @_ variable? If not, what is 'while' checking to see
> if '1' exists in that variable? Also, I just don't get how that breaks
the
> recursion. It never exits stayalive!! Either alternatives, either 'if'
or
> 'else' both have the script go back to stayalive. I have tried the code
and
> it works great; I just don't fully understand why or how.:-)
>
> What is the difference between 'print' and 'print scalar'? A scalar is
just
> a variable and isn't a hash or array correct? Does it merely print a
> variables contents without the need of using double quotes around the
> variable? What if you want to print a \n or \t but still want to 'print
> scalar'?
>
> Thanks for your help! It is greatly appreciated.
>
> Chris A.
>
> p.s. - here's what I have now
>
> #!/usr/bin/perl -w
>
> use strict;
>
> stayalive();
>
> sub stayalive {
>
> while (1) {
>
> my $processes = `ps -aux`;
> if ($processes =~ /named/) {
> sleep 10;
> stayalive();
> }
>
> else {
> print "NAMED HAS SHUT DOWN !!! Restarting...\t";
> print scalar localtime;
> system ("named -q") || print "\nnamed has
restarted
> successfully.\n";
> my $processes = `ps -aux`;
> stayalive();
> }
>
> }
>
> }
>
>
> "Walt Mankowski" <waltman@netaxs.com> wrote in message
> news:874rvtjvsv.fsf@netaxs.com...
> > "Chris A." <chris62vw@hotmail.com> writes:
> >
> > > I run perl with the -w flag. I am getting a warning. Is there a
place
> > > where I can find the meaning to various warnings and errors in my
> script?
> >
> > Perl's error messages are all in the perldiag manpage, accessible by
> > typing:
> >
> > perldoc perldiag
> >
> > > I am getting this error in particular:
> > >
> > > Deep recursion on subroutine "main::stayalive" at keepalive line 11.
> >
> > Here's what perldiag has to say about your error:
> >
> > Deep recursion on subroutine ""%s""
> > (W recursion) This subroutine has called itself
> > (directly or indirectly) 100 times more than it has
> > returned. This probably indicates an infinite
> > recursion, unless you're writing strange benchmark
> > programs, in which case it indicates something else.
> >
> > And in fact, that's exactly what you're doing. You've written an
> > infinitely recursive subroutine. When you write recursive
> > subroutines, you've got to have some way for the routine to break out
> > of the recursion and return. Otherwise you eat up a little more RAM
> > each time you recurse until eventually you run out of memory.
> >
> > There's not really any need for you to use recursion at all.
> > stayalive() can be easily rewritten to use an infinite loop:
> >
> > sub stayalive {
> >
> > while (1) {
> > $processes = `ps -aux`;
> > if ($processes =~ /named/) {
> > sleep 5;
> > }
> >
> > else {
> > print "NAMED HAS SHUT DOWN !!! Restarting...";
> > print "\t";
> > print `date`;
> > system ("named -q") || print "named has restarted successfully.\n";
> > }
> > }
> > }
> >
> > While I'm mucking around in there, I should point out that calling
> > `date` is hardly ever necessary, since localtime returns a formatted
> > date when called in scalar context. So you should replace
> >
> > print `date`;
> >
> > with
> >
> > print scalar localtime;
> >
> > Walt
>
>
------------------------------
Date: Fri, 13 Apr 2001 06:27:52 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Large File Help
Message-Id: <3AD69C5C.CA32D88A@acm.org>
Jody Fedor wrote:
>
> I have a large file, about 540Mbs. The first 3018 bytes are garbage
> but the records I would like to extract are now every 1087 bytes
> after the first 3018 bytes. Any help or idea how to do this in Perl?
>
> After I get rid of the first 3018 bytes, I'll need to parse the 1087
> byte records and gleen the appropriate information. Most are
> variable data in a fixed field, ie LastName, FirstName in one
> fixed field of 50 characters. This is the reason I wanted to use
> Perl instead of VB or other language.
[untested]
open IN, "< $file" or die "Cannot open $file: $!";
binmode IN;
seek IN, 3018, 0;
while ( $size = read IN, $data, 1087 ) {
die "Record length error\n" unless $size == 1087;
@fields = unpack 'A10 A15 ...', $data;
# process fields
}
close IN;
John
--
use Perl;
program
fulfillment
------------------------------
Date: 13 Apr 2001 09:24:36 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Large File Help
Message-Id: <9b6gkk$g86$2@plutonium.btinternet.com>
Jody Fedor <Jodyman@usa.net> wrote:
> I have a large file, about 540Mbs. The first 3018 bytes are garbage
> but the records I would like to extract are now every 1087 bytes
> after the first 3018 bytes. Any help or idea how to do this in Perl?
>
> After I get rid of the first 3018 bytes, I'll need to parse the 1087
> byte records and gleen the appropriate information. Most are
> variable data in a fixed field, ie LastName, FirstName in one
> fixed field of 50 characters. This is the reason I wanted to use
> Perl instead of VB or other language.
>
Something like this (typed straight in as I dont have your data) :
open(FILE,'thefile') || die "Cant open - $!\n";
my $record;
binmode FILE;
read(FILE,$record,3018); # read and throw away the first 3018 bytes
while(read(FILE,$record,1087) == 1087)
{
# process the record probably using unpack or substr
}
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: 12 Apr 2001 12:04:12 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: perl hacker wanted
Message-Id: <987072864.8010@itz.pp.sci.fi>
In article <3AD50593.CC55098D@qwest.net>, A_Geekette wrote:
>Ilmari Karonen wrote:
>
>> It seems you just managed to break another one of those subtle rules.
>
>Where are these rules? I will overcome my impatience (:-) to read and study them
>thoroughly, as I have insulted way too many people in this group.
Well, they can't really be called unwritten rules, given that Usenet is
a written medium, but they're not collected anywhere, and everyone plays
by their own slightly different ones. Maybe someone someday could make
a list of them, but I feel that's rather unlikely.
The only way to figure out exactly what is tolerated and what isn't is
to sit back and watch. In the meantime, you just have to be careful.
Stay strictly on topic, don't ask FAQs, and never ever give incorrect
answers. And stay out of threads like this one.
The point is that the threads people here like are those that reveal
something new about Perl. That could be an answer to a question, a
debate about an obscure syntax feature, or a game of Perl golf. But
anything else, in comp.lang.perl.misc, is at best tolerated.
That goes for this discussion too. It doesn't really belong here, and
would be better carried out through private e-mail. I'm posting this in
the newsgroup in the hope that other newcomers might see it, but this is
probably going to be the last post from me in this thread.
>Maybe, I should have introduced myself before asking and answering questions. It's
>that impatience thing. I tend to jump right in. It does help me learn better, but I
Naw.. introductions don't tell anyone anything about Perl, at least not
unless you have some impressive Perl tricks to share. Jumping in is the
right approach, but watch where you jump.
>don't like hurting people or causing a raucous. Do you think it's too late to
>introduce myself? Maybe change my name which would preclude a change in attitude.
Maybe. A lot of the regulars seem to get along just fine under an
alias, but using your real name does give a slightly better first
impression.
On the other hand, if someone has killfiled you because they really
don't want to see your posts (can happen to anyone), and they still find
you annoying after your name change, they might accuse you of killfile
dodging -- a common tactic of trolls.
If you do change your name, or even if you don't, please keep your posts
as on topic as possible. Don't answer unless you're sure you know the
answer, and stay out of long off-topic threads like this one, even if it
means not saying something you want to say. That way people will see
that you're contributing signal instead of noise, and will hopefully
decide that you're worth listening to after all.
>"follow rules and behave like an adult"
>this, however, I have a little disagreement with....but that's OT.
Well, I agree that wasn't the best possible phrasing. But the point was
that if one behaves on Usenet like a child among adults, demanding to be
indulged because of one's inability or unwillingness to accommodate the
others, then one will soon get killfiled.
In this newsgroup, with too much volume for anyone to read it all, even
the slightest hint in that direction will suffice. Your sentence about
unwillingness to follow rules could be interpreted as such a hint.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: 12 Apr 2001 12:51:13 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: perl hacker wanted
Message-Id: <987079806.16142@itz.pp.sci.fi>
In article <3AD50593.CC55098D@qwest.net>, A_Geekette wrote:
>Ilmari Karonen wrote:
>
>> It seems you just managed to break another one of those subtle rules.
>
>Where are these rules? I will overcome my impatience (:-) to read and study them
>thoroughly, as I have insulted way too many people in this group.
Well, they can't really be called unwritten rules, given that Usenet is
a written medium, but they're not collected anywhere, and everyone plays
by their own slightly different ones. Maybe someone someday could make
a list of them, but I feel that's rather unlikely.
The only way to figure out exactly what is tolerated and what isn't is
to sit back and watch. In the meantime, you just have to be careful.
Stay strictly on topic, don't ask FAQs, and never ever give incorrect
answers. And stay out of threads like this one.
The point is that the threads people here like are those that reveal
something new about Perl. That could be an answer to a question, a
debate about an obscure syntax feature, or a game of Perl golf. But
anything else, in comp.lang.perl.misc, is at best tolerated.
That goes for this discussion too. It doesn't really belong here, and
would be better carried out through private e-mail. I'm posting this in
the newsgroup in the hope that other newcomers might see it, but this is
probably going to be the last post from me in this thread.
>Maybe, I should have introduced myself before asking and answering questions. It's
>that impatience thing. I tend to jump right in. It does help me learn better, but I
Naw.. introductions don't tell anyone anything about Perl, at least not
unless you have some impressive Perl tricks to share. Jumping in is the
right approach, but watch where you jump.
>don't like hurting people or causing a raucous. Do you think it's too late to
>introduce myself? Maybe change my name which would preclude a change in attitude.
Maybe. A lot of the regulars seem to get along just fine under an
alias, but using your real name does give a slightly better first
impression.
On the other hand, if someone has killfiled you because they really
don't want to see your posts (can happen to anyone), and they still find
you annoying after your name change, they might accuse you of killfile
dodging -- a common tactic of trolls.
If you do change your name, or even if you don't, please keep your posts
as on topic as possible. Don't answer unless you're sure you know the
answer, and stay out of long off-topic threads like this one, even if it
means not saying something you want to say. That way people will see
that you're contributing signal instead of noise, and will hopefully
decide that you're worth listening to after all.
>"follow rules and behave like an adult"
>this, however, I have a little disagreement with....but that's OT.
Well, I agree that wasn't the best possible phrasing. But the point was
that if one behaves on Usenet like a child among adults, demanding to be
indulged because of one's inability or unwillingness to accommodate the
others, then one will soon get killfiled.
In this newsgroup, with too much volume for anyone to read it all, even
the slightest hint in that direction will suffice. Your sentence about
unwillingness to follow rules could be interpreted as such a hint.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: 13 Apr 2001 08:16:18 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Prefix-based IP address check
Message-Id: <9b6cki$8ip$3@plutonium.btinternet.com>
Vlaho Kaminski <vlaho@email.hinet.hr> wrote:
> Hello !
>
> I have to make restriction on usage of some stuff based on IP address.
> So, I have prefix-based defined IP address range, e.g. 123.123.123.123/29
> and I have incoming IP address.
> Question: how can I check if incoming IP address matches given range?
> Is there any built in function? Or, does someone have a code snipet which
> could help me solve the problem.
>
I think you might find the module Net::IPv4Addr useful.
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Fri, 13 Apr 2001 07:10:07 GMT
From: "dkh" <projectobjects@earthlink.net>
Subject: RegEx novice
Message-Id: <jDxB6.3401$yh.337333@newsread2.prod.itd.earthlink.net>
How would I go about building a regular expression that would exclude one
phrase from the other, like so:
1. <word>[_- ]<word>
2. <word>[_- ]<word>[_- ]<word>
so that 1 would be excluded even though it is part of 2.
thanks for any replies,
dale
------------------------------
Date: 13 Apr 2001 08:08:27 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Request
Message-Id: <9b6c5r$8ip$2@plutonium.btinternet.com>
Chris A. <chris62vw@hotmail.com> wrote:
> I am posting this here as this is the .*.perl.misc group. If you would
> rather not read this message that doesn't mostly pertain to a help question,
> please ceast reading now, or forever hold your peace (or rage).
>
> There is a script that I have been working on at
> http://chrisangell.com/unix/gallery/avirt . I would like people to make
> suggestions pertaining to the usage of this script and to the viability of
> this script. I know I could work on the part where the $username and $dest
> is checked for errors,
>
As Martien mentioned you probably should be using 'strict' and the check
on the assignment is franky bizarre - if you want to check for the existence
of a file you should use the appropriate '-X' operator as described in the
perlfunc manpage.
You almost certainly want to be using Getopts::Std to be getting the
command line switches.
You should be be setting $runvirt to be either 1 or 0 rather than
'y' or 'n' so you can do the clearer:
if ( $runvirt )
{
...
}
You are not locking the file to protect against simulataneous access by
the program.
Are you sure that :
/!|#|\$|%|\^|&|\*|\(|\)|\+|=|\{|\}|\[|\]|\;|\:|\"|\'|\?|\/|\,|\>|\<|\~|\`|\||\\|@.*@/
Catches all of the special characters that you might be concerned with ?
It is usually safer to invert the logic and select for characters that are
not in the set of allowable characters.
Also your subroutines getname and getdest duplicate the checks - this is
a builtin in maintanence problem - you should probably put any repeated
checks in a separate subroutine.
The comment ' # Show entry in the /etc/aliases file ' is untrue, a wrong
comment is worse than no comment.
I think thats enough for you to be getting on with.
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Thu, 12 Apr 2001 23:55:53 -0700
From: "Chris A." <chris62vw@hotmail.com>
Subject: Sorry, fixed
Message-Id: <tdd8o56i1kn5ee@corp.supernews.com>
I removed the sub part of the script and now it doesn't recurse.
Thanks, everyone, for all the help given!!
Chris A.
"Chris A." <chris62vw@hotmail.com> wrote in message
news:tdd63sa9joqn17@corp.supernews.com...
> Thanks Walt! You have provided MANY helpful hints and a great answer to
the
> question at hand. I have now learned how to use the perldoc more
> effectively.
>
> I just ran top and perl was taking up 12 megs of RAM!! The script has
only
> been running for two hours.
>
> A few questions...with while (1)
>
> is while testing the @_ variable? If not, what is 'while' checking to see
> if '1' exists in that variable? Also, I just don't get how that breaks
the
> recursion. It never exits stayalive!! Either alternatives, either 'if'
or
> 'else' both have the script go back to stayalive. I have tried the code
and
> it works great; I just don't fully understand why or how.:-)
>
> What is the difference between 'print' and 'print scalar'? A scalar is
just
> a variable and isn't a hash or array correct? Does it merely print a
> variables contents without the need of using double quotes around the
> variable? What if you want to print a \n or \t but still want to 'print
> scalar'?
>
> Thanks for your help! It is greatly appreciated.
>
> Chris A.
>
> p.s. - here's what I have now
>
> #!/usr/bin/perl -w
>
> use strict;
>
> stayalive();
>
> sub stayalive {
>
> while (1) {
>
> my $processes = `ps -aux`;
> if ($processes =~ /named/) {
> sleep 10;
> stayalive();
> }
>
> else {
> print "NAMED HAS SHUT DOWN !!! Restarting...\t";
> print scalar localtime;
> system ("named -q") || print "\nnamed has
restarted
> successfully.\n";
> my $processes = `ps -aux`;
> stayalive();
> }
>
> }
>
> }
>
>
> "Walt Mankowski" <waltman@netaxs.com> wrote in message
> news:874rvtjvsv.fsf@netaxs.com...
> > "Chris A." <chris62vw@hotmail.com> writes:
> >
> > > I run perl with the -w flag. I am getting a warning. Is there a
place
> > > where I can find the meaning to various warnings and errors in my
> script?
> >
> > Perl's error messages are all in the perldiag manpage, accessible by
> > typing:
> >
> > perldoc perldiag
> >
> > > I am getting this error in particular:
> > >
> > > Deep recursion on subroutine "main::stayalive" at keepalive line 11.
> >
> > Here's what perldiag has to say about your error:
> >
> > Deep recursion on subroutine ""%s""
> > (W recursion) This subroutine has called itself
> > (directly or indirectly) 100 times more than it has
> > returned. This probably indicates an infinite
> > recursion, unless you're writing strange benchmark
> > programs, in which case it indicates something else.
> >
> > And in fact, that's exactly what you're doing. You've written an
> > infinitely recursive subroutine. When you write recursive
> > subroutines, you've got to have some way for the routine to break out
> > of the recursion and return. Otherwise you eat up a little more RAM
> > each time you recurse until eventually you run out of memory.
> >
> > There's not really any need for you to use recursion at all.
> > stayalive() can be easily rewritten to use an infinite loop:
> >
> > sub stayalive {
> >
> > while (1) {
> > $processes = `ps -aux`;
> > if ($processes =~ /named/) {
> > sleep 5;
> > }
> >
> > else {
> > print "NAMED HAS SHUT DOWN !!! Restarting...";
> > print "\t";
> > print `date`;
> > system ("named -q") || print "named has restarted successfully.\n";
> > }
> > }
> > }
> >
> > While I'm mucking around in there, I should point out that calling
> > `date` is hardly ever necessary, since localtime returns a formatted
> > date when called in scalar context. So you should replace
> >
> > print `date`;
> >
> > with
> >
> > print scalar localtime;
> >
> > Walt
>
>
------------------------------
Date: 13 Apr 2001 08:38:36 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Testing open ports
Message-Id: <9b6duc$8ip$5@plutonium.btinternet.com>
Michael Cook <mikecook@cigarpool.com> wrote:
> Hello,
> I am trying to write a Perl script to test whether certain ports on
> other servers are listening. I have searched CPAN, but can find nothing -
> can someone point me in the right direction?
You mean like this :
#!/usr/bin/perl -w
use strict;
use IO::Socket;
for my $port ( 1 ... 255 )
{
my $sock = IO::Socket::INET->new( PeerAddr => 'localhost',
PeerPort => $port,
Proto => 'tcp' );
print "$port\n" if $sock;
}
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Fri, 13 Apr 2001 06:29:24 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Warning Message
Message-Id: <slrn9dd763.uk3.tjla@thislove.dyndns.org>
I was shocked! How could Chris A. <chris62vw@hotmail.com>
say such a terrible thing:
>Is it bad to call a sub inside itself? Take my following example:
Not necessarily. This is a peculiar form of looping known as
"Recursion". The trouble with recursion is that each time you call a
function, the variables and so on have to be stored on the stack for
when the function returns. If your recursive function never returns,
then you will run out of memory*. Recursion is actually pretty cool for
some tasks so I wouldn't never use it. You do have to ensure that there
is some stopping condition.
A better design would be to use an explicit loop:
while (1)
{
# check something
if (something is true)
{
# do something
}
else
{
# do something else
}
}
* actually this is not always true. Some compilers can transform
recursive calls like the one in your example into an explicit loop in
which case they will use constant memory. perl doesn't, as far as I know
do this.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A slick talking pirate named Bruce
To steal code, had a plan to seduce
An Apple II+.
Now Bruce wears a truss
And was jailed for computer abuse.
------------------------------
Date: Thu, 12 Apr 2001 23:50:17 -0700
From: "Chris A." <chris62vw@hotmail.com>
Subject: Re: Warning Message
Message-Id: <tdd8dkkcb0r70f@corp.supernews.com>
Thanks Gwyn. I wasn't sure if recursion was bad or okay.
Chris A.
"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn9dd763.uk3.tjla@thislove.dyndns.org...
> I was shocked! How could Chris A. <chris62vw@hotmail.com>
> say such a terrible thing:
>
> >Is it bad to call a sub inside itself? Take my following example:
>
> Not necessarily. This is a peculiar form of looping known as
> "Recursion". The trouble with recursion is that each time you call a
> function, the variables and so on have to be stored on the stack for
> when the function returns. If your recursive function never returns,
> then you will run out of memory*. Recursion is actually pretty cool for
> some tasks so I wouldn't never use it. You do have to ensure that there
> is some stopping condition.
>
> A better design would be to use an explicit loop:
>
> while (1)
> {
> # check something
>
> if (something is true)
> {
> # do something
> }
> else
> {
> # do something else
> }
> }
>
> * actually this is not always true. Some compilers can transform
> recursive calls like the one in your example into an explicit loop in
> which case they will use constant memory. perl doesn't, as far as I know
> do this.
>
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> A slick talking pirate named Bruce
> To steal code, had a plan to seduce
> An Apple II+.
> Now Bruce wears a truss
> And was jailed for computer abuse.
------------------------------
Date: 13 Apr 2001 06:54:44 GMT
From: Tassilo.Parseval@post.rwth-aachen.de (Tassilo v. Parseval)
Subject: Re: Warning Message
Message-Id: <9b67rk$okc$1@nets3.rz.RWTH-Aachen.DE>
On Thu, 12 Apr 2001 23:11:12 -0700, Chris A. <chris62vw@hotmail.com> wrote:
>#!/usr/bin/perl -w
>
>use strict;
>
>stayalive();
>
>sub stayalive {
>
> while (1) {
>
> my $processes = `ps -aux`;
> if ($processes =~ /named/) {
> sleep 10;
> stayalive();
> }
>
> else {
> print "NAMED HAS SHUT DOWN !!! Restarting...\t";
> print scalar localtime;
> system ("named -q") || print "\nnamed has restarted
>successfully.\n";
> my $processes = `ps -aux`;
> stayalive();
> }
>
> }
>
>}
No, no, no, no, no! In this sub the while(1)-loop is obsolete...it just runs
once and then stayalive() is called again with the same deep-recursion problem
as before. Just remove both recursive calls to stayalive().
while(1) just means that it loops forever. while(condition) loops as long as
the contition is true...a condition of 1 always is true. That's why it loops
forever.
So, once stayalive is called, Perl will get into the while-loop and forever
test the if-else-statement and perform either the if or else part.
When done so it'll start the loop all over again which is the reason why you
do not need to call stayalive() again. That is, stayalive() will never be left
but not called recursively either which can in general be considered a good
thing.
Regards,
Tassilo
--
"It's ten o'clock... Do you know where your AI programs are?" -- Peter Oakley
------------------------------
Date: 13 Apr 2001 08:20:51 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Warning Message
Message-Id: <9b6ct3$8ip$4@plutonium.btinternet.com>
Chris A. <chris62vw@hotmail.com> wrote:
> I run perl with the -w flag. I am getting a warning. Is there a place
> where I can find the meaning to various warnings and errors in my script?
>
man perldiag.
> I am getting this error in particular:
>
> Deep recursion on subroutine "main::stayalive" at keepalive line 11.
>
Yes you will see below.
> stayalive is a sub. My 'named' is crashing so I made a cheap little perl
> script to keep it alive until I can get the new version.
>
> #!/usr/bin/perl -w
>
>
> stayalive();
>
> sub stayalive {
>
> $processes = `ps -aux`;
> if ($processes =~ /named/) {
> sleep 5;
> stayalive();
> }
>
> else {
> print "NAMED HAS SHUT DOWN !!! Restarting...";
> print "\t";
> print `date`;
> system ("named -q") || print "named has restarted successfully.\n";
> $processes = `ps -aux`;
> stayalive();
>
> }
>
> }
>
> It isn't pretty, but it doesn't need to be. It only took a few minutes to
> make.
>
>
You are recursing on the subroutine stayalive() forever (well until the
program dies anyhow) and you certainly do need or want to do this -
lose the recursive calls to stayalive() within itself and put a loop round
the initial call to it :
while(1)
{
stayalive();
}
Or more succinctly :
stayalive() while(1);
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: 13 Apr 2001 09:19:35 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Warning Message
Message-Id: <9b6gb7$g86$1@plutonium.btinternet.com>
Chris A. <chris62vw@hotmail.com> wrote:
> "Uri Guttman" <uri@sysarch.com> wrote in message
> news:x7ae5lo4hk.fsf@home.sysarch.com...
>> >>>>> "CA" == Chris A <chris62vw@hotmail.com> writes:
>>
>> CA> stayalive();
>>
>> CA> sub stayalive {
>>
>> CA> $processes = `ps -aux`;
>> CA> if ($processes =~ /named/) {
>>
>> ever heard about indentation? sub code is usually indented from the sub
>> start.
>>
>> CA> sleep 5;
>> CA> stayalive();
>> CA> }
>>
>>
>> CA> stayalive();
>>
>> why are you calling stayalive from INSIDE stayalive? that is recursion
>> and it is never ends which is what triggers your warning.
>>
>>
>> CA> It isn't pretty, but it doesn't need to be. It only took a few
>> CA> minutes to make.
>>
>> then take a few minutes to make it more readable.
>>
>> and then take a few more to understand what calling a sub from inside
>> itself means. question for you: when will any call to that sub ever
> return?
>
> I did indent the code; maybe when I copied it from SecureCRT and pasted it
> into here the indention went away.
>
> Ahh...now I understand...the code is intented from when the sub
> starts...that makes sense. I usually only indent when using if/elsif/until
> , etc. I'll start doing that now.
>
> Is it bad to call a sub inside itself? Take my following example:
>
There are occasions when you want to have a recursive but this example and
your previous one are ones where simple iteration is all that is required.
> ------------
> #!/usr/lib/perl -w
>
> use strict;
>
> getword();
>
> sub getword {
>
> print "Enter a word\n";
> my $word = <STDIN>;
> chop $word;
>
> if (!$word) {
> print "Nothing entered; try again.\n";
> getword();
> }
>
> }
>
>
> Is the above example acceptable in the fact that the sub getword calls
> itself from inside getword? How else would you do it?
>
Simple iteration is all that is required :
my $word;
until ( $word )
{
print "Enter a word\n";
$word = <STDIN>;
chomp $word;
}
The recursion in your example could potentially run into the deep recursion
problem you encountered before.
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
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 690
**************************************