[29981] in Perl-Users-Digest
Perl-Users Digest, Issue: 1224 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 22 21:09:40 2008
Date: Tue, 22 Jan 2008 18:09:09 -0800 (PST)
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, 22 Jan 2008 Volume: 11 Number: 1224
Today's topics:
Re: AuthDBI log out is it possible <jcharth@gmail.com>
Re: AuthDBI log out is it possible <glex_no-spam@qwest-spam-no.invalid>
Re: Chat client/server print failed <ben@morrow.me.uk>
Re: File Monitoring modules <tzz@lifelogs.com>
Re: incorrect errno/perror with IO::socket->new <brandon.mayfield@att.net>
Re: sprintf rouding error <hjp-usenet2@hjp.at>
Re: Variable interpolation and m in regular expression <jurgenex@hotmail.com>
Re: Variable interpolation and m in regular expression <jurgenex@hotmail.com>
XML Reference problem sharon@blue-linedesign.com
Re: XML Reference problem <peter@makholm.net>
Re: XML Reference problem sharon@blue-linedesign.com
XML results questions sharon@blue-linedesign.com
Re: XML results questions <smallpond@juno.com>
Re: XML results questions <simon.chao@fmr.com>
Re: XML results questions <glex_no-spam@qwest-spam-no.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 22 Jan 2008 10:04:48 -0800 (PST)
From: joe <jcharth@gmail.com>
Subject: Re: AuthDBI log out is it possible
Message-Id: <75da1262-3294-48e3-bbea-606fd5d8175f@v67g2000hse.googlegroups.com>
Thanks Joost. I guess there is no way to log out. I tried a few php
authentication script with no luck. Now I was asked if it possible to
have a session life. I did not find any settings for this in the
AuthDBI.pm file and suggestions? Thanks
On Jan 18, 2:06 pm, Joost Diepenmaat <jo...@zeekat.nl> wrote:
> joe <jcha...@gmail.com> writes:
> > Hello I am using AuthDBI in my apache server, is there a way to code a
> > log out button? thanks.
>
> /As far as I know/ you can't force a log out from basic authentication
> from the server. Clients will usually remember the login credentials
> until they're restarted.
>
> Joost.
------------------------------
Date: Tue, 22 Jan 2008 12:29:22 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: AuthDBI log out is it possible
Message-Id: <47963603$0$506$815e3792@news.qwest.net>
joe wrote:
> Thanks Joost. I guess there is no way to log out. I tried a few php
> authentication script with no luck.
Please don't top post.
You might be able to force the "logout" by sending a 401 Unauthorized
header. Here's what I've used in the past.
sub unauth_header
{
my $realm = shift;
print "HTTP/1.0 401 Unauthorized\n";
print "401 Unauthorized\n";
print "WWW-Authenticate: Basic realm=\"$realm\"\n\n";
}
> Now I was asked if it possible to
> have a session life. I did not find any settings for this in the
> AuthDBI.pm file and suggestions? Thanks
Sure, you could store the date/time it expires and check it, or
have something else that removes the session after X
minutes/days, however you do have to use sessions first, which
isn't part of AuthDBI. You could either write your own or
use one of the many session modules available from CPAN.
------------------------------
Date: Tue, 22 Jan 2008 19:12:08 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Chat client/server print failed
Message-Id: <8prh65-onu.ln1@osiris.mauzo.dyndns.org>
Quoth deadpickle <deadpickle@gmail.com>:
> Thanks for the help, I think your right about a timer being a bad
> choice. I added the lines, and edited them, to the program. When I ran
> the client I got an error that was referenced to the add_watch of the
> Gtk2::Helper (located in the connect_server sub):
> *** unhandled exception in callback:
> *** Not a GLOB reference at chat-client.pl line 120.
> *** ignoring at chat-client.pl line 67.
> I have gotten these errors before but I don't understand what they
> mean or how I fixed them. I reposted the program with the new code.
> I'm not sure if I got it implemented correctly.
<snip>
>
> $conn = IO::Socket::INET->new(PeerAddr => $host, PeerPort =>
> $port, Proto => 'tcp') or popup_err(1);
>
> if ($conn) {
> %inbuffer = ();
> %outbuffer = ();
> %ready = ();
> tie %ready, 'Tie::RefHash';
This is almost certainly wrong. Either %ready hasn't been used before,
in which case the = () is unnecessary; or it has, in which case you
would need to untie it first.
> nonblock($conn);
> $select = IO::Select->new($conn);
> $conn_stat = 'connected';
> &update_buffer(my $msg = "Connected!");
Don't call subs with & unless you know what it does and why you need it.
> #send login to server
> send_login();
>
> Gtk2::Helper->add_watch ( fileno $select, 'in',sub{ my ($fh) =
$select isn't a filehandle, so you can't pass it to fileno. Messages
about GLOB refs usually refer to filehandles.
Why did you create $select at all? Just pass $conn to ->add_watch.
> @_; \&wait_for_msg($fh);},$select);
What do you think this syntax does? I think yu probably just meant to
call wait_for_msg?
Also, you are allowed to use more than one line per statement :).
Gtk2::Helper->add_watch(
$conn,
in => sub {
my ($fh) = @_;
wait_for_msg($fh);
},
$conn,
);
Since anon subs in Perl close over lexicals, I would write this without
the parameter:
Gtk2::Helper->add_watch($conn, in => sub { wait_for_msg($conn) });
The anon sub picks up the surrounding $conn and remembers it until it is
called.
<snip>
> if ($error_code == 1) {$error = "Cannot create Socket!"}
> elsif ($error_code == 2) {$error = "Username to Short!"}
> elsif ($error_code == 3) {$error = "No connection Established!"}
> elsif ($error_code == 4) {$error = "Already Logged on with This User
> Name!"}
> elsif ($error_code == 5) {$error = "Not Connected!"}
> else {$error = "Unkown Error!"}
my @errors = (
'Unknown error',
'Cannot create socket',
'Username too short',
'No connection established',
'Already logged on with this username',
'Not connected',
);
$error = $errors[$error_code] || $errors[0];
<snip>
> $fh->recv($msg, 'POSIX::BUFSIZ', 0) or die "recv: $!";
HUH? What made you think quoting this was sensible? It's a function, not
a string.
$fh->recv($msg, POSIX::BUFSIZ, 0)
or die "recv: $!";
Note that depending on your system recv (and everything else) can fail
with EINTR, which isn't a failure at all and just means you need to
retry.
Ben
------------------------------
Date: Tue, 22 Jan 2008 14:59:00 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: File Monitoring modules
Message-Id: <86ve5lefvv.fsf@lifelogs.com>
On Mon, 21 Jan 2008 23:29:20 -0800 (PST) nagandla@gmail.com wrote:
n> For monitoring files in directories i am using SGI::FAM module...
n> this module is monitoring perfectlt but taking more 90% CPU usage
n> while monitoring ... so any one can suggest me the better module to
n> monitor the files in directoties....here one more thing i want to
n> monitor more than a single directory at a time...
It could be a bug in your code. Can you show the code?
Use `top' or something similar to see what's actually using the CPU. Is
it the FAM daemon or your code? You could be in a busy loop...
Ted
------------------------------
Date: Tue, 22 Jan 2008 17:17:41 -0800 (PST)
From: brandon <brandon.mayfield@att.net>
Subject: Re: incorrect errno/perror with IO::socket->new
Message-Id: <157a007b-4672-4d5a-af38-180bc0fe0e81@c23g2000hsa.googlegroups.com>
On Jan 17, 10:34=A0am, brandon <brandon.mayfi...@att.net> wrote:
> On Jan 17, 10:06=A0am, xhos...@gmail.com wrote:
>
> > brandon <brandon.mayfi...@att.net> wrote:
>
> > > =A0So that is the behavior I think is inconsistent. Why would passing
> > > Timout result in EINVAL on AIX and HP boxes when an error is
> > > encountered in connect?
>
> > In a similar situation in the past, I made a IO::Socket::INET copy and
> > replaced the contents of _error with something that does a Carp::confess=
> > instead. =A0That way you can get a back-trace of what is going on.
>
> > Xho
>
> =A0Sounds good. I think I'm going to see if I can find out if RH is
> changeing anything in IO::Socket, IO::Select, etc., when they build
> their perl distribution too. Always a possibility that they are making
> some changes that AIX for example is not. If I find anything
> interesting I'll let ya'll know.
>
>
>
> > --
> > --------------------http://NewsReader.Com/--------------------
> > The costs of publication of this article were defrayed in part by the
> > payment of page charges. This article must therefore be hereby marked
> > advertisement in accordance with 18 U.S.C. Section 1734 solely to indica=
te
> > this fact.- Hide quoted text -
>
> - Show quoted text -
For anyone that continued reading this - I've given up on trying to
use Timeout to limit the amount of time I wait for a sucessful connect
before giving up. I wanted to do that because this is only one of many
checks I need to do and some of these servers (Sun I think) are taking
3 minutes + to timeout.
So I got rid of the Timeout and just fork a child and kill it after
30 sec if there is no response. Works great and does what I need it to
do and the sysadmins won't forget what they were doing by the time the
whole program finishes.
Without Timeout I encountered a few old clients that would not return
a correct perror with $@ and a few old clients that would not return a
correct perror with $!. The vast majority return the same perror for
both $! and $@.
I can't update the version of Perl on these clients but I could haul
the modules .so's around with me, though I prefer not to do that. So I
finally settled on checking the perror (first $@, then if $@ is not a
socket perror I test $!), and printing my own error message. If I
don't recognize either as a socket perror I print a message to that
effect along with both $@ and $!. So far I have not hit that condition
and I've run this on a couple thousand servers.
Thanks to everyone including Uri.
------------------------------
Date: Tue, 22 Jan 2008 19:23:42 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: sprintf rouding error
Message-Id: <slrnfpcd5g.41a.hjp-usenet2@hrunkner.hjp.at>
On 2008-01-22 14:42, Joost Diepenmaat <joost@zeekat.nl> wrote:
> Broki@gmx.de writes:
>> Thanks for your replies.
>> To reduce the problem I will try to use expressions like 115/100 than
>> 1.15.
>
> If I understand you correctly, I think that won't make any
> difference.
It does in many cases, if used correctly.
> I'm sure it won't once you assign 115/100 to a variable;
That's the incorrect way :-).
What I meant when I suggested that (and I think I already wrote that,
but I probably wasn't clear enough), is to use terms like 115 / 100 in
an expression:
my $x = 5830;
my $y = $x * 115 / 100;
will first compute the product of 5830 and 115 (which is 670450) and
then divide it by 100. The result is exactly 6704.5.
my $y = $x * (115 / 100);
will first compute 115 / 100: This is exactly representable in a finite
binary number, so it is rounded (to 53 binary digits, usually). Then $x
is divided by the rounded number, which is of course only approximately
6704.5.
Variations like
my $y = $x * 1.15;
or
my $z = 115 / 100;
my $y = $x * $z;
do the same, so they produce the same error.
[...]
>> What about the IEEE rounding and Perl...is it a fact that the
>> "uncorrectness" with floating point conversion leads to the
>> statistically interesting way to round 50% up/ 50% down?
>
> For some sets of data, yes.
If I understood the question correctly, no. The "statistically
interesting way to round" is just a way to deal with the errors
introduced by rounding in general. As the Wikipedia article mentions, it
was already the recommended way of rounding in 1906 - long before
computers. (Although it is true that if you used infinitely precise
numbers and if your functions were all continous, the error would be
infinitely small - so in a way it is the "uncorrectness of floating
point numbers" which is the reason for the rule).
hp
------------------------------
Date: Tue, 22 Jan 2008 18:59:16 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Variable interpolation and m in regular expression matching
Message-Id: <66fcp3pbmndlfrcl9p0a1iobvp1te35qdj@4ax.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>Jürgen Exner wrote:
>> 2: the m modifier allows an RE to expand across multiple lines within a
>> single string. However the given RE does not contain a \n or any wild card
>> that could match a \n. Therefore the m modifier is of no use in this RE.
>
>Why would you need things that match newlines in order for the /m
>modifier to make a difference?
>
>C:\home>type test.pl
>$_ = "alpha one\nbeta two\ngamma three\n";
>@lastword = /(\w+)$/g;
>@allnums = /(\w+)$/gm;
>print "\@lastword: @lastword\n";
>print "\@allnums: @allnums\n";
>
>C:\home>test.pl
>@lastword: three
>@allnums: one two three
Interesting example!
Thank you for sharing.
jue
------------------------------
Date: Tue, 22 Jan 2008 19:02:45 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Variable interpolation and m in regular expression matching
Message-Id: <uafcp398d4gg4omi7lrsi15rn7nonlrn4i@4ax.com>
Josef Moellers <josef.moellers@fujitsu-siemens.com> wrote:
>Jürgen Exner wrote:
[...]
>> 1: the dollar sign in a RE is only special if it is the last character in
>> the RE. In that case and only in that case it anchors(!) the RE to the end
>> of the string. It does not(!) match the newline character.
[...]
> m Treat string as multiple lines. That is, change "^"
> and "$" from matching the start or end of the string
> to matching the start or end of any line anywhere
> within the string.
Ooops! Somehow I must have gotten something badly mixed up.
>You may be right in that a $ is only special at the end of the RE,
>though, so I won't be able to match across line boundaries.
>
> > So the RE matches the text 'word' followed by the content of $var
> > interpreted as a RE.
You may want to ignore this :-((
jue
------------------------------
Date: Tue, 22 Jan 2008 10:43:31 -0800 (PST)
From: sharon@blue-linedesign.com
Subject: XML Reference problem
Message-Id: <2256e008-7e33-4cb6-8cab-77badc6d8f11@s8g2000prg.googlegroups.com>
I have an XML hash that has $xmlResults->{Ack} = Failure
I use an if statement with $xmlResults->{Ack} == "Success" and getting
true instead of false.
I about to pull some hairs about and I don't have to many left, please
help me save the last ones I have.
thanks
Arik
------------------------------
Date: Tue, 22 Jan 2008 18:54:59 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: XML Reference problem
Message-Id: <87odbdoflo.fsf@hacking.dk>
sharon@blue-linedesign.com writes:
> I use an if statement with $xmlResults->{Ack} == "Success" and getting
> true instead of false.
When comparing strings you have to use the string comparison operator
instead of the number comparison operator. That is to use
'$xmlResults->{Ack} eq "Sucess"' instead.
By using '==' you're comparing the numeric value of both sides, which
is very probale 0.
//Makholm
------------------------------
Date: Tue, 22 Jan 2008 11:01:04 -0800 (PST)
From: sharon@blue-linedesign.com
Subject: Re: XML Reference problem
Message-Id: <5ee9f285-33c5-4dac-8d33-6f55d60f7e51@l1g2000hsa.googlegroups.com>
On Jan 22, 10:54 am, Peter Makholm <pe...@makholm.net> wrote:
> sha...@blue-linedesign.com writes:
> > I use an if statement with $xmlResults->{Ack} == "Success" and getting
> > true instead of false.
>
> When comparing strings you have to use the string comparison operator
> instead of the number comparison operator. That is to use
> '$xmlResults->{Ack} eq "Sucess"' instead.
>
> By using '==' you're comparing the numeric value of both sides, which
> is very probale 0.
>
> //Makholm
I'm not going to be completely bold after all, thanks a lot
------------------------------
Date: Tue, 22 Jan 2008 13:47:02 -0800 (PST)
From: sharon@blue-linedesign.com
Subject: XML results questions
Message-Id: <8e07a530-aa04-4db2-a574-d10442feca48@u10g2000prn.googlegroups.com>
I'm retrieving an XML result from a website and the the result changes
according to the number of Items returned.
if only one item returned the XML use a hash to hold the name and
value, however if more then one Item was returned it uses an Array to
hold all the results.
I'm trying to right a foreach statement to extract all the information
and when I get one Item I get an error that this is not an Aray
referance (which is obvius).
does anyone have a seggestion, how can I find if the results are in an
array or a hash?
Thanks
Arik
------------------------------
Date: Tue, 22 Jan 2008 13:55:37 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: XML results questions
Message-Id: <34f9575c-04ed-46cc-aaef-3074037e651c@k39g2000hsf.googlegroups.com>
On Jan 22, 4:47 pm, sha...@blue-linedesign.com wrote:
> I'm retrieving an XML result from a website and the the result changes
> according to the number of Items returned.
> if only one item returned the XML use a hash to hold the name and
> value, however if more then one Item was returned it uses an Array to
> hold all the results.
> I'm trying to right a foreach statement to extract all the information
> and when I get one Item I get an error that this is not an Aray
> referance (which is obvius).
> does anyone have a seggestion, how can I find if the results are in an
> array or a hash?
>
> Thanks
> Arik
Some subs return either a scalar or list based on context
which may be the problem you are having. If you posted
the code which is returning the morphing value and the
way that you are calling it then someone might be able
to help you.
--S
------------------------------
Date: Tue, 22 Jan 2008 14:02:45 -0800 (PST)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: XML results questions
Message-Id: <e14331f8-654d-420a-906e-2c95687d0381@h11g2000prf.googlegroups.com>
On Jan 22, 4:47=A0pm, sha...@blue-linedesign.com wrote:
> I'm retrieving an XML result from a website and the the result changes
> according to the number of Items returned.
> if only one item returned the XML use a hash to hold the name and
> value, however if more then one Item was returned it uses an Array to
> hold all the results.
> I'm trying to right a foreach statement to extract all the information
> and when I get one Item I get an error that this is not an Aray
> referance (which is obvius).
> does anyone have a seggestion, how can I find if the results are in an
> array or a hash?
Since you're dealing with references, this is easy.
There's a built-in function (ref) which does precisely this.
if ( ref($r) eq 'HASH' ) {
print "r is a reference to a hash.\n";
}
else if ( ref($r) eq 'ARRAY' ) {
print "\$r is an array ref.\n";
}
HTH
------------------------------
Date: Tue, 22 Jan 2008 16:07:49 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: XML results questions
Message-Id: <47966936$0$503$815e3792@news.qwest.net>
nolo contendere wrote:
> On Jan 22, 4:47 pm, sha...@blue-linedesign.com wrote:
>> I'm retrieving an XML result from a website and the the result changes
>> according to the number of Items returned.
>> if only one item returned the XML use a hash to hold the name and
>> value, however if more then one Item was returned it uses an Array to
>> hold all the results.
>> I'm trying to right a foreach statement to extract all the information
>> and when I get one Item I get an error that this is not an Aray
>> referance (which is obvius).
>> does anyone have a seggestion, how can I find if the results are in an
>> array or a hash?
>
> Since you're dealing with references, this is easy.
>
> There's a built-in function (ref) which does precisely this.
> if ( ref($r) eq 'HASH' ) {
> print "r is a reference to a hash.\n";
> }
> else if ( ref($r) eq 'ARRAY' ) {
> print "\$r is an array ref.\n";
> }
In addition, if you're using XML::Simple, read the documentation for
ForceArray.
------------------------------
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 V11 Issue 1224
***************************************