[28203] in Perl-Users-Digest
Perl-Users Digest, Issue: 9567 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 5 21:05:42 2006
Date: Sat, 5 Aug 2006 18:05:04 -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 Sat, 5 Aug 2006 Volume: 10 Number: 9567
Today's topics:
Re: A possable bug in the "warnings" pragma. <1usa@llenroc.ude.invalid>
Re: A possable bug in the "warnings" pragma. <1usa@llenroc.ude.invalid>
Re: Apache htaccess and perl robertutah@gmail.com
Re: Apache htaccess and perl <David.Squire@no.spam.from.here.au>
Re: Apache htaccess and perl robertutah@gmail.com
Re: Bit::Vector::Block_Read() returns too many bits <sisyphus1@nomail.afraid.org>
Re: FAQ 3.27 Where can I learn about object-oriented Pe <brian.d.foy@gmail.com>
Further to: Printing Hash Marks During File Download <hlarons@yahoo.com>
Re: Further to: Printing Hash Marks During File Downloa usenet@DavidFilmer.com
Re: Hash in inherited object fields not properly access <bik.mido@tiscalinet.it>
Re: Hash in inherited object fields not properly access <shenkin@gmail.com>
Re: Hash in inherited object fields not properly access <shenkin@gmail.com>
Proc::Daemon and Sockets <shrike@cyberspace.org>
Re: Proc::Daemon and Sockets <1usa@llenroc.ude.invalid>
Re: Reading value from File and using in another file <David.Squire@no.spam.from.here.au>
Re: Reading value from File and using in another file <1usa@llenroc.ude.invalid>
Re: Recursion <news@lawshouse.org>
Re: scroll down menu with mechanize <no@email.com>
Re: scroll down menu with mechanize <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 05 Aug 2006 23:20:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: A possable bug in the "warnings" pragma.
Message-Id: <Xns9816C4D74D5Dasu1cornelledu@127.0.0.1>
Dale Wiles <WilesIgnoreMe@IgnoreMeModArnis.Com> wrote in
news:36kf5ovh19w.vyr@IgnoreMeModArnis.Com:
> I think I found a bug in perl's "warnings" pragma, but I want to
> make sure that it's an actual, reproducible bug before reporting it.
Well, I have to tell you, there seems to be a problem with your posting
software. XNews thinks this post was made on 30 Dec 1899.
I'll have to say up front, I am always skeptical of people whose first
post starts with a claim that they have found a bug in Perl or core Perl
modules.
> This program, posted below, should die at "Killed me.". If I run
> it I get:
>
> Saw me. at perl_warnings_fails line 36
> Killed me. at perl_warnings_fails line 40
> Revenge from beyond the grave! at perl_warnings_fails line 43
> Out of the function. at perl_warnings_fails line 48
>
> If I uncomment "my $y = \@_;"
>
> Saw me. at perl_warnings_fails line 36
> Killed me. at perl_warnings_fails line 40
>
> which is what's expected.
>
> There's nothing special about "my $y = \@_;". Pretty much anything
> that touches "@_" masks the bug. "@_ = ();" works as does "print \@;"
> That's why I think it's a bug in the Perl interpreter.
...
> ---- perl_warnings ----
>
> #!/usr/bin/perl
>
> package Foo;
> use strict;
> use warnings::register;
>
> sub new($)
Why are you using prototypes with methods?
> {
> my ($self) = @_;
>
> my $class = { };
> bless $class, $self;
>
> return $class;
> }
You have the concepts mixed up here: New is passed the name of the
package as its first argument. Then, you bless an instance into that
package, returned the blessed reference which is the instance of the
class. Hence, your new method, in this case, should be:
sub new {
my $class = shift;
bless { }, $class;
}
>
> sub warnme($$)
Ditto. No point in having prototypes with warnings.
> {
> my ($self, $text) = @_;
>
> warnings::warnif($self, $text);
Now, your confusion with classes and instances carries over here. The
category you have created is called 'Foo'. Do you think $self eq 'Foo'?
Replace this with:
warnings::warnif(Foo => $text);
D:\UseNet\clpmisc> cat t97.pl
#!/usr/bin/perl
package Foo;
use strict;
use warnings::register;
sub new {
my $pkg = shift;
bless { }, $pkg;
}
sub warnme {
my $self = shift;
my ($text) = @_;
warnings::warnif(Foo => $text);
}
package main;
use strict;
use warnings;
sub wtest {
my $f = shift;
$f->warnme('Saw me.');
{
use warnings FATAL => 'Foo';
$f->warnme('Killed me.');
}
$f->warnme('Revenge from beyond the grave!');
}
my $g = Foo->new;
wtest($g);
$g->warnme('Out of the function.');
D:\UseNet\clpmisc> t97
Saw me. at D:\UseNet\clpmisc\t97.pl line 26
Killed me. at D:\UseNet\clpmisc\t97.pl line 30
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 05 Aug 2006 23:28:27 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: A possable bug in the "warnings" pragma.
Message-Id: <Xns9816C632C95CAasu1cornelledu@127.0.0.1>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in
news:Xns9816C4D74D5Dasu1cornelledu@127.0.0.1:
> Dale Wiles <WilesIgnoreMe@IgnoreMeModArnis.Com> wrote in
> news:36kf5ovh19w.vyr@IgnoreMeModArnis.Com:
...
>> sub warnme($$)
>
> Ditto. No point in having prototypes with warnings.
Of course, s/warnings/methods/.
Sorry.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: 5 Aug 2006 11:06:51 -0700
From: robertutah@gmail.com
Subject: Re: Apache htaccess and perl
Message-Id: <1154801211.771224.258300@m73g2000cwd.googlegroups.com>
David Squire skrev:
> robertutah@gmail.com wrote:
> > David Squire skrev:
> >
> >> robertutah@gmail.com wrote:
> >>> Hi all
> >>>
> >>> I have a apache running with mod_perl, it is set up with access-control
> >>> by a .htaccess-file with more than 1 user in it.
> >>>
> >>> I need to get the username from the one that have logged in. How do I
> >>> do that ?
> >>>
> >> It's a standard CGI environment variable: REMOTE_USER
> >>
> >> You get access to environment variables in Perl via the %ENV hash.
> >>
> >>
> >> DS
> >
> > For some resson REMOTE_USER i not in %ENV ?
> >
>
> It works for me. Note that it is only set for pages protected using
> .htaccess files - which you say you are using.
>
> Please show us some code so that we have some chance of diagnosing your
> problem.
>
>
> DS
# From my apache (one of the, got at apache running behind with
mod_perl this apache rewrite to it)
Maby this it the problem ?
<VirtualHost *>
ServerName somedomain.com
<Location />
AuthName MyDomain
AuthType basic
AuthUserFile /home/user/.htpasswd
require valid-user
</Location>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.jpeg$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.jpe$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.ico$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.html$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.htm$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.pdf$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.js$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.pl$ [NC]
RewriteCond %{REQUEST_URI} !^.*\.txt$ [NC]
RewriteRule ^(.*)$ http://127.0.0.1:8097$1 [P,NC]
<Directory />
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
ServerAdmin admin@somedomain.com
DocumentRoot /home/user/html
ErrorLog /home/user/log/error_log-admin
CustomLog /home/user/log/access_log-admin common
</VirtualHost>
------------------------------
Date: Sat, 05 Aug 2006 19:11:30 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Apache htaccess and perl
Message-Id: <eb2n0i$m89$2@gemini.csx.cam.ac.uk>
robertutah@gmail.com wrote:
> David Squire skrev:
>
>> robertutah@gmail.com wrote:
>>> David Squire skrev:
>>>
>>>> robertutah@gmail.com wrote:
>>>>> Hi all
>>>>>
>>>>> I have a apache running with mod_perl, it is set up with access-control
>>>>> by a .htaccess-file with more than 1 user in it.
>>>>>
>>>>> I need to get the username from the one that have logged in. How do I
>>>>> do that ?
>>>>>
>>>> It's a standard CGI environment variable: REMOTE_USER
>>>>
>>>> You get access to environment variables in Perl via the %ENV hash.
>>>>
>>> For some resson REMOTE_USER i not in %ENV ?
>>>
>> It works for me. Note that it is only set for pages protected using
>> .htaccess files - which you say you are using.
>>
>> Please show us some code so that we have some chance of diagnosing your
>> problem.
>>
> # From my apache (one of the, got at apache running behind with
> mod_perl this apache rewrite to it)
> Maby this it the problem ?
>
> <VirtualHost *>
> ServerName somedomain.com
[snip]
Show us your *Perl* code.
DS
------------------------------
Date: 5 Aug 2006 11:12:06 -0700
From: robertutah@gmail.com
Subject: Re: Apache htaccess and perl
Message-Id: <1154801526.822043.300340@h48g2000cwc.googlegroups.com>
robertu...@gmail.com skrev:
> David Squire skrev:
>
> > robertutah@gmail.com wrote:
> > > David Squire skrev:
> > >
> > >> robertutah@gmail.com wrote:
> > >>> Hi all
> > >>>
> > >>> I have a apache running with mod_perl, it is set up with access-control
> > >>> by a .htaccess-file with more than 1 user in it.
> > >>>
> > >>> I need to get the username from the one that have logged in. How do I
> > >>> do that ?
> > >>>
> > >> It's a standard CGI environment variable: REMOTE_USER
> > >>
> > >> You get access to environment variables in Perl via the %ENV hash.
> > >>
> > >>
> > >> DS
> > >
> > > For some resson REMOTE_USER i not in %ENV ?
> > >
> >
> > It works for me. Note that it is only set for pages protected using
> > .htaccess files - which you say you are using.
> >
> > Please show us some code so that we have some chance of diagnosing your
> > problem.
> >
> >
> > DS
>
> # From my apache (one of the, got at apache running behind with
> mod_perl this apache rewrite to it)
> Maby this it the problem ?
>
> <VirtualHost *>
> ServerName somedomain.com
>
> <Location />
> AuthName MyDomain
> AuthType basic
> AuthUserFile /home/user/.htpasswd
> require valid-user
> </Location>
>
> RewriteEngine On
> RewriteCond %{REQUEST_URI} !^.*\.gif$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.jpeg$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.jpg$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.jpe$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.ico$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.css$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.html$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.htm$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.pdf$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.js$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.png$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.pl$ [NC]
> RewriteCond %{REQUEST_URI} !^.*\.txt$ [NC]
> RewriteRule ^(.*)$ http://127.0.0.1:8097$1 [P,NC]
>
> <Directory />
> AllowOverride AuthConfig
> Order allow,deny
> Allow from all
> </Directory>
>
>
> ServerAdmin admin@somedomain.com
> DocumentRoot /home/user/html
> ErrorLog /home/user/log/error_log-admin
> CustomLog /home/user/log/access_log-admin common
> </VirtualHost>
I put my Auth-things in my second apache-conf, then i worked...
Thanks for all your help
------------------------------
Date: Sun, 6 Aug 2006 10:02:51 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Bit::Vector::Block_Read() returns too many bits
Message-Id: <44d532a2$0$11968$afc38c87@news.optusnet.com.au>
"Clyde Ingram"
<clydenospamorham@nospamorhamgetofftheline.freeservenospamorham.co.uk> wrote
in message
.
.
>
> 1. Man page for Bit::Vector::Block_Read():
>
> a.. $buffer = $vector->Block_Read();
> This method allows you to export the contents of a given bit vector in one
> block.
>
I couldn't find any documentation that was conclusive, but I *think* that
"block" is equivalent to "machine word" (32 bits on your machine), and that
any blocks that are unfilled by the vector are padded with zeros. See the
documentation on Block_Store and Word_Size for additional hints that this is
the case.
If you alter the code so that the vector size is in the range 33..64, then
Block_Read returns a buffer of length 64.
Cheers,
Rob
------------------------------
Date: Sat, 05 Aug 2006 19:17:32 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 3.27 Where can I learn about object-oriented Perl programming?
Message-Id: <050820061917325273%brian.d.foy@gmail.com>
In article <1154520843.071682.53060@m79g2000cwm.googlegroups.com>, Paul
Lalli <mritty@gmail.com> wrote:
> PerlFAQ Server wrote:
> > --------------------------------------------------------------------
> >
> > 3.27: Where can I learn about object-oriented Perl programming?
> This FAQ should likely be updated with the new title of the Alpaca,
> "Intermediate Perl"
Indeed, I should find all references to the Alpaca and ensure the new
name is there.
Thanks :)
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Sat, 05 Aug 2006 19:11:09 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Further to: Printing Hash Marks During File Download
Message-Id: <slrned9rad.ld.hlarons@Beagle.mylocal.net>
xhoster@gmail.com wrote on Aug 1 14:36:20 2006:
>>HaroldWho <hlarons@yahoo.com> wrote:
>> I am using the Net::POP3 module to retrieve mail from a dialup POP3
>> server.
...
>> I'd like to print hash marks during the d/l, much like an ftp d/l does,
>> but I'm stumped for a way to do it, at using some kind of loop.
>For CGI where the web browser (software, not human) might give up if it
>doesn't hear anything after a while, I use something like this:
>
> {
> local $SIG{ALRM}= sub { print ".\n"; alarm 10 };
> alarm 10;
> $t->long_operation();
> alarm 0;
> };
I tried a version of this using Time::HiRes, floating times, and
'eval', thus:
print "\nGet message $msgnum ($$msgnums{$msgnum} octets) ";
eval {
local $SIG{ALRM}= sub { print "# "; alarm 1.5 };
alarm 1.5;
my $msg = $pop->get($msgnum); # The 'long operation'
alarm 0.0;
print "\n";
};
Alas, the 'print #' operation seems to get buffered or something, and
does not appear until the 'long op' has finished. Sample:
Get message 3 (5118 octets)
Get message 4 (32907 octets) # #
Get message 5 (7145 octets)
The hash marks don't appear while msg 4 is being downloaded (the
desired behavior), but afterwards.
I'm out of my depth here.
HaroldWho
--
Powered by Slackware 10.2 Linux -- Kernel 2.6.13
News Reader slrn 0.9.8.1
------------------------------
Date: 5 Aug 2006 14:08:12 -0700
From: usenet@DavidFilmer.com
Subject: Re: Further to: Printing Hash Marks During File Download
Message-Id: <1154812092.291799.191040@p79g2000cwp.googlegroups.com>
HaroldWho wrote:
> Alas, the 'print #' operation seems to get buffered or something
Your dignosis is correct. So you need to unbuffer the output:
select(STDOUT); $| = 1;
is the traditional way, but the more modern (and better way) would be
more like"
use IO::Handle;
autoflush STDOUT 1;
--
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 5 Aug 2006 21:56:31 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Hash in inherited object fields not properly accessible (5.8.6, RH 7.3)
Message-Id: <ktt9d2dgdv77isiksf18q52fejqpvvrp3u@4ax.com>
On Sat, 05 Aug 2006 12:49:13 -0400, Uri Guttman <uri@stemsystems.com>
wrote:
> >> not from the level of perl code AFAIK.
>
> a> Devel::Peek::Dump shows the state of a hash iterator.
>
>i am sure that module does xs stuff. so that doesn't contradict what i
>said which was from the perl level. i should have said pure perl
>level. :)
I see the smiley, but in any case I'm quite sure that Anno's remark
had not the slightest intention of contradicting your "claim".
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 5 Aug 2006 14:13:56 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Re: Hash in inherited object fields not properly accessible (5.8.6, RH 7.3)
Message-Id: <1154812436.599431.199900@75g2000cwc.googlegroups.com>
OK, boys and girls. I found the problem. I also trust Perl more than
I trust my eyes; but how much do you trust Data::Dumper?
Here is a complete example that illustrates the problem. In my test
program, I had called Data::Dumper::Dump just before the call that
generated the bad results. I had set Data::Dumper::Sortkeys to True.
Apparently, when a dump is done with this option, a hash traversal is
incompletely done within Data::Dumper, causing a subsequent call to
"each" to return 0 unless the iterator is manually reset between the
two calls.
In the following example, commenting out the offending line causes the
second "while" to print out the hash table. With the offending line
left in, the second "while" is silent.
-P.
########## snip #######################
use strict;
use Data::Dumper;
my %hash= (
a => 1,
b => 2,
c => 3,
d => 4,
);
while( my ($key,$val) = each %hash ) {
my $val = $hash{ $key };
print "while each: key,val= '$key', '$val'\n";
}
my $dumper = Data::Dumper->new( [\%hash] );
$dumper->Sortkeys( 1 ); #### offending line
my $dump_string = $dumper->Dump();
# the following block is silent
# unless the Sortkeys line is removed:
while( my ($key,$val) = each %hash ) {
my $val = $hash{ $key };
print "2nd while each: key,val= '$key', '$val'\n";
}
########## snip #######################
------------------------------
Date: 5 Aug 2006 17:22:14 -0700
From: "PeterSShenkin" <shenkin@gmail.com>
Subject: Re: Hash in inherited object fields not properly accessible (5.8.6, RH 7.3)
Message-Id: <1154823733.938331.318200@m79g2000cwm.googlegroups.com>
Here are two more data points:
1. If I specify Data::Dumper::Useperl(1), the problem goes away.
2. I also see the problem unless I specify Useperl(1) with the
following version of Perl. Thus, the problem does not appear to be
specific to the build of Perl I was using earlier or to the OS I was
running on (though it could still be specific to 5.8.6).
Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
Platform:
osname=darwin, osvers=8.0, archname=darwin-thread-multi-2level
uname='darwin b28.apple.com 8.0 darwin kernel version 7.5.0: thu
mar 3 18:48:46 pst 2005; root:xnuxnu-517.99.13.obj~1release_ppc power
macintosh powerpc '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe
-Dldflags=-Dman3ext=3pm -Duseithreads -Duseshrplib'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-g -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include',
optimize='-Os',
cppflags='-no-cpp-precomp -g -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build
1809)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags
='-L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true,
libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-bundle -undefined dynamic_lookup
-L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES
PERL_IMPLICIT_CONTEXT
Locally applied patches:
23953 - fix for File::Path::rmtree CAN-2004-0452 security issue
33990 - fix for setuid perl security issues
Built under darwin
Compiled at Mar 20 2005 16:34:19
@INC:
/System/Library/Perl/5.8.6/darwin-thread-multi-2level
/System/Library/Perl/5.8.6
/Library/Perl/5.8.6/darwin-thread-multi-2level
/Library/Perl/5.8.6
/Library/Perl
/Network/Library/Perl/5.8.6/darwin-thread-multi-2level
/Network/Library/Perl/5.8.6
/Network/Library/Perl
/System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.8.6
/Library/Perl/5.8.1
.
------------------------------
Date: 5 Aug 2006 12:42:28 -0700
From: "shrike@cyberspace.org" <shrike@cyberspace.org>
Subject: Proc::Daemon and Sockets
Message-Id: <1154806948.895445.23940@b28g2000cwb.googlegroups.com>
Howdy,
I've written a TCP proxy in Perl. It is non-forking and restarts a
listening socket on the original port after a disconnection. From the
CLI it runs correctly. listen->connect->disconnect->listen.
But when I try to daemonize:
&Proc::Daemon::Init ;
The first socket will come up, but after closing it, I can not build a
socket again on the same port.
Anybody know how to fix this?
It dies at "The socket will not listen.", but only when running
daemonized.
I've included copies of my listen, accept and disconnect functions.
These use AUTOLOADed set/gets, so these examples won't build unless you
use Class::GAPI or some equivilant. I'm also using IO::Poll instead of
select. In a nutshell, $self->foo("bar") is the same as $self->{'foo'}
= "bar" ; Probably won't help much, but there it is.
-Thanks
-Matt
package Proxy ;
use IO::Poll qw(POLLIN POLLOUT POLLHUP POLLNVAL POLLERR) ;
use Time::HiRes qw(usleep) ;
use Socket qw(inet_aton inet_ntoa); # string to bin, bin to string
use IO::Socket::INET ;
use Class::GAPI ;
our @ISA = qw(Class::GAPI) ;
# Listen
#################
sub _createsock_listen {
my $self = shift ;
my $foo = IO::Socket::INET->new(Listen => 1,
LocalPort => $self->{'l'},
Reuse => 1,
Blocking => 0,
Proto => 'tcp')
|| die "The socket will not listen." ;
$self->_LISTEN($foo) ;
warn("Listening for a client on $foo") if ($self->{'W'}) ;
}
#Accept
#################
sub _wait_accept { # Listen to Connect
my $self = shift ;
my $waiting = 1 ;
my $foo ;
while ($waiting) {
usleep $self->{'_listendelay'} ;
next unless $foo = $self->_LISTEN->accept ;
$waiting = 0 ;
next ;
}
$foo->blocking(0) ;
$self->_handles->mask($foo => POLLIN|POLLOUT) ;
$self->_IN($foo);
warn ("Client connection accepted on $foo") if ($self->{'W'})
;
}
# disconnect
##################
sub _disco { # Reset Everything but the running flag
my $self = shift ;
$self->CONNECTED(0) ; # stop transmitting
$self->AUTHENTICATED(0) ; # kick the user
$self->_delshims() ; # Waste any shim hooks
$self->_handles->mask($self->_IN() => 0) ; # Tell poll to drop
the handles
$self->_handles->mask($self->_OUT() => 0) ; #
close($self->{'_IN'}) ; # Then close them
close($self->{'_OUT'}) ; #
close($self->{'_LISTEN'}) ; #
warn "Disconnection complete" ; #
}
1;
------------------------------
Date: Sat, 05 Aug 2006 21:07:42 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Proc::Daemon and Sockets
Message-Id: <Xns9816AE55BCDD9asu1cornelledu@127.0.0.1>
"shrike@cyberspace.org" <shrike@cyberspace.org> wrote in
news:1154806948.895445.23940@b28g2000cwb.googlegroups.com:
> my $foo = IO::Socket::INET->new(Listen => 1,
> LocalPort => $self->{'l'},
> Reuse => 1,
> Blocking => 0,
> Proto => 'tcp')
> || die "The socket will not listen." ;
I don't have time to look into this now, but, how about checking why
listen failed?
die "Listen failed:\n\$! = $!\n\$@ = $@";
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 05 Aug 2006 19:08:53 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Reading value from File and using in another file
Message-Id: <eb2mrl$m89$1@gemini.csx.cam.ac.uk>
vedpsingh@gmail.com wrote:
> Hi,
> Based on the suggestions, I made few changes.
> First i thought to do the read and write in file independently.
> Writting in file is not a problem.
> But I am not able to do reading from a file . Please give your comment.
> I am a beginer in perl.
> Thanks
>
> --------------------------------
> use strict;
> use warnings;
> my $data_file = 'data.txt';
> ($data_file) = @ARGV;
Do you intend to clobber the value of $data_file here if no command line
argument was given? From the warnings and error messages below, it is
clear that $data_file is not initialized - because the first element of
@ARGV is undef. I'll bet you ran this with out a command line parameter.
It's not clear what you're trying to do, but it might be something like
this:
@ARGV and ($data_file) = @ARGV; # use first command line argument if
any are present.
(though this ignores any other command line arguments).
> open my $read_handle, '<', $data_file or die "Cannot open '$data_file':
> ";
> {
> print "@ARGV";
What is this about? Why the enclosing braces? Why are you printing the
@ARGV array?
> }
> close ($read_handle);
> ----------------------------------
>
> ------Error message I am getting
>
> C:\Perl\Myperl>perl read_NOT_DONE.pl
> Use of uninitialized value in open at read_NOT_DONE.pl line 5.
> Use of uninitialized value in concatenation (.) or string at
> read_NOT_DONE.pl li
> ne 5.
> Cannot open '': at read_NOT_DONE.pl line 5.
>
------------------------------
Date: Sat, 05 Aug 2006 18:11:40 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Reading value from File and using in another file
Message-Id: <Xns9816907D3F8EFasu1cornelledu@127.0.0.1>
vedpsingh@gmail.com wrote in news:1154800761.462191.255540
@n13g2000cwa.googlegroups.com:
> Based on the suggestions,
What suggestions? Please quote an appropriate amount of context.
...
> But I am not able to do reading from a file .
...
> --------------------------------
> use strict;
> use warnings;
> my $data_file = 'data.txt';
> ($data_file) = @ARGV;
This is pointless. This is also the reason for the error message below
(looks like you did not provide any command line arguments to the
script, and therefore the assignment above produced the undefined
value).
If you want to be able to specify the name of a file on the command-line
as well as providing a default filename, do the following:
my ($data_file) = @ARGV;
defined $data_file or $data_file = 'data.txt';
> open my $read_handle, '<', $data_file
> or die "Cannot open '$data_file':";
You should include the reason the file could not be opened in the error
message. I am pretty sure I showed you that:
open my $read_handle, '<', $data_file
or die "Cannot open '$data_file': $!";
> {
> print "@ARGV";
> }
What do you think is the purpose of this line? You are just
interpolating and printing the command line arguments. You are not
reading at all from any files. You are not even attempting to.
> close ($read_handle);
OK, so now you have closed the file without ever reading anything from
it?
perldoc -f readline
> C:\Perl\Myperl>perl read_NOT_DONE.pl
> Use of uninitialized value in open at read_NOT_DONE.pl line 5.
> Use of uninitialized value in concatenation (.) or string at
> read_NOT_DONE.pl line 5.
> Cannot open '': at read_NOT_DONE.pl line 5.
See above for the reason for this message.
It is high time you invested in a book.
http://learn.perl.org/
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Sat, 05 Aug 2006 23:42:26 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Recursion
Message-Id: <1154817746.17431.0@proxy00.news.clara.net>
Bernard El-Hagin wrote:
> The usefulness of this group has become questionable at best.
Not my experience at all. I have several times recently posted here
with some Perl problem, and always had prompt, accurate and wise advice.
From time to time people have put themselves out to help me, e.g.
installing modules in order to run my problem code and so on.
> Most questions asked here are rejected immediately because they don't conform to *every*
> *single* *fucking* *point* in the guidelines, even if they are perfectly clear. The only ones left
> are so simple, they can be answered with a perldoc reference.
Do you understand the truth - and therefore the irony - of what you've
just written? If a poster spends the time required to follow the
guidelines (Googling, pruning the problem program down to its essence,
providing good test data, checking code levels and so forth) time after
time the solution becomes clear.
In other words the whole point of the guidelines is not so much that
they've been followed: it's that following them helps clarify the
problem and makes it easier for someone - often the poster - to find the
solution.
--
Henry Law <>< Manchester, England
------------------------------
Date: Sat, 05 Aug 2006 19:50:50 +0100
From: Brian Wakem <no@email.com>
Subject: Re: scroll down menu with mechanize
Message-Id: <4jk7kaF7ota6U1@individual.net>
Nospam wrote:
> can someone clarify something in the www::mechanize module, to select a
> field I understand it would something similar to
> $mech->field('nameoffield, $value); however suppose the selection was a
> scroll down menu? with
> javascript : something like <script scr=...
> JSActions=[[variable,"response1"],[variable2,"response2"]</script> ?
WWW::Mechanize does not understand javascript. You have to work around it
yourself.
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
------------------------------
Date: Sat, 5 Aug 2006 21:05:51 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: scroll down menu with mechanize
Message-Id: <eb31mn.1ag.1@news.isolution.nl>
Nospam schreef:
> can someone clarify something in the www::mechanize module
The name is WWW::Mechanize. Case matters.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 9567
***************************************