[22918] in Perl-Users-Digest
Perl-Users Digest, Issue: 5138 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 26 09:05:45 2003
Date: Thu, 26 Jun 2003 06:05:12 -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 Thu, 26 Jun 2003 Volume: 10 Number: 5138
Today's topics:
Altering values by reference <dlovecraft@remove.this.to.emai.lme.breathe.com>
Re: Altering values by reference <noreply@gunnar.cc>
Re: Altering values by reference <ubl@schaffhausen.de>
Re: Altering values by reference <nobull@mail.com>
array question (Math55)
Re: array question (Anno Siegel)
Re: DB_File, large hash, memory. (A24061)
Re: DB_File, large hash, memory. <paul.marquess@btinternet.com>
Extracting/Matching Comments <member31962@dbforums.com>
Forking child process with WWW::Automate <Graham.T.Wood@oracle.com>
GLOB/FH/String <greving@gamic.com>
Re: GLOB/FH/String (Anno Siegel)
Re: GLOB/FH/String <greving@gamic.com>
Re: GLOB/FH/String (Anno Siegel)
Re: Hide source, compiling, whatever! <bigj@kamelfreund.de>
Re: Hide source, compiling, whatever! (Helgi Briem)
Locale doesnt work when LANG=C under CGI (apache) (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Re: Looking for inspiration: cascading CGI <g4rry_short@zw4llet.com>
Re: Looking for inspiration: cascading CGI (Jonathan Lonsdale)
Re: Offer tips, comments on this code (generates html t <bigj@kamelfreund.de>
Re: Offer tips, comments on this code (generates html t <spamblock@junkmail.com>
Re: Perl 5.6 and Perl 5.8 <ndronen@io.frii.com>
Re: Perl 5.6 and Perl 5.8 (Villy Kruse)
regexp help (spam)
regexp: resetting search position to start of string <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk>
Re: regexp: resetting search position to start of strin (Anno Siegel)
Re: soap::lite hellp needed with sms (Bryan Castillo)
speedier alternative to LWP? (Andrew Fisher)
Re: speedier alternative to LWP? <ubl@schaffhausen.de>
win32::perms owner problems (mathew grove)
Write to a filehandle and to STDOUT without double prin (dnrg)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 26 Jun 2003 10:55:08 +0000
From: Dela Lovecraft <dlovecraft@remove.this.to.emai.lme.breathe.com>
Subject: Altering values by reference
Message-Id: <XpzKa.1087$QA2.193283@newsfep2-win.server.ntli.net>
Dear All,
I was having a discussion with a die-hard Pascal programmer yesterday, and a
point was raised I couldn't answer, and I said I would try and find the
answer for him. Is there a way of altering a variable sent as a reference
to a subroutine in Perl *without* using a return value? As I recall, in
Pascal, you send to a function using either the value or declaring it as
var, in which case in can get altered in the procedure:
procedure myProc(x : Integer; var y : Integer)
Whatever is sent to the procedure as x remains unchanged, but anything which
happens to y (because of the var keyword) is changed in the original
variable. I think (sorry of the syntax for Pascal is off, but it has been a
long time.) Is such a thing possible in Perl?
Suppose I had a sub doSomething which added 10 to a value. Assuming I sent
it by reference, it could like something like this:
sub doSomething
{
my $reference = shift;
my $value = $$reference;
return ($value + 10);
}
And it would be called:
my $x = 1;
my $y = doSomething(\$x);
No problem. But is there a way I could call the sub such that the value of
$x could be altered in situ without returning a value, even over different
packages? Something like:
my $x = 1;
myOtherPackage::doSomething(\$x); #such that $x now equals 11
Any help would be really appreciated.
Dela
------------------------------
Date: Thu, 26 Jun 2003 12:32:26 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Altering values by reference
Message-Id: <bdeik9$qvjso$1@ID-184292.news.dfncis.de>
Dela Lovecraft wrote:
> Is there a way of altering a variable sent as a reference to a
> subroutine in Perl *without* using a return value?
<snip>
> Suppose I had a sub doSomething which added 10 to a value. Assuming
> I sent it by reference, it could like something like this:
>
> sub doSomething
> {
> my $reference = shift;
> my $value = $$reference;
> return ($value + 10);
> }
>
> And it would be called:
> my $x = 1;
> my $y = doSomething(\$x);
>
> No problem. But is there a way I could call the sub such that the
> value of $x could be altered in situ without returning a value,
> even over different packages? Something like:
>
> my $x = 1;
> myOtherPackage::doSomething(\$x); #such that $x now equals 11
sub doSomething { ${$_[0]} += 10 }
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 26 Jun 2003 12:42:19 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Altering values by reference
Message-Id: <bdelqk$oop$1@news.dtag.de>
Dela Lovecraft wrote:
> Dear All,
>
> I was having a discussion with a die-hard Pascal programmer yesterday, and a
> point was raised I couldn't answer, and I said I would try and find the
> answer for him. Is there a way of altering a variable sent as a reference
> to a subroutine in Perl *without* using a return value? As I recall, in
> Pascal, you send to a function using either the value or declaring it as
> var, in which case in can get altered in the procedure:
>
> procedure myProc(x : Integer; var y : Integer)
>
> Whatever is sent to the procedure as x remains unchanged, but anything which
> happens to y (because of the var keyword) is changed in the original
> variable. I think (sorry of the syntax for Pascal is off, but it has been a
> long time.) Is such a thing possible in Perl?
Parameters in Perl are always passed by reference (That is, the
references reside inside the magical array @_). "Pass by value" only
happens when you take things out of @_ (e.g. by calling shift without
arguments). If you access @_ directly you get the desired behavior.
some code: (untested)
sub inc {
$_[0]++
}
my $i = 0;
inc($i);
print $i
shows that $i has been modified inside the subroutine inc.
bye
malte
------------------------------
Date: 26 Jun 2003 12:48:56 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Altering values by reference
Message-Id: <u93chxhxef.fsf@wcl-l.bham.ac.uk>
Dela Lovecraft <dlovecraft@remove.this.to.emai.lme.breathe.com> writes:
> sub doSomething
> {
> my $reference = shift;
> my $value = $$reference;
> return ($value + 10);
> }
>
> And it would be called:
> my $x = 1;
> my $y = doSomething(\$x);
>
> No problem. But is there a way I could call the sub such that the value of
> $x could be altered in situ without returning a value, even over different
> packages?
packages are irrelevant unless you are using _symbolic_ references.
Something like:
> my $x = 1;
> myOtherPackage::doSomething(\$x); #such that $x now equals 11
No problem
package myOtherPackage;
sub doSomething
{
my $reference = shift;
$$reference += 10;
}
I you dont like putting the \ in the call to doSomething() you can put
it in a prototype instead. Or you can manipulate $_[0] directly rather
than using shift.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 26 Jun 2003 05:37:35 -0700
From: magelord@t-online.de (Math55)
Subject: array question
Message-Id: <a2b8188a.0306260437.2fdc5ed1@posting.google.com>
hi, this is a piece of code from a program.
----
my $size;
my $realPath;
my @filterArray;
open READFILTEREDLIST,'</tmp/FILTEREDLIST' or die "Datei kann nicht
geoeffnet werden: $!\n";
while(<READFILTEREDLIST>) {
@filterArray=<READFILTEREDLIST>;
}
close READFILTEREDLIST;
open (WRITEPATHS, ">/tmp/FILTEREDPATHS") or die "Datei konnte nicht
gefunden werden";
print "open \n";
foreach(@filterArray){
print "array: $_\n"; #NOTHING!!!
(my $datei, my $pfad)=fileparse($_);
($size, $realPath)=split('\s', $pfad);
print "path: $realPath\n";
print WRITEPATHS "$realPath\n";
}
close WRITEPATHS;
----
the file FILTEREDLIST contains something like:
132k /var/backups/dpkg.status.1.gz
132k /var/backups/dpkg.status.2.gz
124k /var/backups/dpkg.status.3.gz
8.0k /var/log/auth.log.1.gz
12k /var/log/auth.log.2.gz
4.0k /var/log/auth.log.3.gz
12k /var/log/daemon.log.1.gz
12k /var/log/daemon.log.2.gz
8.0k /var/log/daemon.log.3.gz
8.0k /var/log/debug.1.gz
12k /var/log/debug.2.gz
4.0k /var/log/debug.3.gz
8.0k /var/log/kern.log.1.gz
4.0k /var/log/kern.log.2.gz
8.0k /var/log/kern.log.3.gz
8.0k /var/log/messages.1.gz
8.0k /var/log/messages.2.gz
8.0k /var/log/messages.3.gz
4.0k /var/log/setuid.changes.1.gz
but when i want to read that into the array, something does wrong. the
array is always empty, do you see the mistake? the file is not
empty...
THANKS!!
------------------------------
Date: 26 Jun 2003 13:04:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: array question
Message-Id: <bder0d$78f$1@mamenchi.zrz.TU-Berlin.DE>
Math55 <magelord@t-online.de> wrote in comp.lang.perl.misc:
> hi, this is a piece of code from a program.
>
> ----
> my $size;
> my $realPath;
> my @filterArray;
> open READFILTEREDLIST,'</tmp/FILTEREDLIST' or die "Datei kann nicht
> geoeffnet werden: $!\n";
>
> while(<READFILTEREDLIST>) {
This reads one line from the file into $_
>
> @filterArray=<READFILTEREDLIST>;
This reads the rest of the lines into @filterArray.
>
> }
> close READFILTEREDLIST;
>
> open (WRITEPATHS, ">/tmp/FILTEREDPATHS") or die "Datei konnte nicht
> gefunden werden";
> print "open \n";
> foreach(@filterArray){
>
> print "array: $_\n"; #NOTHING!!!
> (my $datei, my $pfad)=fileparse($_);
^^^^^^^^^
The function "fileparse()" is nowhere defined. So the program exits
the first time through the loop.
> ($size, $realPath)=split('\s', $pfad);
> print "path: $realPath\n";
> print WRITEPATHS "$realPath\n";
The variable "$realPath" is never assigned to. "$pfad" isn't even
declared. If the program compiles for you, you are not using "strict",
which is bad.
>
> }
> close WRITEPATHS;
>
> ----
>
> the file FILTEREDLIST contains something like:
>
> 132k /var/backups/dpkg.status.1.gz
> 132k /var/backups/dpkg.status.2.gz
> 124k /var/backups/dpkg.status.3.gz
[more data snipped]
Your diagnosis is wrong. The file *is* read into the array (save for
the first line, and after getting compile-time errors out of the way).
I don't know why you think it isn't.
To get the whole file, do away with the while-loop and just say
@filterArray=<READFILTEREDLIST>;
Anno
------------------------------
Date: 26 Jun 2003 02:23:10 -0700
From: a24061@yahoo.com (A24061)
Subject: Re: DB_File, large hash, memory.
Message-Id: <8228723b.0306260123.12359076@posting.google.com>
"Paul Marquess" <paul.marquess@btinternet.com> wrote in message news:<3ef9b72c$0$10632$ed9e5944@reading.news.pipex.net>...
> Nope, DB_File will only store everything in memory if you explicitly ask it
> to. By default, it only keeps a small amount in memory.
So it should be possible to work with a hash that is larger than the
available memory?
------------------------------
Date: Thu, 26 Jun 2003 11:11:28 +0100
From: "Paul Marquess" <paul.marquess@btinternet.com>
Subject: Re: DB_File, large hash, memory.
Message-Id: <3efac6d3$0$18488$ed9e5944@reading.news.pipex.net>
"A24061" <a24061@yahoo.com> wrote in message
news:8228723b.0306260123.12359076@posting.google.com...
> "Paul Marquess" <paul.marquess@btinternet.com> wrote in message
news:<3ef9b72c$0$10632$ed9e5944@reading.news.pipex.net>...
> > Nope, DB_File will only store everything in memory if you explicitly ask
it
> > to. By default, it only keeps a small amount in memory.
>
> So it should be possible to work with a hash that is larger than the
> available memory?
Absolutely - that is what the underlying database system that DB_File uses,
namely Berkeley DB, is designed for.
The default cache memory Berkeley DB uses is 256K. The actual database can
be in the gigabyte range.
Paul
------------------------------
Date: Thu, 26 Jun 2003 09:47:37 +0000
From: darkname <member31962@dbforums.com>
Subject: Extracting/Matching Comments
Message-Id: <3045329.1056620857@dbforums.com>
Hello everyone!!
Does anyone knows a module that parses and extracts comments of a given
source code file?? (such as C, C++, Java, PL/SQL, PERL, etc)!!?
Thereīs a module in CPAN that was designed to do this
(Regexp::Common::comment) but this module donīt preview all cases for
example in PERL!!
Because.. there are special cases that should be contemplated such as:
@array=/1 # 2 3 4/;
print"#This is not a comment";
$size=?#array;
@array=("#", 1,2,3);
How can i do this?
There is another module Text::Balanced that should work to.. with the
function extract_delimited, where the delimitators would be starting
with # and ending with \n! But i canīt make this work! :((
Another issue.. is this regex that should get the comments in Perl but
it doesnīt work also!!
~ m{
( \# .*? \n ) # extract a comment wich starts
with # to \n
| " (?: [^"\#]* | \#. )* " # skip over "..."
| ' (?: [^'\#]* | \#. )* ' # skip over '...'
| . [^\#"']* # skip over non-comments-or-quotes
}xgs;
Can someone tell me why??
Thank you all very much!
darkname...:p
--
Posted via http://dbforums.com
------------------------------
Date: Thu, 26 Jun 2003 10:58:41 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Forking child process with WWW::Automate
Message-Id: <3EFAC3D1.46CDA25C@oracle.com>
This is a multi-part message in MIME format.
--------------14E8CC0B5A32C6B4A554A2C7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi all,
I'm attempting to automate a login to a web server with WWW::Automate
and then to continue navigating through the website. I've hit a problem
where I'm able to log in to the web site but then I don't get
automatically returned to the page I logged in from and all attempts to
get there have just resulted in a repeat request to log in.
Can anyone tell me how I could fork a child agent to handle the login
and then continue in the parent process safe in the knowledge that I am
logged in?
Here's what I'm doing now:
use WWW::Automate;
my $agent = WWW::Automate->new();
$agent->get("http://hostnamename.us.company.com/pls/show_logon_form");
$agent->field("p_username","jbloggs");
$agent->field("p_password","jbpass");
$agent->submit();
print "$agent->{content}";
#
# this shows..
#<H2>Logon Successful</H2>
#<H4>Please navigate back to the application</H4>
#<SCRIPT><!--opener.location.reload(true);
#opener.location = opener.location;
#//--></SCRIPT>
#<SCRIPT>
#<!--
#self.close();
#//--></SCRIPT>
#
# This is the page I need to access after the login
#
$agent->get("http://hostnamename.us.company.com/pls/page\$.startup");
print "$agent->{content}";
# but this just sends me back to the login page
<H2>Logon Required</H2>
<H4>Please enter your username and password to log on</H4>
<FORM ACTION="page.process_logon" METHOD="POST" NAME="Logonform">
<TABLE >
<TR>
<TD>Username: </TD>
<TD><INPUT TYPE="text" NAME="p_username"></TD>
</TR>
<TR>
<TD>Password: </TD>
<TD><INPUT TYPE="password" NAME="p_password"></TD>
</TR>
<TR>
<TD><INPUT TYPE="submit" VALUE="Log on"></TD>
I've tried using the $agent->back(); to return to the previous page but
the seems to result in my logged in ness disappearing as well.
I've also tried creating $agent2 to just do the login but it doesn't let
$agent stay logged in.
Any suggestions? I'm running on WinNT but can switch to W2K or Solaris
or Linux if it helps or makes any difference to anything.
Thanks
Graham
--------------14E8CC0B5A32C6B4A554A2C7
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------14E8CC0B5A32C6B4A554A2C7--
------------------------------
Date: Thu, 26 Jun 2003 13:53:38 +0200
From: Hendrik GReving <greving@gamic.com>
Subject: GLOB/FH/String
Message-Id: <bdemif$hn$1@nets3.rz.RWTH-Aachen.DE>
Hi,
I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated as
a String and it prints the filename. I need to have a scalar string (for a
list) now, how can I "cast" the FH into a String?
greetings Hendrik
------------------------------
Date: 26 Jun 2003 12:25:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: GLOB/FH/String
Message-Id: <bdeomv$5o5$1@mamenchi.zrz.TU-Berlin.DE>
Hendrik GReving <greving@gamic.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated as
> a String and it prints the filename.
The file *name*? That is a strange filehandle indeed.
That it is interpreted as a string is normal. It's just the way Perl
resolves this particular ambiguity. Write "print $fh, $_" for the
other interpretation.
> I need to have a scalar string (for a
> list) now, how can I "cast" the FH into a String?
...but this is what happened, it was used as a string. To enforce
stringification (on any Perl variable), put it in double quotes: "$fh".
Anno
------------------------------
Date: Thu, 26 Jun 2003 14:44:53 +0200
From: Hendrik Greving <greving@gamic.com>
Subject: Re: GLOB/FH/String
Message-Id: <bdepj1$4fi$1@nets3.rz.RWTH-Aachen.DE>
Anno Siegel wrote:
> Hendrik GReving <greving@gamic.com> wrote in comp.lang.perl.misc:
>> Hi,
>>
>> I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated
>> as a String and it prints the filename.
>
> The file *name*? That is a strange filehandle indeed.
>
> That it is interpreted as a string is normal. It's just the way Perl
> resolves this particular ambiguity. Write "print $fh, $_" for the
> other interpretation.
>
>> I need to have a scalar string (for
>> a
>> list) now, how can I "cast" the FH into a String?
>
> ...but this is what happened, it was used as a string. To enforce
> stringification (on any Perl variable), put it in double quotes: "$fh".
>
> Anno
Ok :-) I should have tried this. Anyway, what happens when doing ""? Is this
a cast or can a Filehandle return its Filename implicitly?
greetings Hendrik
------------------------------
Date: 26 Jun 2003 12:46:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: GLOB/FH/String
Message-Id: <bdepud$5o5$3@mamenchi.zrz.TU-Berlin.DE>
Hendrik Greving <greving@gamic.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Hendrik GReving <greving@gamic.com> wrote in comp.lang.perl.misc:
> >> Hi,
> >>
> >> I have an FileHandle $fh; When I do "print $fh" the FileHandle is treated
> >> as a String and it prints the filename.
> >
> > The file *name*? That is a strange filehandle indeed.
> >
> > That it is interpreted as a string is normal. It's just the way Perl
> > resolves this particular ambiguity. Write "print $fh, $_" for the
> > other interpretation.
> >
> >> I need to have a scalar string (for
> >> a
> >> list) now, how can I "cast" the FH into a String?
> >
> > ...but this is what happened, it was used as a string. To enforce
> > stringification (on any Perl variable), put it in double quotes: "$fh".
> >
> > Anno
>
>
> Ok :-) I should have tried this. Anyway, what happens when doing ""? Is this
> a cast or can a Filehandle return its Filename implicitly?
A file can have any number of names, from zero to anything. A filehandle
knows nothing about them. There is no way to go from an open file to
(any of its) name(s) in the file system.
Anno
------------------------------
Date: Thu, 26 Jun 2003 06:28:47 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Hide source, compiling, whatever!
Message-Id: <pan.2003.06.26.04.28.45.778212@kamelfreund.de>
Mike wrote at Wed, 25 Jun 2003 21:19:36 -0700:
> Hey, I have several programs that I would like to install on a
> client's website. However, this client has been known to be very good
> friends with a local competing designer (who happens to be a terrible
> programmer), and in my opinion is very likely to give his friend
> access to the server and download my programs, regardless of
> copyright. One of these programs I've spent years perfecting, and I
> would be pretty upset if it was swiped by this guy.
>
> [...]
>
> Are there any modules that I can install to permanently encrypt the
> source code? Any other suggestions? This would likely be a one-time
> occurrence, so I'm hesitant to buy a program unless I have to, but at
> this point I'm open to any suggestions.
Have you already read
perldoc -q hide
Greetings,
Janek
------------------------------
Date: Thu, 26 Jun 2003 11:59:17 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Hide source, compiling, whatever!
Message-Id: <3efade67.268708968@news.cis.dfn.de>
On 25 Jun 2003 21:19:36 -0700, csdude@hotmail.com (Mike) wrote:
>Hey, I have several programs that I would like to install on a
>client's website. However, this client has been known to be very good
>friends with a local competing designer (who happens to be a terrible
>programmer), and in my opinion is very likely to give his friend
>access to the server and download my programs, regardless of
>copyright. One of these programs I've spent years perfecting, and I
>would be pretty upset if it was swiped by this guy.
This is a FAQ. Read all about it in:
perldoc -q hide
Short answer, can't be done.
>At this point, I am looking for any option possible. I tried Perl2Exe,
>but can't get even the simplest script to work in the browser (they'll
>work at the Dos command prompt, but not when I try to open them from
>the browser).
What on earth does a browser have to do with Perl?
Are you trying to make a CGI program? Your web
server is probably configured to allow CGI programs
with the .pl or .cgi extensions, but not .exe, but
thatīs a web server configuration issue, not a Perl issue.
Perl2exe works extremely well, in my experience, but
it's not free and the code is not well hidden.
The PAR module (available from CPAN) does the
same thing and is free.
PerlApp from Activestate is similar, but not free.
> I've also tried PerlCC that came with ActivePerl, but
>get nothing but errors when trying to compile (and it never completes
>the compilation).
Never has and probably never will.
>Are there any modules that I can install to permanently encrypt the
>source code?
No. I don't think so. Licence it properly.
>Any other suggestions? This would likely be a one-time
>occurrence, so I'm hesitant to buy a program unless I have to, but at
>this point I'm open to any suggestions.
I doubt very much that your programs are so super
duper that it will be worth his while to steal them.
There are a lot of *superb* Perl programs available
for free out there at www.stonehenge.com, www.perlmonks.org
and nms-cgi.sourceforge.net for example.
------------------------------
Date: 26 Jun 2003 04:11:53 -0700
From: ra9af7y02@sneakemail.com (=?ISO-8859-1?Q?Peter_Valdemar_M=F8rch?=)
Subject: Locale doesnt work when LANG=C under CGI (apache)
Message-Id: <17243cc8.0306260311.5807f18@posting.google.com>
Hi,
I've read in `perldoc perllocale` about the need to configure LANG or
LC_ALL to get locales to work properly with perl. But when attempting
to develop CGI scripts I do not have control over apache's
configuration that exports the hardcoded environment variable LANG=C.
Is there really no way to get locales to work if LANG=C, or any other
value not mentioned in locale -a?
This script prints $! in french if LANG=en_US or has any other value
from
locale -a, but in english otherwise, e.g. under apache...
#!/usr/bin/perl -w
$ENV{"LANGUAGE"}="fr";
open I, "nonexistant" or print $!;
close I;
Without some sort of workaround, I either have to modify httpd.conf to
export LANG=en_US or use something other than gettext, neither of
which sound exciting...
------------------------------
Date: Thu, 26 Jun 2003 09:46:55 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: Looking for inspiration: cascading CGI
Message-Id: <bdec2i$23d$1$8300dec7@news.demon.co.uk>
Garry Short wrote:
> Hi all,
>
> I'm looking for a little inspiration! I'm working on a site involving a
> lot of CGI - each script generates an HTML page that connects to another
> script.
>
> I'm currently thinking I need a way of passing variables from one script
> to the next. At the moment I can think of two possibilities, and I'm not
> convinced by either of them!
>
> 1. Write the variables to a logfile somewhere, which each script can read
> and then overwrite.
>
> 2. Have a "Next >" button, as follows:
> <INPUT TYPE="SUBMIT" NAME="cgi_passed_vars" VALUE="$var1##$var2##$var3">
> Then, in the new script, this section of code:
>
> use CGI;
> my $form_data = new CGI;
> my ($var1, $var2, $var3) =
> split /##/, $form_data->param( "cgi_passed_vars" );
>
>
> Which is the better approach? Is there an even better alternative? Which
> would be the easiest for someone else to support after I'm gone?
>
> Personally, I'm inclined to go with #2 at the moment. What do you guys
> think?
>
> Cheers,
>
> Garry
Wow! What a response!
Thanks for the advice, everyone - really should have thought of hidden
variables myself :-)
Not too worried about sanitizing data, etc - this is for an intranet site
with restricted access (it'll be a configuration management system,
actually). Everything will be logged and version controlled anyway.
I'm also not too worried about performance - there'll be half a dozen users,
max.I think the server should be able to cope :-)
Thanks again,
Garry
------------------------------
Date: 26 Jun 2003 02:02:58 -0700
From: jon3001@hotmail.com (Jonathan Lonsdale)
Subject: Re: Looking for inspiration: cascading CGI
Message-Id: <5a2621be.0306260102.6ae58ddb@posting.google.com>
Garry Short <g4rry_short@zw4llet.com> wrote in message news:<bdcg7m$mdn$1$8300dec7@news.demon.co.uk>...
> I'm looking for a little inspiration! I'm working on a site involving a lot
> of CGI - each script generates an HTML page that connects to another
> script.
The main techniques (some of which have already been mentioned on the
thread) are:
1. Passing values in hidden fields for form submission.
2. Passing values via the query string.
3. Passing values via cookies.
4. Using a session system to associate a session ID (passed using one
of the above techniques) with storage on the server (flat file, RDBMS,
DBM).
"CGI Programming with Perl" (O'Reilly) gives good coverage of these
kind of techniques together with a discussion of the security issues.
------------------------------
Date: Thu, 26 Jun 2003 06:28:49 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <pan.2003.06.26.04.25.11.180243@kamelfreund.de>
David Oswald wrote at Wed, 25 Jun 2003 23:35:55 -0700:
> Please offer suggestions, comments, and tips on the following perl code. I
> had a need to quickly generate an html document indexing and displaying all
> image files within a given directory.
Sounds on the first glance like a standard job for Apache.
> #!/usr/bin/perl
use strict;
use warnings;
Allthough, you try to write like these styles suggest,
you don't enforce it. That involves the danger of making little mistkaes.
> [Snipped good comments]
> # --- Declarations ---
>
> my ($outfile)="index.html"; # declare the output html file's name.
You can also leave out the brackets:
my $outfile = "index.html";
I would recommend it also, as the other tells Perl something very
different as you primarly wanted (allthough it still works).
my ($outfile) is a list context,
where the simple "index.html" is a scalar context.
In this case, it's not a problem, as Perl interpretes it right,
but it can become a problem for you in future, as a clear distinction
between list and scalar contexts reduces the error rates.
The simplest way to avoid it is to use the principle:
Left is a list/scalar => Right is a list/scalar
unless you really want something different.
> my (@imagefiles); # declare the list to hold the image files. Leave undef
> until list retrieved.
> my ($dirname) = "./"; # define the input directory.
> my ($htmltitle)="Picture List"; # Give a title to the output html document
> via <title> tag,
> # and a first line <h1> caption.
>
>
> # --- Main body ---
> [Snipped]
> # --- Subroutine definitions ---
>
>
> sub getdir() { #Opens the current directory and gets all image filenames
> into an array.
> my ($dir)=@_;
> my @entries;
> opendir (CURRENTDIR, $dir) || die "Error: Unable to open directory: $dir \n
> $!";
> while (defined ( $file = readdir(CURRENTDIR))) {
Where does $file come from?
> if ($file =~ /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i) {
^^
That's not necessary.
A test whether a file has a specific ending is easier with:
if ($file =~ /\.(jpe?g|tiff?|bmp|gif)$/i) {
Note, that the many extra brackets you wrote,
aren't necessary at all.
> push (@entries,$file);
> }
> }
> closedir(CURRENTDIR);
> return sort(@entries);
> }
>
> [...]
>
> sub printheader() { #Prints the html header to the outfile.
> my ($title)=@_; #$title becomes both the html title as well as the <h1>
> header.
> print HTML "<html>\n<head>\n<title>$title</title>\n</head>\n";
> print HTML "<body>\n";
> print HTML "<h1>$title</h1>\n";
> print HTML "<hr>\n<p>\n";
> print HTML "Click on any link to open image in its own window. \n";
> print HTML "By opening an image in its own window, you can print or easily
> save ";
> print HTML "individual images.\n";
> print HTML "</p><hr>";
Perhaps it's easier to use a HERE doc:
print HTML <<END_OF_HTML;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
<hr>
<p>
Click on any link to open image in its own window.
By opening an image in its own window, you can print or easily save
individual images.
</p>
<hr>
END_OF_HTML
You still play a lot with global variables,
but the code is good structured and easy to understand.
(If it's really your first Perl project, I'm impressed).
Greetings,
Janek
------------------------------
Date: Thu, 26 Jun 2003 02:41:20 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: Offer tips, comments on this code (generates html to index image files)
Message-Id: <vflg4jr19ing3e@corp.supernews.com>
Thanks for the comments. I would like to hear more.
Yes, it was my first perl project. I read Learning Perl, Programming Perl,
Mastering Regular Expressions, about four years ago, cover to cover because
it intrigued me, but never tinkered until now when I finally found myself
with a little time. I had to brush up with a half-day of reading again
before I could dive in and create this. My other experience was a few
classes in Comp Sci about twelve years ago where I learned to tinker in
Pascal, C, and of all things, Modula II. I haven't touched C since about
1992 though, and the others disappeared from my vocabulary even before that.
Anyway, Perl intrigues me because it's one language where a lot can be
accomplished without getting bogged down in the details of user interfaces
and other such clutter. It just gets the job done quickly. Seems kind of
like putting together a puzzle.
In the following remarks I'm going to ask a few questions about your
comments:
"Janek Schleicher" <bigj@kamelfreund.de> wrote in message
news:pan.2003.06.26.04.25.11.180243@kamelfreund.de...
> David Oswald wrote at Wed, 25 Jun 2003 23:35:55 -0700:
>
>
<snip>
> > my ($outfile)="index.html"; # declare the output html file's name.
>
> You can also leave out the brackets:
>
> my $outfile = "index.html";
>
> I would recommend it also, as the other tells Perl something very
> different as you primarly wanted (allthough it still works).
>
You're right. I should have caught that myself. For some reason after
brushing up I was still vague on that but I understand now.
> > # --- Subroutine definitions ---
> >
> >
> > sub getdir() { #Opens the current directory and gets all image
filenames
> > into an array.
> > my ($dir)=@_;
> > my @entries;
> > opendir (CURRENTDIR, $dir) || die "Error: Unable to open directory:
$dir \n
> > $!";
> > while (defined ( $file = readdir(CURRENTDIR))) {
>
> Where does $file come from?
I should have declared $file as "my $file;" within the subroutine getdir().
But without declaring it, its creation is implicit, though to your earlier
point, use strict; would balk at that notion, forcing me to declare it as I
should.
As far as how it gets loaded, readdir(CURRENTDIR) is loading it. As I'm
looking at it now, I'm wondering if I could leave out all references to
$file and thus imply $_? In other words, "while defined
readdir(CURRENTDIR)" .... would that load $_ with a value if I didn't
explicitly state $file= ? And then I could do away with the =~ operator in
my reg exp, and I would just push @entries,$_ ...just a thought.
> > if ($file =~ /.*\.((jpe?g)|(tiff?)|(bmp)|(gif))$/i) {
> ^^
>
> That's not necessary.
> A test whether a file has a specific ending is easier with:
>
> if ($file =~ /\.(jpe?g|tiff?|bmp|gif)$/i) {
>
> Note, that the many extra brackets you wrote,
> aren't necessary at all.
>
I should have looked up order of precidence again. But I was concerned
that, for example, the | (alternate) operator would grab "g" and "t" instead
of "jpe?g" and "bmp"... and so on. I wasn't sure how greedy | is. Why
isn't .* necessary if I'm trying to match the entire filename? I guess I
understand that; the entire filename gets loaded into $file even if I'm only
matching a portion of it.
> > push (@entries,$file);
Is there a better way of doing this? I read somewhere that it's best to
avoid subscript access, so push seemed like a good alternative. But is
there a construct that avoids any call at all? ...something like @entries=
(@entries,$file); ??
<snip>
>
> > sub printheader() { #Prints the html header to the outfile.
> > my ($title)=@_; #$title becomes both the html title as well as the
<h1>
> > header.
> > print HTML "<html>\n<head>\n<title>$title</title>\n</head>\n";
> > print HTML "<body>\n";
> > print HTML "<h1>$title</h1>\n";
> > print HTML "<hr>\n<p>\n";
> > print HTML "Click on any link to open image in its own window. \n";
> > print HTML "By opening an image in its own window, you can print or
easily
> > save ";
> > print HTML "individual images.\n";
> > print HTML "</p><hr>";
>
> Perhaps it's easier to use a HERE doc:
>
> print HTML <<END_OF_HTML;
> <html>
> <head>
> <title>$title</title>
> </head>
> <body>
> <h1>$title</h1>
> <hr>
> <p>
> Click on any link to open image in its own window.
> By opening an image in its own window, you can print or easily save
> individual images.
> </p>
> <hr>
> END_OF_HTML
>
Wow, I forgot all about here docs. The books only devote a couple
paragraphs to here documents, but you're right, that's a cleaner solution.
> You still play a lot with global variables,
> but the code is good structured and easy to understand.
> (If it's really your first Perl project, I'm impressed).
I think I had four globals. Did I miss something, or what could I have done
to further reduce that while maintaining re-configurability?
Thanks for taking the time to respond. I'd like to improve my proficiency.
Dave
>
>
> Greetings,
> Janek
------------------------------
Date: 26 Jun 2003 07:06:27 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Re: Perl 5.6 and Perl 5.8
Message-Id: <3efa9b73$0$199$75868355@news.frii.net>
Alvise Valsecchi <alvise@hochfeiler.it> wrote:
AV> Hi, I am new to this newsgroup, hence you might have discussed this
AV> topic in the past. Sorry for this.
AV> Here stands my problem: I wrote a network daemon that has been working
AV> fine under Perl 5.6 and Red Hat 7.3 for many months.
AV> Then I installed Red Hat 8, and Perl 5.8 that comes togheter, and the
AV> script started failing continuously.
I don't use Red Hat, so I don't know about problems associated
with upgrading to its version 8.
Exactly how does it fail? You might have to put logging and
debugging code in your daemon to find out.
AV> I investigated and discovered that Perl 5.8 introduces Unicode as a
AV> default, but there should be more than this.
It's hard to tell whether Unicode is the source of the problem until
you say what the problem is.
[ snip ]
AV> These are my questions: is Perl 5.8 backward compatible?
Should be.
[ snip ]
Regards,
Nicholas
--
"Why shouldn't I top-post?" http://www.aglami.com/tpfaq.html
"Meanings are another story." http://www.ifas.org/wa/glossolalia.html
------------------------------
Date: 26 Jun 2003 08:51:16 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Perl 5.6 and Perl 5.8
Message-Id: <slrnbfld04.3mq.vek@station02.ohout.pharmapartners.nl>
On Thu, 26 Jun 2003 08:25:18 +0200,
Alvise Valsecchi <alvise@hochfeiler.it> wrote:
>
>Then I installed Red Hat 8, and Perl 5.8 that comes togheter, and the
>script started failing continuously.
>
>I investigated and discovered that Perl 5.8 introduces Unicode as a
>default, but there should be more than this.
>
That is only because RH8 by default set the LANG variable to a value
including the string "utf8". That is the crucial change and that also
affects othey utilities as well, and the console and keyboard too.
The effect of setting LANG to this value is to tell perl that all text
will be utf-8 encoded, unless you specify otherwise in your perl programs.
Villy
------------------------------
Date: Thu, 26 Jun 2003 12:35:08 +0200
From: "sjaak" <sjaak538(spam)@domein.nl>
Subject: regexp help
Message-Id: <3efacd13$0$28905$1b62eedf@news.euronet.nl>
Hello
Can anybody set me a little on the wright direction how to replace
route.htm"></a> to generate
route.htm">route</a>
so
.htm"></a>
.html"></a>
must replaced to
.htm">route</a>
.html">route</a>
I don't know where to begin this with regexp.
To avoid futher questions in this does anyone knows a good howto with many
examples.
Like this problem is a combination of regexp's and I don't understand them
all so it's heard to do.
I just need them ones a year that's why i don't stay in touch with regexp.
So many thanks
Sjaak
------------------------------
Date: Thu, 26 Jun 2003 09:35:43 +0100
From: Paul Burton <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk>
Subject: regexp: resetting search position to start of string
Message-Id: <3EFAB05F.9030102@pmburtonNOT-THIS.claraORTHIS.co.uk>
As I understand it, the normal behaviour of regexp, if the /g modifier
is used, is that each successive search starts from the position of the
last sucessful match. Is there any way, within the regexp syntax to ask
it to start the search from the beginning again?
At the moment I'm forcing this to happen by sticking my regexp within a
"boring" while statement, ie.
1 while ($string =~ s/complicated/replacement/);
which has the desired effect. Is there any neater way of achieving this
without the "boring" while loop?
Paul.
------------------------------
Date: 26 Jun 2003 12:41:03 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexp: resetting search position to start of string
Message-Id: <bdepkv$5o5$2@mamenchi.zrz.TU-Berlin.DE>
Paul Burton <newsonly@pmburtonNOT-THIS.claraORTHIS.co.uk> wrote in comp.lang.perl.misc:
> As I understand it, the normal behaviour of regexp, if the /g modifier
> is used, is that each successive search starts from the position of the
> last sucessful match. Is there any way, within the regexp syntax to ask
> it to start the search from the beginning again?
>
> At the moment I'm forcing this to happen by sticking my regexp within a
> "boring" while statement, ie.
> 1 while ($string =~ s/complicated/replacement/);
>
> which has the desired effect. Is there any neater way of achieving this
> without the "boring" while loop?
You mean, s///g should loop until the regex part no longer matches?
The only conceivable way I can think of would be to reset pos( $string)
after each successful match (via "(?{ pos( $string) = 0})"). I don't
know if this works as expected (the regex engine may keep its pointer
elsewhere). In any case it's obscure and probably fagile. Stick with
boring.
Anno
------------------------------
Date: 26 Jun 2003 00:09:38 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: soap::lite hellp needed with sms
Message-Id: <1bff1830.0306252309.37d0fd9@posting.google.com>
mike solomon <mike_solomon@lineone.net> wrote in message news:<3EF983E2.9030302@lineone.net>...
> Yarden Katz wrote:
> > mike solomon <mike_solomon@lineone.net> writes:
> >
> > [snip]
> >
> >>If anyone knows if there is a way to produce a / rather than a # I
> >>will be really grateful
> >
> >
> > It's very easy, just use:
> >
> > -> on_action(sub {sprintf '%s/%s', @_})
> >
> > In your SOAP object. To have the changes affect all SOAP objects
> > (globally), use:
> >
> > use SOAP::Lite
> > on_action => sub {sprintf '%s/%s', @_};
> >
> > HTH,
>
> Thanks, that solved one problem
>
> now I just have to work out hw to generate the correct format xml
>
> the code I am using is
>
> #The name of the module
> my $soap = SOAP::Lite->uri($uri);
> #print "soap = $soap\n";
>
> #The url for the request
> $soap = $soap->proxy($proxy);
> #print "soap = $soap\n";
>
my $method = SOAP::Data
->name('SendMessageFull')
->attr({xmlns=>'com.esendex.ems.soapinterface'});
> # send the request w/ header
# my $response = $soap->SendMessageFull(
my $response = $soap->call($method =>
>
> # HEADER
> SOAP::Header->name(Username => $username),
> SOAP::Header->name(Password => $password),
> SOAP::Header->name(Account => $account),
>
> # PARAMETERS FOR BODY
> SOAP::Data->name(originator =>$originator),
> SOAP::Data->name(recipient => $recipient),
> SOAP::Data->name(body => $body),
> SOAP::Data->name(type =>$type),
> SOAP::Data->name(validityperiod => 99)
>
> );
>
> this generates a header like this
>
> <SOAP-ENV:Header>
> <Username xsi:type="xsd:string">mike.solomon</Username>
> <Password xsi:type="xsd:string">password</Password>
> <Account xsi:type="xsd:int">account</Account>
> </SOAP-ENV:Header>
>
> but the service requires
>
> <soap:Header>
> <MessengerHeader xmlns="com.esendex.ems.soapinterface">
> <Username>USERNAME</Username>
> <Password>PASSWORD</Password>
> <Account>ACCOUNT</Account>
> </MessengerHeader>
> </soap:Header>
>
See the changes above, I specified the xml namespace for the method.
I had some luck with another .NET web service after specifying the
xml namespace.
What error are you receiving now when you try to send the request?
About the sockets.... Just look at IO::Socket::INET and the perlipc document.
I wouldn't reccomend you use plain sockets to call a soap service though.
I tried it just to see if the service was even working.
If you were going to generate the xml and then parse it from scratch you would
probably use LWP::UserAgent and then use an XML parser to examine the result.
>
> Regards
>
>
> Mike Solomon
------------------------------
Date: 26 Jun 2003 04:05:25 -0700
From: drewfisher@hotmail.com (Andrew Fisher)
Subject: speedier alternative to LWP?
Message-Id: <3934b71c.0306260305.5e110558@posting.google.com>
Hi there all,
I am writing a little script that gets some data from a couple of
servers. One of these is a database and no probs there though the
other is a web server that I don't have control over. I am using LWP
to get the page I want then dump it so I can do some processing,
matching etc as you normally do.
I am running this as a CGI script on an Apache Web server. LWP has
been updated to current version. Final medium for this app is a WAP
phone.
Now, the interesting bits:
Total script time on average is < 10 seconds [lots of processing] and
has been optimised quite heavily.
If I run the script locally it works like a dream.
If I run the script from a web browser it returns without a problem.
If I run the script from a wap phone OR wap emulator it fails. It is
failing at the point where I do my $response=get($url); giving a read
timeout error.
The timeout on the server is 300 seconds as per normal and this is for
scripts as well as pages so no probs there [as it works from web
browser this definitely isn't the problem].
If I take the get command out and just process from a file the script
works 100%. If I put it back in then it fails. I have had it working
once but I suspect that the time I had it working, the response was
cached so it returned blindingly fast.
Getting to the bottom of this now, my question is: Is there a faster
alternative to LWP or am I going to have to scratch my idea?
Cheers
Andrew F
------------------------------
Date: Thu, 26 Jun 2003 13:20:12 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: speedier alternative to LWP?
Message-Id: <bdeo1l$saq$1@news.dtag.de>
Andrew Fisher wrote:
> Getting to the bottom of this now, my question is: Is there a faster
> alternative to LWP or am I going to have to scratch my idea?
I guess the real question is: "Is there a faster alternative to your
current internet connection?"
Its very unlikely the overhead is caused by LWP but rather by the path
the data requested through LWP is taking. Try to connect to a machine on
your local network using LWP. If the problem still occurs, contact us again.
malte
------------------------------
Date: 26 Jun 2003 03:17:17 -0700
From: mathew_grove@yahoo.co.uk (mathew grove)
Subject: win32::perms owner problems
Message-Id: <e57bf6b8.0306260217.2f3fb167@posting.google.com>
I have recently undertaken the onerous task of changing registry
entries...
I am using the following
PERL version 5.005_03 build 518 provided by ActiveState
Win32-Perms [0.2002.06.05]
I am trying to change the owner on a series of keys (see code) - but
this fails and just reports the original owner - any ideas?
#------------------------------------------------
use Win32::Perms;
Win32::Perms::LookupDC(0);
@reg_entry_winnt =("HKEY_CLASSES_ROOT\\\.UDL",
"HKEY_CLASSES_ROOT\\\.dsn",
"HKEY_CLASSES_ROOT\\\.evt",
"HKEY_CLASSES_ROOT\\ADODB\.Command",
"HKEY_CLASSES_ROOT\\ADODB\.Command.2.6",
"HKEY_CLASSES_ROOT\\ADODB\.Connection",
"HKEY_CLASSES_ROOT\\ADODB\.Connection.2.6",
"HKEY_CLASSES_ROOT\\SQLXMLX\.1",
"HKEY_CLASSES_ROOT\\evt_auto_file");
foreach $reg_entry(@reg_entry_winnt){
print "$reg_entry\n";
my($Perms) = new Win32::Perms( 'registry:'.$reg_entry )|| next;
if($Perms){
$Perms->Owner('BUILTIN\Adminstrators');
$Perms->SetOwner();
$Perms->Dump();
#$Perms->Add( {Account=>'Administrators', Mask=>FULL } );
#$Perms->SetDacl() || "die cannot set it\n";
#$Perms->Dump();
undef $Perms;
}
}
#-----------------------------------------------------
------------------------------
Date: 26 Jun 2003 06:03:01 -0700
From: dananrg@yahoo.com (dnrg)
Subject: Write to a filehandle and to STDOUT without double print statements?
Message-Id: <c1888d06.0306260503.3195fce@posting.google.com>
I'd like to output the same text to the screen as well as to a file.
I've always used double print statements to achieve this in the past
but it always seemed like a dopey way to do it. Is there a more
elegant, space-saving way to do this? Can you use two or more
filehandles in the same print statement?
Thanks in advance.
- Dana
------------------------------
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 5138
***************************************