[31330] in Perl-Users-Digest
Perl-Users Digest, Issue: 2575 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 30 09:09:44 2009
Date: Sun, 30 Aug 2009 06:09:08 -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 Sun, 30 Aug 2009 Volume: 11 Number: 2575
Today's topics:
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DA <jawad.karachi2010@gmail.com>
cgi and escapeHTML but not ampersand <mstep@podiuminternational.org>
Re: cgi and escapeHTML but not ampersand (Jens Thoms Toerring)
Re: cgi and escapeHTML but not ampersand <mstep@podiuminternational.org>
Re: cgi and escapeHTML but not ampersand (Jens Thoms Toerring)
Re: end-of-line conventions <ben@morrow.me.uk>
Re: Perl on Windows - use Perl as DLL <thepoet_nospam@arcor.de>
Re: Perl on Windows - use Perl as DLL <claus.kick@googlemail.com>
Re: perl script to generate server round-robin assignme <inetquestion@hotmail.com>
Re: Possibly useful perl script to filter lines in one <ben@morrow.me.uk>
Re: trapping errors using $! <ben@morrow.me.uk>
Re: windows one liner to output unix line feed <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 Aug 2009 10:57:21 -0700 (PDT)
From: Jawad Alam <jawad.karachi2010@gmail.com>
Subject: "EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON www.pak-web-pages.blogspot.com
Message-Id: <001d88d8-7061-4d88-b2e7-935e80f655d3@u16g2000pru.googlegroups.com>
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
"EXPRESS NEWSPAPER" "EXPRESS NEWS" "DAWN NEWSPAPER" "DAWN NEWS" "JANG
NEWS" "JANG NEWSPAPERS" "AAJKAL NEWSPAPER" "WAQT NEWSPAPER" ON
www.pak-web-pages.blogspot.com
------------------------------
Date: Sun, 30 Aug 2009 01:45:25 -0700 (PDT)
From: Marek <mstep@podiuminternational.org>
Subject: cgi and escapeHTML but not ampersand
Message-Id: <02c0afa1-87c5-4634-a371-3e2ef1c74044@d34g2000vbm.googlegroups.com>
Hello all!
Please if this is not the appropriate group, point my to the right
one.
I am trying to find since a good while, how to convince the CGI server
module, not to replace the ampersand, by &
I have an array like follows with two entity encoded *Umlauts*:
my @element_liste =3D
(
...
{ type =3D> "text", name =3D> "email",
bez =3D> "Email (zur Auftragsbestätigung):", size =3D>
36 },
{ type =3D> "text", name =3D> "fahrgast",
bez =3D> "Fahrgäste:", size =3D> 36, muss =3D> 1 },
...
);
and later the cgi I is producing a form with :
foreach my $f (@{$element_liste_ref})
{
print escapeHTML ($f->{bez}), " ",
textfield (-name =3D> $f->{name},
-size =3D> $f->{size}),
br (), "\n";
}
How to prevent, that the entity encoded ä is coming back as
&auml; ?
In my @element_liste I tried with every imaginable tricks, like :
bez =3D> "Fahrg=E4ste:",
bez =3D> "Fahrg\äste:",
bez =3D> "Fahrg\\äste:",
bez =3D> "Fahrg&auml;ste:",
or remove the escapeHTML
The header of the cgi is:
print header (),
start_html (-dtd =3D> '-//W3C//DTD XHTML 1.0 Transitional//EN',
-title =3D> "Title",
-lang =3D> 'de',
-style=3D>{'src'=3D>'/style/style.css',
-type=3D>'text/css',
-media=3D>'screen'},
-charset=3D>'utf-8'
),
which is producing the non valid <body charset=3D"utf-8">. On the server
is running unfortunately an outdated CGI version: CGI.pm Version:
2.752
Thank you for your help.
marek
------------------------------
Date: 30 Aug 2009 10:18:35 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: cgi and escapeHTML but not ampersand
Message-Id: <7fv1vrF2n0kjpU1@mid.uni-berlin.de>
Marek <mstep@podiuminternational.org> wrote:
> I am trying to find since a good while, how to convince the CGI server
> module, not to replace the ampersand, by &
> I have an array like follows with two entity encoded *Umlauts*:
> my @element_liste =
> (
> ...
> { type => "text", name => "email",
> bez => "Email (zur Auftragsbestätigung):", size =>
> 36 },
> { type => "text", name => "fahrgast",
> bez => "Fahrgäste:", size => 36, muss => 1 },
> ...
> );
> and later the cgi I is producing a form with :
> foreach my $f (@{$element_liste_ref})
> {
> print escapeHTML ($f->{bez}), " ",
> textfield (-name => $f->{name},
> -size => $f->{size}),
> br (), "\n";
> }
> How to prevent, that the entity encoded ä is coming back as
> &auml; ?
The only way to prevent replacement of characters that have a
special meaning in HTML is not to call a function that's meant
to do just that. And I don't see the need to call escapeHTML()
here since what you output seems to be fully written by you
and not derived from user input, so you can manually "escape"
everything that needs escaping.
> In my @element_liste I tried with every imaginable tricks, like :
> bez => "Fahrgäste:",
That, of course, works since there's nothing in that string that
would need conversion. On the other hand, then the encoding for
the page must be set correctly (probably either iso-8859-1 or
utf-8) to get it displayed correctly on the client side.
> bez => "Fahrg\äste:",
> bez => "Fahrg\\äste:",
The backslash isn't an "escape character" recognized by that
function.
> bez => "Fahrg&auml;ste:",
That can only make things worse, you will end up with
"Fahrg&amp;auml;ste:";-)
> or remove the escapeHTML
Looks like the way to go if the text to be output is written
by you and doesn't incorporate elements coming from the out-
side. If you need to use text coming from the outside then
run escapeHTML() on it before you use in the text you want
to output.
> The header of the cgi is:
> print header (),
> start_html (-dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
> -title => "Title",
> -lang => 'de',
> -style=>{'src'=>'/style/style.css',
> -type=>'text/css',
> -media=>'screen'},
> -charset=>'utf-8'
> ),
> which is producing the non valid <body charset="utf-8">. On the server
> is running unfortunately an outdated CGI version: CGI.pm Version:
> 2.752
Iif you have to you could simply forgo using start_html() and
output the text for the page header directly. Just take what
the call of start_html() outputs, correct it as necessary, and
then output it with a simple print.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Sun, 30 Aug 2009 04:44:03 -0700 (PDT)
From: Marek <mstep@podiuminternational.org>
Subject: Re: cgi and escapeHTML but not ampersand
Message-Id: <cd687375-d749-4d94-a88a-e0a19d265d47@p15g2000vbl.googlegroups.com>
On 30 Aug., 12:18, j...@toerring.de (Jens Thoms Toerring) wrote:
>
> The only way to prevent replacement of characters that have a
> special meaning in HTML is not to call a function that's meant
> to do just that. And I don't see the need to call escapeHTML()
> here since what you output seems to be fully written by you
> and not derived from user input, so you can manually "escape"
> everything that needs escaping.
>
> > In my @element_liste I tried with every imaginable tricks, like :
> > bez =A0=3D> "Fahrg=E4ste:",
>
> That, of course, works since there's nothing in that string that
> would need conversion. On the other hand, then the encoding for
> the page must be set correctly (probably either iso-8859-1 or
> utf-8) to get it displayed correctly on the client side.
>
> > bez =A0=3D> "Fahrg\äste:",
> > bez =A0=3D> "Fahrg\\äste:",
>
> The backslash isn't an "escape character" recognized by that
> function.
>
> > bez =A0=3D> "Fahrg&auml;ste:",
>
> That can only make things worse, you will end up with
> "Fahrg&amp;auml;ste:";-)
>
> > or remove the escapeHTML
>
> Looks like the way to go if the text to be output is written
> by you and doesn't incorporate elements coming from the out-
> side. If you need to use text coming from the outside then
> run escapeHTML() on it before you use in the text you want
> to output.
>
> > The header of the cgi is:
> > print header (),
> > =A0 =A0 =A0 =A0 start_html (-dtd =3D> '-//W3C//DTD XHTML 1.0 Transition=
al//EN',
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -title =3D> "Title",
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -lang =3D> 'de',
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -style=3D>{'src'=3D>'/s=
tyle/style.css',
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -type=3D>'text/css',
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -media=3D>'screen'},
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 -charset=3D>'utf-8'
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ),
> > which is producing the non valid <body charset=3D"utf-8">. On the serve=
r
> > is running unfortunately an outdated CGI version: CGI.pm Version:
> > 2.752
>
> Iif you have to you could simply forgo using start_html() and
> output the text for the page header directly. Just take what
> the call of start_html() outputs, correct it as necessary, and
> then output it with a simple print.
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Regards, =
Jens
> --
> =A0 \ =A0 Jens Thoms Toerring =A0___ =A0 =A0 =A0j...@toerring.de
> =A0 =A0\__________________________ =A0 =A0 =A0http://toerring.de
Jens! Vielen Dank!
I am appreciating your help! You were right! I thought, that I tried
really everything, but your hints helped me out of an impasse! Here my
steps:
1. I put in a blank start_html()
2. I removed all escapeHTML
3. I tried with Umlauts "=E4" etc (not working)
4. So I tried with entity-encoding (working!!! Uff!!)
5. I reinserted the wished Doctype and style-sheet
to 5.:
My server is giving back a non valid Doctype:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
Strange, my html-validator is telling me, that such kind of beast does
not exist. Probably this is due to the old cgi version: CGI.pm
Version: 2.752
A last question: how to set correctly the encoding to utf-8?
Thank you again Jens
------------------------------
Date: 30 Aug 2009 12:40:07 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: cgi and escapeHTML but not ampersand
Message-Id: <7fva97F2n3s14U1@mid.uni-berlin.de>
Marek <mstep@podiuminternational.org> wrote:
> My server is giving back a non valid Doctype:
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
> "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
> Strange, my html-validator is telling me, that such kind of beast does
> not exist. Probably this is due to the old cgi version: CGI.pm
> Version: 2.752
> A last question: how to set correctly the encoding to utf-8?
I guess you will need to output something like the following
instead of calling start_html() (if you it all manually I do
not think you should call it at all, even without arguments):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>
At least that seems to get accepted by the HTML validator;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Sun, 30 Aug 2009 11:14:20 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: end-of-line conventions
Message-Id: <s00qm6-o181.ln1@osiris.mauzo.dyndns.org>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <atjtl6-7f03.ln1@osiris.mauzo.dyndns.org>, on 08/19/2009
> at 04:55 PM, Ben Morrow <ben@morrow.me.uk> said:
>
> >More due to my inability to convert quoting styles on the fly. Sorry,
> >what I meant was of course
>
> > perl -le"print for unpack q{C*}, qq{\n}"
>
> Now I'm really confused. That gave the result you were expecting (10
> decimal), but way back when I tried using \n in a regex and had to change
> it to \x0a to get it to work. It doesn't seem reasonable that the meaning
> of \n would differ between string constants and literals, and it also
> doesn't seem reasonable that either would have changed since 5.6, so what
> is or was going on?
I have no idea, unless there was some sort of shell substitution going
on that was causing perl not to see the \n at all. Presumably this was
on OS/2, not some EBCDIC platform (where the numerical values *are*
different)? Does
perl -le"print "match" if qq{\x0a} =~ /\n/"
work correctly now?
Ben
------------------------------
Date: Sat, 29 Aug 2009 17:18:17 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Perl on Windows - use Perl as DLL
Message-Id: <4a99468d$0$32668$9b4e6d93@newsspool2.arcor-online.net>
claus.kick@googlemail.com wrote:
> On 29 Aug., 16:12, Christian Winter <thepoet_nos...@arcor.de> wrote:
>> claus.k...@googlemail.com schrieb:
>>>> http://docs.activestate.com/activeperl/5.8/Components/Windows/PerlEz....
>>>> is I think what I need.
>>>> I had been wondering whether there were better ways than doing (sorry
>>>> for the Java)
>>>> Runtime.getRuntime().exec(new String[] {"perl.exe", "script.pl",
>>>> "arg1", "arg2"});
>>> Ok progress:
>>> I can load the library, create an interpreter, but calling PerlEzCall1
>>> (...) fails with: 5 -> Function call caused an exception
>>> I figure my error is not knowing what to pass as pFunction - pointer
>>> name of the function to call.
>>> What do I have to pass as function parameter?
>> The name of the function. If you're just trying to run a script,
>> you don't have to invoke PerlEzCall at all, the script will be
>> executed when you call PerlEzCreate. What you won't have is
>> a capturing facility for STDOUT and STDERR, so in case you need
>> that, invoking a command line perl or linking the interpreter
>> directly as in perlembed might be more convenient in the long run.
>> PerlEzCall is used to invoke a specific function, see
>> http://www.perlmonks.org/?node_id=571371
>> for an example.
>
> I am sorry to ask in such a stupid way, but do you mean "sub routine"
> with "function"?
Exactly.
> Wouldnt it be possible to basically create a main() sub routine in a
> script like this:
>
> #!c:\perl\bin
>
> my $name = $ARGV[0];
>
> main();
>
> sub main
> {
> print "hello world: ".$name."!\n";
> }
>
>
> and hence be able to have STDOUT and STDERR (thats probably what
> lpBuffer is for)?
lpBuffer is the storage for the sub's return value, i.e. if your sub
read:
sub main
{
return "hello world";
}
then lpBuffer would contain the string "hello world". Anything you
print to STD(OUT|ERR) will be invisible, unless you redirect it
explicitely in the perl code.
A downside of this kind of invokation is that the size of lpBuffer
is defined before the invokation, so there IMHO is no (or better, no
both easy and sensible way) to capture arbitrarily long return values,
making it neccessary to be very thorough in defining possible return
values for subs called this way.
-Chris
------------------------------
Date: Sat, 29 Aug 2009 08:26:20 -0700 (PDT)
From: "claus.kick@googlemail.com" <claus.kick@googlemail.com>
Subject: Re: Perl on Windows - use Perl as DLL
Message-Id: <ba39e002-e4ec-4e77-9875-b743fbe52715@r36g2000vbn.googlegroups.com>
On 29 Aug., 17:18, Christian Winter <thepoet_nos...@arcor.de> wrote:
> claus.k...@googlemail.com wrote:
> > On 29 Aug., 16:12, Christian Winter <thepoet_nos...@arcor.de> wrote:
> >> claus.k...@googlemail.com schrieb:
> >>>>http://docs.activestate.com/activeperl/5.8/Components/Windows/PerlEz....
> >>>> is I think what I need.
> >>>> I had been wondering whether there were better ways than doing (sorry
> >>>> for the Java)
> >>>> Runtime.getRuntime().exec(new String[] {"perl.exe", "script.pl",
> >>>> "arg1", "arg2"});
> >>> Ok progress:
> >>> I can load the library, create an interpreter, but calling PerlEzCall1
> >>> (...) fails with: 5 -> Function call caused an exception
> >>> I figure my error is not knowing what to pass as pFunction - pointer
> >>> name of the function to call.
> >>> What do I have to pass as function parameter?
> >> The name of the function. If you're just trying to run a script,
> >> you don't have to invoke PerlEzCall at all, the script will be
> >> executed when you call PerlEzCreate. What you won't have is
> >> a capturing facility for STDOUT and STDERR, so in case you need
> >> that, invoking a command line perl or linking the interpreter
> >> directly as in perlembed might be more convenient in the long run.
> >> PerlEzCall is used to invoke a specific function, see
>
> >>http://www.perlmonks.org/?node_id=571371
>
> >> for an example.
>
> > I am sorry to ask in such a stupid way, but do you mean "sub routine"
> > with "function"?
>
> Exactly.
>
>
>
> > Wouldnt it be possible to basically create a main() sub routine in a
> > script like this:
>
> > #!c:\perl\bin
>
> > my $name = $ARGV[0];
>
> > main();
>
> > sub main
> > {
> > print "hello world: ".$name."!\n";
> > }
>
> > and hence be able to have STDOUT and STDERR (thats probably what
> > lpBuffer is for)?
>
> lpBuffer is the storage for the sub's return value, i.e. if your sub
> read:
> sub main
> {
> return "hello world";}
>
> then lpBuffer would contain the string "hello world". Anything you
> print to STD(OUT|ERR) will be invisible, unless you redirect it
> explicitely in the perl code.
OK, thanks for pointing that out.
> A downside of this kind of invokation is that the size of lpBuffer
> is defined before the invokation, so there IMHO is no (or better, no
> both easy and sensible way) to capture arbitrarily long return values,
> making it neccessary to be very thorough in defining possible return
> values for subs called this way.
I have been wondering about that.
One thing that comes to my mind is just to return a pointer (plus
size)
and have the calling language read the return value.
Or the easy solution: just return a temporary file name.
Thank you very much for your help - I still get Error 5 (Function call
caused an exception - sounds very generic) but that is just me doing
something wrong with calling the DLL.
------------------------------
Date: Sat, 29 Aug 2009 12:35:51 -0700 (PDT)
From: inetquestion <inetquestion@hotmail.com>
Subject: Re: perl script to generate server round-robin assignments
Message-Id: <2e2b4405-bbf6-4df5-be4f-10622387ff2d@z28g2000vbl.googlegroups.com>
On Aug 28, 10:14=A0pm, "John W. Krahn" <some...@example.com> wrote:
> inetquestionwrote:
> > #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> > ##################
> > ### Main Begin ###
> > ##################
>
> > if ($#ARGV < 0) {
> > =A0 =A0 &DoUsage;
>
> if ( @ARGV < 1 ) {
> =A0 =A0 =A0DoUsage();
>
> Or probably better as:
>
> if ( @ARGV !=3D 2 ) {
> =A0 =A0 =A0DoUsage();
>
> > =A0 =A0 exit;
> > }
>
> > my ($hostname, $limit) =3D @ARGV; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Script inputs
>
> > if ($hostname =3D~ /^([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)$/) { =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 # Filter
>
> Why use capturing parentheses? =A0Why put the \d character class inside a
> character class?
>
> if ( $hostname =3D~ /^\d+\.\d+\.\d+\.\d+$/ ) {
>
> > on IP address
> > =A0 =A0 =A0 $hostString=3D$hostname; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Save IP
> > } else {
> > =A0 =A0 =A0($hostString) =3D split /\./,$hostname; =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 # Obtain first portion
> > of FQDN component
> > }
>
> > @B =3D qw(svr01 svr02 svr03 svr04 svr05 svr06); =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0# Array containing
> > assignable server
> > $binaryNumber =3D DoAsc2bin($hostString); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0# Convert string
> > into base2
> > $binaryNumber =3D~ s/\s+//g; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Remove spaces
>
> Why does DoAsc2bin() add the whitespace if you are just going to remove i=
t?
>
> > from base2 string
> > $decString =3D DoBin2dec($binaryNumber); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 # Convert base2
> > string to base10
> > $assignment =3D DoAssign(scalar(@B), $decString, $hostname, $limit); #
>
> You should probably pass a reference to @B instead of using it globally.
>
>
>
> > Call subroutine to get assignments
>
> > print "$hostname: $assignment\n";
> > exit;
>
> > ########################
> > ### Subroutine Begin ###
> > ########################
>
> > sub DoUsage() {
>
> > print <<EOM;
>
> > Generates assignment values where servers in list-A need to
> > communicate with all or some of the servers in list-B. =A0The input to
> > the script is a single server hostname or IP from list-A. =A0This serve=
r
> > name will go through a conversion (ascII->Binary->Dec), then the order
> > of the assignments will be made. =A0As long as no two servers have the
> > same hostname, the assignment will be varied across the list to ensure
> > the servers in List-B are distributed evenly across those in List-A.
>
> > Usage: $0 <hostname|IP> <entry limit>
>
> > EOM
> > }
>
> > sub DoAsc2bin { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Convert ASCII string to b=
inary equivalent
> > =A0 =A0 my ($string) =3D @_; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Input
> > =A0 =A0 my @bytes; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Decla=
re byte array
> > =A0 =A0 for (split //, $string) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Run throuh for loo=
p per character
> > of string being split
> > =A0 =A0 =A0 push @bytes, unpack "B8", $_; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Store binary equivalent of
> > each character into @bytes
> > =A0 =A0 }
> > =A0 =A0 return wantarray ? @bytes : join " ", @bytes; =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0# Return @bytes or
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 ^^^^
> Why are you adding these spaces if you don't really want them?
>
>
>
> > a string of all content of @bytes
> > }
>
> > sub DoBin2dec {
> > =A0 =A0 return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));=
=A0#
> > Converts binary string to decimal equivalent
> > }
>
> > sub DoAssign {
> > =A0 =A0 my ($numListB, $num, $host, $lim) =3D @_; =A0 =A0 =A0 =A0# Func=
tion inputs
> > =A0 =A0 $lim ||=3D 100; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Set lim=3D100 unless =
otherwise specified
> > =A0 =A0 @B =3D reverse(@B); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Reverse array, then pop last
> > =A0 =A0 my $popNum =3D $num % $numListB; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 # Get modulus, then pop that
> > many elements from reversed array
> > =A0 =A0 while ( $popNum !=3D 0 ) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 #
> > Iterate until all values have been popped off array
> > =A0 =A0 =A0 =A0 push(@popSave, pop(@B)); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 # Save popped elements
> > =A0 =A0 =A0 =A0 $popNum--; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Decrement pop counter
> > =A0 =A0 }
> > =A0 =A0 @B =3D reverse(@B); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# Reverse array
> > =A0 =A0 push(@B, @popSave); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 =A0 =A0# Appennd popped elements to
> > reversed (original direction) array
>
> > =A0 =A0 for( $i =3D 0; $i < scalar(@B); $i++) { =A0 =A0 =A0 =A0 =A0 =A0=
=A0 =A0 =A0 =A0 =A0 # Loop
> > through all array elements, maintain counter
> > =A0 =A0if( $B[$i] eq $host ) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 # Look for match
> > =A0 =A0 =A0 =A0 =A0 =A0 #print "Match on $host\n"; =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 # Debug statement
> > =A0 =A0 =A0 =A0 =A0 =A0 @B =3D ($B[$i], @B[0..($i-1)], @B[($i+1)..scala=
r
> > (@B)]); =A0 =A0 =A0 # Modify array order by moving the "match" to front
>
> > last; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 # Move on
> > =A0 =A0 =A0 =A0 }
> > =A0 =A0 }
> > =A0 =A0 return join " ", @B[0..($lim-1)]; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=A0 =A0 =A0# Return space
> > deleimited string
> > }
>
> There is no need to reverse the contents of @B to get the same results:
>
> sub DoAssign {
> =A0 =A0 =A0# Here $ListB contains a reference to @B
> =A0 =A0 =A0my ( $ListB, $num, $host, $lim ) =3D @_;
>
> =A0 =A0 =A0$lim ||=3D 100;
>
> =A0 =A0 =A0push @$ListB, splice @$ListB, 0, $num % @$ListB;
>
> =A0 =A0 =A0for my $i ( 0 .. $#$ListB ) {
> =A0 =A0 =A0 =A0 =A0if ( $ListB->[ $i ] eq $host ) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0#print "Match on $host\n"; =A0 =A0 =A0 =A0 =A0=
# Debug statement
> =A0 =A0 =A0 =A0 =A0 =A0 =A0# Modify array order by moving the "match" to =
front
> =A0 =A0 =A0 =A0 =A0 =A0 =A0unshift @$ListB, splice @$ListB, $i, 1;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0last;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0}
> =A0 =A0 =A0 =A0 =A0}
>
> =A0 =A0 =A0return "@{ $ListB }[ 0 .. $lim - 1 ]";
> =A0 =A0 =A0}
>
> John
> --
> Those people who think they know everything are a great
> annoyance to those of us who do. =A0 =A0 =A0 =A0-- Isaac Asimov
It is impressive you "can and would" take the time to make my original
function more efficient. Being able to take someone else's code in
which wasn't explained at all, and modify it so quickly truly
impresses me. Your version worked immediately after I changed my
calling code to pass a reference array.
Thanks again!
-Inet
------------------------------
Date: Sun, 30 Aug 2009 11:45:29 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Possibly useful perl script to filter lines in one file out of another.
Message-Id: <9r1qm6-o181.ln1@osiris.mauzo.dyndns.org>
Quoth Tad J McClellan <tadmc@seesig.invalid>:
>
> open() does not die, if it fails it fails silently (which is why
> you should always, yes *always*, check its return value).
>
> So I don't know what you mean.
>
> Show me some code where an open() dies...
~% perl -Mautodie -e'open my $F, "/not/there"'
Can't open($fh, '/not/there'): No such file or directory at
-e line 1
:)
autodie is a rewrite of Fatal, whith nicer error messages, exception
objects, and (most importantly) lexical effect. I'm considering adding
use autodie;
to my standard
use strict;
use warnings;
Ben
------------------------------
Date: Sun, 30 Aug 2009 11:30:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: trapping errors using $!
Message-Id: <201qm6-o181.ln1@osiris.mauzo.dyndns.org>
Quoth "John" <john1949@yahoo.com>:
>
>
> At the moment I'm using :
>
> eval {read (STDIN,$request,$length);};
> if ($@ ne '') {$response=$error1}
>
> which appears to be working.
Well, yes, it works as long as nothing goes wrong. 'read' doesn't throw
an exception on error (unless you 'use Fatal' or 'use autodie', which I
would probably recommend nowadays), so you are just completely ignoring
any possible errors.
Ben
------------------------------
Date: Sun, 30 Aug 2009 11:25:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: windows one liner to output unix line feed
Message-Id: <dl0qm6-o181.ln1@osiris.mauzo.dyndns.org>
Quoth "Newsgroup only please, address is no longer replyable." <bad@example.invalid>:
> On Thu, 27 Aug 2009 11:58:06 -0700 (PDT) in comp.lang.perl.misc, boman
> <shambo_p@yahoo.com> wrote,
> >Chris's suggestion worked:
> >
> >perl -pi.orig -e "binmode(ARGVOUT); s|foo|bar|g" myfile.txt
>
> I knew there had to be a binmode in it, but I might never have found
> ARGVOUT. It's not in a lot of the usual lists of prefab file handles.
It's in perlvar, which is the only place you should be looking.
I would have though you could binmode all filehandles (if you wanted to)
with an appropriate -Mopen=... option, even if Win32 perl doesn't honour
$ENV{PERLIO}.
Ben
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2575
***************************************