[23590] in Perl-Users-Digest
Perl-Users Digest, Issue: 5797 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 13 21:05:40 2003
Date: Thu, 13 Nov 2003 18:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 13 Nov 2003 Volume: 10 Number: 5797
Today's topics:
Re: "tree" view of directory <mikeflan@earthlink.net>
Re: "tree" view of directory <mikeflan@earthlink.net>
(exit $?0) - challenge <ahoward@ngdc.noaa.gov>
Re: (exit $?0) - challenge <usenet@morrow.me.uk>
Re: (exit $?0) - challenge <ahoward@ngdc.noaa.gov>
arrange form data in same order as on form <bxtrap01@comcast.net>
Re: arrange form data in same order as on form <usenet@morrow.me.uk>
Re: arrange form data in same order as on form <asu1@c-o-r-n-e-l-l.edu>
Re: arrange form data in same order as on form <REMOVEsdnCAPS@comcast.net>
Re: arrange form data in same order as on form <noreply@gunnar.cc>
Re: arrange form data in same order as on form <usenet@morrow.me.uk>
Re: arrange form data in same order as on form <noreply@gunnar.cc>
Re: arrange form data in same order as on form <emschwar@pobox.com>
Re: arrange form data in same order as on form <noreply@gunnar.cc>
Re: CGI - unreloadable page? <REMOVEsdnCAPS@comcast.net>
Re: Evaluating nester variables <uri@stemsystems.com>
Re: Evaluating nester variables <noreply@gunnar.cc>
Re: Evaluating nester variables <gtb104gtb@netscape.net>
Re: Giving back <tore@aursand.no>
Re: last index of array reference <abigail@abigail.nl>
Re: List into hash <tore@aursand.no>
Re: long running perl programs & memory untilization <stanb@panix.com>
Re: long running perl programs & memory untilization <usenet@morrow.me.uk>
Re: Need help with a program (rband)
newbie dealings with OS "grep -P" <hexkid@hotpop.com>
Re: newbie dealings with OS "grep -P" <invalid-email@rochester.rr.com>
Re: Problem with IO::Socket::INET and pop <asu1@c-o-r-n-e-l-l.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 13 Nov 2003 23:20:16 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: "tree" view of directory
Message-Id: <3FB41267.1316AA12@earthlink.net>
Louis Erickson wrote:
> I've never seen Windows 2000's command prompt behave that way. Am I
> misunderstanding what you mean?
>
> If that were the case, this perl would produce nothing:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> for(0...100) {
> print "$_ ";
> }
>
> __END__
>
> And, when run, it produces the integers between zero and one hundred,
> with spaces between them. The command prompt even gives you a trailing
> carriage return before it prints the prompt.
>
> (Bash on Linux and in Cygwin shows everything, but the prompt immediately
> follows the space after '100'. This is probably more correct. Microsoft's
> is more readable.)
>
> Am I misunderstanding what you mean by "one unterminated line"? Or is there
> something else going on?
I know you are not talking to me, but when I run your
script is works as intended. Prints 1 .. 100 all on one line.
------------------------------
Date: Thu, 13 Nov 2003 23:31:09 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: "tree" view of directory
Message-Id: <3FB414F6.AA80918E@earthlink.net>
Jay Tilton wrote:
>
> The readADir() subroutine is never called. :)
>
> It should work just fine after that is fixed.
>
> @ARGV = '.' unless @ARGV; # whatever should happen if @ARGV is empty
> readADir( @ARGV );
Thank you all. I'm not too good at subroutines yet, but
should have seen that.
Interestingly, now the program only prints:
"<ul><li> Io.sys </li><li> Msdos.sys </li></ul>"
Never mind - apparently that is exactly what it's supposed to
do on an empty directory. It works now - sort of. It just
doesn't list the paths very good.
Call me stupid, but I don't know why the original programer
did the <ul> <li> stuff. Must be some kind of html or something.
Mike
------------------------------
Date: Thu, 13 Nov 2003 17:02:24 -0700
From: "Ara.T.Howard" <ahoward@ngdc.noaa.gov>
Subject: (exit $?0) - challenge
Message-Id: <Pine.LNX.4.44.0311131658030.8330-100000@fattire.ngdc.noaa.gov>
gurus-
i've got a really strange looking bit of perl i'm trying to grok and it's been
too long since i've been in perl mode. actually, i'm not sure i'd ever have
gotten this one - any insight appreciated:
#!/usr/bin/perl
eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' & eval 'exec /usr/bin/perl -S $0 $argv:q' if 0;
# ... the rest is a really normal looking perl script
regards.
-a
--
ATTN: please update your address books with address below!
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
------------------------------
Date: Fri, 14 Nov 2003 00:33:16 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: (exit $?0) - challenge
Message-Id: <bp17sc$imm$1@wisteria.csv.warwick.ac.uk>
Ara.T.Howard@noaa.gov wrote:
> gurus-
>
> i've got a really strange looking bit of perl i'm trying to grok and
> it's been too long since i've been in perl mode. actually, i'm not
> sure i'd ever have gotten this one - any insight appreciated:
>
> #!/usr/bin/perl eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0
> ${1+"$@"}' & eval 'exec /usr/bin/perl -S $0 $argv:q' if 0;
This line is not actually Perl :).
It is a trick to make the script run on systems that don't support the
#! syntax. On (some of) those systems, executing a text file always
tries to run it as a shell script, and this line is to make the shell
re-execute the script with perl. The 'if 0' at the end means that perl
will always ignore the entire line. I don't fully understand the shell
magic: my guess would be that it is supposed to work under both sh and
csh, but my knowledge of shell is not that good.
If your system understands #!, you can just take it out.
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| ben@morrow.me.uk
------------------------------
Date: Thu, 13 Nov 2003 17:53:07 -0700
From: "Ara.T.Howard" <ahoward@ngdc.noaa.gov>
Subject: Re: (exit $?0) - challenge
Message-Id: <Pine.LNX.4.44.0311131752080.11069-100000@fattire.ngdc.noaa.gov>
On Fri, 14 Nov 2003, Ben Morrow wrote:
> Date: Fri, 14 Nov 2003 00:33:16 +0000 (UTC)
> From: Ben Morrow <usenet@morrow.me.uk>
> Newsgroups: comp.lang.perl.misc
> Subject: Re: (exit $?0) - challenge
>
>
> Ara.T.Howard@noaa.gov wrote:
> > gurus-
> >
> > i've got a really strange looking bit of perl i'm trying to grok and
> > it's been too long since i've been in perl mode. actually, i'm not
> > sure i'd ever have gotten this one - any insight appreciated:
> >
> > #!/usr/bin/perl eval '(exit $?0)' && eval 'exec /usr/bin/perl -S $0
> > ${1+"$@"}' & eval 'exec /usr/bin/perl -S $0 $argv:q' if 0;
>
> This line is not actually Perl :).
>
> It is a trick to make the script run on systems that don't support the
> #! syntax. On (some of) those systems, executing a text file always
> tries to run it as a shell script, and this line is to make the shell
> re-execute the script with perl. The 'if 0' at the end means that perl
> will always ignore the entire line. I don't fully understand the shell
> magic: my guess would be that it is supposed to work under both sh and
> csh, but my knowledge of shell is not that good.
>
> If your system understands #!, you can just take it out.
i'd hoped as much - i had a vague feeling that the (exit) syntax was creating
a subshell or something - but couldn't find any reference to it in perlsyn.
guess that's because it's not perl.
thanks!
-a
--
ATTN: please update your address books with address below!
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| STP :: http://www.ngdc.noaa.gov/stp/
| NGDC :: http://www.ngdc.noaa.gov/
| NESDIS :: http://www.nesdis.noaa.gov/
| NOAA :: http://www.noaa.gov/
| US DOC :: http://www.commerce.gov/
|
| The difference between art and science is that science is what we
| understand well enough to explain to a computer.
| Art is everything else.
| -- Donald Knuth, "Discover"
|
| /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done'
===============================================================================
------------------------------
Date: Thu, 13 Nov 2003 23:10:59 GMT
From: "bbxrider" <bxtrap01@comcast.net>
Subject: arrange form data in same order as on form
Message-Id: <7cUsb.139690$mZ5.963708@attbi_s54>
is there a way to sort (or other method) the 'method=post' data fields from
a form into
the same order they appear in the form
when i use the following code there doesn't appear to be any particular
order to how they are arranged
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
------------------------------
Date: Thu, 13 Nov 2003 23:40:05 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp14om$h0a$1@wisteria.csv.warwick.ac.uk>
"bbxrider" <bxtrap01@comcast.net> wrote:
> is there a way to sort (or other method) the 'method=post' data fields from
> a form into
> the same order they appear in the form
> when i use the following code there doesn't appear to be any particular
> order to how they are arranged
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
Firstly, you *really* should be using CGI or CGI::Lite rather than
parsing stdin yourself.
If the browser doesn't return them in order, then the only way to put
them back in order is to know what order they were in on the original
form. One way of doing this might be to give them names beginning with
'01', '02' etc.: if you generate the form yourself you can automate
this.
Note that hashes are inherently unordered: if you create a hash with
more than one key there is *no* guarantee about the order you will get
the keys back in when you list them. If you need there to be, then
either keep a separate array of keys to hold the order, or use
Tie::IxHash from CPAN which does that for you.
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: 13 Nov 2003 23:40:59 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: arrange form data in same order as on form
Message-Id: <Xns9432BE0E59754asu1cornelledu@132.236.56.8>
"bbxrider" <bxtrap01@comcast.net> wrote in
news:7cUsb.139690$mZ5.963708@attbi_s54:
> is there a way to sort (or other method) the 'method=post' data
> fields from a form into the same order they appear in the form
> when i use the following code there doesn't appear to be any
> particular order to how they are arranged
why do you care?
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
this code is buggy. either write your own, taking into account all the fine
points of the specs, or just use CGI.pm. but don't use someone else's buggy
code.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Thu, 13 Nov 2003 18:01:41 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: arrange form data in same order as on form
Message-Id: <Xns9432C1A592BAFsdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"bbxrider" <bxtrap01@comcast.net> wrote in
news:7cUsb.139690$mZ5.963708@attbi_s54:
> is there a way to sort (or other method) the 'method=post' data
> fields from a form into
> the same order they appear in the form
> when i use the following code there doesn't appear to be any
> particular order to how they are arranged
The CGI spec does not guarantee that the form variables will be submitted
in any particular order, so you're out of luck.
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
This is exceedingly bad code. Unless you really know what you're doing,
and have strong reasons not to, you should use the CGI module.
We keep seeing this exact same bad code posted to this newsgroup. Out of
curiosity, where did you copy it from?
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP7Qbf2PeouIeTNHoEQKb6gCfbgrhGAcLpyRLTC5cUW4U1AsVIsQAn3Ev
bAiVGyJb/3J4v/fhU4Yi9w1q
=vDoO
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 14 Nov 2003 01:22:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp17ik$1jfu48$1@ID-184292.news.uni-berlin.de>
A. Sinan Unur wrote:
> "bbxrider" <bxtrap01@comcast.net> wrote in
> news:7cUsb.139690$mZ5.963708@attbi_s54:
>
>>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>>@pairs = split(/&/, $buffer);
>
> this code is buggy.
Do you know the context in which that code is used? If not, you can't
reasonably tell whether it's "buggy".
> either write your own, taking into account all the fine
> points of the specs,
That's important only if you are writing a general purpose function or
module. What makes you think that that is what OP is about to do?
> or just use CGI.pm.
That is one option.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 14 Nov 2003 00:40:10 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp189a$imm$2@wisteria.csv.warwick.ac.uk>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> A. Sinan Unur wrote:
> > "bbxrider" <bxtrap01@comcast.net> wrote in
> > news:7cUsb.139690$mZ5.963708@attbi_s54:
> >
> >>read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> >>@pairs = split(/&/, $buffer);
> >
> > this code is buggy.
>
> Do you know the context in which that code is used? If not, you can't
> reasonably tell whether it's "buggy".
The OP is attempting to interpret a CGI POST request, as stated in the
Original Post.
> > either write your own, taking into account all the fine
> > points of the specs,
>
> That's important only if you are writing a general purpose function or
> module. What makes you think that that is what OP is about to do?
It is important in all circumstances where the data being received is
not entirely under your control; eminently the case in a CGI
environment.
> > or just use CGI.pm.
>
> That is one option.
...and by far the best[1], unless you are (a) very clever and (b) need to
do something particular that CGI.pm doesn't do for you.
The whole *point* of CPAN is so that people don't have to keep failing
to solve the same difficult problems over and over again.
Ben
[1] modulo equivalent alternatives, such as CGI::Lite.
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: Fri, 14 Nov 2003 01:59:16 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp19n3$1iabf3$1@ID-184292.news.uni-berlin.de>
Ben Morrow wrote:
> Gunnar Hjalmarsson wrote:
>> A. Sinan Unur wrote:
>>> bbxrider wrote:
>>>>
>>>> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs =
>>>> split(/&/, $buffer);
>>>
>>> this code is buggy.
>>
>> Do you know the context in which that code is used? If not, you
>> can't reasonably tell whether it's "buggy".
>
> The OP is attempting to interpret a CGI POST request, as stated in
> the Original Post.
I meant context in a more narrow sense, of course.
Still don't understand what it is that makes the above code "buggy".
>>> either write your own, taking into account all the fine points
>>> of the specs,
>>
>> That's important only if you are writing a general purpose
>> function or module. What makes you think that that is what OP is
>> about to do?
>
> It is important in all circumstances where the data being received
> is not entirely under your control; eminently the case in a CGI
> environment.
What's important in those circumstances is that you validate the data
properly, run the program in taint mode, etc. Using CGI.pm does not
take care of everything, right?
>>> or just use CGI.pm.
>>
>> That is one option.
>
> ...and by far the best[1], unless you are (a) very clever and (b)
> need to do something particular that CGI.pm doesn't do for you.
>
> The whole *point* of CPAN is so that people don't have to keep
> failing to solve the same difficult problems over and over again.
I'm not questioning the advantages with code reuse in general. I'm
just (once again) reacting to the aggressive way, sometimes not to the
point, in which some people here argue for using CGI.pm.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 13 Nov 2003 18:09:03 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: arrange form data in same order as on form
Message-Id: <etok7634uz4.fsf@fc.hp.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>>>> bbxrider wrote:
>>>>> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> Still don't understand what it is that makes the above code "buggy".
The read() may not read $ENV{'CONTENT_LENGTH'} bytes into $buffer, and
there's no attempt made to detect or handle this event. Without going
to the effort of reading the original post I don't know for sure, but
I'd bet there's at least three or four other instances where CGI.pm
handles things correctly that the OP's code does not.
> What's important in those circumstances is that you validate the data
> properly, run the program in taint mode, etc. Using CGI.pm does not
> take care of everything, right?
No, but it removes one axis of variability from the list of things
that could be buggy. Given the option of using known-good code and
hacking something up yourself, why (other than learning excercises,
which are surely valuable) would you not use the tested and verified
code?
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Fri, 14 Nov 2003 02:38:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: arrange form data in same order as on form
Message-Id: <bp1c15$1in3ke$1@ID-184292.news.uni-berlin.de>
Eric Schwartz wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> writes:
>>>>> bbxrider wrote:
>>>>>
>>>>>> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>>
>> Still don't understand what it is that makes the above code
>> "buggy".
>
> The read() may not read $ENV{'CONTENT_LENGTH'} bytes into $buffer,
> and there's no attempt made to detect or handle this event.
Some kind of exception handling is most often useful, but the lack of
it isn't exactly a _bug_, is it?
> Without going to the effort of reading the original post I don't
> know for sure, but I'd bet there's at least three or four other
> instances where CGI.pm handles things correctly that the OP's code
> does not.
None of us knows which of those "things" that are _applicable_ in OP's
program.
>> What's important in those circumstances is that you validate the
>> data properly, run the program in taint mode, etc. Using CGI.pm
>> does not take care of everything, right?
>
> No, but it removes one axis of variability from the list of things
> that could be buggy. Given the option of using known-good code and
> hacking something up yourself, why (other than learning
> excercises, which are surely valuable) would you not use the tested
> and verified code?
I very much dislike the aggressive way in which some people here
advocate the use of CGI, and the lack of faith that is shown in
people's own judge. The described attitude makes me suspicious and
less inclined to listen. How about that for a reason? :)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 13 Nov 2003 17:11:41 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: CGI - unreloadable page?
Message-Id: <Xns9432B92BCB165sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Roman Khutkyy" <roman@sky.lviv.ua> wrote in
news:bp0339$1c7t$1@news.uar.net:
> Hi all.
> There is a problem (i hope so). When i submit the form first time, the
> script put fields data into database. But when on next page i make
> "Reload" this process repeats again, and the same record are being
> placed. How to disallow this. I mean, how to make the new page withot
> any parameter in address string?
>
>
Not really a Perl question, but hey.
The usual method is to include a unique identifier string as a hidden
field in the submission. The receiving page can query the database to
see if that unique string has been submitted already; if so, scold the
user for double-clicking. :-)
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP7QPyWPeouIeTNHoEQJpFACg1wzF5HuMgqAcDe10o5cLjxc7xBUAn1tq
CBCgnvIro3P0jr7MiGxsj7Lf
=SAf/
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 13 Nov 2003 23:14:36 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Evaluating nester variables
Message-Id: <x7vfpnsvxf.fsf@mail.sysarch.com>
gack!! use dbi bindings. and regular loops will do. there is no reason
for code generation there. at the worst you would need to generate some
sql but (almost) never perl in a dbi situation. go back and rethink your
design. your current code is nasty and brutish and way off base.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 14 Nov 2003 01:02:45 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Evaluating nester variables
Message-Id: <bp16d1$1jigdu$1@ID-184292.news.uni-berlin.de>
Please study and comply with the posting guidelines for this group:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
Geoff wrote:
> Alright, here's a code snippet:
A lot of things could be said about that code, but I'll try to limit
myself to the initial problem.
I suppose that it's the variable @values you are struggling with. Your
code populates it with:
@values = ('$name0', '$phone0', '$etc0');
which is something quite different compared to
@values = [\$name0, \$phone0, \$etc0];
So now we know that you are not dealing with references at all.
Your initial question was (the equivalent of): "How do I evaluate what
$name0 is?". Now my question to you is: Do you anywhere in your code
assign anything to the variable $name0? If you don't, there isn't much
to evaluate, is there?
As a sidenote, you would probably need symbolic references to assign
anything to that and other similar variables, and that approach is not
advisable.
But that aside, assuming that you somewhere in your program has:
$name0 = 'Some name';
you should be able to access the content of $name0 by saying:
print eval $values[0];
But I think you have a lot of debugging to do.
HTH
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 13 Nov 2003 16:10:52 -0800
From: Geoff <gtb104gtb@netscape.net>
Subject: Re: Evaluating nester variables
Message-Id: <bp16ib0310i@enews3.newsguy.com>
OK. Well, the string that comes from the HTML looks like so:
action=add&name1=tom&phone1=123&name2=bob&phone2=456.... and so on.
Why you ask? Because I have a block of input fields like:
Name: |________________|
Phone: |________________|
If you click an "add" button, it adds a second block on input fields
like so:
Name: |________________|
Phone: |________________|
Name: |________________|
Phone: |________________|
...
If you enter data into the form, then click the add button, the
Javascript needs to save the existing data into an array, so that when
the form is redrawn, it populates the fileds you've already entered data
into.
The way I figured out to do this was to increment the variable names by
1 so that the right data goes into the right fields.
Uri Guttman wrote:
>gack!! use dbi bindings. and regular loops will do. there is no reason
>for code generation there. at the worst you would need to generate some
>sql but (almost) never perl in a dbi situation. go back and rethink your
>design. your current code is nasty and brutish and way off base.
>
>uri
>
>
>
------------------------------
Date: Fri, 14 Nov 2003 00:50:21 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Giving back
Message-Id: <pan.2003.11.13.23.16.54.102677@aursand.no>
On Thu, 13 Nov 2003 18:36:12 +0000, Default wrote:
> print "\n" . " " . "="x78 . "\n";
> print " Reads a text file and capitalizes the first letter of each sentence.\n\n";
> print "\tUSAGE:\t perl 15_1.plx <inputfile> <outputfile> [options]\n";
> print "\tNOTE:\t wildcards are not allowed.\n";
> print "\tOPTIONS: -l Lowercases everything before doing the capitalization.\n";
> print "\t\t -d Display work being done on screen.\n";
> print "\n\tEXAMPLE: perl 15_1.plx fixcase.txt casefixed.txt\n";
> print " " . "="x78 . "\n\n";
print() isn't very nice, so please don't feel free to use it this much,
although it's nothing wrong with the code above. I would rather have put
this text in a subroutine, and outputted it using only one (or just a few)
print() statements;
sub display_usage {
print qq|Your
text
here|;
}
> our $lines = "";
Sure you want to use 'our' instead of 'my'? 'perldoc -f our' and 'perldoc
-f my' might be of help.
> our $options1 = "";
> our $options2 = "";
> $options1 = shift || $options1 eq "";
> $options2 = shift || $options2 eq "";
This could have been written like this:
my $options1 = shift || '';
my $options2 = shift || '';
> $options1 =~ tr/A-Z/a-z/;
> $options2 =~ tr/A-Z/a-z/;
'tr' _is_ nice, but don't use it to lowercase/uppercase strings, as it
doesn't take the locale in mind. uc() and lc() does that;
perldoc -f lc
perldoc -f uc
perldoc perllocale
> while (our $line = <INPUT>)
> {
> $lines = "$lines $line";
> }
Personally, I prefer this style;
while ( <INPUT> ) {
$lines .= ' ' . $_;
}
Could easily have been written on one line, too.
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 13 Nov 2003 23:17:18 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: last index of array reference
Message-Id: <slrnbr847u.g29.abigail@alexandra.abigail.nl>
Ryan Tate (ryantate@ryantate.com) wrote on MMMDCCXXVI September MCMXCIII
in <URL:news:bp0tnb$2305$1@agate.berkeley.edu>:
()
() apocalypse.OCF.Berkeley.EDU [58] perl -ewT '$arrayref=["one","two","three"];print foreach 0 .. $#{@$arrayref}'
() apocalypse.OCF.Berkeley.EDU [59] perl -ew '$arrayref=["one","two","three"];print foreach 0 .. $#{@$arrayref}'
Eh, that will execute the program
w
with as argument
'$arrayref=["one","two","three"];print foreach 0 .. $#{@$arrayref}'
Since you don't have warnings or strict turned on, 'w' is just a bareword,
and it happily compiles and runs. No unquoted string, or useless use of
a constant in void context warnings.
Try using '-we' and '-Twe'.
Abigail
--
# Perl 5.6.0 broke this.
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi
------------------------------
Date: Fri, 14 Nov 2003 00:50:36 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: List into hash
Message-Id: <pan.2003.11.13.23.21.13.359922@aursand.no>
On Thu, 13 Nov 2003 14:42:32 -0800, Randy wrote:
> I am trying to take a list of domains and put them into a listing and
> keep track of how many are repeated.
my %domains = ();
foreach ( @domain ) { # @domain is defined elsewhere
$domains{$_}++;
}
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: Thu, 13 Nov 2003 23:24:03 +0000 (UTC)
From: Stan Brown <stanb@panix.com>
Subject: Re: long running perl programs & memory untilization
Message-Id: <bp13qj$puu$1@reader2.panix.com>
In <20031113163837.417$N1@newsreader.com> ctcgag@hotmail.com writes:
>Stan Brown <stanb@panix.com> wrote:
>>
>> Thanks. The latest one of these "long running" scripts to exhibit this
>> behavior, is really quite simple, in what it does, and has no real
>> complex data structures.
>>
>> I suppose it would be inappropriate to post it here for criticism, right?
>As long as the script is short and strict, it wouldn't be at all
>inappropriate. Does the script run full-bore for months, or is it some
>kind of server-like thing that spends most of it's time waiting?
It does setup stuff (a lot of that), and then goes into a loop. In this
loop it does a system call to v4lctl to capture an image, then goes bacl to
sleep and waits. Curently it's one image every 10 seconds. Running since
moday, it had grown to a size of 1/2 a gig :-(
--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin
------------------------------
Date: Thu, 13 Nov 2003 23:46:15 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: long running perl programs & memory untilization
Message-Id: <bp1547$h0a$2@wisteria.csv.warwick.ac.uk>
Stan Brown <stanb@panix.com> wrote:
> In <20031113163837.417$N1@newsreader.com> ctcgag@hotmail.com writes:
>
> >Stan Brown <stanb@panix.com> wrote:
> >>
> >> Thanks. The latest one of these "long running" scripts to exhibit this
> >> behavior, is really quite simple, in what it does, and has no real
> >> complex data structures.
> >>
> >> I suppose it would be inappropriate to post it here for criticism, right?
>
> >As long as the script is short and strict, it wouldn't be at all
> >inappropriate. Does the script run full-bore for months, or is it some
> >kind of server-like thing that spends most of it's time waiting?
>
> It does setup stuff (a lot of that), and then goes into a loop. In this
> loop it does a system call
This is a little confusing... when I first read it, I parsed it as
'system call' in the sense of something like fcntl(2). It would be
better to say 'it runs v4lctl with system()' or something :).
> to v4lctl to capture an image, then goes bacl to
> sleep and waits. Curently it's one image every 10 seconds. Running since
> moday, it had grown to a size of 1/2 a gig :-(
What does it do with the image? Are you sure you aren't keeping them
all in memory somewhere by mistake?
Post just the loop for us to have a look at.
Ben
--
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~ Jorge Luis Borges, 'The Babylon Lottery'
------------------------------
Date: 13 Nov 2003 15:56:26 -0800
From: rband@yahoo.com (rband)
Subject: Re: Need help with a program
Message-Id: <1618337a.0311131556.368b30eb@posting.google.com>
will try it. Thanks.
Glenn Jackman <xx087@freenet.carleton.ca> wrote in message news:<slrnbr7h2h.6be.xx087@smeagol.ncf.ca>...
> rband <rband@yahoo.com> wrote:
> > People,
> >
> > Need your help with a problem.
> > I need a program that will
> > 1. take two input files of strings, file1 and file2.
> > 2. read strings one by one from file1, and search for strings in
> > file2 that contain the string in file1 and append these to output
> > file3.
>
> I'd write:
>
> open F1, $file1 or die "can't open $file1: $!\n";
> open F2, $file2 or die "can't open $file2: $!\n";
> open F3, '>', $file3 or die "can't open $file3 for writing: $!\n";
>
> my @lines = <F1>;
> close F1;
>
> my $string = join '|', @lines;
> my $re = qr($string);
>
> while (<F2>) {
> print F3 $_ if /$re/;
> }
> close F2;
> close F3;
------------------------------
Date: 14 Nov 2003 00:43:20 GMT
From: Pedro Graca <hexkid@hotpop.com>
Subject: newbie dealings with OS "grep -P"
Message-Id: <bp18f8$1hoke3$1@ID-203069.news.uni-berlin.de>
My system grep does not support the -P option (perl regexp pattern).
So I thought it would be a good idea to make a perl script for that
(after all, only Perl parses perl, right?)
my first working attempt is grepp1 at the bottom
And then I realized this wouldn't allow me to pipe things to grepp1,
so out comes the second attempt (grepp2)
By now I'm using grepp2 very happily until I needed a case sensitive
match :(
After a tough time, this came out:
$ cat grepp3
#!/usr/bin/perl -nsw
# use strict; ## BEGIN does not like strict
# grepp [-I] pattern [file1 [file2 [...]]]
BEGIN {
$expr = shift; ## need error checking!!!
$regex = qr/$expr/i;
{ no warnings; ## -I might not have been specified
if ($I) { $regex = qr/$expr/; }
} # end no warnings
$\ = "\n"; ## nice little trick
}
chomp;
print if /$regex/;
Now I'm working on grepp4, trying to add options from the 'real' grep.
+ -c == only count matches
+ -H == print the file name
+ -n == print the line number
+ -V == print version and exit
but I don't like having the "use strict;" out.
Is it better to manually shift all parameters and verify if they're
options or the pattern or filenames?
Did I do something wrong with the "perl -s", "use strict;" and "BEGIN"
block?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$ cat grepp1
#!/usr/bin/perl -w
use strict;
# grepp pattern file
my $pt = shift; ## need error checking!!!!
my $fn = shift; ## need error checking!!!!
open (my $FILE, '<', $fn) || die $!;
while (my $line = <$FILE>) {
chomp $line;
print "$line\n" if $line =~ /$pt/i;
}
$ cat grepp2
#!/usr/bin/perl -nw
use strict;
# grepp pattern [file1 [file2 [...]]]
my $pt = shift; ## need error checking!!!!
$\ = "\n"; ## nice little trick :)
while (<>) {
chomp;
print if /$pt/i;
}
--
@ "=qw f Jt ss x_x am os hd q y_y Pd rk z_z Hab kd q f; $
_ =join "",(map ++ $ _, @ "); s/1/ /g and print; print $/
------------------------------
Date: Fri, 14 Nov 2003 01:12:00 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: newbie dealings with OS "grep -P"
Message-Id: <3FB42B7F.7070202@rochester.rr.com>
Pedro Graca wrote:
> My system grep does not support the -P option (perl regexp pattern).
> So I thought it would be a good idea to make a perl script for that
> (after all, only Perl parses perl, right?)
>
> my first working attempt is grepp1 at the bottom
>
>
> And then I realized this wouldn't allow me to pipe things to grepp1,
> so out comes the second attempt (grepp2)
>
...
You might check out what the folks at the Unix Reconstruction Project
did with grep:
http://www.perl.com/language/ppt/src/grep/index.html
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 13 Nov 2003 23:49:15 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Problem with IO::Socket::INET and pop
Message-Id: <Xns9432BF749A82asu1cornelledu@132.236.56.8>
unixverse@yahoo.com (Joe) wrote in
news:fcc97b00.0311130526.fe5e615@posting.google.com:
> Ben Morrow <usenet@morrow.me.uk> wrote in message
> news:<boueo5$9cp$1@wisteria.csv.warwick.ac.uk>...
>> unixverse@yahoo.com (Joe) wrote:
>> > # Connect to the POP server using port 110
>> > $SocketHandle = IO::Socket::INET->new (Proto=>"tcp",
>> > PeerAddr=>$ServerName, PeerPort=>$Port);
are you sure $Port == 110 at this point?
...
>> > The web hosting company keeps telling me that they didn't change
>> > anything and that they can connect fine via telnet ServerName 110.
...
> For $! I get 'Bad file number' and for $@ 'IO::Socket::INET:
> Connection refused'
That means your script could not connect to $ServerName on that port.
Could it be a firewall issue? This does not seem to have much to do with
Perl.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
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 5797
***************************************