[18814] in Perl-Users-Digest
Perl-Users Digest, Issue: 982 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 25 00:05:43 2001
Date: Thu, 24 May 2001 21: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)
Message-Id: <990763511-v10-i982@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 24 May 2001 Volume: 10 Number: 982
Today's topics:
Re: "Alan J. Flavell" wrote: <rebelvideo@hotmail.com>
-w and Text::Wrap <somewhere@in.paradise.net>
Re: Array slice: how about the remainder? <krahnj@acm.org>
Re: Array slice: how about the remainder? <godzilla@stomp.stomp.tokyo>
Re: Capturing matches from several regexpes <goldbb2@earthlink.net>
Constant -vs- Variable File Handles? <pettyr_no_spam@hotmail.com>
Constant -vs- Variable File Handles? <pettyr_no_spam@hotmail.com>
Re: Converting spaces to plus signs <somewhere@in.paradise.net>
Re: find executable files only (David Efflandt)
Re: Hash reference and copying (Eric Bohlman)
Re: Help slim down Perl code <goldbb2@earthlink.net>
I don't want global variables ? <Kevin Hancock@arcom.com.au>
Re: I don't want global variables ? <Kevin Hancock@arcom.com.au>
Re: I don't want global variables ? <godzilla@stomp.stomp.tokyo>
Re: I don't want global variables ? <tony_curtis32@yahoo.com>
Re: I don't want global variables ? <Kevin Hancock@arcom.com.au>
Re: I don't want global variables ? <jjclarke@optusnet.com.au>
Re: I don't want global variables ? <godzilla@stomp.stomp.tokyo>
Re: Limiting Characters - CGI Form <bkennedy99@Home.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 25 May 2001 10:49:55 +0930
From: Chris <rebelvideo@hotmail.com>
Subject: Re: "Alan J. Flavell" wrote:
Message-Id: <3B0DB33B.4C85D773@hotmail.com>
META headers are for HTML
try include that in a zip file
or a custom file format
.htaccess files where off limits on my server - thats what took me two
weeks to convince them, that I should have access to them.
Yes I know I should get a better ISP, especially since they have now
chosen to kill my cron perl script that does regular maintenance on my
database and transaction(ecommerce) server
and no they don't give me access to cron
BUT I am in Australia, to find a suitable ISP is almost impossible as
most charge a commercial operation like mine for data at 18 -20c PER
MEGABYTE
As I use about 30 Gigs per month that comes to about $6,000.00 per
month, more than my gross income!
I could set up my own server but I work on my own so apart from reading
the ocasional News Item I don't get the time required for such a setup
I could go to a server farm in the US but I am reticent as I recently
had one of my mirror servers in the US go offline for 6 weeks without
even an apology. (I off course ditched them)
Imagine what would have happened if that was my main server
NOW all of the above are my problems not yours
I just wanted to relate that it is not all black and white in the real
world, something you don't seem to understand.
The off subject topic was "Default Server Settings Corrupt Data"
as you chosen not to respond to that, I assume you either agree with me
or
have no idea how to respond.
"Alan J. Flavell" wrote:
>
> This is desperately O.T, so I'll be brief...
>
> On Sat, 19 May 2001, Chris wrote:
>
> > Oh and for those who don't realise it, many of us have to work with
> > virtual servers, we can't all afford the luxury of our own server.
>
> > We cannot simply change a servers settings,
>
> .htaccess in your web root directory. Assuming the ISP is running
> Apache, of course (and if not, why ever not...).
>
> > we have to negotiate with
> > often inflexible ISP's who either take forever or simply refuse to
> > change settings on the server to accomodate special requirements,
>
> I'd say the advice given at http://www.mnot.net/cache_docs/#META
> applies here too
>
> If your site is hosted at an ISP or hosting farm and they don't give
> you the ability to set arbitrary HTTP headers [...], complain
> loudly; these are tools necessary for doing your job.
>
> >
> >
> [much rudeness omitted]
> >
> >
> > > > But Hey arent we a little of topic :)
> > >
> > > Yes. f'ups prophylactically set.
>
> Hmmm.
--
Regards
Chris
rebelvideo@hotmail.com
P.S. I could have chosen to serve my files thru a perl script thereby
inserting any header I want, except again my ISP comes to the rescue by
limiting the cycles a script can use (common practice) hence the files
probably would take a day or two to deliver.
------------------------------
Date: Fri, 25 May 2001 13:52:03 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: -w and Text::Wrap
Message-Id: <tKkP6.13$fI3.164901@news.interact.net.au>
I'm trying to be a good boy and use -w and use strict with all my scripts.
I'm using Text::Wrap by importing it when required, eg:
require Text::Wrap;
Text::Wrap->import('wrap');
$Text::Wrap::columns=60;
This produces:
Name "Text::Wrap::columns" used only once: possible typo at ......
How do I pre-declare the variable, or get warnings to shut up?
------------------------------
Date: Fri, 25 May 2001 03:03:13 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Array slice: how about the remainder?
Message-Id: <3B0DCB6D.C86E8EC9@acm.org>
Chris Stith wrote:
>
> John W. Krahn <krahnj@acm.org> wrote:
> > Chris Stith wrote:
> >>
> >> > John W. Krahn wrote:
>
> [snip]
>
> > $ perl -v
>
> > This is perl, version 5.005_03 built for i586-linux
>
> [snip]
>
> There you go. I'd still like to see where some of the others
> failed. ;-)
Ok, here's the code that was copied from usenet and tested. Some changes
where made for code that modified the original @array and/or @chosen.
Following the code is the results I got.
my @array = ( 'AA' .. 'DV' );
my @chosen = (0,3,5,7,21,35,63,66,68);
print 'Size of @array = ', scalar @array, "\n\@array = @array\n";
print 'Size of @chosen = ', scalar @chosen, "\n\@chosen = @chosen\n\n";
sub Lin {
# original post by John Lin
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my @not_chosen = grep { !grep( $_, @chosen ) } 0 .. $#array;
my @stay_home = @array[ @not_chosen ];
return "@stay_home\n@go_picnic";
}
sub nobull1 {
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my %not_chosen;
undef @not_chosen{ 0 .. $#array };
delete @not_chosen{ @chosen };
# Can, of course, skip sort() if @stay_home order unimportant
my @stay_home = @array[ sort { $a <=> $b } keys %not_chosen ];
return "@stay_home\n@go_picnic";
}
sub nobull2 {
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
# Can, of course, skip sort() if @chosen known to be pre-sorted
my @chosen_copy = sort { $a <=> $b } @chosen;
my @not_chosen = grep {
$_ != $chosen_copy[ 0 ] || do { shift @chosen_copy; 0 }
} 0 .. $#array;
my @stay_home = @array[ @not_chosen ];
return "@stay_home\n@go_picnic";
}
sub Siegel {
# Anno Siegel's reply to nobull's first post
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my $aux = '';
vec( $aux, $_, 1 ) = 1 for @chosen;
my @stay_home = @array[ grep vec( ~ $aux, $_, 1 ), 0 .. $#array ];
return "@stay_home\n@go_picnic";
}
sub Godzilla {
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my (@stay_home);
my (@array2) = @array;
my (@chosen2) = @chosen;
foreach $chosen (@chosen2)
{undef ($array2[$chosen2]); }
foreach $stay_home (@array2)
{
if (defined ($stay_home))
{ push (@stay_home, $stay_home); }
}
return "@stay_home\n@go_picnic";
}
sub Dominus {
# Mark Jason Dominus' code
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my @stay_home = @array;
for ( reverse @chosen ) {
splice @stay_home, $_, 1;
}
return "@stay_home\n@go_picnic";
}
sub Stith {
# Chris Stith's reply to MJD
my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
my @stay_home = ();
my %chosen = ();
keys( %chosen ) = @chosen;
for( @array ) {
unless( exists( $chosen{$_} ) ) {
push @stay_home, $_;
}
}
return "@stay_home\n@go_picnic";
}
sub Krahn {
my @stay_home = @array;
my @go_picnic;
push @go_picnic, splice @stay_home, $_, 1 for sort { $b <=> $a }
@chosen;
return "@stay_home\n@go_picnic";
}
my %test = (
'Lin' => \&Lin,
'nobull1' => \&nobull1,
'nobull2' => \&nobull2,
'Siegel' => \&Siegel,
'Godzilla' => \&Godzilla,
'Dominus' => \&Dominus,
'Stith' => \&Stith,
'Krahn' => \&Krahn,
);
for ( sort keys %test ) {
my $r = $test{$_}->();
my ( $s, $t ) = split /\n/, $r;
my $u = (split " ", $s);
my $v = (split " ", $t);
if ( $u + $v == @array ) {
printf "%10s: OK\n", $_;
}
else {
printf "%10s: \@array = %3d \@chosen = %3d : \@stay_home =
%3d \@go_picnic = %3d\n",
$_, scalar @array, scalar @chosen, $u, $v;
}
print "$r\n";
}
print "\n";
__END__
$ try.pl
Size of @array = 100
@array = AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU
AV AW AX AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS
BT BU BV BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ
CR CS CT CU CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO
DP DQ DR DS DT DU DV
Size of @chosen = 9
@chosen = 0 3 5 7 21 35 63 66 68
Dominus: OK
AB AC AE AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ BA BB BC
BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB
CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT CU CV CW CX CY CZ DA DB DC
DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV
AA AD AF AH AV BJ CL CO CQ
Godzilla: @array = 100 @chosen = 9 : @stay_home = 99
@go_picnic = 9
AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY
AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV BW
BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT CU
CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS
DT DU DV
AA AD AF AH AV BJ CL CO CQ
Krahn: OK
AB AC AE AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ BA BB BC
BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB
CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT CU CV CW CX CY CZ DA DB DC
DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV
CQ CO CL BJ AV AH AF AD AA
Lin: @array = 100 @chosen = 9 : @stay_home = 0
@go_picnic = 9
AA AD AF AH AV BJ CL CO CQ
Siegel: @array = 100 @chosen = 9 : @stay_home = 63
@go_picnic = 9
AB AC AE AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ BA BB BC
BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB
CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT
AA AD AF AH AV BJ CL CO CQ
Stith: @array = 100 @chosen = 9 : @stay_home = 100
@go_picnic = 9
AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX
AY AZ BA BB BC BD BE BF BG BH BI BJ BK BL BM BN BO BP BQ BR BS BT BU BV
BW BX BY BZ CA CB CC CD CE CF CG CH CI CJ CK CL CM CN CO CP CQ CR CS CT
CU CV CW CX CY CZ DA DB DC DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR
DS DT DU DV
AA AD AF AH AV BJ CL CO CQ
nobull1: OK
AB AC AE AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ BA BB BC
BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB
CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT CU CV CW CX CY CZ DA DB DC
DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV
AA AD AF AH AV BJ CL CO CQ
nobull2: OK
AB AC AE AG AI AJ AK AL AM AN AO AP AQ AR AS AT AU AW AX AY AZ BA BB BC
BD BE BF BG BH BI BK BL BM BN BO BP BQ BR BS BT BU BV BW BX BY BZ CA CB
CC CD CE CF CG CH CI CJ CK CM CN CP CR CS CT CU CV CW CX CY CZ DA DB DC
DD DE DF DG DH DI DJ DK DL DM DN DO DP DQ DR DS DT DU DV
AA AD AF AH AV BJ CL CO CQ
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 24 May 2001 20:40:44 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Array slice: how about the remainder?
Message-Id: <3B0DD43C.DB211E58@stomp.stomp.tokyo>
"John W. Krahn" wrote:
> Chris Stith wrote:
> > John W. Krahn <krahnj@acm.org> wrote:
> > > Chris Stith wrote:
> > >> > John W. Krahn wrote:
(snipped)
> sub Godzilla {
> my @go_picnic = @array[ @chosen ]; # those who are chosen go picnic
> my (@stay_home);
> my (@array2) = @array;
> my (@chosen2) = @chosen;
> foreach $chosen (@chosen2)
> {undef ($array2[$chosen2]); }
> foreach $stay_home (@array2)
> {
> if (defined ($stay_home))
> { push (@stay_home, $stay_home); }
> }
> return "@stay_home\n@go_picnic";
> }
This is _not_ my code. Do not involve me in your
telling of technological lies.
Are you very clear on this? I will not condone
nor support your lies.
Godzilla!
------------------------------
Date: Thu, 24 May 2001 22:17:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Capturing matches from several regexpes
Message-Id: <3B0DC09E.BDDF8EB9@earthlink.net>
Craig Berry wrote:
>
> Daniel Zinsli (dzinsli+news@snapp.no) wrote:
> : I've falled into a trap that i think might be newbe'ish :)
> :
> : $_ = 'foozbaz';
> : m/(fooz)/; # matches, $1 is now fooz
> : m/(xyzzy)/; # don't match, $1 is still fooz
> :
> : If i now test the value of $1, i might falsely belive that it
> : captured something in the second regexp, while it still contains the
> : match from the first one.
> :
> : Any advice on avoiding these situations?
>
> Yes; never use the match variables further away than right after the
> match that (may have) set them. If you need them to last longer than
> that, stash them in your own variables.
It's not stashing you need to do, it's explicit testing of whether the
match succeeded. After all, the code is still broken if you change it
to the following:
my ($foomatch, $barmatch); $_ = 'foozbaz';
m/(fooz)/; $foomatch = $1;
m/(barz)/; $barmatch = $1;
The above is just as broken as the first bit of code.
However, if you changed it to this:
my ($foomatch, $barmatch); $_ = 'foozbaz';
m/(fooz)/ && $foomatch = $1;
m/(barz)/ && $barmatch = $1;
The code is no longer broken. Why? Because the assignment only occurs
if the match takes place.
> : Now, i've been using:
> :
> : if (1) { # Entering a new scope
>
> No need to fake a condition. Just using { to open a bare block works
> fine.
>
> But again, I'd advise explicit stashing over scope tricks any day of
> the week.
That's not the only problem with the code. Suppose something like this
occurs.
my ($foomatch, $barmatch);
{ $_ = 'blah'; /(blah)/;
# many many lines of code later, but within the same scope as above:
{ $_ = 'foozbaz'; m/(fooz)/; $foomatch = $1; }
{ $_ = 'foozbaz'; m/(barz)/; $barmatch = $1; }
}
Unless I'm mistaken, $barmatch will end up equal to "blah".
So you can see, if you plan on using captured text from $1 etc. you
should always, yes *always*, check the return value of the match
operator. In a way, this is like checking the return value of open.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: Fri, 25 May 2001 01:46:26 GMT
From: "Robert" <pettyr_no_spam@hotmail.com>
Subject: Constant -vs- Variable File Handles?
Message-Id: <SPiP6.286618$fs3.49011384@typhoon.tampabay.rr.com>
I don't want to look like an idiot by asking such a simple question though I
cannot find a definitive answer to my query...
Which is better and why...
'Constant' file handles or 'Variable' file handles?
Example of what I understand a CONSTANT filehandle to be:
open (FH, "< /etc/passwd");
while (<FH>) {
chomp;
print $_,"\n";
}
close (FH);
exit(0);
Example of what I understand a VARIABLE filehandle to be:
my ($FH) = "";
open ($FH, "< /etc/passwd");
while (<$FH>) {
chomp;
print $_,"\n";
}
close ($FH);
exit(0);
Both seem to work exactly the same in my limited testing but the 'variable'
type doesn't cause issues when I use strict and warn because I can declare
it. What are your thoughts?
-Robert
------------------------------
Date: Fri, 25 May 2001 01:46:41 GMT
From: "Robert" <pettyr_no_spam@hotmail.com>
Subject: Constant -vs- Variable File Handles?
Message-Id: <5QiP6.286619$fs3.49011894@typhoon.tampabay.rr.com>
I don't want to look like an idiot by asking such a simple question though I
cannot find a definitive answer to my query...
Which is better and why...
'Constant' file handles or 'Variable' file handles?
Example of what I understand a CONSTANT filehandle to be:
open (FH, "< /etc/passwd");
while (<FH>) {
chomp;
print $_,"\n";
}
close (FH);
exit(0);
Example of what I understand a VARIABLE filehandle to be:
my ($FH) = "";
open ($FH, "< /etc/passwd");
while (<$FH>) {
chomp;
print $_,"\n";
}
close ($FH);
exit(0);
Both seem to work exactly the same in my limited testing but the 'variable'
type doesn't cause issues when I use strict and warn because I can declare
it. What are your thoughts?
-Robert
------------------------------
Date: Fri, 25 May 2001 11:08:27 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Converting spaces to plus signs
Message-Id: <jgiP6.11$Zw3.85076@news.interact.net.au>
"Ken Philbrick" <kenphilbrick@mindspring.com> wrote in message
news:3B0DA1AC.D0B73D85@mindspring.com...
> I have some strings that contain spaces, but I'd like to convert all the
> spaces into plus signs. I've tried various methods using split and
> join, but nothing has worked. The FAQ on perl.com doesn't seem to
> mention anything about it either. Any ideas?
No need for split or join, use tr
eg:
tr/ /+/;
I'm suspicious about your reasons for wanting to do this. I suspect you are
doing the classic case of asking the wrong question to solve your problem.
Go back a step and explain why you think you want/need to do this.
------------------------------
Date: Fri, 25 May 2001 03:53:18 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: find executable files only
Message-Id: <slrn9grlpe.5u2.see-sig@typhoon.xnet.com>
On Thu, 24 May 2001 16:34:06 -0400, Claudio Inglesi <cinglesi@puc.cl> wrote:
> Does anyone know how to use the find command so that it only finds files
> that are executable (files whose permissions are set as executable for the
> user, group or everybody).
> Thanks.
> Claudio Inglesi
> Chile - South America
Maybe not totally developed, but this seems to work:
#!/usr/bin/perl -w
use File::Find;
print "Files with owner, group or other execute:\n";
find(\&wanted,'public_html');
sub wanted {
$file = $File::Find::name;
$mode = (stat($_))[2];
$mode = sprintf "%lo",$mode; # convert to octal
if ($mode =~ /^(\d)\d\d(\d)(\d)(\d)/) {
return 0 unless $1 == 1; # file?
$owner = $2; $group = $3; $other = $4;
return 0 unless ($owner & 1 || $group & 1 || $other & 1);
} else { print "regex problem for $file $mode"; return 0; }
print "$file $owner$group$other\n";
}
--
David Efflandt (Reply-To is valid) http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 25 May 2001 01:08:46 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Hash reference and copying
Message-Id: <9ekbau$ln4$2@bob.news.rcn.net>
Chris Stith <mischief@velma.motion.net> wrote:
> Eric Bohlman <ebohlman@omsdev.com> wrote:
>> Unless our two newsfeeds are badly out of sync, I haven't seen anybody in
>> this thread suggest symrefs; in fact they've all said the same thing you
>> did, just without the curly braces (which aren't syntactically required in
>> this case).
> Yes, sorry. My eyes deceived me, as those hard refs without the
> optional curlies start to _look_ like symrefs towards the end of
> the day. I should have read more closely.
> Carry on... There's nothing to see here.
Actually there *is* something healthy for newbies to see here, namely that
even experienced Perl programmers make mistakes and correct each other for
doing it, and that they don't perceive such corrections as attacks.
------------------------------
Date: Thu, 24 May 2001 21:31:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help slim down Perl code
Message-Id: <3B0DB5D9.1643D1A0@earthlink.net>
Uri Guttman wrote:
> > In article <x7g0du4pbz.fsf@home.sysarch.com>,
> > Uri Guttman <uri@sysarch.com> wrote:
> >> symrefs and eval should only be used when there is absolutely no
> >> other way to do it. a few areas that qualify are generating perl
> >> code on the
[snip]
> it is not the case that symrefs are pure evil. but the ease of which
> people think they are useful is the problem. they are used all the
> time when you use modules that export stuff, but the code that does
> the symref stuff is isolated and stable. if you roll your own symref
> code it is highly likely it will break one day.
>
> i use symrefs in once case to install closure methods in an
> AUTOLOAD. but that is very isolated and stable.
>
> seeing symrefs used (and promoted) for data structures is the biggest
> evil use as that is never needed.
My symref use was not for a data structure. It was to load three files
with closely related names into three global variables with closely
related names. Sure, it's fragile, but then again, so is hard coding
filenames into a script.
All parts of the variable names came from within that block -- so I
*know* that nothing strange is getting in them. It's when you get the
names nonlocally that problems can arise.
I try to treat stuff going into symref names as carefully as I would
treat tainted data in a CGI script -- maybe even more carefully. Hmm...
for( my ($key,$val) = each %ENV ) {
if( $key =~ s/^HTTP_([A-Z0-9_]+)$/\L$1/ && !defined &$key ) {
*{$key} = sub { $val };
}
}
Now the above *is* evil. *That* is the type of symref you should be
warning us about. It's something that looks useful, but is very
dangerous.
--
Customer: "I would like to try on that suit in the window."
Salesman: "Sorry sir, you will have to use the dressing room."
------------------------------
Date: Fri, 25 May 2001 11:05:39 +0930
From: "Kevin Hancock" <Kevin Hancock@arcom.com.au>
Subject: I don't want global variables ?
Message-Id: <3b0db69c@kastagir.senet.com.au>
Ok I give up!
I have looked everywhere and cannot resolve this issue I do not want to
deal with any global variables and am trying to declare a scope for all
variables I use. The following code as far as I can tell declares the hash
%in as local to the procedure it is called from. I pass it by reference to
ReadParse and ReadParse populates it.
What I do not understand is how come sub test can change the values of %in?
Does my() declare a variable local to all lower procedures and if so how do
I prevent %in from being accesable to lower procedures unless passed
explicitely in to the procedure?
ReadParse is used unchanged from cgi-lib @ http://cgi-lib.berkeley.edu/#doc
Thanks
Code outputs:
username: "foo".
password: "bah".
vendor: "tu".
username after test: "freddy".
password after test: "freddy".
vendor after test: "freddy".
Code here:
$ENV{'REQUEST_METHOD'} = "GET";
$ENV{'QUERY_STRING'} = "username=foo&password=bah&vendor=tu";
use strict 'vars';
my $username = "";
my $vendor = "";
my $password = "";
my %in;
&ReadParse(\%in);
for my $i ( keys %in ){
print "$i: \"$in{$i}\".\n";
}
&test;
for my $i ( keys %in ){
print "$i after test: \"$in{$i}\".\n";
}
sub test {
$in{'username'} = freddy;
$in{'password'} = freddy;
$in{'vendor'} = freddy;
}
------------------------------
Date: Fri, 25 May 2001 11:34:56 +0930
From: "Kevin Hancock" <Kevin Hancock@arcom.com.au>
Subject: Re: I don't want global variables ?
Message-Id: <3b0dbd78$1@kastagir.senet.com.au>
One answer that I have discovered is to wrap the code up in {} code block
and hey it works. Is this the best (only) way of doing this?
Thanks
{ # Start code block
$ENV{'REQUEST_METHOD'} = "GET";
$ENV{'QUERY_STRING'} = "username=foo&password=bah&vendor=tu";
use strict 'vars';
my $username = "";
my $vendor = "";
my $password = "";
my %in;
&ReadParse(\%in);
for my $i ( keys %in ){
print "$i: \"$in{$i}\".\n";
}
&test;
for my $i ( keys %in ){
print "$i after test: \"$in{$i}\".\n";
}
} # End code block
sub test {
$in{'username'} = freddy;
$in{'password'} = freddy;
$in{'vendor'} = freddy;
}
------------------------------
Date: Thu, 24 May 2001 19:06:36 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: I don't want global variables ?
Message-Id: <3B0DBE2C.5101D55@stomp.stomp.tokyo>
Kevin Hancock wrote:
(snipped)
> ReadParse is used unchanged from cgi-lib @ http://cgi-lib.berkeley.edu/#doc
What you indicate for output is untrue. Your script, when using
a Brenner cgi-lib style read and parse routine, produces results
similar to what is displayed beneath my signature.
Godzilla!
--
Variable "$in" is not imported at test1.pl line 23.
Variable "@in" is not imported at test1.pl line 24.
Variable "$in" is not imported at test1.pl line 24.
Variable "@in" is not imported at test1.pl line 25.
Variable "@in" is not imported at test1.pl line 27.
Variable "@in" is not imported at test1.pl line 28.
Global symbol "$i" requires explicit package name at test1.pl line 22.
Global symbol "$key" requires explicit package name at test1.pl line 22.
Global symbol "$val" requires explicit package name at test1.pl line 22.
Global symbol "$in" requires explicit package name at test1.pl line 23.
Global symbol "@in" requires explicit package name at test1.pl line 24.
Global symbol "$in" requires explicit package name at test1.pl line 24.
Global symbol "$i" requires explicit package name at test1.pl line 25.
Global symbol "@in" requires explicit package name at test1.pl line 25.
Global symbol "@in" requires explicit package name at test1.pl line 27.
Global symbol "$i" requires explicit package name at test1.pl line 27.
Global symbol "$key" requires explicit package name at test1.pl line 28.
Global symbol "$val" requires explicit package name at test1.pl line 28.
Global symbol "@in" requires explicit package name at test1.pl line 28.
Global symbol "$i" requires explicit package name at test1.pl line 28.
Global symbol "$val" requires explicit package name at test1.pl line 29.
Global symbol "$key" requires explicit package name at test1.pl line 30.
Global symbol "$val" requires explicit package name at test1.pl line 31.
Global symbol "$key" requires explicit package name at test1.pl line 32.
Global symbol "$key" requires explicit package name at test1.pl line 32.
Global symbol "$key" requires explicit package name at test1.pl line 33.
Global symbol "$val" requires explicit package name at test1.pl line 33.
Execution of test1.pl aborted due to compilation errors.
------------------------------
Date: 24 May 2001 21:06:50 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: I don't want global variables ?
Message-Id: <87lmnmfah1.fsf@limey.hpcc.uh.edu>
>> On Fri, 25 May 2001 11:05:39 +0930,
>> "Kevin Hancock" <Kevin Hancock@arcom.com.au> said:
> Ok I give up! I have looked everywhere and cannot
> resolve this issue I do not want to deal with any global
> variables and am trying to declare a scope for all
> variables I use. The following code as far as I can tell
> declares the hash %in as local to the procedure it is
> called from. I pass it by reference to ReadParse and
> ReadParse populates it.
Yikes, cgi-lib?! Use CGI.pm instead.
perldoc CGI
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Fri, 25 May 2001 12:23:11 +0930
From: "Kevin Hancock" <Kevin Hancock@arcom.com.au>
Subject: Re: I don't want global variables ?
Message-Id: <3b0dc8c8@kastagir.senet.com.au>
The code in the origional message with a require cgi-lib.pl before the "use
strict" produced exactly that output. You are requiring it after the "use
strict" or including it in the same program file?
Either way it doesn't answer the scope question although wrapping it in a
code block solves the problem for now.
One day I will resolve the scope problem, may even venture to CGI.pm too one
day.
Thanks
Kevin
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3B0DBE2C.5101D55@stomp.stomp.tokyo...
> Kevin Hancock wrote:
>
> (snipped)
>
> > ReadParse is used unchanged from cgi-lib @
http://cgi-lib.berkeley.edu/#doc
>
> What you indicate for output is untrue. Your script, when using
> a Brenner cgi-lib style read and parse routine, produces results
> similar to what is displayed beneath my signature.
>
>
> Godzilla!
> --
> Variable "$in" is not imported at test1.pl line 23.
> Variable "@in" is not imported at test1.pl line 24.
> Variable "$in" is not imported at test1.pl line 24.
> Variable "@in" is not imported at test1.pl line 25.
> Variable "@in" is not imported at test1.pl line 27.
> Variable "@in" is not imported at test1.pl line 28.
> Global symbol "$i" requires explicit package name at test1.pl line 22.
> Global symbol "$key" requires explicit package name at test1.pl line 22.
> Global symbol "$val" requires explicit package name at test1.pl line 22.
> Global symbol "$in" requires explicit package name at test1.pl line 23.
> Global symbol "@in" requires explicit package name at test1.pl line 24.
> Global symbol "$in" requires explicit package name at test1.pl line 24.
> Global symbol "$i" requires explicit package name at test1.pl line 25.
> Global symbol "@in" requires explicit package name at test1.pl line 25.
> Global symbol "@in" requires explicit package name at test1.pl line 27.
> Global symbol "$i" requires explicit package name at test1.pl line 27.
> Global symbol "$key" requires explicit package name at test1.pl line 28.
> Global symbol "$val" requires explicit package name at test1.pl line 28.
> Global symbol "@in" requires explicit package name at test1.pl line 28.
> Global symbol "$i" requires explicit package name at test1.pl line 28.
> Global symbol "$val" requires explicit package name at test1.pl line 29.
> Global symbol "$key" requires explicit package name at test1.pl line 30.
> Global symbol "$val" requires explicit package name at test1.pl line 31.
> Global symbol "$key" requires explicit package name at test1.pl line 32.
> Global symbol "$key" requires explicit package name at test1.pl line 32.
> Global symbol "$key" requires explicit package name at test1.pl line 33.
> Global symbol "$val" requires explicit package name at test1.pl line 33.
> Execution of test1.pl aborted due to compilation errors.
------------------------------
Date: Fri, 25 May 2001 13:02:49 +1000
From: "Steven Clarke" <jjclarke@optusnet.com.au>
Subject: Re: I don't want global variables ?
Message-Id: <3b0dcbb0$0$25468$7f31c96c@news01.syd.optusnet.com.au>
Kevin,
the my declarations are block scoped. The same notion as Pascal, Modual-2,
C, etc.
you can use local, but I think it applies module wide.
my %in; # input hash
ReadParse(\%in);
test {
$in{"username"} = "freddy";
}
in the above code the \%in refers to the address of the %in hash. It is
equlivant to pointer pasing in C. The $in{"username"} is the same variable
as the %in in the main program. If you want to block the %in, you have to
declare a my variable in the test function, otherwise any assignments will
change the global %in variable.
Also you should be using the CGI module from CPAN. It makes writing dynamic
pages easy.
If you own a PC download the ActiveState Perl. It has an extensive module
library and help file system.
Please email me If you need to know more.
Regards,
Steven Clarke.
"Kevin Hancock" <Kevin Hancock@arcom.com.au> wrote in message
news:3b0db69c@kastagir.senet.com.au...
> Ok I give up!
>
> I have looked everywhere and cannot resolve this issue I do not want to
> deal with any global variables and am trying to declare a scope for all
> variables I use. The following code as far as I can tell declares the hash
> %in as local to the procedure it is called from. I pass it by reference to
> ReadParse and ReadParse populates it.
>
> What I do not understand is how come sub test can change the values of
%in?
>
> Does my() declare a variable local to all lower procedures and if so how
do
> I prevent %in from being accesable to lower procedures unless passed
> explicitely in to the procedure?
>
> ReadParse is used unchanged from cgi-lib @
http://cgi-lib.berkeley.edu/#doc
>
> Thanks
>
> Code outputs:
>
> username: "foo".
> password: "bah".
> vendor: "tu".
> username after test: "freddy".
> password after test: "freddy".
> vendor after test: "freddy".
>
>
> Code here:
>
> $ENV{'REQUEST_METHOD'} = "GET";
> $ENV{'QUERY_STRING'} = "username=foo&password=bah&vendor=tu";
> use strict 'vars';
> my $username = "";
> my $vendor = "";
> my $password = "";
> my %in;
>
> &ReadParse(\%in);
>
> for my $i ( keys %in ){
> print "$i: \"$in{$i}\".\n";
> }
>
> &test;
>
> for my $i ( keys %in ){
> print "$i after test: \"$in{$i}\".\n";
> }
>
>
> sub test {
> $in{'username'} = freddy;
> $in{'password'} = freddy;
> $in{'vendor'} = freddy;
> }
>
>
------------------------------
Date: Thu, 24 May 2001 20:20:44 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: I don't want global variables ?
Message-Id: <3B0DCF8C.5457BF38@stomp.stomp.tokyo>
Kevin Hancock wrote:
> The code in the origional message with a require cgi-lib.pl before the "use
> strict" produced exactly that output. You are requiring it after the "use
> strict" or including it in the same program file?
(snipped)
Your code does not reflect a "require" statement, nor did you
mention use of require. Your code does make a direct call
to a subroutine "ReadParse" which might indicate a require,
although you indicate you use the read and parse routine "from"
Brenner's cgi-lib, and fail to mention if you are using his
first or second version, although he produced more than
two versions.
I would suggest you get your act together. Your article
strongly suggests you copied his read and parse directly
into your script, which is precisely what I did.
Godzilla!
------------------------------
Date: Fri, 25 May 2001 03:57:50 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Limiting Characters - CGI Form
Message-Id: <2LkP6.3181$lP5.1555792@news1.rdc2.pa.home.com>
"Jacob" <jpetrie@kitsapcu.org> wrote in message
news:cedf7c1b.0105231426.172142a2@posting.google.com...
> This is not working. How should I go about escaping these characters?
You should investigate using the $dbh->quote() method provided by DBI, which
will perform the necessary escapes for interpolated quotes. Another option
is to use prepared statement handles with placeholders - this will also
eliminate issues with quoting. See "perldoc DBI"
--Ben Kennedy
------------------------------
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 982
**************************************