[8726] in Perl-Users-Digest
Perl-Users Digest, Issue: 2343 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 16 22:07:26 1998
Date: Thu, 16 Apr 98 19:00:23 -0700
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, 16 Apr 1998 Volume: 8 Number: 2343
Today's topics:
Re: Bill Gates should be invited to O'Reilly's "Free So <ucntcme@cyberhighway.net>
Re: cgi perl ? (Abigail)
Re: commenting a whole block? <lr@hpl.hp.com>
Re: Deleting cookies from PERL (Abigail)
Re: Deleting cookies from PERL (Mark-Jason Dominus)
Re: Easy way to count lines in a file <ebohlman@netcom.com>
htaccess & htpasswd help!!! <keith@cca.munet.edu>
Re: HTTP Perl Question (Martien Verbruggen)
Image instead of button in Perl Script <batkins@age.net>
Re: Incrementing counter (Martien Verbruggen)
Re: Perl 5.004_64 Slower??? <sneaker@earthling.net>
POP3.pm open (STDERR, ">&STDOUT"); <craigs@3rdstone.net>
Re: Server Side Include (Abigail)
Re: Server Side Include (Abigail)
Re: shorten array (Andrew M. Langmead)
Re: shorten array (Abigail)
Re: Simple Unix Question, ( Simple for you maybe ) <craigs@3rdstone.net>
Re: Simple Unix Question, ( Simple for you maybe ) (Craig Berry)
Re: Simple Unix Question, ( Simple for you maybe ) (Craig Berry)
Re: Wanna laugh? (My First cgi.pm Script) (Craig Berry)
Re: Wanna laugh? (My First cgi.pm Script) (Tad McClellan)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Apr 1998 19:31:53 -0600
From: Bill Anderson <ucntcme@cyberhighway.net>
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <3536B109.B11723E@cyberhighway.net>
Ben Bullock wrote:
>
> Bill Anderson wrote:
>
> > If you have evidence, and lack _inconclusive_ proof, you must have _conclusive_
> > proof. Then, by all means, demonstrate it.
>
> Bill, I posted a correction to this statement about ten minutes
> after the original post, so there is not much excuse for your
> attack here.
>
Oh, really? Well, let me clarify something for you: The above was not an
attack, and if it was, you presume my newserver has/had received your
retraction/correction prior to it. I believe you are in err in this, as I have
not seen it.
> > Then your argument fails, for I have not seen any of your 'opinions' about
> > OpenSource Software and the documentation of it. If *you* don't see a topic
> > worth discussing/debating then stay out and let others do what *they* see fit
> > to do.
>
> I can't understand how you can have missed my opinions on this
> thread. :-).
>
> Would you like a summary? Or could you look at dejanews.
I am fully capable of utilizing DejaNews, it is also a good way of tracking
crackers ...
>
> Incidentally I wrote something about the `open source'
> controversy which is at
>
> http://www.hayamasa.demon.co.uk/open-source.html
>
> I hope there are lots of trivial inaccuracies in there that
> will keep the flames burning for another 40 or so posts but
> if not please let me know so that I can add some.
Ok ;
(presuming that was sarcasm ...)
BTW, a correction by another does not mean it is a flame.
--
Bill Anderson Cyberhighway Internet Services, SYCON
"Pluralitas non est ponenda sine neccesitate."
Plurality should not be assumed without neccesity.
------------------------------
Date: 17 Apr 1998 01:21:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: cgi perl ?
Message-Id: <6h6aq4$o8h$2@client3.news.psi.net>
~arthur (star@sonic.net) wrote on MDCLXXXIX September MCMXCIII in
<URL: news:35369867.7AC0@sonic.net>:
++ Hi,
++
++ I have a program from the camel book:
++
++ my $favorite = param("flavor");
++ print "<P>Your favorite flavor is $flavor.";
++
++ -----
++ How do I get it to work on the web I have it at
++ http://www.sonic.net/cgi-bin/star/hiw- (dash is pat of the address)I
++ made it executable but how do I make it execute.
By telnetting to port 80!
$ telnet www.sonic.net 80
Trying 208.201.224.21...
Connected to thunder.sonic.net.
Escape character is '^]'.
GET /cgi-bin/star/hiw-?flavor=chocolate HTTP/1.0
HTTP/1.0 200 Document follows
Date: Fri, 17 Apr 1998 01:17:41 GMT
Server: NCSA/1.5.2
Content-type: text/plain
Content type: text/html
<html>
<head>
<title>hiw-</title>
<body>
Hello World
<P>Your favorite flavor is .</body>
</html>
Connection closed by foreign host.
$
Now, if you don't misspell '$favourite' and '$flavor', it might
actually return something sensible.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Thu, 16 Apr 1998 17:42:55 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: commenting a whole block?
Message-Id: <6h68iq$gme@hplntx.hpl.hp.com>
Andrew M. Langmead wrote in message ...
>Larry Rosler <lr@hpl.hp.com> writes:
>
>>With all respect, this is a glib and totally useless response. I
>>followed your suggestion, and searched for "perl comment block", and
>>got 19 totally irrelevant responses (only 7 of which were from "perl"
>>groups, by the way).
>
>Would it be preferable to point them to the FAQ entry "How can I
>comment out a large block of perl code?"
><URL:http://www.perl.com/CPAN/doc/manual/html/pod/
>perlfaq7/How_can_I_comment_out_a_large_bl.html>
>
>--
>Andrew Langmead
It might be, if it were true. On the other hand, if they followed the links
themselves from www.perl.com (as I have done until now), they might start
with "FAQs", then select "html format" and get to here:
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html
which does *not* have this entry in perlfaq7. For that matter, if I go the
URL given in your letter, I am redirected to .../CPAN-local/... which does
*not* have this entry either. Kind of makes one wonder, doesn't it?
I *have* found this entry via "perldoc perlfaq7" in a 5.004_03 installation
(the FAQ is Revision 1.18, 1997/04/24). The index at
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq7/ identifies the
files as 15-Mar-97, and the URL I give above identifies itself as Revision
1.15.
Now that brian d foy has so courteously helped me to improve my web skills
(by selecting the tiny "old" box under the search input in Dejanews), I've
been able to read the discussion of block comments with great amusement --
noting in particular the (ab)use of a documentation convention which is
"part of the Perl language" (even though it isn't described in the Camel
Book, which everyone in this newsgroup -- including me -- considers to be
the definitive reference for Perl).
I recently saw a quote along the lines of "I know that what I said last year
differs from what I say now. I was right then, and I'm right now." This is
the mark of religious fanaticism, not of sound engineering evolution. Yet
that seems to be the dominant attitude of Perl gurus in this group. "Come
back after you've upgraded to the latest -- and therefore, the only
acceptable -- version of perl." Too bad that even the official on-line FAQs
can't meet up with this expectation.
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: 17 Apr 1998 01:24:18 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Deleting cookies from PERL
Message-Id: <6h6b02$o8h$3@client3.news.psi.net>
Mike Shannon (mshannon@lds.com) wrote on MDCXC September MCMXCIII in
<URL: news:6h614l$6rb$2@newsreader.digex.net>:
Perl doesn't have cookies.
There was nothing Perl specific to your question. Please ask your
question in a group more relevant (alt.milk.and.cookies?)
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: 16 Apr 1998 21:51:51 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Deleting cookies from PERL
Message-Id: <6h6cjn$mmq$1@monet.op.net>
Keywords: bituminous platitudinous Siena trompe
In article <6h614l$6rb$2@newsreader.digex.net>,
Mike Shannon <mshannon@lds.com> wrote:
>Short of making the user close the browser, is there anyway to do this
>programatically?
If you set a cookie with an expiration date in the past, the browser
is supposed to forget it.
Not that this has anything to do with Perl.
------------------------------
Date: Fri, 17 Apr 1998 01:00:15 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Easy way to count lines in a file
Message-Id: <ebohlmanErJ9GG.5EJ@netcom.com>
brian d foy <comdog@computerdog.com> wrote:
: In article <x6eogy1mnca.fsf@pearl.fi.bear.com>, Justin Vallon <vallon@pearl.fi.bear.com> posted:
: >May I suggest just using the number of bytes in the file? It should
: >give a very reasonable approximation of the number of lines. So, you
: >could notify on every 1k lines, or 80k bytes.
: i'm curious how you translate bytes to lines. for instance, i have
: a data file that i'm avoiding at the moment - it's about 200 lines [1]
: and about 500 characters per line. another data file for the same
: project has 6000 lines of about 20 characters per line.
Remember that the original poster wanted to know the number of lines so
that he could display a progress report in percentage of lines processed.
If the variance of the line lengths is relatively small, then percentage
of bytes processed is a good approximation to percentage of lines
processed, certainly good enough for a progress display. If the file
contains a mixture of very short and very long lines, then of course the
approximation will diverge.
------------------------------
Date: Thu, 16 Apr 1998 20:16:51 -0400
From: keith <keith@cca.munet.edu>
Subject: htaccess & htpasswd help!!!
Message-Id: <35369F72.93F8608C@cca.munet.edu>
I'm trying to use htpasswd in perl5. I have a form that submits a user
name, I then want to take that name and use the htpasswd
command to add them to a user list with a password. Has anyone ever
tried this? Please post or send me email asap!
Thanks in advance,
Keith
------------------------------
Date: 17 Apr 1998 00:20:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: HTTP Perl Question
Message-Id: <6h6783$2hd$2@comdyn.comdyn.com.au>
In article <044B4AFA4898D1118248006097BDA86704029139@news.jccc.net>,
Phil Mein <pmein@johnco.cc.ks.us> writes:
> Does anyone have a simple perl script
Use the LWP package. You can get it from CPAN, if it isn't already
installed.
documentation:
# perldoc lwpcook
# perldoc LWP
and, oooooh, look, a tool to get web pages comes with it:
# perldoc lwp-request
> that fetches a nonlocal web page
non-local? I'd hope so. If it was local, you already would have it,
wouldn't you?
> in a text only mode?
What is this supposed to mean? What would a 'web page' in 'not text only
mode' be? A 'web page' is just a HTML document. HTML is just text.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd. | things get worse.
NSW, Australia |
------------------------------
Date: Thu, 16 Apr 1998 21:12:20 -0400
From: Brad Atkins <batkins@age.net>
Subject: Image instead of button in Perl Script
Message-Id: <3536AC74.62E803B8@age.net>
I've been trying to get an image instead of a normal form button in a
web based email client. The problem is, that with certain functions
(everything except logging in) the Script does not fetch the datum.
Any Suggestions?!
Brad Atkins
support@liquid-web.com
------------------------------
Date: 17 Apr 1998 00:10:01 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Incrementing counter
Message-Id: <6h66kp$2hd$1@comdyn.comdyn.com.au>
In article <3536c4df.10586548@news.zip.com.au>,
daclay@NOSPAMzip.com.au (Excession) writes:
> the alternative is to use \010 to backspace over chars and then reprint
> them, but I don't know of an easy way to move the cursor back up after a
> carraige return.
A carriage return ("\r") Will move the cursor back to the start of the
line, in NT command windows.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd. | excuse - Lazarus Long
NSW, Australia |
------------------------------
Date: Fri, 17 Apr 1998 00:23:03 GMT
From: Bill 'Sneex' Jones <sneaker@earthling.net>
Subject: Re: Perl 5.004_64 Slower???
Message-Id: <35369F51.9DE67E7@earthling.net>
This is a multi-part message in MIME format.
--------------B6811EA499D6FA81943CF9E2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
lvirden@cas.org wrote:
> I just found the cause of _my_ discrepancies!
>
> The perl 5.04 version i was running turned out to NOT have the -DDEBUGGING
> on while the 5.04_064 does. When I had both of them using the -DDEBUGGING,
> the user and real times practically were the same.
>
I too went thru the DEBUGGING path and discovered that
without Debugging, see perl -V output below - the
only performance penalty is on startup. Once that code
is resident in memory, looping thru the substr(reverse...
code produced indistiguishable results.
So... I believe I will keep Threading support, but without
the Debugging Compile time option. Also, when I compiled
with Threading support, I get this error -
--------------B6811EA499D6FA81943CF9E2
Content-Type: text/plain; charset=us-ascii; name="x"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="x"
Failed Test Status Wstat Total Fail Failed List of failed
------------------------------------------------------------
lib/open3.t 21 1 4.76% 17
Failed 1/165 test scripts, 99.39% okay.
1/5360 subtests failed, 99.98% okay.
--------------B6811EA499D6FA81943CF9E2
Content-Type: text/plain; charset=us-ascii; name="perl-V.Threaded.II"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="perl-V.Threaded.II"
Summary of my perl5 (5.0 patchlevel 4 subversion 64) configuration:
Platform:
osname=linux, osvers=2.0.31, archname=i586-linux-thread
uname='linux sneex 2.0.31 #1 sun nov 9 21:45:23 est 1997 i586 unknown '
hint=recommended, useposix=true, d_sigaction=define
usethreads=define useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=2.7.2.3
cppflags='-D_REENTRANT -Dbool=char -DHAS_BOOL'
ccflags ='-D_REENTRANT -Dbool=char -DHAS_BOOL'
stdchar='char', d_stdstdio=define, usevfork=true
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
alignbytes=4, usemymalloc=y, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lposix -lcrypt
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under linux
Compiled at Apr 16 1998 18:01:46
@INC:
/usr/lib/perl5/i586-linux-thread/5.00464
/usr/lib/perl5
/usr/lib/perl5/site_perl/i586-linux-thread
/usr/lib/perl5/site_perl
.
--------------B6811EA499D6FA81943CF9E2--
------------------------------
Date: Thu, 16 Apr 1998 17:55:46 -0700
From: Craig <craigs@3rdstone.net>
Subject: POP3.pm open (STDERR, ">&STDOUT");
Message-Id: <3536A892.7DCE@3rdstone.net>
Below is a script I am working on. I want to check my mail through a
browser. The deal is I can not figure how to get the data that comes
back fro this in a way I can pars. Notice the "open (STDERR,
">&STDOUT");" line in my if statement. It seem that POP3.pm returns data
as STDERR. I would like to pars this info into tables with just To:
From: etc. Once I can do that I will have this going. Any ideas.
#!/usr/bin/perl -w
# use strict; #not tonight I have a head ache! I will clean up later.
use Net::POP3;
require 'cgi-lib.pl';
use Getopt::Long;
if ($ENV{'REQUEST_METHOD'} eq "GET") {
$FORM_DATA = $ENV{'QUERY_STRING'};
} else {
$LENGTH = $ENV{'CONTENT_LENGTH'};
while ($LENGTH) {
$FORM_DATA .= getc(STDIN);
$LENGTH--;
}
}
foreach (split(/&/, $FORM_DATA)) {
($a, $b) = split(/=/, $_);
$a =~ s/\+/ /g;
$a =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C,hex($1))/eg;
$b =~ s/\+/ /g;
$b =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C,hex($1))/eg;
$STRING{$a} = $b;
}
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Check Mail STDOUT</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<CENTER><BIG>Check Mail STDOUT</BIG></CENTER>\n";
print "<B>InBox of $STRING{'user'}:</B><BR><BR>\n";
# open (STDERR, ">&STDOUT");
# $fh = *STDOUT;
# $fh = \*STDOUT;
my $opt_debug = 1; # Show what happens
GetOptions(qw(debug user=s));
my $pop = Net::POP3->new('aka', Debug => $opt_debug ? 6 : 0);
my $count = $pop->login($STRING{'user'}, $STRING{'pass'}); # This is
where we log in
if($count) #this is where we get what is in the box
{
open (STDERR, ">&STDOUT");
for ($i = 1; $i <= $pop->get($i++);) {
foreach ($pop->get($i)) {
/^(From|Subject): / and print $_, "\n";
}
print "\n";
}
}
$pop->quit;
print "</BODY>\n</HTML>\n";
__END__
------------------------------
Date: 17 Apr 1998 01:28:49 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Server Side Include
Message-Id: <6h6b8h$o8h$4@client3.news.psi.net>
Jerry (zolan@nwinfo.net) wrote on MDCLXXXIX September MCMXCIII in
<URL: news:35367f97.3023569@news.nwinfo.net>:
++ Is there any way to write one line in HTML that will run a PERL script
++ that just prints part of a web page?
Not, not in HTML. HTML doesn't execute anything. But the subject
looks like you're on the right track. SSI questions belong in
a server group.
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: 17 Apr 1998 01:29:56 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Server Side Include
Message-Id: <6h6bak$o8h$5@client3.news.psi.net>
Bob Trieger (sowmaster@juicepigs.com) wrote on MDCLXXXIX September
MCMXCIII in <URL: news:35368AA6.7DA7@juicepigs.com>:
++ Jerry wrote:
++ >
++ > Is there any way to write one line in HTML that will run a PERL script
++ > that just prints part of a web page? I'm not interested in having the
++ > entire page CGI..
++
++ Let me beat Abigail to this one. This is an HTML question and has no
++ business being posted in clpm.
++
++ try news:comp.infosystems.www.authoring.html
Oh, right, so I have to yell at him twice for posting off topic?
SSI is *not* HTML.
Abigail
--
perl -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
print chr 0x$& and q
qq}*excess********}'
------------------------------
Date: Fri, 17 Apr 1998 01:04:27 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: shorten array
Message-Id: <ErJ9nF.23w@world.std.com>
~arthur <star@sonic.net> writes:
>I have a Perl program (thanks David Black) that picks a random word in a
>game. If you play the game more than once in a row you may get the same
>word. Is there a way that once the word is used it taken out of the
>array?
I'm sorry if this sounds condescending, but since lists and arrays are
so intrinsic to the perl language, if you are having a problem
figuring out how to manipulate an array, you would probably be best
off getting a descent tutorial book on Perl. One that gets praise from
most is "Learning Perl", by Randal Schwartz and Tom Christiansen
(published by O'Reily and Associates.)
<URL:http://www.ora.com/catalog/lperl2>
A couple of ways of removing array elements is with the pop(),
shift(), and splice() operators.
The pop() function removes the last element.
The shift() function removes the first element. (renumbering all the
other elements as it does so.)
The splice() function adds and/or removes an arbitrary number
contigious of elements from anyplace is the array.
If you accessed a random element, you probably want to use splice() to
remove it.
$element = rand @array; # get a random element
print "$array[$element]\n"; # print it
splice @array, $element, 1; # remove it.
Take a look at the splice() entry in the perlfunc man page for
details.
--
Andrew Langmead
------------------------------
Date: 17 Apr 1998 01:32:34 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: shorten array
Message-Id: <6h6bfi$o8h$6@client3.news.psi.net>
~arthur (star@sonic.net) wrote on MDCLXXXIX September MCMXCIII in
<URL: news:35369554.717E@sonic.net>:
++ Hi,
++
++ I have a Perl program (thanks David Black) that picks a random word in a
++ game. If you play the game more than once in a row you may get the same
++ word. Is there a way that once the word is used it taken out of the
++ array?
perldoc -f splice and/or perldoc -f grep
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Thu, 16 Apr 1998 17:34:47 -0700
From: Craig <craigs@3rdstone.net>
To: UNIXstuff <unixstuff@aol.com>
Subject: Re: Simple Unix Question, ( Simple for you maybe )
Message-Id: <3536A3A7.5A76@3rdstone.net>
UNIXstuff wrote:
>
> From with a perl script.
> I want to run the UNIX command ls -l
> and have the info/string stored in a variable.
>
> If I do
> $MY_VARIABLE = system (ls -l);
>
> $MY_VARIABLE is set to equal 0, which
> is the unix return code for ls.
>
> How do I get $MY_VARIABLE to eqaul
> -rwxr-xr-x 1 root sys .......... some_file_name
>
> Thanks
This is what I would do
#!/usr/bin/perl
@my_data=`ls -lta`;
open(FILE, "some_real_file");
foreach($line, @my_data) {
print FILE $_ }
close(FILE)
------------------------------
Date: 17 Apr 1998 00:40:21 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Simple Unix Question, ( Simple for you maybe )
Message-Id: <6h68dl$rgk$8@marina.cinenet.net>
Craig (craigs@3rdstone.net) wrote:
: This is what I would do
:
: #!/usr/bin/perl
No -w?
: @my_data=`ls -lta`;
:
: open(FILE, "some_real_file");
:
: foreach($line, @my_data) {
That's not even syntactically valid.
: print FILE $_ }
Printing to a file opened in read-only mode? And using $_ rather than the
$line which you (seem to be trying to) use as your iteration variable?
: close(FILE)
And even if you wanted to use this scheme, you could rewrite it in just
three lines:
open(FILE, "> some_real_file") or die $!;
print FILE `ls -lta`;
close FILE;
Wow.
Personally I'd use globbing or opendir/readdir to get the file names,
then stat to get the needed statistics about each.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 17 Apr 1998 00:44:44 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Simple Unix Question, ( Simple for you maybe )
Message-Id: <6h68ls$rgk$9@marina.cinenet.net>
Craig Berry (cberry@cinenet.net) wrote:
: : foreach($line, @my_data) {
:
: That's not even syntactically valid.
Correcting myself: It's syntactically valid, but I very much doubt it
does what the poster intended.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 17 Apr 1998 00:08:31 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Wanna laugh? (My First cgi.pm Script)
Message-Id: <6h66i0$rgk$7@marina.cinenet.net>
Darryl Lee (lee@spam-me-not-darryl.com) wrote:
: Well, i went and took a crudely crafted plain ole perl CGI, and made
: it into a crudely crafted cgi.pm CGI.
:
: So...if you ski in Tahoe, or just want to laugh, check out:
:
: http://www.darryl.com/tahoe/
: http://www.darryl.com/tahoe/index.cgi.txt <- latest script
: http://www.darryl.com/tahoe/index.cgi.old.txt <- original script
:
: And why yes, this is a troll for pointers on optimizing my code.
You asked for it...
open(SKIDATA, "datatab.txt");
open(HEADER, "header.htmlf");
open(FOOTER, "footer.htmlf");
Your really ought to error-check these opens...someday a server change or
your own mistyping will nail one of them, and when that day comes, your
debugging time will be orders of magnitude shorter if your code checks
the results of every open and dies with a meaningful (and browser or log
visible!) message.
Also, I advise single-quoting strings in which there's no interpolation
going on. That way, when you see double quotes, you can assume there
*is* interpolation and be primed to see it. Makes your code a tiny bit
easier to parse by eyeball.
while (<HEADER>) {
print $_;
}
That can be written as: print <HEADER>;
@headings = ( a({href=>"?KEY=0"}, "Resort"),
"Phone Number(s)",
a({href=>"?KEY=3"}, "One\<br\>Full\<br\>Day"),
No need to backslash < and > here or in the many similar cases I've
snipped.
if ( ! param("KEY") ) { # was a key submitted at all?
$sortkey = 0; # no? Then set it to 0
} else {
$sortkey = param("KEY");
}
Perhaps more easily expressed as: $sortkey = param('KEY') || 0;
(Which is a really useful idiom for defaulting in general.)
while (<SKIDATA>) {
chop;
'chomp' is generally a better choice.
@skifields = split(/ /,$_); # put data into @skifields
Avoid hand-counting spaces, it's a recipe for disaster; use {n} instead.
Also, the $_ is a default. Rewriting to do both of these, we get:
@skifields = split / {8}/;
Unless that's really a tab, of course, in which case use the pattern /\t/
instead.
$record{$skifields[0]} = [ @skifields ] ; # create hash with
} # resort name as key
# @skifields as value
To avoid saving the 0th element twice (once as hash key, once as first
element of value), I'd suggest:
$name = shift @skifields;
$record{$name} = [ @skifields ];
...though of course this would reduce all indices into the hash value by
1.
That's all the time I have to pick nits at the moment...overall, it's a
nice piece of work. I hope my comments prove helpful.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 16 Apr 1998 20:23:14 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Wanna laugh? (My First cgi.pm Script)
Message-Id: <2ua6h6.ppf.ln@localhost>
Craig Berry (cberry@cinenet.net) wrote:
: Darryl Lee (lee@spam-me-not-darryl.com) wrote:
: : Well, i went and took a crudely crafted plain ole perl CGI, and made
: : it into a crudely crafted cgi.pm CGI.
: :
: : So...if you ski in Tahoe, or just want to laugh, check out:
: :
: : http://www.darryl.com/tahoe/
: : http://www.darryl.com/tahoe/index.cgi.txt <- latest script
: : http://www.darryl.com/tahoe/index.cgi.old.txt <- original script
: :
: : And why yes, this is a troll for pointers on optimizing my code.
: You asked for it...
: while (<HEADER>) {
: print $_;
: }
: That can be written as: print <HEADER>;
But you (Darryl) should also know that the rewritten one reads _all_ of
the contents from the HEADER filehandle into memory before printing
it all back out again. Your original way is much more parsimonious
with regards to memory usage (I learned to program on a Timex Sinclair
with 2Kb of memory. I guess I never got over it ;-)
Perhaps undesirable if it is a large file, or if you have a
memory challenged 'puter...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 2343
**************************************