[22911] in Perl-Users-Digest
Perl-Users Digest, Issue: 5131 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 24 14:06:14 2003
Date: Tue, 24 Jun 2003 11:05:10 -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, 24 Jun 2003 Volume: 10 Number: 5131
Today's topics:
Can the Repetition Operator Be Nested? (MES)
Re: Can the Repetition Operator Be Nested? <ddunham@redwood.taos.com>
Re: Can the Repetition Operator Be Nested? <usenet@dwall.fastmail.fm>
Re: Can't locate @INC & not finding files in local dire (Tad McClellan)
Re: chomp (@filecontents = <HANDLE>); slows down <mikeflan@earthlink.net>
Re: chomp (@filecontents = <HANDLE>); slows down <mikeflan@earthlink.net>
Database Connection Pooling in Perl CGI Script WITHOUT (Pete Butler)
Re: Database Connection Pooling in Perl CGI Script WITH <GPatnude@adelphia.net>
Re: Distributed CGI script in taint mode (re-post) <noreply@gunnar.cc>
LWP Extra Header Lines (Robert)
perlio problem? redhat 9, perl 5.8.0 (gordon)
Re: Please help with a script, knoledge needed! <estrunk @ home.nl>
Re: s/// substitution with capture / memory in a variab <aburger@rogers.com>
Re: s/// substitution with capture / memory in a variab (Tad McClellan)
Re: s/// substitution with capture / memory in a variab <nobody@dev.null>
Re: s/// substitution with capture / memory in a variab <nobull@mail.com>
serial input _and_ time of day based tasks? <stanb@panix.com>
Re: serial input _and_ time of day based tasks? <peter.dintelmann@dresdner-bank.com>
Re: soap::lite hellp needed with sms (Bryan Castillo)
Re: Write line at beginning of file? (Eric Pement)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Jun 2003 09:43:33 -0700
From: mesmith@mygfa.org (MES)
Subject: Can the Repetition Operator Be Nested?
Message-Id: <f6104297.0306240843.35217f93@posting.google.com>
I want to nest the repetition operator. Here is something like what I
want
print ("This " x 3 . "That \n") x 2;
This does not work because of the list context on the left hand side
of the x operator. Is there a way to do this?
Thanks
------------------------------
Date: Tue, 24 Jun 2003 16:54:36 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Can the Repetition Operator Be Nested?
Message-Id: <gn%Ja.1038$%N7.113530075@newssvr21.news.prodigy.com>
MES <mesmith@mygfa.org> wrote:
> I want to nest the repetition operator. Here is something like what I
> want
> print ("This " x 3 . "That \n") x 2;
> This does not work because of the list context on the left hand side
> of the x operator. Is there a way to do this?
Did you use -w and see that the parentheses are being interpreted as the
limit of the arguments to print?
print (("This " x 3 . "That \n") x 2);
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Tue, 24 Jun 2003 17:35:47 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Can the Repetition Operator Be Nested?
Message-Id: <Xns93A48A4ED1309dkwwashere@216.168.3.30>
Darren Dunham <ddunham@redwood.taos.com> wrote:
> MES <mesmith@mygfa.org> wrote:
>> I want to nest the repetition operator. Here is something like
>> what I want
>
>> print ("This " x 3 . "That \n") x 2;
>
> Did you use -w and see that the parentheses are being interpreted
> as the limit of the arguments to print?
>
> print (("This " x 3 . "That \n") x 2);
Or even:
print +("This " x 3 . "That \n") x 2;
------------------------------
Date: Tue, 24 Jun 2003 10:18:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't locate @INC & not finding files in local directory
Message-Id: <slrnbfgquj.1n4.tadmc@magna.augustmail.com>
Jennifer <jennlee.2@eudoramail.com> wrote:
> I've got several Perl scripts that use custom perl modules which are
> called from routines that are in the same directory as the scripts.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
They way you said that makes me think that you lack an understanding
of the fundamentals involved. Let's see if I can help with that...
1)
Routines cannot be in a directory.
_Files_ can be in a directory.
2)
Where the function is _called_ from does not matter.
You are getting a fatal error before getting to where the
function is invoked.
> For example dir.pl in folder dir references dir_utilities.pl.
You are using a relative path to dir_utilities.pl which assumes
that you know what your current working directory (cwd) is.
Do you *know* what your cwd is?
> This worked fine for a number of years and this morning, all my
> scripts are erroring with this type of message: Can't locate
> dir_utilities.pl in @INC (@INC contains: sys:\perl\lib .) at dir.pl
^
^
You have the cwd in @INC, so perl should be able to find it if
your cwd just happens to be the same directory that the main
program is in.
Since perl can *not* find it, your cwd must be different from the
directory where your main program is (assuming sufficient permissions).
> Our web administrator says they haven't made changes to our Perl
> install or the web server itself
If I don't believe that, then I'm pretty sure I know what your
problem is.
If I do believe that, then I have no idea how you can experience
the symptoms you attempt to describe.
What happened when you ran the program from the command line
rather than in a CGI environment?
> It looks as though when Perl is executing the script it is not reading
> the local directory as it used to and therefore is not finding the
> files there.
But there is another plausible explanation as well...
What if the cwd ("local directory"??) is not what it used to be?
> I tried adding this to see if I can get it to have the directory
> reference:
> BEGIN {
> push ( @INC, 'sys:\perl\web\dir' );
> }
>
> This does stop the error for the require calls, but when other files
> in the directory are referenced in the script (HTML templates used for
> output, etc) it gives an error that it cannot find these, so it's like
> it can find nothing from the directory where the script is.
The directory where the script is does not matter at all!
You are concentrating on the wrong thing.
What matters is your current working directory. Sometimes a web server
is configured to make the cwd the same as the directory where the
script is, but sometimes the cwd is set to something else.
> Does anyone have any suggestions?
Use forward slashes in paths whenever possible
(and it *is* possible in this case).
Either:
_force_ the cwd be what you want it to be rather than assuming that
it will be what you want it to be:
chdir 'sys:/perl/web/dir' or die "could not cd to 'sys:/perl/web/dir' $!";
or
use absolute (not relative) paths so that the contents of
@INC are never even consulted:
require 'sys:/perl/web/dir/dir_utilities.pl';
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 24 Jun 2003 15:36:55 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: chomp (@filecontents = <HANDLE>); slows down
Message-Id: <3EF8709A.4AB30A8E@earthlink.net>
Bart Lateur wrote:
> Tad McClellan wrote:
>
> He did say he ordered it in the library. He didn't say he spent money on
> it.
Right. I just picked up "Perl in a Nutshell" at a different
library last night. Not exactly a beginners book, but I'm getting
some good info out of it so far.
------------------------------
Date: Tue, 24 Jun 2003 15:49:50 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: chomp (@filecontents = <HANDLE>); slows down
Message-Id: <3EF8739A.ED748C94@earthlink.net>
Uri Guttman wrote:
> perlsyn has all of the perl syntax, not just a lot of things. as people
> have been telling you, perl has the best docs of any lang out
> there. over 1000+ pages. you have to read and reread them all the time,
> especially when beginning. read perlsyn, perlop, perlfunc ALL the way
> through even if you don't understand stuff. and read the entire perl FAQ
> as well (also skip stuff if you don't understand it). you will learn
> more this way than by posting more in this thread.
>
> uri
Thanks, I will do that.
I think I finally have enough info to strike out on my own here.
I'll be back though, from time to time.
------------------------------
Date: 24 Jun 2003 10:36:48 -0700
From: pmbutler@attbi.com (Pete Butler)
Subject: Database Connection Pooling in Perl CGI Script WITHOUT mod_perl
Message-Id: <9b766f0.0306240936.3832028c@posting.google.com>
I'm working on a Perl CGI application, and I'd like to set up database
connection pooling for obvious performance-related reasons.
However, the server I'm working on is provided by a third party, so I
do NOT have access to mod_perl.
Does anybody know of a way I can do connection pooling under these
conditions? Or am I just screwed without mod_perl?
(The database I'm accessing is MySQL, if that matters.)
Thanks,
-- Pete Butler
------------------------------
Date: Tue, 24 Jun 2003 18:00:09 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: Database Connection Pooling in Perl CGI Script WITHOUT mod_perl
Message-Id: <Jk0Ka.16470$Jw6.6946502@news1.news.adelphia.net>
"Pete Butler" <pmbutler@attbi.com> wrote in message
news:9b766f0.0306240936.3832028c@posting.google.com...
> I'm working on a Perl CGI application, and I'd like to set up database
> connection pooling for obvious performance-related reasons.
>
> However, the server I'm working on is provided by a third party, so I
> do NOT have access to mod_perl.
>
> Does anybody know of a way I can do connection pooling under these
> conditions? Or am I just screwed without mod_perl?
>
> (The database I'm accessing is MySQL, if that matters.)
>
> Thanks,
> -- Pete Butler
DB Connections are relatively LOW overhead compared to loading / compiling /
executing a Perl CGI --> Perhaps your CGI's need to be optimized... the
other question is: How manny DB connections does your third-party server
allow each account to have ??? you may be up against an arbitrary limit over
which you have no control...
Connection poool managers typically run as a daemon & you probably won't be
allowed to run your own daemons on someone else's server.... the server
software will probably kill your pool manager process if it runs over a
certain amount of time or uses more than a specified memory limit (this is
pretty standard on third party web servers...).
On top of that -- you'd probably be better off implicitly "connecting" and
"disconnecting" in your script so you can immediately "free-up" any open
connections that are not really in use... the Perl DBD::DBI drivers are
"supposed" to disconnect automatically or disconnect when the CGI process
terminates... I've found many DBD drivers that do NOT actually do this --
When the CGI terminates -- you're left with an open connection and the OS /
DBMS is left to do the cleanup (usually cleaned up based on the "connection
timeout" setting which can be anywehere from 1/2 second to 5 minutes before
the connection is released...)...
I'd make sure and do implicit connect / disconnects in your code for
starters and not rely on the OS to do my cleanup for me...
connect...
code...
code..
code....
disconnect
I have a FreeBSD / mySQL / postgreSQL dedicated server with about 200 sites
hosted on it --- Roughly 30,000 queries per day and have no performance
issues with database connections.... Perhaps your "third-party" server is
'over-hosting"... you might also analyze your SQL queries for efficiency /
speed while you're at it...
------------------------------
Date: Tue, 24 Jun 2003 18:16:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Distributed CGI script in taint mode (re-post)
Message-Id: <bd9tsv$r4bt2$1@ID-184292.news.dfncis.de>
Thanks for your comments, Helgi.
Helgi Briem wrote:
> On Tue, 24 Jun 2003 14:36:58 +0200, Gunnar Hjalmarsson
> <mailbox@gunnar.cc> wrote:
>
>> To be able to run other programs, without knowing their location,
>> I'm currently doing the following:
>>
>> $ENV{PATH} = securepath();
>>
>> sub securepath {
>> my $sep = $^O eq 'MSWin32' ? ';' : ':';
>> my @paths = ();
>> for (split $sep, $ENV{PATH}) {
>> if (m!^((?:\w:)?[\w-./ \\~]*)$!) {
>> push @paths, $1;
>> } else {
>> die 'Insecure $ENV{PATH}';
>> }
>> }
>> return join $sep, @paths;
>> }
>>
>> The above function doesn't change the contents of $ENV{PATH}, it
>> just untaints it.
>
> Why go to all this trouble to circumvent a security measure?
The reason is that the program includes features to make installation,
mostly on shared server accounts, easy for the typically inexperienced
users of the program.
Two examples of what I'm doing:
- tar and gzip/gunzip are used for backup handling (yes, I know there
are Perl modules, and I'm using Archive::Zip as an option, but they
require the zlib compression library, which is often not available)
- If the path to sendmail is incorrectly stated, I let the program
look for the path using File::Find, and suggest that change of the
configuration.
> Why not simply say something like:
>
> if ($^O =~/win/i) {
> $ENV{PATH} = 'C:\Perl\bin\;C:\WINNT\system32;C:\WINNT;'; }
> else { $ENV{PATH} = '/usr/bin:/usr/sbin:/bin'; }
The reason would be that it may not cover all variants out there. On
the other hand, since the features in question are basically only
applicable on *nix platforms, maybe I should consider something like
this:
$ENV{PATH} = $^O =~ /win/i ? '' : '/usr/bin:/usr/sbin:/bin';
At the same time I'm taking into account that it is an application
that handles trivial information, and it's most often installed on
shared servers where the providers allow hundreds of other users to
run scripts without approval. Considering that, making use of the PATH
variable may not be that bad after all, or...?
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 24 Jun 2003 09:10:26 -0700
From: robert@nrc.net (Robert)
Subject: LWP Extra Header Lines
Message-Id: <22d0e990.0306240810.69454449@posting.google.com>
Hi,
Does anyone know how to add extra request header lines with LWP?
I've seen this way but thought I'd see if there's a 'better' way:
my @headers = (
'User-Agent' => 'Mozilla/4.76 [en] (Win98)',
'Accept-Language' => 'en',
'Accept-Charset' => 'iso-8859-1',
'Accept-Encoding' => 'gzip',
'Accept' => 'image/gif, image/jpeg');
my $response = $browser->get($url, @headers);
And, maybe more importantly does anyone know where I can find a list
of how different browser headers look?
------------------------------
Date: 24 Jun 2003 09:06:10 -0700
From: gordon@ockham.be (gordon)
Subject: perlio problem? redhat 9, perl 5.8.0
Message-Id: <2369e2ad.0306240806.142022a9@posting.google.com>
I'm having some problems running a bit of legacy perl code on a newly
installed redhat 9. With the perl 5.8.0 that comes with redhat 9, the
match against the string literal works, the match against the same
string read from a file fails.
The weird thing is that with a 5.8.0 compiled from source with default
settings, both matches work, which is what we'd expect.
To make the script work you can add a binmode F after the second file
open, or you can change the [^\s]+ to [\S]+ or \S+. But the question
is, why are either of these things necessary? I don't understand the
fundamental cause of this problem and don't want to go through all the
legacy scripts if I can help it.
Is there a problem in the redhat 9 perl distribution, or just a
misunderstanding of something on my part?
Here's a tiny script to show the problem:
my $x = "this\n";
open(F, ">/tmp/test.txt");
print F "$x";
close(F);
open(F, "</tmp/test.txt");
my @lines = <F>;
close(F);
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' internal string matched OK\n";
}
else
{
print "'$x' internal string FAILED!\n";
}
for $x (@lines)
{
if ($x =~ /^\s*([^\s]+)/)
{
print "'$x' file string matched OK\n";
}
else
{
print "'$x' file string FAILED!\n";
}
}
- gordon
------------------------------
Date: Tue, 24 Jun 2003 18:52:16 +0200
From: Eric Strunk <estrunk @ home.nl>
Subject: Re: Please help with a script, knoledge needed!
Message-Id: <950hfvggr7k55v4t7riav1011i9le7kbgk@4ax.com>
On Tue, 24 Jun 2003 00:49:56 GMT, Michael Budash <mbudash@sonic.net>
wrote:
>In article <nf7ffv47h4efaiu3ps50u80s5vsdv62nih@4ax.com>,
> Eric Strunk <estrunk @ home.nl> wrote:
>
>> Hello all,
>>
Cut out
----------------------------------------------------------
>
>^^^^^^^^^^^^^^^^^^^
>remove this line
>
>> }
cut out again ----------------------------------------------------
>> This is it, can anyone help me please to get all the lines in one file
>> and go to the next file after that.
>>
>> Kind regards
>> Eric.
>
>hth-
Great that's working the way it must work.
Many thanks for solving the problem, and thanks again.
Eric.
------------------------------
Date: Tue, 24 Jun 2003 15:14:29 GMT
From: Alex Burger <aburger@rogers.com>
Subject: Re: s/// substitution with capture / memory in a variable
Message-Id: <pVZJa.8589$O31.4810@news02.bloor.is.net.cable.rogers.com>
David K. Wall wrote:
>>I am trying to get this to work:
>>
>> $string = 'one two three four five';
>> $left = 'two (\w+) four';
>> $right = 'two **** $1 **** four' ;
>>
>>
>
>The value of $1 does not yet contain what you wanted from the capturing
>parentheses because the regular expression in $left has yet to be
>evaluated. Also, you're using a single-quoted string, so no variable
>interpolation takes place.
>
The $left and $right will be entered by the user, or read from a file at
the start of the program. This is why I used single quotes in my
example. That is correct that the value of $1 will not contain anything
at that time.
>> $string =~ s/$left/$right/;
>>
>>but it only prints out:
>> one two **** $1 **** four five
>>
>>
>
>For your test case, this will work:
>
> # always enable strict and warnings - let perl help you
> use strict;
> use warnings;
>
> my $string = 'one two three four five';
> my $left = 'two (\w+) four';
> if ( $string =~ /$left/ ) {
> my $right = "two **** $1 **** four"; # note: double quotes
> $string =~ s/$left/$right/;
> }
> print $string;
>
>This uses $left as a regex twice; offhand I can't think of a way
>around that if you want to use $1. (There may be a way, it's just not
>immediately obvious to *me*.)
>
The problem here (for me) is that you are using double quotes to have $1
evaulated after the $left is evaulated. Like I said above, $right is
defined at the start of the program.
So basically I am trying to get Perl to treat the exact contents of
$right as if it was entered directly into the source code on the $string
=~ line.
Does that make sense?
Alex
------------------------------
Date: Tue, 24 Jun 2003 10:31:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: s/// substitution with capture / memory in a variable
Message-Id: <slrnbfgrne.1n4.tadmc@magna.augustmail.com>
Alex Burger <aburger@rogers.com> wrote:
> I am trying to get this to work:
>
> $string = 'one two three four five';
> $left = 'two (\w+) four';
> $right = 'two **** $1 **** four' ;
> $string =~ s/$left/$right/;
>
> but it only prints out:
> one two **** $1 **** four five
>
> Is there a way to make $string =~ s/$left/$right/ interopolate the $1
> inside of $right when executing the expression?
$right = '"two **** $1 **** four"' ; # made a subtle change here...
...
$string =~ s/$left/$right/ee;
> $left and $right are
> strings that are entered by the user
Warning Will Robinson!!
Then you should be wary of the large security issues associated
with allowing such a thing.
Are you aware of the danger?
Think about what would happen if:
$left = '@{[ unlink("*") ]}';
if that does not scare you, then you don't understand the threat.
perldoc -q expand
How do I expand function calls in a string?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 24 Jun 2003 16:16:27 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: s/// substitution with capture / memory in a variable
Message-Id: <3EF878F0.5040207@dev.null>
Alex Burger wrote:
>
> I am trying to get this to work:
>
> $string = 'one two three four five';
> $left = 'two (\w+) four';
> $right = 'two **** $1 **** four' ;
> $string =~ s/$left/$right/;
>
> but it only prints out:
> one two **** $1 **** four five
>
> Is there a way to make $string =~ s/$left/$right/ interopolate the $1
> inside of $right when executing the expression? $left and $right are
> strings that are entered by the user inside of the program.
>
How about
use strict;
use warnings;
my $string='one two three four';
my $left = 'two (\w+) four';
my $right= 'two **** $1 **** four';
$string =~ s/$left/right($1, $right)/e;
print $string;
sub right{
my ($arg,$RIGHT)=@_;
$RIGHT=~s/\$1/$arg/g;
return $RIGHT;
};
------------------------------
Date: 24 Jun 2003 17:55:25 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: s/// substitution with capture / memory in a variable
Message-Id: <u9r85jmn42.fsf@wcl-l.bham.ac.uk>
Repeating one of my favorite unlisted FAQs Alex Burger
<aburger@rogers.com> writes:
> $string = 'one two three four five';
> $left = 'two (\w+) four';
> $string =~ s/$left/two **** $1 **** four/;
>
> That works fine with the output being:
> one two **** three **** four five
>
> I am trying to get this to work:
>
> $string = 'one two three four five';
> $left = 'two (\w+) four';
> $right = 'two **** $1 **** four' ;
> $string =~ s/$left/$right/;
>
> but it only prints out:
> one two **** $1 **** four five
Please see my contributions to some of the numerous previous threads
on this subject.
Eg.
<u9hegut7pe.fsf@wcl-l.bham.ac.uk>
http://groups.google.com/groups?selm=u9hegut7pe.fsf%40wcl-l.bham.ac.uk
<u9elk19jgu.fsf@wcl-l.bham.ac.uk>
http://groups.google.com/groups?selm=u9elk19jgu.fsf%40wcl-l.bham.ac.uk
Could somebody _please_ get this one into the FAQ!
I'd write it up myself but the FAQ maintainers appear to ignore my
contibutions these days.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 24 Jun 2003 15:59:10 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: serial input _and_ time of day based tasks?
Message-Id: <bd9sge$nsa$1@reader1.panix.com>
I've got a script that reads from a serial port, and blocks on that.
Now I need to have it swap log files at midnight. I looked at Event.pm,
but it seemed a bit overkill, and I could not see how to make time of day
trigger it.
What other choices might I consider?
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Tue, 24 Jun 2003 18:25:11 +0200
From: "Peter Dintelmann" <peter.dintelmann@dresdner-bank.com>
Subject: Re: serial input _and_ time of day based tasks?
Message-Id: <bd9sof$g3@news-1.bank.dresdner.net>
Hi,
"Stan Brown" <stanb@panix.com> wrote in message
news:bd9sge$nsa$1@reader1.panix.com...
> Now I need to have it swap log files at midnight. I looked at Event.pm,
> but it seemed a bit overkill, and I could not see how to make time of day
> trigger it.
>
> What other choices might I consider?
have a look at setitimer() in the Time::HiRes module
which offers periodical SIGALRMs.
HTH,
Peter Dintelmann
------------------------------
Date: 24 Jun 2003 10:29:34 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: soap::lite hellp needed with sms
Message-Id: <1bff1830.0306240929.41018740@posting.google.com>
mike solomon <mike_solomon@lineone.net> wrote in message news:<3EF8563A.10802@lineone.net>...
> Bryan Castillo wrote:
> > mike solomon <mike_solomon@lineone.net> wrote in message news:<3EF70B29.3050106@lineone.net>...
> >
> >>I am trying to send sms messages using a SOAP interface
> >>
> >>I think the way to go is to use soap::lite
> >>
> >>I have had a look at the documentation and I must admit that I don't
> >>understand what I need to do
> >>
> >>the XML example I have been given is as follows:
> >>
> >>POST /secure/messenger/soap/SendService.asmx HTTP/1.1
> >>Host: www.esendex.com
> >>Content-Type: text/xml; charset=utf-8
> >>Content-Length: length
> >>SOAPAction: "com.esendex.ems.soapinterface/SendMessageFull"
> >>
> SNIP
> >
> > I'm really don't know SOAP too well, but here is my shot at it.
> >
<snip> cut out the first shot at the code
> >
> >
>
> Bryan
>
> Thanks for your help with this
>
> I tried your code and I am getting the same error message
>
> soap::lite appears to be generating # not / which apears to be what
> their server is complaining about
>
> I have contacted the company concerned and they are going to try and
> trace what is being received at their end
>
> If anyone knows if there is a way to produce a / rather than a # I will
> be really grateful
I was able to send the request with the / instead of # by using the
wsdl (file?)
use strict;
use warnings;
use SOAP::Lite +trace => 'all';
# put soap trace (all stderr really) into soap.log
open(STDERR, ">soap.log") || die "Error: can't open soap.log - $!";
# change the host to the correct one!
my $host = 'www.esendex.com';
#my $host = 'localhost:6060';
my $proxy = "http://$host/secure/messenger/soap/SendService.asmx";
my $uri = "http://$host/com.esendex.ems.soapinterface";
my $wsdl = 'https://www.esendex.com/secure/messenger/soap/SendService.asmx?wsdl';
my $service = SOAP::Lite->proxy($proxy)->service($wsdl);
# send the request w/ header
my $response = $service->SendMessageFull(
SOAP::Header->name('Username' => 'bryan'),
SOAP::Header->name('Password' => 'monkeyman'),
SOAP::Header->name('Account' => '0099'),
SOAP::Data->name(originator => 'Bank One'),
SOAP::Data->name(recipient => 'me'),
SOAP::Data->name(body => 'give me the dough'),
SOAP::Data->name(type => 'USD'),
SOAP::Data->name(validityperiod => 99)
);
print "response = $response\n";
# get the result and print the error message if it failed
if (defined (my $result = $response->result)) {
print "result = $result\n";
}
else {
print "Fault: ", $response->faultstring, "\n",
"Detail:\n", $response->faultdetail, "\n";
}
It generates the following request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
<Password xsi:type="xsd:string">monkeyman</Password>
<Account xsi:type="xsd:int">0099</Account>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<SendMessageFull xmlns="">
<Username xsi:type="xsd:string">bryan</Username>
<originator xsi:type="xsd:string">Bank One</originator>
<recipient xsi:type="xsd:string">me</recipient>
<body xsi:type="xsd:string">give me the dough</body>
<type xsi:type="xsd:string">USD</type>
<validityperiod xsi:type="xsd:int"
>99</validityperiod>
</SendMessageFull>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But now its generating this response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server
was unable to process request. ---> System.NullReferenceException:
Object reference not set to an instance of an object.
at com.esendex.ems.soapinterface.ExceptionHandler.HandleException(Exception
ex, String source, MessengerHeader header, Object[] args)
at com.esendex.ems.soapinterface.SendService.SendMessageFull(String
originator, String recipient, String body, MessageType type, Int32
validityperiod)
--- End of inner exception stack trace ---</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>
I think this error is a little better than the last one.
If you look at the request the Username is showing up in the body
instead of the header (I don't know why though?) Might have to break
into the source for SOAP::Lite to figure that out.
There is another thread with the above error right now, better watch
that thread also. In that thread the op says he gets the same error
at www.worldwidedesktop.com where they have a spell checking service.
I was able to do it by packaging the soap request myself (I just used
plain sockets instead of SOAP::Lite).
------------------------------
Date: 24 Jun 2003 08:23:21 -0700
From: pemente@northpark.edu (Eric Pement)
Subject: Re: Write line at beginning of file?
Message-Id: <227a55e9.0306240723.13b2f2e2@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbfe194.mf6.tadmc@magna.augustmail.com>...
> Math55 <magelord@t-online.de> wrote:
>
> > how can i write a line at the beginning of a file, so the other
> ^^^^^^^^^
> > already existing lines are not overwritten or something?
>
>
> The way it says to in the Perl FAQ.
>
> perldoc -q beginning
>
> How do I change one line in a file/delete a line in a
> file/insert a line in the middle of a file/append to the
> beginning of a file?
>
>
> You are expected to check the Perl FAQ *before* posting to
> the Perl newsgroup.
Some people may disagre, but I found the Perl FAQ disappointing in
this answer. I have a recent ActiveState Perl, and the FAQ says this:
Although humans have an easy time thinking of a text file as
being a sequence of lines that operates much like a stack of
playing cards--or punch cards--computers usually see the text
file as a sequence of bytes. In general, there's no direct way
for Perl to seek to a particular line of a file, insert text
into a file, or remove text from a file.
Huh? Maybe the authors mean something by "direct way" that I'm not
understanding properly. I think the question can be answered directly.
$. is the current line number under default circumstances:
perl -pe 'print "Prepended line\n" if $.==1;' infile >outfile
It works on Perl v5.6.1, at any rate. The questioner should know not
to put more than one file on the command line for this one-liner. If
he wants to process several files, it's probably better to use a shell
script or a batch file in conjunction with the -i switch to perform
in-place replacement, and pass each individual filename as a shell or
batch variable.
HTH.
--
Eric Pement
------------------------------
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 5131
***************************************