[19951] in Perl-Users-Digest
Perl-Users Digest, Issue: 2146 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 17 03:05:36 2001
Date: Sat, 17 Nov 2001 00:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005984310-v10-i2146@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 17 Nov 2001 Volume: 10 Number: 2146
Today's topics:
Re: attach file <hkdennis2k@yahoo.com.hk>
Re: Best language for low IQ programmers? (Kirsten Bayes)
Re: Best language for low IQ programmers? (Alexandre)
Re: Binary issues.. <mds@wam.umd.edu>
Re: Binary issues.. <mds@wam.umd.edu>
Re: Binary issues.. <mgjv@tradingpost.com.au>
Re: Binary issues.. <joe+usenet@sunstarsys.com>
Re: Binary issues.. <mds@wam.umd.edu>
Re: Binary issues.. <mgjv@tradingpost.com.au>
Re: Can someone tell me what i am doing wrong. Unix soc (David Efflandt)
Cancel button to exit confirmation page? (David Kenneally)
Re: Compilation error (Houda Araj)
Re: Compilation error <nobody@nowhere.com>
Re: Extracting number from an string <Tassilo.Parseval@post.rwth-aachen.de>
Re: Fast Portable Logical Shift Right in Perl ? <joe+usenet@sunstarsys.com>
Re: Fast Portable Logical Shift Right in Perl ? <slytobias@home.com>
Re: maximum input buffer length exceeded <mrp@hafatel.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Nov 2001 15:53:33 +0800
From: "Dennis" <hkdennis2k@yahoo.com.hk>
Subject: Re: attach file
Message-Id: <9t54jc$fhj4@rain.i-cable.com>
This is a multi-part message in MIME format.
------=_NextPart_000_029C_01C16F80.02A74C20
Content-Type: text/plain;
charset="big5"
Content-Transfer-Encoding: 7bit
Take this,
--
Dennis
======
Homepage(chinese)
http://hkdennis2k.virtualave.net
------=_NextPart_000_029C_01C16F80.02A74C20
Content-Type: application/octet-stream;
name="attach_email.cgi"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="attach_email.cgi"
#!/usr/local/bin/perl
$sendmail=3D'/var/qmail/bin/qmail-inject';
$to_email=3D'"hkdennis2k" <hkdennis2k@yahoo.com.hk>';
$from_email=3D'"hkdennis2k" <hkdennis2k@yahoo.com.hk>';
eval{
use CGI;
use MIME::Base64;
$query=3Dnew CGI;
};
&error("=B3o=AD=D3 CGI =BB=DD=ADn=A5=CE=A4W cgi.pm =A9M mime::base64 =
=B3o=A8=E2=AD=D3 Perl 5.005 =AA=BA=B5{=A6=A1=AEw=A1I<br>$@ <br>$!") =
if($@);
if($ENV{REQUEST_METHOD}=3D~/POST/i){
&error('=B1z=ACO=B1q=A8=BA=A8=E0=A8=D3=A7r=A1H') if($ENV{HTTP_REFERER} =
ne $ENV{SCRIPT_URI});
$filename=3D$query->param('upfile');
&error('=B1z=A7=D1=B0O=A4F=ADn=BF=EF=A4W=B8=FC=AA=BA=B9=CF=A4=F9') =
unless($filename);
$filename=3D~s/.*[\/|\\]//g;
$filename=3D~s/\s/_/g;
$file_handle=3D$query->param('upfile');
binmode($file_handle);
srand;
$boundary=3D'------------boundary_'.time.'_'.rand(time);
&error('=B1z=A7=D1=B0O=A4F=A5=B4=A4J =
subject')unless($subject=3D$query->param('subject'));
&error('=B1z=A7=D1=B0O=A4F=A5=B4=A4J =
message')unless($message=3D$query->param('message'));
&error('=B1z=A7=D1=B0O=A4F=A5=B4=A4J=B1z=AA=BA=A6W=A6r =
')unless($from_name=3D$query->param('from'));
&error('=B1z=A7=D1=B0O=A4F=A5=B4=A4J=B1z=AA=BA=A6W=A6r =
')unless($from_eml=3D$query->param('email'));
open(MAIL,"|$sendmail -t")||&error('=A4=A3=AF=E0=B0=F5=A6=E6 =
sendmail');
print MAIL<<END_OF_MAIL;
From: $from_email
To: $to_email
Subject: $subject
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=3D"$boundary"
This is a multi-part message in MIME format.
--$boundary
Content-type: text/plain;
charset=3D"big5"
Content-Transfer-Encoding: 8bit
$from_name
$from_eml
--
$message
END_OF_MAIL
print MAIL "--$boundary\n";
print MAIL "Content-type: image/jpeg;\n\tname=3D\"$filename\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-disposition: =
attachment;\n\tfilename=3D\"$filename\"\n\n";
while(read($file_handle,$buf,60*57)){
print MAIL encode_base64($buf);
}
print MAIL "\n\n--$boundary--";
close(MAIL);
print<<HTML;
Content-type: text/html; charset=3Dbig5
Content-language: zh-tw
Pragma: no-cache
Cache-control: no-cache, must-revalidate, private
Expires: Thu, 1 Jan 1970 00:00:00 GMT
<html><head
><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dbig5"
><meta http-equiv=3D"Content-Language" content=3D"zh-tw"
><meta http-equiv=3D"Pragma" content=3D"no-cache"
><meta http-equiv=3D"Cache-control" content=3D"no-cache, =
must-revalidate, private"
><meta http-equiv=3D"Expires" content=3D"Thu, 1 Jan 1970 00:00:00 GMT"
><meta name=3D"GENERATOR" content=3D"=A4=DF=C2=C5 Dennis"
><meta name=3D"AUTHOR" content=3D"=A4=DF=C2=C5 Dennis"
></head><body>\=A4w\=B8g\=A6=A8\=A5\\=B0e\=A5X\=A1I\<br><br>
From: $from_email
To: $to_email
Subject: $subject
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=3D"$boundary"
This is a multi-part message in MIME format.
--$boundary
Content-type: text/plain;
charset=3D"big5"
Content-Transfer-Encoding: 8bit
$from_name
$from_eml
--
$message
</body></html>
HTML
foreach(<CGItemp*>){unlink;}
exit;
}
print<<HTML;
Content-type: text/html; charset=3Dbig5
Content-language: zh-tw
Pragma: no-cache
Cache-control: no-cache, must-revalidate, private
Expires: Thu, 1 Jan 1970 00:00:00 GMT
<html><head
><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dbig5"
><meta http-equiv=3D"Content-Language" content=3D"zh-tw"
><meta http-equiv=3D"Pragma" content=3D"no-cache"
><meta http-equiv=3D"Cache-control" content=3D"no-cache, =
must-revalidate, private"
><meta http-equiv=3D"Expires" content=3D"Thu, 1 Jan 1970 00:00:00 GMT"
><meta name=3D"Generator" content=3D"=A4=DF=C2=C5 Dennis"
><meta name=3D"Author" content=3D"=A4=DF=C2=C5 Dennis"
></head><body><form method=3D"POST" enctype=3D"multipart/form-data">
=B1z=AA=BA=A6W=A6r : <input type=3D"text" name=3D"from"><br>
=B1z=AA=BA E-mail : <input type=3D"text" name=3D"email"><br>
=A5D=A6=AE :<input type=3D"text" name=3D"subject"><br>
=AA=FE=A5=F3 :<input type=3D"file" name=3D"upfile"><br>
<textarea name=3D"message"></textarea><br>
<input type=3D"submit">
</form></body></html>
HTML
sub error{
my $error_message=3D$_[0];
print<<HTML;
Content-type: text/html; charset=3Dbig5
Content-language: zh-tw
Pragma: no-cache
Cache-control: no-cache, must-revalidate, private
Expires: Thu, 1 Jan 1970 00:00:00 GMT
<html><head
><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dbig5"
><meta http-equiv=3D"Content-Language" content=3D"zh-tw"
><meta http-equiv=3D"Pragma" content=3D"no-cache"
><meta http-equiv=3D"Cache-control" content=3D"no-cache, =
must-revalidate, private"
><meta http-equiv=3D"Expires" content=3D"Thu, 1 Jan 1970 00:00:00 GMT"
><meta name=3D"GENERATOR" content=3D"=A4=DF=C2=C5 Dennis"
><meta name=3D"AUTHOR" content=3D"=A4=DF=C2=C5 Dennis"
></head><body>=B5o=A5=CD=BF=F9=BB~=A1I<br
>$error_message<br
>=BD=D0=A6^=A4W=AD=B6=A6A=B8=D5</body></html>
HTML
foreach(<CGItemp*>){unlink;}
exit;
}
------=_NextPart_000_029C_01C16F80.02A74C20--
------------------------------
Date: 16 Nov 2001 18:13:14 -0800
From: KirstenBayes@aol.com (Kirsten Bayes)
Subject: Re: Best language for low IQ programmers?
Message-Id: <3e68a8bb.0111161813.77de6474@posting.google.com>
BrianMetc@aol.com (Brian Metc) wrote in message news:<1004990076967295@aol.com>...
> I would like to get into the programing field. My problem is that I have low IQ due to
> early childhool learning deprivation and TV overdose. Simply said I am stuped, I am
> pretty good amongst my friends, but not solving problems. You know what I
> mean. Anyways, I want to go into computor programing because of money
> issue. I now need to choose languege for programming, simple enough
> for me.
>
> My friend wh does C plus plus recommended that I learn either Visual Basic or Eiffel.
> My ex girlfriend who is a sys admin who did perl, sugested that I learn Ada because
> it has "serious type system" which is fool proof.
>
> She dis couraged me from using Eiffel because itr was a language going out of the
> market, no longer used by any serious corporation, She said the same thing for Ada.
>
> Java is simple compared to c plus plus but a scam language, based on hype.
>
> This only leaves visual basic. Especally because it is used under Windows, Microsoft
> stuff is always easier.
>
> Would any one sugest the best language for me.
>
> Brian
Dear Brian
If marketability is what you want, it's often good to go with the
scripting languages of popular systems. So, for UNIX that's C/C++ and
Perl, for Windows its Visual Basic & VBScript, for web apps its Java &
Javascript.
New languages grow from the established base, so up and coming
languages like PHP or Python owe alot to Perl, for example. Start with
what's out there, before moving onto languages which are out-there.
I'd let your prejudices guide you. Larry Wall, the Perl guy, often
jokes that impatience, laziness and hubris are the essential
characteristics of a good programmer. Lots of people like Microsoft,
many others think Windows is bad enough without writing more of it. A
day without Java is a day without Sun, and that's fine for many
people.
In the end, it's not the language or the platform that matters, but
the person. And, hey, you matter, Brian.
Best wishes
Kirsten
------------------------------
Date: 16 Nov 2001 19:51:48 -0800
From: armence@hotmail.com (Alexandre)
Subject: Re: Best language for low IQ programmers?
Message-Id: <5fa2087e.0111161951.5c1af2a1@posting.google.com>
BrianMetc@aol.com (Brian Metc) wrote in message news:<1004990076967295@aol.com>...
> I would like to get into the programing field. My problem is that I have low IQ due to
> early childhool learning deprivation and TV overdose. Simply said I am stuped, I am
> pretty good amongst my friends, but not solving problems. You know what I
> mean. Anyways, I want to go into computor programing because of money
> issue. I now need to choose languege for programming, simple enough
> for me.
>
> My friend wh does C plus plus recommended that I learn either Visual Basic or Eiffel.
> My ex girlfriend who is a sys admin who did perl, sugested that I learn Ada because
> it has "serious type system" which is fool proof.
>
> She dis couraged me from using Eiffel because itr was a language going out of the
> market, no longer used by any serious corporation, She said the same thing for Ada.
>
> Java is simple compared to c plus plus but a scam language, based on hype.
>
> This only leaves visual basic. Especally because it is used under Windows, Microsoft
> stuff is always easier.
>
> Would any one sugest the best language for me.
>
> Brian
Go away, a good way to formulate you question would be:
I'm a stupid monkey who has no interest in computer science and want
to be a rich ass like bill gates. What should I start with?
If you want an easy language, choose QBASIC, it does exactly what you
deserve to be able do for the effort you want to put in it: almost
nothing, you might if you are lucky be able to writte a book on QBASIC
for monkeys like you who want money without effort != programming (!=
stands for not equal in C). My friendliest advice is get to work on
VB, Perl, Java(it is easier to C/C++ almost as powerful, but still
easy), C++, C, ASM and then you will get a bunch of cash by trying to
choose and love a language (Not VB, no offence, but u dont want to
carry OCXs around). (The normal way is love a language and then since
you are good, you get lots of cash, but it might work the other way
around who knows)
------------------------------
Date: Fri, 16 Nov 2001 22:25:32 -0500
From: "Mike Schmitt" <mds@wam.umd.edu>
Subject: Re: Binary issues..
Message-Id: <9t4lc7$8a5$1@hecate.umd.edu>
sysop wrote in message ...
On Fri, 16 Nov 2001 05:37:01 -0500, Falco98 wrote:
I assume you want to seperate out the data files into individual files
for some sort of inspection, and keep a version of the log file without
the included data files.
open(IN, "log");
open(OUT, ">log.out");
$/="</data>"; #record seperator
while(<IN>){
The problem here is, reading in the file from standard input (or file input
as it were) doesn't preserve the binary stuff for some reason. The solution
I found is to use read() in binmode(), and I got it to work with my test
file. Now my problem is, my real file is ~108 megs, and though the program
works perfectly with the 8 meg test file, it is utterly unproductive with
the test file (if it doesn't run my system out of memory, it just seems to
go dead). I'd like to read the data in by chunks (using "offset" and
"length to read" settings with read()), but I can think of no good way to
read a chunk, process it, then read the next chunk, since there's no way of
telling where the different pieces of the file are located.. if you know
what i mean.
BTW- sorry for double-posting my original query.
------------------------------
Date: Fri, 16 Nov 2001 22:26:22 -0500
From: "Mike Schmitt" <mds@wam.umd.edu>
Subject: Re: Binary issues..
Message-Id: <9t4ldo$8j4$1@hecate.umd.edu>
Martien Verbruggen wrote in message ...
open() it, binmode() the handle, then process with read. Find the <data>
and </data> start and end tags, and do what you need to do.
Searching thru the activePerl help file I stumbled on the read() command.
Now my problem is, my real file is ~108 megs, and though the program works
perfectly with the 8 meg test file, it is utterly unproductive with the test
file (if it doesn't run my system out of memory, it just seems to go dead).
I'd like to read the data in by chunks (using "offset" and "length to read"
settings with read()), but I can think of no good way to read a chunk,
process it, then read the next chunk, since there's no way of telling where
the different pieces of the file are located.. if you know what i mean.
------------------------------
Date: Sat, 17 Nov 2001 16:27:48 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Binary issues..
Message-Id: <slrn9vbtak.3j7.mgjv@martien.heliotrope.home>
On Fri, 16 Nov 2001 22:26:22 -0500,
Mike Schmitt <mds@wam.umd.edu> wrote:
>
> Martien Verbruggen wrote in message ...
>
>> open() it, binmode() the handle, then process with read. Find the <data>
>> and </data> start and end tags, and do what you need to do.
>
> Searching thru the activePerl help file I stumbled on the read() command.
> Now my problem is, my real file is ~108 megs, and though the program works
> perfectly with the 8 meg test file, it is utterly unproductive with the test
> file (if it doesn't run my system out of memory, it just seems to go dead).
> I'd like to read the data in by chunks (using "offset" and "length to read"
> settings with read()), but I can think of no good way to read a chunk,
> process it, then read the next chunk, since there's no way of telling where
> the different pieces of the file are located.. if you know what i mean.
Yes, I do, I think.
You'd need to keep track of possible end segments that could contain
part of a marker you're looking for. I'd look through the file once,
marking up the starts and ends of the data segments, and then I'd seek
through it, just to pull them out. Something like:
#!/usr/local/bin/perl -w
use strict;
use Fcntl qw/ :seek /;
open FILE, "/tmp/data" or die $!;
binmode FILE;
my $old_buf = '';
my $in_data = 0;
my @markers;
my $filepos = 0;
my $marker = "<data>";
while (my $nbytes = read FILE, my $buf, 4096)
{
my $pos = my $old_pos = 0;
$buf = $old_buf . $buf;
while (($pos = index $buf, $marker, $old_pos) > -1)
{
$pos += length $marker unless $in_data;
$in_data ^= 1; #toggle
$marker = $in_data ? "</data>" : "<data>";
push @markers, $filepos + $pos - length $old_buf;
$old_pos = $pos;
}
$filepos += $nbytes;
$old_buf = substr $buf, -length $marker;
}
while (my ($start, $end) = splice @markers, 0, 2)
{
seek FILE, $start, SEEK_SET;
read FILE, my $data, $end - $start;
printf "From $start to $end, %d bytes, [%s..%s]\n",
length $data, substr ($data, 0, 5), substr ($data, -5);
}
This has been tested on a smallish file with four data segments and
various input buffer sizes (varying from 56 to 4096 bytes, where some
values were chosen in such a way that at least one tag was read in two
parts. This should run quite fast. I'd try buffer sizes of about 64 kB
and maybe larger even. Note the binmode. Very important on Windows
systems.
Note that there is no checking for inappropriate <data> or </data> tags
in this code. it just alternately looks for the different marker.
Martien
--
|
Martien Verbruggen | Failure is not an option. It comes
| bundled with your Microsoft product.
|
------------------------------
Date: 17 Nov 2001 00:48:23 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Binary issues..
Message-Id: <m3ofm20wyg.fsf@mumonkan.sunstarsys.com>
"Mike Schmitt" <mds@wam.umd.edu> writes:
> Martien Verbruggen wrote in message ...
>
> > open() it, binmode() the handle, then process with read. Find the
> > <data> and </data> start and end tags, and do what you need to do.
>
> Searching thru the activePerl help file I stumbled on the read()
> command. Now my problem is, my real file is ~108 megs, and though the
> program works perfectly with the 8 meg test file, it is utterly
> unproductive with the test file (if it doesn't run my system out of
> memory, it just seems to go dead). I'd like to read the data in by
> chunks (using "offset" and "length to read" settings with read()), but
> I can think of no good way to read a chunk, process it, then read the
> next chunk, since there's no way of telling where the different pieces
> of the file are located.. if you know what i mean.
Take a look at some of the SAX parsers for XML on CPAN- they're very
effective at coping with this type of problem. If your html is clean
enough, you might be able to get away with using a SAX parser on it;
otherwise you might need to tweak things a bit to suit your needs.
OTOH, if you're just starting out with Perl, that might be too much
to manage. What you need to do is keep track of when you're inside
a data block. Assuming these tags don't break on lines, and the
data blocks are not themselves nested, you could try something like
(untested)
my $data = ''; # holds text inside a <data/> block
while (<FILE>) {
my $have_data = s#.*?<data>##s .. s#(.*?)</data>##s;
# see perlop for scalar .. above
next unless $have_data;
if (substr($have_data,-2) eq "E0") {
# second substitution matched;
# found the end of the <data/> block
$data .= $1; # $data holds an entire block now
do_something($data);
$data = '';
redo; # parse $_ again
}
else {
# still inside a <data/> block,
# but haven't reached the end yet
$data .= $_;
}
}
To convert this code to use read() instead of readline(),
you'll need to account for the possibility that one of your
tags falls on the edge of a single read(). But if the situation
is much more complex than this, you might try one of the SAX
parsers, or maybe Parse::RecDescent instead.
HTH
--
$.=$[|3*rand;$_=67014523;END{print@_};*UNIVERSAL::AUTOLOAD=sub{&A;pop->();++
$#;*A};$.++,*[=*]=*\=sub{$].=pop.(--$#%2?q: ::qq::)};*#=sub{split m, (?<=^.{2})
(.{$.}),x,shift};@#=qw[just another Perl hacker];*A=*AUTOLOAD=sub{split"::",$A;
&]};map{splice@#,$_,1,&#($#[$_])}3,1;$_="@{[@#[m$.$g]]}";s;P;,p;;eval;$\.="\n"
------------------------------
Date: Sat, 17 Nov 2001 01:30:02 -0500
From: "Mike Schmitt" <mds@wam.umd.edu>
Subject: Re: Binary issues..
Message-Id: <9t5067$56r$1@hecate.umd.edu>
Martien Verbruggen wrote in message ...
You'd need to keep track of possible end segments that could contain
part of a marker you're looking for. I'd look through the file once,
marking up the starts and ends of the data segments, and then I'd seek
through it, just to pull them out. Something like:
Wow, you seem to have put some definite thought into this (!)..
for your info, here are the specifics of the file format (in pseudo-RE /
bnf):
<header> := "<hR>** YYYY/MM/DD HH:MM:SS IM with -<screen name>-"
<binary data> := "<DATA id="\d*" size="\d*"><binary information></DATA>"
<body> := <header>\n<message body> | <header>\n<message body><binary data>
<message body> := html of saved AIM sessions (no line breaks, of course)
<content> := <body> | <body><content>
so, not only is it important for me to maintain the integrity of the binary
files, but also of the HTML (since my program saves all the HTML along with
the binaries).
Within the last 10 minutes, i thought of an approach that might work: How
about if i read() through, byte by byte, collecting all bytes into one
variable, until I reach the following <header>? I've already perfected the
algorithm which, when applied to a sample of this data, does the correct
processing, so would this allow me to do what i want? I'm relatively new to
PERL (and really, any low-level programming), so i'm not sure if i'm missing
some limitation. meanwhile, i'm giving it a go.
thanx!
~Mike
programmer / bus driver / skydiver
AIM: Falco98mds
------------------------------
Date: Sat, 17 Nov 2001 18:07:07 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Binary issues..
Message-Id: <slrn9vc34r.3j7.mgjv@martien.heliotrope.home>
[Fixed quoting, once again. Please tell your newsreader to quote text
you refer to]
On Sat, 17 Nov 2001 01:30:02 -0500,
Mike Schmitt <mds@wam.umd.edu> wrote:
> Martien Verbruggen wrote in message ...
>> You'd need to keep track of possible end segments that could contain
>> part of a marker you're looking for. I'd look through the file once,
>> marking up the starts and ends of the data segments, and then I'd seek
>> Wow, you seem to have put some definite thought into this (!)..
Not the first time this sort of problem comes up.
> so, not only is it important for me to maintain the integrity of the binary
> files, but also of the HTML (since my program saves all the HTML along with
> the binaries).
*nod*
> Within the last 10 minutes, i thought of an approach that might work: How
> about if i read() through, byte by byte, collecting all bytes into one
> variable, until I reach the following <header>? I've already perfected the
> algorithm which, when applied to a sample of this data, does the correct
> processing, so would this allow me to do what i want? I'm relatively new to
> PERL (and really, any low-level programming), so i'm not sure if i'm missing
> some limitation. meanwhile, i'm giving it a go.
> thanx!
No need to do it byte by byte. The program I posted could do that, with
a few little changes. I thought you were only interested in the date
segments, so that's all it deals with. The HTML segments are of course
the exact inverse of the data segments, minus the tags themselves.
All you need to do is either keep track of another set of marker, or
change the meaning of @markers to also include the HTML segment markers.
Anyway, it shouldn't be too hard to adapt that code. Reading byte by
byte is almost never a good idea in Perl, even though it would be a good
idea in C.
Martien
--
|
Martien Verbruggen | Can't say that it is, 'cause it
| ain't.
|
------------------------------
Date: Sat, 17 Nov 2001 03:19:57 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Can someone tell me what i am doing wrong. Unix sockets
Message-Id: <slrn9vblqs.kgn.efflandt@typhoon.xnet.com>
On Fri, 16 Nov 2001 11:08:07 -0000, Scott <thechile@ntlworld.com> wrote:
> I am trying to get the below code to print out the data sent to the
> listening port and send a response back to the browser but I can get the
> damn thing working
>
> I open up a listening socket here on port 80 and then this code. It listens
> and prints out the where the connection came from bit but I can't get it to
> print the HTTP 1.0 GET request that the browser should have sent, nor can I
> get the printing to the client stream to work so the browser reports a 404.
>
> while () {
> $paddr = accept(Client,Server);
> my $buf = <$paddr>;
>
> my($port,$iaddr) = sockaddr_in($paddr);
> my $name = gethostbyaddr($iaddr,AF_INET);
>
> print "connection from $name [",inet_ntoa($iaddr), "] at port $port\n";
> print "$buf\n\n";
> print Client "HTTP/1.0 404\n\nContent-type: text/html\n\nBad command";
>
> }
>
> Any help or pointers as to what i'm doing wrong mucho appreciated.
> Scott
I don't know that much about this to tell if you are getting any input.
Maybe you should review the "TCP Servers with IO::Socket" example in
'perldoc perlipc'.
But I definitely know that you are not returning proper headers. Each
header line should end with "\015\012" and the last header should end with
a blank line (or "\015\012\015\012"). In case your client accepts just a
newline (or if a newline on your server OS is carriage return, linefeed)
your headers terminate before you send any Content-type: header. Another
puzzle is why are you attempting to say that content is text/html when it
is not (it is text/plain)?
--
David Efflandt - All spam is ignored - http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 16 Nov 2001 23:39:46 -0800
From: dwk@auto-graphics.com (David Kenneally)
Subject: Cancel button to exit confirmation page?
Message-Id: <57a902f4.0111162339.2199c59b@posting.google.com>
Hello-
First off, maybe I should be in an html group instead, but bare with
me, I'm learning here...
I am using perl/CGI to generate a confirmation page. From a html page,
users submit the name of a file then want to delete. I use a cgi
script to echo that info back to them, as in:
Are you sure you want to delete $filename?
Submit Cancel
From here I can easily get submit to call a perl script to go delete
the file. My problem is I can't seem to find a way to make the cancel
button exit them out, or return them to the original page.
Any ideas would be welcome!
David
------------------------------
Date: 16 Nov 2001 18:10:31 -0800
From: houda.araj@cogmedia.com (Houda Araj)
Subject: Re: Compilation error
Message-Id: <7d0055df.0111161810.632e44a4@posting.google.com>
cpryce <cpryce@pryce.net> wrote in message news:<B81AB6DD.3089%cpryce@pryce.net>...
> in article 36cd2dbf.0111161001.266e10e@posting.google.com, Houda Araj at
> Houda.araj@cogmedia.com wrote on 11/16/01 12:01 PM:
>
> > #!/usr/bin/perl
> > use strict;
> > use diagnostics;
> > use CGI qw/:standard/;
> > use CGI::Carp 'fatalsToBrowser';
> >
> > my $regex;
> > {
> > my $phrase_file = 'phrases.txt';
> > open PHRASES, $phrase_file or die "$phrase_file: $!";
> > chomp( my @phrases = <PHRASES> );
> > $_ = "(?:$_)" foreach @phrases;
> > $regex = join '|', @phrases;
> > }
> >
> > my $paragraph;
> > {
> > my $source_file = 'source.txt';
> Hint: ^^^^^^^^^
>
> > open PHRASES, $phrase_file or die "$phrase_file: $!";
> ^^^^^^^^^^^^ ^^^^^^^^^^^^^
>
> > chomp( my @source = <PHRASES> );
> > $paragraph = join ' ', @source;
> > }
> >
> > $paragraph =~ s/($regex)/b($1)/ige;
> > print p($paragraph);
> >
> > __END__
>
> Diagnostics TELLS you what is wrong, and it tells you WHAT LINE to Fix! Did
> you run this from the command line and get your error message??
I invoke perl with this command.
Perl high.pl
------------------------------
Date: Sat, 17 Nov 2001 13:07:55 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Compilation error
Message-Id: <qtkJ7.331203$8x1.93616@newsfeeds.bigpond.com>
"Houda Araj" <houda.araj@cogmedia.com> wrote in message
news:7d0055df.0111161810.632e44a4@posting.google.com...
> I invoke perl with this command.
> Perl high.pl
Go back to sleep.
gtoomey
------------------------------
Date: Sat, 17 Nov 2001 08:42:20 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Extracting number from an string
Message-Id: <9t54cs$g88$00$1@news.t-online.com>
On Sat, 17 Nov 2001 01:36:31 GMT, sysop wrote:
> On Fri, 16 Nov 2001 08:29:28 -0500, Bernard El-Hagin wrote:
>> my ( $FirstNr, $SecNr ) = $String =~ m/(\d+)/g;
>>
>>
>> If you knew ahead of time that there would be two matches.
>
> You could name them independantly (not that you'd want to) this way:
> my @a = $str =~ m/(\d+)/g;
> foreach (@a){
> ${"Number".$a++} = $_;
> }
This will break under the strict 'refs' pragma. I really don't see a
point of having variables with names like $Number0, $Number1 if you can
have an array @Number. No clobbering of your symbol-table, no fiddling
with global variables ($Number0 ... will have to be globals) and no "no
strict 'refs'".
Tassilo
--
Old mail has arrived.
------------------------------
Date: 16 Nov 2001 21:08:43 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Fast Portable Logical Shift Right in Perl ?
Message-Id: <m3snbe174k.fsf@mumonkan.sunstarsys.com>
"Mark Shelor" <shelorm@earthlink.net> writes:
> A function such as
>
> use integer;
>
> sub lshr { # returns $x >>> $n, where >>> means logical shift right
> my $x = shift;
> my $n = shift;
>
> $x = ($x >> 1) & 0x7fffffff if ($n--);
> return($x >> $n);
> }
>
> isn't portable since it assumes a 32-bit integer. Also, it doesn't
> seem particularly efficient. Of course, one could do this in C, but
> I'm looking for a good implementation in straight Perl.
Have you tried using
no integer;
in your shift sub?
--
Joe Schaefer "Imagination is more important than knowledge."
--Albert Einstein
------------------------------
Date: Sat, 17 Nov 2001 04:35:59 GMT
From: David Sletten <slytobias@home.com>
Subject: Re: Fast Portable Logical Shift Right in Perl ?
Message-Id: <3BF5E968.4090207@home.com>
It's not quite what you meant, but your code is entirely portable (at
least for the time being) since Perl converts numeric scalars from
double precision floats to unsigned 32-bit ints before applying
bit-shifting ops:
$x = -1; # 0xFFFFFFFF as 32-bit int
$x >>= 1; # 0x7FFFFFFF => MSB is 0
print($x, "\n");
$x <<= 1; # 0xFFFFFFFE
print($x, "\n");
Output:
2147483647
4294967294
Again, at least for the time being, you can probably count on any Perl
implementation behaving this way.
I'm curious what tests you conducted to conclude that Perl performs an
arithmetic right shift?
David Sletten
Mark Shelor wrote:
> Crypto algorithms often require a "logical right shift" operation. Perl's
> right shift operator (>>) appears to be arithmetic: i.e. the
> most-significant bit (MSB) remains set after shifting to preserve sign. In
> contrast, a logical right shift operation would shift a zero bit into the
> MSB.
>
> A function such as
>
> use integer;
>
> sub lshr { # returns $x >>> $n, where >>> means logical shift right
> my $x = shift;
> my $n = shift;
>
> $x = ($x >> 1) & 0x7fffffff if ($n--);
> return($x >> $n);
> }
>
> isn't portable since it assumes a 32-bit integer. Also, it doesn't seem
> particularly efficient. Of course, one could do this in C, but I'm looking
> for a good implementation in straight Perl.
>
>
>
------------------------------
Date: Sat, 17 Nov 2001 17:23:49 +1000
From: "Mike Pierotti" <mrp@hafatel.com>
Subject: Re: maximum input buffer length exceeded
Message-Id: <9t53c402l12@enews3.newsguy.com>
Nevermind the question. I answerd it myself.
"Mike Pierotti" <mrp@hafatel.com> wrote in message
news:9t1e8f02tlq@enews3.newsguy.com...
> maximum input buffer length exceeded: 1048576 bytes at
> /home/httpd/cgi-bin/main.
> pl line 1551
> Issuing rollback() for database handle being DESTROY'd without explicit
> disconne
> ct().
>
> I am running a command that fetches a rather large array from Net::telnet
> and it is returning the above error. Any ideas on how I could fix this
> would be greatly appriciated.
>
>
>
>
>
------------------------------
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 2146
***************************************