[21864] in Perl-Users-Digest
Perl-Users Digest, Issue: 4068 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 5 18:07:24 2002
Date: Tue, 5 Nov 2002 15:05:12 -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, 5 Nov 2002 Volume: 10 Number: 4068
Today's topics:
Re: CGI Upload Problems <stedman@siam.org>
Re: CGI Upload Problems <flavell@mail.cern.ch>
Re: CGI Upload Problems <stedman@siam.org>
Re: CGI Upload Problems (Fourth Monkey)
Re: CGI Upload Problems <stedman@siam.org>
Re: Complex search/replace <perl-dvd@ldschat.com>
Re: Complex search/replace <barryk2@delete_me.mts.net>
Re: Complex search/replace <Graham.T.Wood@oracle.com>
Re: Complex search/replace <robert.bunney@hotmail.com>
cookies again <g-preston1@ti.com>
DBI <bobx@linuxmail.org>
Re: DBI <trammell+usenet@hypersloth.invalid>
defaults in packages <cyberjeff@sprintmail.com>
Re: defaults in packages <garry@ifr.zvolve.net>
Re: defaults in packages <cyberjeff@sprintmail.com>
Re: Flash sendXML with CGI <nobody@dev.null>
Re: Flash sendXML with CGI <rrobbins@kolbnetworks.com>
Re: fork() and socket? <troc@netrus.net>
Re: fork() and socket? <nospam@nospam.com>
Help Simplifying <ihave@noemail.com>
Re: Help Simplifying <wksmith@optonline.net>
Re: Help Simplifying <garry@ifr.zvolve.net>
Re: Help Simplifying <ihave@noemail.com>
Re: Help Simplifying <flavell@mail.cern.ch>
Re: How to copy some sections of a file that varies eve (Karen)
Re: HTTPS Post <rajkothary@hotmail.com>
Re: HTTPS Post <twhu@lucent.com>
Re: interacting with processes that diddle with tty (Kevin Cline)
Is it wrong to store method definitions in a database? (Phil Brodd)
param($var); <todd@mrnoitall.com>
split() results limited to 32k length? (Noam Stopak)
Re: Tie'd filehandle and the system() function (Tim)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 5 Nov 2002 12:43:08 -0500
From: "Josh Stedman" <stedman@siam.org>
Subject: Re: CGI Upload Problems
Message-Id: <HkTx9.20415$T_.502416@iad-read.news.verio.net>
"ebchang" <echang@netstorm.net> wrote in message
news:Xns92BCF1B602626echangnetstormnet@207.106.93.86...
>
> You didn't mention what you have on the client end - does the form
> use enctype="multipart/form-data"? If you leave the default, the
> form will submit, but the file will not be attached.
>
> EBC
Yeah, I have multipart set on the form. I'm also using POST and not GET.:
<FORM METHOD="POST" ENCTYPE="multipart/formdata">
...
......
<INPUT type="file" name="file1" size="40"><BR>
<INPUT type="SUBMIT" Value="Submit">
<INPUT type="RESET" Value="Reset">
</FORM>
------------------------------
Date: Tue, 5 Nov 2002 19:04:58 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI Upload Problems
Message-Id: <Pine.LNX.4.40.0211051902570.26208-100000@lxplus072.cern.ch>
On Nov 5, Josh Stedman inscribed on the eternal scroll:
> > does the form use enctype="multipart/form-data"?
> <FORM METHOD="POST" ENCTYPE="multipart/formdata">
Look again: multipart/form-data
------------------------------
Date: Tue, 5 Nov 2002 14:43:37 -0500
From: "Josh Stedman" <stedman@siam.org>
Subject: Re: CGI Upload Problems
Message-Id: <C5Vx9.20423$T_.502861@iad-read.news.verio.net>
Sonofafish...
Yeah, that was one thing, but that alone didn't work. So I went back to see what else I may have
mistyped....
POST should not be in quotes, apparently. Now it works. Thanks a bunch, this has been driving me
nuts for weeks, I've had to put it down for a while, I was so frustrated.
Thanks again!
Josh Stedman
"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.40.0211051902570.26208-100000@lxplus072.cern.ch...
> On Nov 5, Josh Stedman inscribed on the eternal scroll:
>
> > > does the form use enctype="multipart/form-data"?
>
> > <FORM METHOD="POST" ENCTYPE="multipart/formdata">
>
> Look again: multipart/form-data
>
>
>
------------------------------
Date: 5 Nov 2002 12:32:35 -0800
From: stuart@mohawk.net (Fourth Monkey)
Subject: Re: CGI Upload Problems
Message-Id: <616fce8f.0211051232.19564d66@posting.google.com>
> I've got a CGI script that I want to use to (among other things, which already work) upload a few
> files. As of now, I'm trying to settle with one file. But I can't get the file to save on the
> server or even print out to the screen.
[snip]
> My upload subfunction looks like this:
>
> ----------------BEGIN CODE----------------
> use CGI qw(:standard);
> use CGI::Carp qw(fatalsToBrowser);
> ------------------------
>
>
> sub uploadfiles {
>
> my $subpath = param('username')."/".$TimeStamp; # path for files after the main DL path -- uses
> the username submitted
> $subpath =~ s!\s!\_!g; # takes out any spaces that may have been in the username,
> replaces with _ for good measure
>
> my $file = param('file1');
> $basename = GetFileName($file);
>
> #my $mime = uploadInfo($file)->{'Content-Type'};
>
> print "<BR><BR>File contents: <BR><BR><TT>";
> while (<$file>){
> print;
> }
Hmm, at this point you've dumped the file, so the file pointer should
be at "EOF".
[snip]
>
> while(read($file, $data, 1024)){
> print STORAGE $data or die "Can't write to the file because of $!\n";
> }
>
> close STORAGE;
Now you try to read from the handle again but you've already done
that. What happens if you take out the loop above that just prints to
the browser window? I'm thinking that the second loop never happens,
you're at the end of the file from the first loop hence no data to
read, nothing in the file that is made on disk.
-Monkey
------------------------------
Date: Tue, 5 Nov 2002 16:20:06 -0500
From: "Josh Stedman" <stedman@siam.org>
Subject: Re: CGI Upload Problems
Message-Id: <1wWx9.20434$T_.503050@iad-read.news.verio.net>
Yeah I got that problem once I got it to work, but recognized it right away. As you can see,
someone else pointed out a problem with my HTML form as the culprit. Now everything is up and
running :)
"Fourth Monkey" <stuart@mohawk.net> wrote in message
news:616fce8f.0211051232.19564d66@posting.google.com...
> > I've got a CGI script that I want to use to (among other things, which already work) upload a
few
> > files. As of now, I'm trying to settle with one file. But I can't get the file to save on the
> > server or even print out to the screen.
> [snip]
> > My upload subfunction looks like this:
> >
> > ----------------BEGIN CODE----------------
> > use CGI qw(:standard);
> > use CGI::Carp qw(fatalsToBrowser);
> > ------------------------
> >
> >
> > sub uploadfiles {
> >
> > my $subpath = param('username')."/".$TimeStamp; # path for files after the main DL path --
uses
> > the username submitted
> > $subpath =~ s!\s!\_!g; # takes out any spaces that may have been in the username,
> > replaces with _ for good measure
> >
> > my $file = param('file1');
> > $basename = GetFileName($file);
> >
> > #my $mime = uploadInfo($file)->{'Content-Type'};
> >
> > print "<BR><BR>File contents: <BR><BR><TT>";
> > while (<$file>){
> > print;
> > }
>
> Hmm, at this point you've dumped the file, so the file pointer should
> be at "EOF".
>
> [snip]
> >
> > while(read($file, $data, 1024)){
> > print STORAGE $data or die "Can't write to the file because of $!\n";
> > }
> >
> > close STORAGE;
>
> Now you try to read from the handle again but you've already done
> that. What happens if you take out the loop above that just prints to
> the browser window? I'm thinking that the second loop never happens,
> you're at the end of the file from the first loop hence no data to
> read, nothing in the file that is made on disk.
>
> -Monkey
------------------------------
Date: Tue, 5 Nov 2002 09:09:59 -0700
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Complex search/replace
Message-Id: <AYRx9.20236$46.4391@fe01>
> "H.Wiersema" <h.wiersema@dbr.agro.nl> wrote in message
news:c990df5a.0211050632.2c5ce2cf@posting.google.com...
> *,
>
> I've a sql script to create lots of objects in a database. The
format
> of the script looks like this:
>
> ...
> create table ABC
> column1 varchar2(10),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
>
> create table DEF
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace UNKNOWN
> /
>
> create table GHI
> column1 varchar2(20),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
> ...
>
> etc etc!
>
> I want to make a (sed|awk|perl) script that is able to grep (for
> example) the 'DEF' object create clause, then catch the
> 'tablespace'occurence of that clause. Then replace the
tablespacename
> after 'tablespace' by another tablespacename. The name of the
> tablespace is the script above is not known, so I cant search for
the
> name. Too make it, perhaps, more clear:
>
> create table DEF <1> Grep on this object
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace NEWNAME <2> Something like
> /^tablespace/s/$2/$NEW_NAME/
> /
>
> Does anyone can give me a hint how to programm this in sed|awk|perl
?
>
> kind regards,
> H.Wiersema
This seems to be a pretty good lead on what you are looking for:
#################################################
my $sql = qq^
create table ABC
column1 varchar2(10),
column2 varchar2(10),
..
columnN varchar2(20)
tablespace UNKNOWN
/
create table DEF
column1 varchar2(20),
column2 varchar2(20),
..
columnN varchar2(30)
tablespace UNKNOWN
/
create table GHI
column1 varchar2(20),
column2 varchar2(10),
..
columnN varchar2(20)
tablespace UNKNOWN
/
^;
my $new_tablespace = "cool";
$sql =~ s/(create table DEF.*?tablespace )\w+/$1$new_tablespace/s;
print qq^*******\n$sql\n*******\n^;
##################################################
The above code produced the following results
##################################################
*******
create table ABC
column1 varchar2(10),
column2 varchar2(10),
..
columnN varchar2(20)
tablespace UNKNOWN
/
create table DEF
column1 varchar2(20),
column2 varchar2(20),
..
columnN varchar2(30)
tablespace cool
/
create table GHI
column1 varchar2(20),
column2 varchar2(10),
..
columnN varchar2(20)
tablespace UNKNOWN
/
*******
##################################################
Regards,
David
------------------------------
Date: Tue, 5 Nov 2002 10:30:37 -0600
From: Barry Kimelman <barryk2@delete_me.mts.net>
Subject: Re: Complex search/replace
Message-Id: <MPG.1831ae2420b00171989741@east.usenetserver.com>
In article <c990df5a.0211050632.2c5ce2cf@posting.google.com>,
h.wiersema@dbr.agro.nl says...
> *,
>
> I've a sql script to create lots of objects in a database. The format
> of the script looks like this:
>
> ...
> create table ABC
> column1 varchar2(10),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
>
> create table DEF
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace UNKNOWN
> /
>
> create table GHI
> column1 varchar2(20),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
> ...
>
> etc etc!
>
> I want to make a (sed|awk|perl) script that is able to grep (for
> example) the 'DEF' object create clause, then catch the
> 'tablespace'occurence of that clause. Then replace the tablespacename
> after 'tablespace' by another tablespacename. The name of the
> tablespace is the script above is not known, so I cant search for the
> name. Too make it, perhaps, more clear:
>
> create table DEF <1> Grep on this object
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace NEWNAME <2> Something like
> /^tablespace/s/$2/$NEW_NAME/
> /
>
> Does anyone can give me a hint how to programm this in sed|awk|perl ?
#!/usr/bin/perl -w
$filename = ARGV[0];
$tablename = $ARGV[1];
$new_tablespace = $ARGV[2];
if ( ! open(INPUT,"<$filename") ) {
die("Can't open \"$filename\" : $!\n");
} # IF
$found = 0;
while ( $buffer = <INPUT> ) {
if ( $buffer =~ m/create\s+table\s+${tablename}/i ) {
$found = 1;
last;
} # IF a match
} # WHILE
if ( ! $found ) {
close INPUT;
die("create table not found for \"$tablename\"\n");
} # IF
$found = 0;
while ( $buffer = <INPUT> ) {
if ( $buffer =~ m/tablespace/i ) {
$found = 1;
last;
} # IF
} # WHILE
if ( ! $found ) {
close INPUT;
die("Tablespace not found for table \"$tablename\"\n");
} # IF
# more code goes here
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Tue, 05 Nov 2002 16:49:50 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Complex search/replace
Message-Id: <3DC7F6AE.DE5A390B@oracle.com>
David wrote:
> my $sql = qq^
> create table ABC
> column1 varchar2(10),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
>
> create table DEF
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace UNKNOWN
> /
>
> create table GHI
> column1 varchar2(20),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
> ^;
>
If you need to read your entire SQL script into a single scalar variable,
use "slurp mode". Basically this means turning off the default record
separator (newline) and reading the entire file as one value. The record
separator's value is held in the predefined variable $/ .
undef $/;
will remove the default setting so you can do
open(FILE,"script.sql") || die "Can't open script.sql $!\n";
undef $/;
$sql=<FILE>;
close FILE;
$/="\n"; # to switch slurp mode off again
You then have your file's contents in $sql and the rest of David's script
will work as is.
perldoc -q match
will give you this snippet:
"There are many ways to get multiline data into a string. If you
want it to happen automatically while reading input, you'll want
to set $/ (probably to '' for paragraphs or "undef" for the
whole file) to allow you to read more than one line at a time."
Graham Wood
------------------------------
Date: Tue, 05 Nov 2002 17:02:04 GMT
From: "robertbu" <robert.bunney@hotmail.com>
Subject: Re: Complex search/replace
Message-Id: <gQSx9.25701$7W2.3639@nwrddc01.gnilink.net>
I am new to perl, so this may not be the "best" way, but
here is code that takes a file on the command line and
replaces one instance of a tablespace name. Multiple
changes could be made by adding a hash that mapped
table name to tablespace name and some minor changes
to the code.
$stTableToFind = "GHI";
$stReplaced = "XYZT";
while (<>)
{
$fInTable = 1 if (/create table (.+)/ && ($1 eq $stTableToFind));
s/tablespace (.+)/tablespace $stReplaced/ if ($fInTable);
print($_);
}
------------------------------
Date: Tue, 5 Nov 2002 16:53:12 -0600
From: "Jerry Preston" <g-preston1@ti.com>
Subject: cookies again
Message-Id: <aq9i52$eff$1@tilde.itg.ti.com>
Hi!
I am I doing this right?
use strict;
use DBI;
use CGI qw(:standard);
use File::Basename;
my $query=new CGI;
print $query->header();
print $query->start_html( -title=>'JERRY PRESTON COOKIES' );
print $query->startform( -method=>'POST', -name =>'JERRY PRESTON
COOKIES');
my $expiration = "+1y";
my $username = "jerryp";
my $database = "testdb";
my $password = "testword";
my $usercookie =
cookie(-name=>"$database.username",-value=>"$username",-expires=>"$expiratio
n");
my $passcookie =
cookie(-name=>"$database.password",-value=>"$password",-expires=>"$expiratio
n");
print header(-cookie=>[$usercookie,$passcookie]);
$username = cookie("$database.username");# or return(1);
$password = cookie("$database.password");# or return(1);
print "<br><br>$database * username *$username* password *$password*<BR>";
I get nothing when I print out:
print "<br><br>$database * username *$username* password *$password*<BR>";
What am I doing wrong?
Is there a better way?
How can I check on my PC to see the cookies?
I am running this script on a SUN 2.8.
Thanks,
Jerry
------------------------------
Date: Tue, 05 Nov 2002 21:40:53 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: DBI
Message-Id: <FVWx9.44212$Lg2.11961676@news2.news.adelphia.net>
Is the O'Reilly book the one to get if I want to learn "all there is to know
about DBI"?
Bob
------------------------------
Date: Tue, 5 Nov 2002 22:02:40 +0000 (UTC)
From: John Joseph Trammell <trammell+usenet@hypersloth.invalid>
Subject: Re: DBI
Message-Id: <slrnasgg00.328.trammell+usenet@bayazid.el-swifto.com>
On Tue, 05 Nov 2002 21:40:53 GMT, Bob X <bobx@linuxmail.org> wrote:
> Is the O'Reilly book the one to get if I want to learn "all there
> is to know about DBI"?
>
Only if the book includes the source code now. :-)
Seriously though, the O'Reilly DBI book is good. It does not
have everything I have needed to know though. You may need
to know less, though.
------------------------------
Date: Tue, 05 Nov 2002 17:50:17 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: defaults in packages
Message-Id: <3DC8055C.449838@sprintmail.com>
I'm having trouble understanding package variables. The perl docs have
helped a lot but haven't gotten me all the way.
I'd like to set defaults for a package
package somePackage;
our $SOME_VAR='default'; # got 5.6
# Why doesn't that work? $SOME_VAR looks undefined.
sub new{
my $class = shift;
...
bless $self, $class;
return $self;
}
sub SOME_VAR{
shift;
$SOME_VAR=shift if @_;
return $SOME_VAR;
}
Is it better to set these in a hash?
------------------------------
Date: Tue, 05 Nov 2002 18:25:47 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: defaults in packages
Message-Id: <slrnasg30b.cqb.garry@zfw.zvolve.net>
On Tue, 05 Nov 2002 17:50:17 GMT, Jeff Thies <cyberjeff@sprintmail.com> wrote:
> I'm having trouble understanding package variables. The perl docs have
> helped a lot but haven't gotten me all the way.
>
> I'd like to set defaults for a package
>
> package somePackage;
>
> our $SOME_VAR='default'; # got 5.6
>
> # Why doesn't that work? $SOME_VAR looks undefined.
No, it doesn't.
$ perl -wl
package somePackage;
our $SOME_VAR='default';
print $SOME_VAR;
package main;
print $somePackage::SOME_VAR;
__END__
default
default
$
> sub new{
> my $class = shift;
> ...
> bless $self, $class;
> return $self;
> }
>
> sub SOME_VAR{
> shift;
> $SOME_VAR=shift if @_;
> return $SOME_VAR;
> }
Perhaps a better style would be:
# set/get class attribute SOME_VAR
sub SOME_VAR {
$SOME_VAR = $_[1] if $_[1];
$SOME_VAR;
}
I see no problem with this either.
> Is it better to set these in a hash?
Better than what? Do you want a class attribute or an object
attribute? The package variable is used to hold class data; the
object holds object data.
I get the feeling we are not seeing something here.
--
Garry Williams
------------------------------
Date: Tue, 05 Nov 2002 19:15:08 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: defaults in packages
Message-Id: <3DC81942.9CBAB39E@sprintmail.com>
> > I'd like to set defaults for a package
> >
> > package somePackage;
> >
> > our $SOME_VAR='default'; # got 5.6
> >
> > # Why doesn't that work? $SOME_VAR looks undefined.
Ah, I've found my problem. I have this package at the bottom of my page.
I thought that was a good way to test it.
print $somePackage::SOME_VAR; # not defined yet.
package somePackage;
our SOME_VAR='default';
1;
# calling SOME_VAR afterwards is different. Apparently I don't
understand the way perl compiles packages
print $somePackage::SOME_VAR; # defined now.
Thanks,
Jeff
>
> No, it doesn't.
>
> $ perl -wl
> package somePackage;
> our $SOME_VAR='default';
> print $SOME_VAR;
> package main;
> print $somePackage::SOME_VAR;
> __END__
> default
> default
> $
>
> > sub new{
> > my $class = shift;
> > ...
> > bless $self, $class;
> > return $self;
> > }
> >
> > sub SOME_VAR{
> > shift;
> > $SOME_VAR=shift if @_;
> > return $SOME_VAR;
> > }
>
> Perhaps a better style would be:
>
> # set/get class attribute SOME_VAR
> sub SOME_VAR {
> $SOME_VAR = $_[1] if $_[1];
> $SOME_VAR;
> }
>
> I see no problem with this either.
>
> > Is it better to set these in a hash?
>
> Better than what? Do you want a class attribute or an object
> attribute? The package variable is used to hold class data; the
> object holds object data.
>
> I get the feeling we are not seeing something here.
>
> --
> Garry Williams
------------------------------
Date: Tue, 05 Nov 2002 17:44:52 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Flash sendXML with CGI
Message-Id: <3DC80387.3090902@dev.null>
Robert Robbins wrote:
> "Andras Malatinszky" <nobody@dev.null> wrote in message
> news:3DC6E35F.6080809@dev.null...
>
>>
>>Andras Malatinszky wrote:
>>
>>
>>>
>>>Robert Robbins wrote:
>>>
>>>
>>>>Hello Perl Programmers,
>>>>
>>>>I am trying to write a Perl script that reads the XML sent by
>>>>Flash using its XML.send method. The XML.send uses the
>>>>content type text/xml and sends the data using POST. I've
>>>>tried the CGI.pm and cgi-lib.pl. The cgi-lib.pl script won't
>>>>work with this content type and the CGI.pm does not provide
>>>>a method for getting the raw post data. I tried $q->param('raw')
>>>>but this did not work. An ASP script can successfully
>>>>get the XML using:
>>>>
>>>>Response.BinaryWrite Request.BinaryRead(Request.TotalBytes)
>>>>
>>>>And PHP has the $GLOBALS["HTTP_RAW_POST_DATA"]
>>>>global variable. I need to do this in Perl.
>>>>
>>>>Robert Robbins
>>>>
>>>
>>>
>>>I have no Flash, so I may be way off base, but a simple script like
>>>
>>>#!/usr/bin/perl -w
>>>use strict;
>>>use CGI;
>>>my $message=<STDIN>;
>>>my $q=new CGI;
>>>print $q->header();
>>>print $message;
>>>
>>>will parrot back everything you have sent to it via the POST method.
>>>
>>>I hope that helps.
>>>
>>>
>>>
>>>
>>
>>OK, maybe we should have @message instead of $message in both instances...
>>
>>Like I said, this is untested.
>>
>>
>>
> $s = $query->header();
> print $s . "\n";
>
> Only returns "Content-Type: text/html; charset=ISO-8859-1"
>
> print $ENV{"ALL_HTTP"},"<br>\n";
>
> Also fails to return the raw post data I'm looking for.
>
>
No, you misunderstood. The raw post data can be read directly from STDIN. Look at line 4 of my script.
------------------------------
Date: Tue, 5 Nov 2002 15:23:20 -0500
From: "Robert Robbins" <rrobbins@kolbnetworks.com>
Subject: Re: Flash sendXML with CGI
Message-Id: <usga53te2mi92c@corp.supernews.com>
my @message=<STDIN>;
causes an Out Of Memory error
"Andras Malatinszky" <nobody@dev.null> wrote in message
news:3DC80387.3090902@dev.null...
>
>
> Robert Robbins wrote:
>
>
> > "Andras Malatinszky" <nobody@dev.null> wrote in message
> > news:3DC6E35F.6080809@dev.null...
> >
> >>
> >>Andras Malatinszky wrote:
> >>
> >>
> >>>
> >>>Robert Robbins wrote:
> >>>
> >>>
> >>>>Hello Perl Programmers,
> >>>>
> >>>>I am trying to write a Perl script that reads the XML sent by
> >>>>Flash using its XML.send method. The XML.send uses the
> >>>>content type text/xml and sends the data using POST. I've
> >>>>tried the CGI.pm and cgi-lib.pl. The cgi-lib.pl script won't
> >>>>work with this content type and the CGI.pm does not provide
> >>>>a method for getting the raw post data. I tried $q->param('raw')
> >>>>but this did not work. An ASP script can successfully
> >>>>get the XML using:
> >>>>
> >>>>Response.BinaryWrite Request.BinaryRead(Request.TotalBytes)
> >>>>
> >>>>And PHP has the $GLOBALS["HTTP_RAW_POST_DATA"]
> >>>>global variable. I need to do this in Perl.
> >>>>
> >>>>Robert Robbins
> >>>>
> >>>
> >>>
> >>>I have no Flash, so I may be way off base, but a simple script like
> >>>
> >>>#!/usr/bin/perl -w
> >>>use strict;
> >>>use CGI;
> >>>my $message=<STDIN>;
> >>>my $q=new CGI;
> >>>print $q->header();
> >>>print $message;
> >>>
> >>>will parrot back everything you have sent to it via the POST method.
> >>>
> >>>I hope that helps.
> >>>
> >>>
> >>>
> >>>
> >>
> >>OK, maybe we should have @message instead of $message in both
instances...
> >>
> >>Like I said, this is untested.
> >>
> >>
> >>
> > $s = $query->header();
> > print $s . "\n";
> >
> > Only returns "Content-Type: text/html; charset=ISO-8859-1"
> >
> > print $ENV{"ALL_HTTP"},"<br>\n";
> >
> > Also fails to return the raw post data I'm looking for.
> >
> >
>
> No, you misunderstood. The raw post data can be read directly from STDIN.
Look at line 4 of my script.
>
------------------------------
Date: Tue, 05 Nov 2002 17:59:43 -0000
From: Rocco Caputo <troc@netrus.net>
Subject: Re: fork() and socket?
Message-Id: <slrnasg1oc.8ma.troc@eyrie.homenet>
On Tue, 05 Nov 2002 16:37:21 +0100, edgue@web.de wrote:
>
> Unfortunately I need to do some things in parallel;
> therefore I have to fork() at some point in time.
>
> Now something strange happens:
> - on W2K with ActiveState Perl 5.6.1 everything
> works fine - parent and child process are able
> to communicate using the TCP connection.
If you have several processes sharing the same socket, and they're not
trying to synchronize their writes, this is probably just a happy
coincidence.
> - on OS/2 with a Perl 5.7.3 built, the same code
> fails. To me it looks like parent/child process
> are really working on the _SAME_ socket object.
> So the data that is read from the socket looks
> "corrupted" immediately.
> I wrote some debugging code - the child process
> runs fine if it avoids to use the TCP connection ...
>
> But my child process needs to send some data,
> otherwise it is useless to me.
This is how fork() works. The parent and child processes will share
the handles, and unsynchronized writes to the sockets will get jumbled
up. You can limit the problem somewhat by making sure your sockets
aren't buffered:
select SOCKET; $| = 1;
select STDOUT;
> I guess one solution would be to open a completely
> new connection for the child process to the server;
> but this would require us to change the server, too.
>
> Do you have better ideas?
Having an arbitrary number of processes writing to a socket is usually
the wrong way to do something. First, if the protocol has any order
to it, you'll never know exactly how stuff is sent on the socket.
Second, as you've seen, willy-nilly concurrent socket writes tend to
clobber themselves.
Likewise, multiple processes reading from the same socket gets ugly
fast. Data read by one process is consumed, so another process won't
ever see it. That leads to partial transactions and broken data.
Another way to do this would be to have the child processes only
communicate to the parent, which synchronizes the transactions and
sends/receives on the socket itself.
SOCKET <--> Parent process <--> Multiple child processes
Then only one process, the parent, is talking on the socket.
> Is there a way to make my perl socket code "reentrant"?
> And why does it work on windows, anyway?
Describe this "reentrant" you speak of.
-- Rocco Caputo - troc@pobox.com - http://poe.perl.org/
------------------------------
Date: Tue, 5 Nov 2002 12:17:19 -0800
From: "Tan D Nguyen" <nospam@nospam.com>
Subject: Re: fork() and socket?
Message-Id: <aq98v7$7u3s7$1@ID-161864.news.dfncis.de>
<edgue@web.de> wrote in message news:3DC7E5B1.9080404@web.de...
[snipped]
> Do you have better ideas?
> Is there a way to make my perl socket code "reentrant"?
> And why does it work on windows, anyway?
As Rocco said, this behavior is expected from forking. I assume you meant
"synchronized" by "reentrant". If so, check out "flock" for more information
on synchronizing I/O on filehandles.
------------------------------
Date: Tue, 05 Nov 2002 16:40:21 GMT
From: "TBN" <ihave@noemail.com>
Subject: Help Simplifying
Message-Id: <TvSx9.4587$lFD1.46465061@news2.randori.com>
Can someone give me some hints on how I can simplify the code below? I'm
thinking there has got to be a more efficient way, but maybe not.
while (<CODE>) {
s/status=\"0\"/status=\"3\"/;
s/info=\".*?\"/info=\"\"/;
s/var=\".*?\"/var=\"\"/;
s/change=\".*?\"/change=\"\"/;
s/<graph>.*<\/graph>//;
s/datafile=\".*?\"/datafile=\"\"/;
}
}
------------------------------
Date: Tue, 05 Nov 2002 17:56:40 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Help Simplifying
Message-Id: <sDTx9.21541$0x.7761@news4.srv.hcvlny.cv.net>
"TBN" <ihave@noemail.com> wrote in message
news:TvSx9.4587$lFD1.46465061@news2.randori.com...
> Can someone give me some hints on how I can simplify the code below? I'm
> thinking there has got to be a more efficient way, but maybe not.
>
> while (<CODE>) {
> s/status=\"0\"/status=\"3\"/;
> s/info=\".*?\"/info=\"\"/;
> s/var=\".*?\"/var=\"\"/;
> s/change=\".*?\"/change=\"\"/;
> s/<graph>.*<\/graph>//;
> s/datafile=\".*?\"/datafile=\"\"/;
> }
> }
>
>
I like your solution. It is very easy to understand. Although it does no
harm, it is not necessary to escape all the double quotes in you regexs.
Your code would less cluttered without them.
Bill
------------------------------
Date: Tue, 05 Nov 2002 18:34:13 GMT
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: Help Simplifying
Message-Id: <slrnasg3g5.cqb.garry@zfw.zvolve.net>
On Tue, 05 Nov 2002 16:40:21 GMT, TBN <ihave@noemail.com> wrote:
> Can someone give me some hints on how I can simplify the code below? I'm
> thinking there has got to be a more efficient way, but maybe not.
>
> while (<CODE>) {
> s/status=\"0\"/status=\"3\"/;
> s/info=\".*?\"/info=\"\"/;
> s/var=\".*?\"/var=\"\"/;
> s/change=\".*?\"/change=\"\"/;
> s/<graph>.*<\/graph>//;
> s/datafile=\".*?\"/datafile=\"\"/;
> }
> }
It's a lot more readable, if you remove those unnecessary back-whacks,
use alternate quoting where appropriate and add some white space:
while ( <CODE> ) {
s/ status="0" /status="3"/x;
s/ info=".*?" /info=""/x;
s/ var=".*?" /var=""/x;
s/ change=".*?" /change=""/x;
s! <graph>.*</graph> !!x;
s/ datafile=".*?" /datafile=""/x;
}
--
Garry Williams
------------------------------
Date: Tue, 05 Nov 2002 19:29:24 GMT
From: "TBN" <ihave@noemail.com>
Subject: Re: Help Simplifying
Message-Id: <n_Ux9.15$F3M2.1573000@news2.randori.com>
"Garry Williams" <garry@ifr.zvolve.net> wrote in message
news:slrnasg3g5.cqb.garry@zfw.zvolve.net...
> On Tue, 05 Nov 2002 16:40:21 GMT, TBN <ihave@noemail.com> wrote:
> > Can someone give me some hints on how I can simplify the code below?
I'm
> > thinking there has got to be a more efficient way, but maybe not.
> >
> > while (<CODE>) {
> > s/status=\"0\"/status=\"3\"/;
> > s/info=\".*?\"/info=\"\"/;
> > s/var=\".*?\"/var=\"\"/;
> > s/change=\".*?\"/change=\"\"/;
> > s/<graph>.*<\/graph>//;
> > s/datafile=\".*?\"/datafile=\"\"/;
> > }
> > }
>
> It's a lot more readable, if you remove those unnecessary back-whacks,
> use alternate quoting where appropriate and add some white space:
>
> while ( <CODE> ) {
> s/ status="0" /status="3"/x;
> s/ info=".*?" /info=""/x;
> s/ var=".*?" /var=""/x;
> s/ change=".*?" /change=""/x;
> s! <graph>.*</graph> !!x;
> s/ datafile=".*?" /datafile=""/x;
> }
>
> --
> Garry Williams
Thanks. I'm unfamiliar with the /x attribute. What does that do?
------------------------------
Date: Tue, 5 Nov 2002 22:10:53 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Help Simplifying
Message-Id: <Pine.LNX.4.40.0211052210050.26208-100000@lxplus072.cern.ch>
On Nov 5, TBN inscribed on the eternal scroll:
[fullquote excised]
> Thanks. I'm unfamiliar with the /x attribute. What does that do?
It causes perceptive Perl cadets to look in the documentation.
SCNR.
------------------------------
Date: 5 Nov 2002 14:10:20 -0800
From: kjbarahona@hotmail.com (Karen)
Subject: Re: How to copy some sections of a file that varies every month?
Message-Id: <ade6ec5e.0211051410.61cc3a3c@posting.google.com>
Hi Martien,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnase71m.2c3.mgjv@verbruggen.comdyn.com.au>...
> On 4 Nov 2002 15:31:02 -0800,
> Karen <kjbarahona@hotmail.com> wrote:
> > Hi everybody,
> >
> > I'm trying to modify a file with a perl script. I get a report once a
> > month (the report has 11 sections), I need to be able to run a script
> > that will make the report have only 5 sections. (It must be done
> > automatically, that's why I don't do it manually)
> >
> > This is part of the file I get originally (the one that needs to be
> > modified by the script):
> >
> > ################################################################
> > ### Section 1
> ><h3>The last Months Daily Availability</h3>
> ><p>Daily Average of svcs monitored and availability of svcs divided by
>
> [SNIP]
>
> Your file looks like HTML. You should probably have a look at the
> various HTML:: modules on CPAN. Maybe HTML::Tree would be useful.
> If your HTML is very clean, and is valid XML, maybe one of the
> XML::DOM modules could be of use.
Ok, I used HTML::Tree, but I run into another problem, I don't know
why my code doesn't work:
my $root = HTML::TreeBuilder->new;
$file=/opt/OpenNMS/share/reports/AVAIL-HTML-File-Servers20020729.html
$root->parse_file($file);
$h=HTML::Element->new("table");
$h->delete();
I have 11 tables in the report, how do I declare each table as
different one: ex, table1, table2, table3....table11 so I can say
$table6->delete()
I read on the Perl documentation but I don't quite understand what
elements it refers to in here:
$h = HTML::Element->new('tag', 'attrname' => 'value', ... )
$h=HTML::Element->new("table"); ## is this the tag is asking me or in
the value?
>
> > With my current script I read the whole file to an array so it's
> > easier to access parts of the file (Ex, $file[202], etc). One of the
> > problems that I've run into is that some sections vary each month so I
> > can't hard code the changes that I need.
>
> Using something that builds an organised tree would probably get rid
> of that problem.
>
> http://search.cpan.org/
>
> Martien
Thanks for your feedback,
-Karen-
------------------------------
Date: Tue, 5 Nov 2002 16:26:41 -0000
From: "Raj" <rajkothary@hotmail.com>
Subject: Re: HTTPS Post
Message-Id: <aq8rg0$28j$1$8302bc10@news.demon.co.uk>
"Bart Lateur" <bart.lateur@pandora.be> wrote in message
news:dgpfsu4p9br0bc2g1pdru9mqqg6lc43hlu@4ax.com...
> Raj wrote:
> Check out anything in LWP (like lwpcook). I think it includes support
> for HTTPS as well. At least, there's a module LWP::Protocol::https, so I
> can't be completely off. :-)
>
> --
> Bart.
Thanks Bart, I'll start there and see what I can learn.
Regards,
Raj
------------------------------
Date: Tue, 5 Nov 2002 11:56:28 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: HTTPS Post
Message-Id: <aq8t7v$pl7@netnews.proxy.lucent.com>
You need to use Crypt-SSLeay with LWP for https.
"Bart Lateur" <bart.lateur@pandora.be> wrote in message ...
> Raj wrote:
>
> >I need to be able to send data to a HTTPS site using the above "protocol"
> >(if it is a valid name for what I need to do).
> >
> >Can anyone provide any test programs on how to acheive this or point me
in
> >the right direction? It will be XML data I am interested in posting.
>
> Check out anything in LWP (like lwpcook). I think it includes support
> for HTTPS as well. At least, there's a module LWP::Protocol::https, so I
> can't be completely off. :-)
>
> --
> Bart.
------------------------------
Date: 5 Nov 2002 11:23:15 -0800
From: kcline17@hotmail.com (Kevin Cline)
Subject: Re: interacting with processes that diddle with tty
Message-Id: <ba162549.0211051123.7fa9a545@posting.google.com>
Dan Becker <what_do_i_do@nothotmail.org> wrote in message news:<3DC6DA20.4424684C@nothotmail.org>...
> I'm trying to write a perl script that interfaces with a 3rd party interactive
> application on solaris using IPC::Open2, where that application apparently does
> things like tcgetattr and tcsetattr...
Use the Expect module.
------------------------------
Date: 5 Nov 2002 14:57:44 -0800
From: pheelb@yahoo.com (Phil Brodd)
Subject: Is it wrong to store method definitions in a database?
Message-Id: <69cfe521.0211051457.110facaa@posting.google.com>
I feel I'm about to perpetrate a miscarriage of OO Perl, so I thought
I'd ask some advice first. I'm kind of an OO newbie.
My project is a system that downloads and parses the contents of
various web pages, each on its own collection schedule. A Perl cron
job checks a DB table to see if any pages are to be collected at that
time, creating a Collector object for each one. For each Collector
object, methods are invoked to download the page, parse its contents,
and insert the results in another DB table.
Here's where I'm not sure how to proceed. The Collector objects will
differ in the URLs they access and the parsing routines they use. I
can think of two approaches:
1) Store the URLs and the parsing routines in the database and
instantiate Collectors from there. I'm not sure how I would go about
defining a class whose methods are taken from a db, though.
2) Use inheritance. Create an abstract Collector class, and subclass
it for each page to be collected. This seems more natural, but if I
do it this way, how will my script know what kind of object to create?
In the first scenario, it's easy because there's only one class. I
can just say 'use Collector;' at the top of my script. With scenario
two, wouldn't I have to put a 'use' statement for every subclass,
whether or not an object of that class is actually created?
My thinking on this is pretty muddy, so I'd appreciate any
suggestions. :^)
Thanks!
Phil Brodd
------------------------------
Date: Tue, 05 Nov 2002 12:30:32 -0700
From: Todd Anderson <todd@mrnoitall.com>
Subject: param($var);
Message-Id: <3DC81C34.9E51983C@mrnoitall.com>
Hello,
The code below replaces \n with <br> for param($var). I need to do the
same thing with variable handles ie: $text = "This is the text"; After
the param($var); has been assigned a handle. ie: $text = param(text);
Any help is appreciated.
Thanks in advance.
foreach $var (@display)
{
my $value = param($var);
$value =~ s/\r\n/<br>/g;
param($var, $value);
}
------------------------------
Date: 5 Nov 2002 13:35:55 -0800
From: noam@orionsci.com (Noam Stopak)
Subject: split() results limited to 32k length?
Message-Id: <8435e2fa.0211051335.7a9c8c49@posting.google.com>
It seems that split limits the length of the results to 32k. My
testing indicates that the result string is truncated if it is longer
than this. This behavior seems to violate the spirit (if not the
letter) of the comment in Programming Perl that "Strings of any length
can be split" (top of page 795 in the 3rd edition). Have others
encountered this? Is it a bug? Is it a known bug?
Running v5.6.1 built for sun4-solaris.
Thanks,
Noam
p.s. please excuse previous erroneous posting to non-existant comp.lang.perl
------------------------------
Date: 5 Nov 2002 14:56:45 -0800
From: google@hoodfamily.org (Tim)
Subject: Re: Tie'd filehandle and the system() function
Message-Id: <1d2abc5d.0211051456.4faf864a@posting.google.com>
<Courtesy follow-up for others who may later read this>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3DC7731B.C1CCB69D@earthlink.net>...
> Supposing that your external script merely sends data to it's STDOUT,
> you can send that data to your tied handle with something like:
>
> open( my($fh), "-|", 'external_process' ) or die horribly;
> print while <$fh>;
> close $fh;
The only problem with that is that the output stays buffered until the
close, so I added
$OUTPUT_AUTOFLUSH=1; # same as $|
select *LOG_FILE;
Finally, I tweaked the print statement to format like I wanted and
<finally> problem solved.
------------------------------
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 4068
***************************************