[24988] in Perl-Users-Digest
Perl-Users Digest, Issue: 7238 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 13 00:07:05 2004
Date: Tue, 12 Oct 2004 21: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)
Perl-Users Digest Tue, 12 Oct 2004 Volume: 10 Number: 7238
Today's topics:
Re: a problem with variable interpolation.. <jurgenex@hotmail.com>
Re: Acceptible idiom ? <gifford@umich.edu>
Creating a random uniqie directory <Deke@nospam.com>
Re: Creating a random uniqie directory <postmaster@castleamber.com>
Fetching to and from and subject from MIME:Parser <Deke@nospam.com>
Re: File extension extraction from filename <usa1@llenroc.ude.invalid>
Re: File extension extraction from filename <jurgenex@hotmail.com>
Re: getting telnet banner (David Efflandt)
Re: Help! Sendmail on Mac OS X Server <vilain@spamcop.net>
Re: Help! Sendmail on Mac OS X Server <usa1@llenroc.ude.invalid>
Re: Help! Sendmail on Mac OS X Server <vilain@spamcop.net>
Re: Help! Sendmail on Mac OS X Server <usa1@llenroc.ude.invalid>
Re: Lagrange Interpolating Polynomial <goofy_headed_punk@msn.com>
Re: Lagrange Interpolating Polynomial (Bidek)
Re: parsing in wrong order? <geoff.cox@removethisplease.freeuk.com>
Trying to force 32-bit in pack() <sammie-nospam@greatergreen.com>
Re: Trying to force 32-bit in pack() <sammie-nospam@greatergreen.com>
Re: Trying to force 32-bit in pack() <usa1@llenroc.ude.invalid>
Re: Trying to force 32-bit in pack() <sammie-nospam@greatergreen.com>
Re: Trying to force 32-bit in pack() <usa1@llenroc.ude.invalid>
Re: Trying to force 32-bit in pack() <sammie-nospam@greatergreen.com>
Re: Trying to force 32-bit in pack() <usa1@llenroc.ude.invalid>
Re: Trying to force 32-bit in pack() <sammie-nospam@greatergreen.com>
Re: undef takes forever <bart.lateur@pandora.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Oct 2004 13:49:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: a problem with variable interpolation..
Message-Id: <Nbwad.3362$y77.849@trnddc05>
Kevin wrote:
> $var1 = 'foo';
> $var2 = 'bar';
> $var3 = 'huh';
>
> $sentence = "\dhdu\$var1\sdjadf\$var2\edjd\$var3";
> print "$sentence";
See "perldoc -q DOS":
Why can't I use "C:\temp\foo" in DOS paths? What doesn't
`C:\temp\foo.exe` work?
On top of that you are escaping the dollar signs, thereby explicitely
telling perl to _not expand the variables $var1, ...
jue
------------------------------
Date: Mon, 11 Oct 2004 11:40:36 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: Acceptible idiom ?
Message-Id: <qsz1xg5e00b.fsf@tetris.gpcc.itd.umich.edu>
"Paul Lalli" <mritty@gmail.com> writes:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:ckdudi$of3$2@mamenchi.zrz.TU-Berlin.DE...
>
>> But anyway, your logic escapes me. Even if it were true that
>> '$a != 0 implies $a ne ""' (which it isn't),
>
> It isn't? Can you give me a non-zero value which is string-equal to the
> empty string?
The problem is warnings. Arithmetically comparing a non-numeric
string, including the empty string, to a numeric value, including 0,
results in a warning under -w:
perl -w -le'print (("" != 0) ? "notzero" : "iszero");'
----Scott.
------------------------------
Date: Tue, 12 Oct 2004 23:33:39 -0400
From: Deke <Deke@nospam.com>
Subject: Creating a random uniqie directory
Message-Id: <10mp8gjmeepiab0@news.supernews.com>
I wanted to create a unique temporary directory for temporary processing
in Perl - since the perl script may be run by several processes at one
time by multiple users. Will someone suggest some efficient CPAN or
builtin function or code for that?
Thanks
------------------------------
Date: 13 Oct 2004 03:39:49 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Creating a random uniqie directory
Message-Id: <Xns9580E68C0D195castleamber@130.133.1.4>
Deke wrote:
> I wanted to create a unique temporary directory for temporary processing
> in Perl - since the perl script may be run by several processes at one
> time by multiple users. Will someone suggest some efficient CPAN or
> builtin function or code for that?
Are "random" named temp files not sufficient enough?
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Tue, 12 Oct 2004 23:40:53 -0400
From: Deke <Deke@nospam.com>
Subject: Fetching to and from and subject from MIME:Parser
Message-Id: <10mp8u7c99t3ff4@news.supernews.com>
When using MIME:Parser, how can one fetch the subject:, to: and from:
fields from the email message?
Thanks
------------------------------
Date: 12 Oct 2004 22:13:00 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: File extension extraction from filename
Message-Id: <Xns9580B997D69AAasu1cornelledu@132.236.56.8>
Deke <Deke@nospam.com> wrote in news:10mojl1hbb74va0@news.supernews.com:
> How does one extract check for the file extension part or a filename in
> Perl?
I assume the filenames you are interested in are in the following format:
name.extension
That is, I am going to require that the extension of
.bashrc
is blank.
We are interested in the string following the last period in the name:
#! /usr/bin/perl
use strict;
use warnings;
my @list = qw(name name.extension .extension);
for (@list) {
my ($ext) = /.+\.(\w+)?$/;
defined $ext or $ext = '';
print "Name: $_\tExtension: $ext\n";
}
__END__
Also, look into File::Basename::fileparse
http://search.cpan.org/~nwclark/perl-5.8.5/lib/File/Basename.pm
Sinan.
------------------------------
Date: Wed, 13 Oct 2004 01:24:00 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: File extension extraction from filename
Message-Id: <Qs%ad.5279$YU4.1860@trnddc06>
Deke wrote:
> How does one extract check for the file extension part or a filename
> in Perl?
Any particular problems with File::Basename?
jue
------------------------------
Date: Tue, 12 Oct 2004 23:32:35 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: getting telnet banner
Message-Id: <slrncmoqcj.44o.efflandt@typhoon.xnet.com>
On Sat, 09 Oct 2004 06:31:56 GMT, Zebee Johnstone <zebee@zip.com.au> wrote:
> In comp.lang.perl.misc on Sat, 9 Oct 2004 04:56:51 +0000 (UTC)
> David Efflandt <efflandt@xnet.com> wrote:
>>
>> I don't know if a telnet banner typically has more than one line (I use
>> ssh instead), but following is a simple example that can read/print a line
>> (works as well for polling smtp servers, etc.):
>
> Mine does... it's one of the reasons I want to read it, as it changes
> depending on certain events.
>
>>
>> use IO::Socket;
>> $remote = IO::Socket::INET->new (
>> Proto => "tcp",
>> PeerAddr => "localhost",
>> PeerPort => "telnet(21)",
>> )
>> or die "can't connect";
>> $_ = <$remote>;
>> print;
>
>
> I can't find any of those items in the IO::Socket perldoc, where do they
> come from? What's the "telnet(21)" thing, telnet's port 23?
My mistake about the telnet port (21 is ftp). The snippet is modified
from something in "perldoc perlipc".
> I tested it on my system and tcpdump tells me it is connecting, but I
> see no output and it doesn't exit, same symptoms as my original program.
>
> If I turn off telnet, then it correctly dies.
Maybe I was mistaken about it working for telnet. I use something similar
to read status of servers that return a 1 line status (smtp, ftp, etc.),
or a loop to send a request and read http reply headers headers (and/or
content). I don't have a local telnetd to test it on and when I tried it
to my Unix ISP (which should have returned a banner with SunOS version) it
hung with no output..
------------------------------
Date: Tue, 12 Oct 2004 15:27:55 -0700
From: "Michael Vilain <vilain@spamcop.net>"
Subject: Re: Help! Sendmail on Mac OS X Server
Message-Id: <vilain-CAEA01.15275512102004@comcast.dca.giganews.com>
In article <MPG.1bd5f22e529cc70e9896b6@news.tc.umn.edu>,
Terry <gobeyondgobeyond@Rem0ve.Yahoo.com> wrote:
> Hi,
>
> I am having trouble running a perl script on a Mac OS X (Panther)
> server. This script ran okay on a Linux web server so I know the script
> is okay. The script uses Sendmail to send an email message as
> following.
>
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_01\n";
> print M "From: $address_from\n";
> ...
> # content of message
>
> close (M);
>
>
> I tested the OS X server with some simple perl scripts without using
> Sendmail and they worked fine. So, I guess the perl interpretor was
> working okay. I was thinking that maybe my script was having trouble
> with Sendmail.
>
> I did a "whereis sendmail" and it returned "/usr/sbin/sendmail". Does
> this mean that sendmail is installed? If I used Postfix, how do I
> change the perl script?
>
> Can someone give me some troubleshooting/configuration tips on Sendmail
> for Mac OS server (Panther)? I never worked on Mac server before.
>
> Thanks in advance!
>
> Terry
I have a contact.cgi script that does the following:
open (MAIL, "|/usr/sbin/sendmail $recipient") || die "Can't open
$mailprog!\n";
In subsequent lines, it writes a Subject:, Reply-To:, and Cc: line
before appending the body of the message. Works just fine on MacOS X
10.3.5.
Have you read the man page for sendmail on MacOS X? It's not the real
sendmail from 10.2.8. It's an interface into postfix.
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: 12 Oct 2004 22:43:53 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Help! Sendmail on Mac OS X Server
Message-Id: <Xns9580BED4ADA90asu1cornelledu@132.236.56.8>
"Michael Vilain <vilain@spamcop.net>" wrote in
news:vilain-CAEA01.15275512102004@comcast.dca.giganews.com:
> I have a contact.cgi script that does the following:
>
> open (MAIL, "|/usr/sbin/sendmail $recipient") || die "Can't open
> $mailprog!\n";
There is no point in passing possibly dangerous data on to the shell.
You should take Keith's advice and use one of the Mail:: modules on CPAN.
Sinan.
------------------------------
Date: Tue, 12 Oct 2004 17:55:26 -0700
From: "Michael Vilain <vilain@spamcop.net>"
Subject: Re: Help! Sendmail on Mac OS X Server
Message-Id: <vilain-55EBED.17552612102004@comcast.dca.giganews.com>
In article <Xns9580BED4ADA90asu1cornelledu@132.236.56.8>,
"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote:
> "Michael Vilain <vilain@spamcop.net>" wrote in
> news:vilain-CAEA01.15275512102004@comcast.dca.giganews.com:
>
> > I have a contact.cgi script that does the following:
> >
> > open (MAIL, "|/usr/sbin/sendmail $recipient") || die "Can't open
> > $mailprog!\n";
>
> There is no point in passing possibly dangerous data on to the shell.
>
> You should take Keith's advice and use one of the Mail:: modules on CPAN.
>
> Sinan.
Unfortunately, my hosting company won't change their perl or php
configuration for me, so I'm stuck using what works. I see the point in
this problem and will fix this approach but can't use CPAN modules
beyond what they have installed. I don't think anything short of my own
co-located server which would cost way more than $30/month would get me
Thanks for the suggestion though.
--
DeeDee, don't press that button! DeeDee! NO! Dee...
------------------------------
Date: 13 Oct 2004 01:04:25 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Help! Sendmail on Mac OS X Server
Message-Id: <Xns9580D6A74A2Dasu1cornelledu@132.236.56.8>
"Michael Vilain <vilain@spamcop.net>" wrote in
news:vilain-55EBED.17552612102004@comcast.dca.giganews.com:
> In article <Xns9580BED4ADA90asu1cornelledu@132.236.56.8>,
> "A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote:
>
>> "Michael Vilain <vilain@spamcop.net>" wrote in
>> news:vilain-CAEA01.15275512102004@comcast.dca.giganews.com:
>>
>> > I have a contact.cgi script that does the following:
>> >
>> > open (MAIL, "|/usr/sbin/sendmail $recipient") || die "Can't open
>> > $mailprog!\n";
>>
>> There is no point in passing possibly dangerous data on to the shell.
>>
>> You should take Keith's advice and use one of the Mail:: modules on
>> CPAN.
> Unfortunately, my hosting company won't change their perl or php
> configuration for me, so I'm stuck using what works.
Not true.
perldoc -q lib
> I see the point in this problem and will fix this approach but
> can't use CPAN modules beyond what they have installed.
> I don't think anything short of my own co-located server
> which would cost way more than $30/month would get me
See what you can get for that money.
http://www.linode.com/products/linodes.cfm
On the cheap side, try:
http://www.digitalspace.net/webhosting/
Sinan.
------------------------------
Date: Tue, 12 Oct 2004 21:35:48 -0500
From: Brian Troutwine <goofy_headed_punk@msn.com>
Subject: Re: Lagrange Interpolating Polynomial
Message-Id: <pan.2004.10.13.02.35.47.7099@msn.com>
On Tue, 12 Oct 2004 12:48:52 +0100, Ben Morrow wrote:
> You could try changing to ::GMP or something to see if it makes
> a difference.
Unfortunately, I need rational number support, and since Math::Fraction
doesn't work particularly well, BigRat seems my best option. Do you know
of any better? (I looked into ::GMP, but that seemed to be large numbers
and not large rationals numbers.)
------------------------------
Date: 12 Oct 2004 19:48:29 -0700
From: darek56@yahoo.com (Bidek)
Subject: Re: Lagrange Interpolating Polynomial
Message-Id: <8fc9aa6f.0410121848.5e87792e@posting.google.com>
Brian,
Have you tries the Newton's method instead, here's a suggestion.
The following Perl program estimates the roots of a polynomial using
Newton's method and Horner's rule.
#################################################
#!/opt/perl/5.8.0/bin/perl -w
use Data::Dumper;
use constant EPSILON => 10 ** -10;
use constant { DEBUG => 0, OUTPUT => 1 };
my @polynomial = qw( 4 -44 165 -224 49 );
print_poly (@polynomial);
@roots = NewtonMethod (@polynomial);
print_roots (@roots);
exit 0;
sub NewtonMethod {
local (@P) = @_;
local (@Q, @PP, @QP, @results) = @P;
local ($count) = ($#P);
# calculate the derivative of the polynomial
for ($i=1; $i <= $count; $i++) {
$QP[$i - 1] = $PP[$i - 1] = $i * $P[$i];
}
do {
# initialize the root with a "small" random number
$x = rand(); # INIT_X;
$val = HornerRule ($count - 1, $x, @Q);
$iteration = 0;
print "=" x 40, "\n" if OUTPUT;
LOOP:
$iteration ++;
my $dx = $val / HornerRule ($count - 1, $x, @QP);
if (abs($dx) > EPSILON) {
for ($c = 0; $c < 40; $c++) {
$y = $x - $dx;
$tmp_val = HornerRule($count, $y, @Q);
printf "I: %3d X: %13.10f Px: %13.10f\n", $iteration, $y, $tmp_val if OUTPUT;
if ($tmp_val ** 2 < $val ** 2) {
$x = $y, $val = $tmp_val;
goto LOOP;
}
$dx /= 4.0;
}
}
# evaluate the polynomial and its derivative
$Px = HornerRule($#P, $x, @P);
$PPx = HornerRule($#P - 1, $x, @PP);
# apply Newton's formula
if ($PPx != 0.0) {
$x -= $Px / $PPx;
$Px = HornerRule($#P, $x, @P);
$PPx = HornerRule($#P - 1, $x, @PP);
# apply Newton's formula a second time
$x -= $Px / $PPx if $PPx;
}
if (abs($x) > EPSILON) {
push @results, $x;
# deflate the polynomial by a linear factor
$A[$count - 1] = $Q[$count];
for ($i = $count - 1; $i >= 1; $i--) {
$A[$i - 1] = $Q[$i] + $x * $A[$i];
}
$count--;
@Q = @A;
}
# calculate the derivative of Q(x)
for ($i = 1; $i <= $count; $i++) {
$QP[$i - 1] = $i * $Q[$i];
}
} while $count > 0;
print Dumper @results if DEBUG;
@results;
}
sub HornerRule {
local ($n, $x, @P) = @_;
local ($result) = $P[$n];
print "=" x 20,"\n", Dumper $n, $x, @P if DEBUG;
for ($i=$n-1; $i >= 0; $i--) {
$result = $result * $x + $P[$i];
}
$result;
}
sub print_roots {
local (@R) = @_;
print "\nThe roots are: \n" , '-' x 20, "\n";
for ($i=0; $i<=$#R; $i++) {
printf "%d = %16.13f\n", $i+1, $R[$i];
}
print "-" x 20,"\n";
}
sub print_poly {
local (@P) = @_;
print "-" x 20,"\n";
print "The polynomial is: \n", '-' x 20, "\n";
for ($i = $#P; $i>0; $i--) {
printf "%5d + 0.0x * X^%d + \n", $P[$i], $i;
}
printf "%5d + 0.0x\n", $P[0], $i;
print "-" x 20,"\n";
return 0;
}
------------------------------
Date: Wed, 13 Oct 2004 00:50:10 GMT
From: Geoff Cox <geoff.cox@removethisplease.freeuk.com>
Subject: Re: parsing in wrong order?
Message-Id: <eouom09nia19d097vrujs56o2an6sv7svc@4ax.com>
On Tue, 12 Oct 2004 20:20:13 GMT, Geoff Cox
<geoff.cox@removethisplease.freeuk.com> wrote:
I seem to have found the error - of all things it seems to be an HTML
error !
Cheers
Geoff
>Hello,
>
>I have just come back to the kind of code shown in the extract below -
>problem is that although the code works, it does not output the data
>in the same order as in the html files.
>
> I would like to get successive sections of
>
><h2>
><p>
><options>
>
>but am getitng all the <h2> and <p> and then all the <options> data.
>
>Can anyone see the "obvious" from the code below?
>
>The
>
> if ( $tagname eq 'option' ) {
>
> main::choice( $attr->{ value } );
>
> }
>
>ought, I would have thought, go off and get the <option> data and then
>return to work through the html in the order found in the html file??
>
>Cheers
>
>Geoff
>
>
>
>package MyParser;
>use base qw(HTML::Parser);
>use strict;
>use diagnostics;
>
>my ($in_heading,$in_p, $fh);
>
>sub register_fh {
>$fh = $_[1];
>}
>
>sub reset { ($in_heading,$in_p)=(0,0)}
>
>sub start {
>
> my ( $self, $tagname, $attr, undef, $origtext ) = @_;
>
> if ( $tagname eq 'h2' ) {
> $in_heading = 1;
> return;
> }
>
> if ( $tagname eq 'p' ) {
> $in_p = 1;
> return;
> }
>
> if ( $tagname eq 'option' ) {
>
> main::choice( $attr->{ value } );
>
> }
>
>}
>
>sub end {
> my ( $self, $tagname, $origtext ) = @_;
> if ( $tagname eq 'h2' ) {
> $in_heading = 0;
> return;
> }
>
> if ( $tagname eq 'p' ) {
> $in_p = 0;
> return;
> }
>}
>
>sub text {
> my ( $self, $origtext ) = @_;
> print $fh "<h2>$origtext</h2> \n" if $in_heading;
> print $fh "<p>$origtext</p> \n" if $in_p;
>
>}
>
>package main;
>
>use File::Find;
------------------------------
Date: Tue, 12 Oct 2004 16:19:13 -0700
From: "Brad Walton" <sammie-nospam@greatergreen.com>
Subject: Trying to force 32-bit in pack()
Message-Id: <AN6dnVxQ75fw-_HcRVn-tA@comcast.com>
I am trying to force 32-bit integers in this pack statement:
pack("iiiaa", 18, 1, 3, "password", "");
18+2+3 should = 22 bytes sent
Instead it is only sending 14 bytes. Is there a way to _force_ 32-bits?
Thanks for any help,
Brad
------------------------------
Date: Tue, 12 Oct 2004 16:27:29 -0700
From: "Brad Walton" <sammie-nospam@greatergreen.com>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <6MidnclxLtey9fHcRVn-jQ@comcast.com>
> 18+2+3 should = 22 bytes sent
Typo there.. should be 18+1+3 = 22
------------------------------
Date: 13 Oct 2004 01:34:02 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <Xns9580DBAC74C97asu1cornelledu@132.236.56.8>
"Brad Walton" <sammie-nospam@greatergreen.com> wrote in news:AN6dnVxQ75fw-
_HcRVn-tA@comcast.com:
> I am trying to force 32-bit integers in this pack statement:
>
> pack("iiiaa", 18, 1, 3, "password", "");
>
> 18+2+3 should = 22 bytes sent
>
> Instead it is only sending 14 bytes.
How did you come to that conclusion?
From perldoc -f pack:
With all types except "a", "A", "Z", "b", "B", "h",
"H", "@", "x", "X" and "P" the pack function will
gobble up that many values from the LIST.
> Is there a way to _force_ 32-bits?
From the same document:
l A signed long value.
L An unsigned long value.
(This 'long' is _exactly_ 32 bits, which may differ from
what a local C compiler calls 'long'. If you want
native-length longs, use the '!' suffix.)
But this is irrelevant because you have misdiagnosed the problem. Just
looking at the hex dump of the result of your pack should have given you a
clue (which is exactly what I did before anything else, because pack is
magic to me):
0000000: 1200 0000 0100 0000 0300 0000 7000
That is 18, 1, 3 and 'p' and '' on a x86 platform.
The solution is to use:
pack('iiiZ*Z*', 18, 1, 3, 'password', '');
On the other hand, if you are sending this stuff over the network you
probably want something else.
Sinan.
------------------------------
Date: Tue, 12 Oct 2004 18:52:29 -0700
From: "Brad Walton" <sammie-nospam@greatergreen.com>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <bsOdnWkLCuH1FPHcRVn-qA@comcast.com>
> But this is irrelevant because you have misdiagnosed the problem. Just
> looking at the hex dump of the result of your pack should have given you a
> clue (which is exactly what I did before anything else, because pack is
> magic to me):
>
> 0000000: 1200 0000 0100 0000 0300 0000 7000
>
> That is 18, 1, 3 and 'p' and '' on a x86 platform.
>
> The solution is to use:
>
> pack('iiiZ*Z*', 18, 1, 3, 'password', '');
>
> On the other hand, if you are sending this stuff over the network you
> probably want something else.
>
> Sinan.
I broke out a packet sniffer and saw this too. And yes, I am sending this
over a network. I am going to try your suggestion and see what happens. What
else would you suggest?
Thanks,
Brad
------------------------------
Date: 13 Oct 2004 01:53:55 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <Xns9580DF0B39E9Basu1cornelledu@132.236.56.8>
"Brad Walton" <sammie-nospam@greatergreen.com> wrote in
news:bsOdnWkLCuH1FPHcRVn-qA@comcast.com:
> And yes, I am sending this over a network. I am going to
> try your suggestion and see what happens. What else would
> you suggest?
Depends on the protocol you are using. That should specify how things get
interpreted at both ends of the connection.
Sinan.
------------------------------
Date: Tue, 12 Oct 2004 19:12:49 -0700
From: "Brad Walton" <sammie-nospam@greatergreen.com>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <TtydnQoAhad1E_HcRVn-pw@comcast.com>
> > And yes, I am sending this over a network. I am going to
> > try your suggestion and see what happens. What else would
> > you suggest?
>
> Depends on the protocol you are using. That should specify how things get
> interpreted at both ends of the connection.
>
It's a TCP/IP connection. Here's the whole script (with my notes):
#!/usr/bin/perl -w
use strict;
use IO::Socket;
# Connect to the rcon server
print "Connecting to server ... ";
my $sock = new IO::Socket::INET(PeerAddr => '209.209.44.30', PeerPort =>
'27015', proto => 'tcp',);
if (!$sock) {
die "Unable to connect $@\n";
}
print "done\n";
# Now we send something
# The packet structure is as follows:
#
# PACKET {
# 32bits size; # This is the size of the data to follow
# # The 32 bits packet size is not included
# 32bits requestid; # The request identifier. This can be a continuously
# # incrementing value (I think) Used to map responses
# # with requests, (I think).
# 32bits commandid # This rells the server which type of request we are
# # makeing In the example it is a LOGIN #3
#
# Random amounts and types of data follow. The types are allways constant
# for a particular command id.
# };
#
# Note 1 32bit integer would be a size 4. Four * 8 bits.
# A char is 1 8 bits to represent the entire ascii table
#
# The example packet was a login packet #3 with the following structure
#
# COMMAND_LOGIN {
# 32bits size = (requestid + commandid + password + unknown)
# (4 + 4 + (8 + 1) + (0 + 1)) # We count the null char.
# 18; # * 8 bits
# 32bits request = 1; # next is 2, 3....
# 32bits command = 3; # COMMAND_LOGIN
# null terminated char = "password\0"; # \0 == null
# null terminated char = "\0"; #
# };
#
#
# Pack packs the data according to a format string
# integer,integer,integer,null terminated string,null terminated string
print "Constructing packet ... ";
my $login_packet = pack('iiiZ*Z*', 18, 1, 3, 'password', '');
print "done: $login_packet\n";
# Send on the wire
print "Sending packet ... ";
print $sock $login_packet;
print "done\n";
# Dirty hack from Alfred_Reynolds program
# sleep(1);
print "Waiting for response ... ";
my $buf;
if (!$sock->recv($buf, 4)) {
die "bad recv $@\n";
}
my $response_size = unpack("i", $buf);
if (!$sock->recv($buf, $response_size)) {
die "bad recv $@\n";
}
my ($request_id, $command_response, $string1, $string2) = unpack("iiaa",
$buf);
print "received: $request_id, $command_response, $string1, $string2\n";
exit(0);
--------------------------
I am getting proper pack size using Z*.
thanks, Brad
------------------------------
Date: 13 Oct 2004 02:21:19 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <Xns9580E3AFF76A2asu1cornelledu@132.236.56.8>
"Brad Walton" <sammie-nospam@greatergreen.com> wrote in
news:TtydnQoAhad1E_HcRVn-pw@comcast.com:
>> > And yes, I am sending this over a network. I am going to
>> > try your suggestion and see what happens. What else would
>> > you suggest?
>>
>> Depends on the protocol you are using. That should specify how things
>> get interpreted at both ends of the connection.
> It's a TCP/IP connection. Here's the whole script (with my notes):
What is the application protocol?
> # Pack packs the data according to a format string
> # integer,integer,integer,null terminated string,null terminated
> # string
> print "Constructing packet ... ";
> my $login_packet = pack('iiiZ*Z*', 18, 1, 3, 'password', '');
You probably want N rather than i.
However, your script will likely have other problems.
> print "Waiting for response ... ";
> my $buf;
> if (!$sock->recv($buf, 4)) {
> die "bad recv $@\n";
Do you realize that recv is for UDP whereas you have specified a tcp
socket?
Sinan.
------------------------------
Date: Tue, 12 Oct 2004 20:08:38 -0700
From: "Brad Walton" <sammie-nospam@greatergreen.com>
Subject: Re: Trying to force 32-bit in pack()
Message-Id: <_bKdnaJVkOV1BvHcRVn-iw@comcast.com>
> What is the application protocol?
Not sure how to answer that, but this is what is sent to/from:
Size,RequestID,Command,String1,String2(String 2 is always null "")
> Do you realize that recv is for UDP whereas you have specified a tcp
> socket?
No, I did not. One problem I am having, is the response is sent without a
newline. I tried:
$response = <$sock>;
But that expects a newline (right?). I need some way to figure out the
length of data being sent, then read it. I also need to be able to receive
multiple responses to one request. I got lots of issues...
Thanks,
Brad
------------------------------
Date: Tue, 12 Oct 2004 22:58:07 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: undef takes forever
Message-Id: <f3oom0p994q34epv1mmhoqngtqf0364has@4ax.com>
KKramsch wrote:
>so the current version of the script tests for the soundness of
>the stored file by saving the hash to a dummy file first, then
>retrieving the hash from memory into a temporary variable $temp,
>and making sure that $temp is defined and that %$temp has the right
>number of keys. If all this is as it should be, then the dummy
>file is used to overwrite the old version of the hash stored on
>disk.
>
> It turns out, however, that this version of the script is about
>10x slower than the original version,
I think the extra slowness is due to your memory being full,causing
extensive swapping.
I'd try to move the check to an external script, which needn't be so
careful about carefully releasing all memory. If necessary, you can
shortcircuit the garbage collection for that external script using a
carefully chosen exec().
--
Bart.
------------------------------
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 7238
***************************************