[17703] in Perl-Users-Digest
Perl-Users Digest, Issue: 5123 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Dec 15 14:05:43 2000
Date: Fri, 15 Dec 2000 11:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976907114-v9-i5123@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Dec 2000 Volume: 9 Number: 5123
Today's topics:
basic code -- why won't it work??!! <jwmsng@greatNOSPAMwebsolutions.com>
[Announce] New Perl module: Iterator.pm <h.camp@scm.de>
ANNOUNCE: vshnu 1.0003 - a visual perl shell applicatio <kinzler@cs.indiana.edu>
Asynchronously putting info to Tk widget <bomr@lin01a.triumf.ca>
Re: basic code -- why won't it work??!! <jdhunter@nitace.bsd.uchicago.edu>
Re: basic code -- why won't it work??!! <jwmsng@greatNOSPAMwebsolutions.com>
Re: basic code -- why won't it work??!! <cantrela@agcs.com>
Re: cookies nobull@mail.com
Errors in HTTP/Response & LWP/Response (BUCK NAKED1)
Re: FAQ 5.11: How can I translate tildes (~) in a fil (Tom Christiansen)
Re: File limit to save on HDD <cbah@chez.com>
Re: flat text file or MySQL <jeff@vpservices.com>
Re: flat text file or MySQL <webmaster@860.org>
Re: Function from string nobull@mail.com
Re: Help!!!! andre_sanchez@my-deja.com
Re: How do I get the last day of a month?? <ryantate@OCF.Berkeley.EDU>
Re: IO::Select::select not blocking on a filehandle <cbah@chez.com>
Re: Is a Hash of Arrays possible? (Tom Christiansen)
Re: Is a Hash of Arrays possible? <timallen449@coldmail.com>
Re: Is there an overhead using long variable names? (Tom Christiansen)
Re: Is there an overhead using long variable names? (Tom Christiansen)
Re: Is there an overhead using long variable names? (Tom Christiansen)
Re: Is there an overhead using long variable names? (Logan Shaw)
Re: Is there an overhead using long variable names? (Tom Christiansen)
Re: Is there an overhead using long variable names? (Ilya Zakharevich)
Re: Parsing files backwards eggrock@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Dec 2000 12:23:29 -0500
From: "John W" <jwmsng@greatNOSPAMwebsolutions.com>
Subject: basic code -- why won't it work??!!
Message-Id: <3a3a52ca_3@goliath2.newsfeeds.com>
Folks, what am I doing wrong here -- why does the following not generate any
output? What I'm looking for, obviously, is:
bob
jane
tim
sue
=================
#!/usr/local/bin/perl
@users = ( 'bob', 'jane', 'tim', 'sue' );
for my $usr (@users) {
print "$usr \n";
}
thanks for the help -- John
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Fri, 15 Dec 2000 17:16:32 +0100
From: "H. Camphausen" <h.camp@scm.de>
Subject: [Announce] New Perl module: Iterator.pm
Message-Id: <t3khj972loo3dc@corp.supernews.com>
Hi all,
I just uploaded a new (plain) Perl module to CPAN: Iterator.pm
>From the readme-file:
Iterator.pm - shows paths/values of complex data structures
DESCRIPTION
Iterator.pm is an object orientated (plain) Perl module to Iterator
over complex data structures (LoL, LoH, HoL, HoH etc.).
While Perl's built-in functions foreach(), each(), keys() and
values() handle just a given level of a structure, Iterator digs deeper -
handling a structure like an one-dimensional hash.
For each element of a nested data structure the symbolic name
("data path"), The Value - as is! - plus some additional information are
retrieved.
That is, Iterator provides an unified syntax for simple handling of
data sources of different types.
Iterator does not alter the referenced structure, though values may
be explicitly modified by the user.
Iterator does not export any variables or functions. You /can/ call
arbitrary packet subs via &Packetname::subname(), but you /might/ be
surprised of the results :-)
[snipped]
You can download the archive from:
http://www.cpan.org/authors/id/H/HC/HCAMP/Iterator_0.02.zip
http://www.creagen.de/downloads/Iterator_0.02.zip
mfg, Hartmut
--
CREAGEN Computerkram Fon: 06422/850527
Hartmut Camphausen Fax: 06422/850528
Am kleinen Born 1 E-Mail: h.camp@creagen.de
35287 Amöneburg WWW: http://www.creagen.de
------------------------------
Date: 13 Dec 2000 20:39:51 GMT
From: Steve Kinzler <kinzler@cs.indiana.edu>
Subject: ANNOUNCE: vshnu 1.0003 - a visual perl shell application
Message-Id: <t3khji9sm6chdf@corp.supernews.com>
Vshnu 1.0003 is now available at
$CPAN/authors/id/K/KI/KINZLER/vshnu-1.0003.tar.gz
or http://www.cs.indiana.edu/~kinzler/vshnu/vshnu-1.0003.tar.gz
Vshnu is a visual shell for Unix finally done right. Best used as an
optional color visual mode to a regular command line shell, vshnu is handy
for powerful directory listing and navigation, Unix command assembly,
special actions on file types, and fileset handling. Written in Perl
for portability and high configurability, it also provides the advantages
of a Perl interpreter as part of your Unix shell environment.
For more information, including motivation and background, please see
http://www.cs.indiana.edu/~kinzler/vshnu
Vshnu was inspired by and initially patterned after the old program `vsh`.
The "nu" in "vshnu" implies "new", of course, as well as invokes the
Hindu god Vishnu, the preserver of the universe and restorer of dharma.
--
from the brain of Steve Kinzler /o)\ kinzler@cs.indiana.edu
an organ with a mind of its own \(o/ www.cs.indiana.edu/~kinzler
Zaniness primus / stockbroker quadrumana / willowware besprent.
------------------------------
Date: 15 Dec 2000 16:58:54 GMT
From: "Rod B. Nussbaumer" <bomr@lin01a.triumf.ca>
Subject: Asynchronously putting info to Tk widget
Message-Id: <91dike$hkj$1@nntp.itservices.ubc.ca>
I am trying to write an application using perl Tk that does some
things that are pushing the envelope of my knowledge sphere, and
am looking for some advice.
I want to have my application rspond to a button press by
launching an externl program that runs for an extend time,
and periodically reports it's prgress by writing strings
to stdout. That much I think I have nailed down, but what
I also want to do is capture the string output, and send it to
a Tk text widget. My general strategy is to create separate
forks for the three activities. However, I am not sure of
how to handle some of the communication & synchronization
issues.
Following is a semi-functioning code sample that shows what
I am trying to do, along with a very simple test application
that I launch as an external program, as well a the console
output resulting from running the program. (Please excuse
any formatting problems resulting from tab corruption
en-route to your news reader)
The main questions are:
How can I get the Tk MainLoop to see data that is occuring
in another forked process?
What do I do with the process that gets forked and spins
around grabbing output from the exec'd external program
once it has run out of data?
Is this anything like a correct strategy at all? Is this even
doable in perl? In any conventional language?
Any advice is welcomed. Thanks in advance.
--- rod.
---------------------<tkAsync.pl>----------------
#! /usr/bin/perl -w
use strict;
use Tk;
my( $mainWin,
$goButton,
$quitButton,
$capWin,
$cppeId,
$watchCPPEid
);
#
# Create a Tk window, and place the widgets in it
#
$mainWin = MainWindow -> new();
$goButton = $mainWin -> Button( -text => " start ",
-command => \&biasScan
) -> pack( -side => 'bottom' );
$quitButton = $mainWin -> Button( -text => " abort ",
-command => \&abortScan
) -> pack( -side => 'bottom' );
$capWin = $mainWin -> Text() -> pack();
MainLoop;
sub biasScan(){
$cppeId = open( CPPE, "-|" );
if( $cppeId ){ # parent of forked processes...
#
# Fork another process to watch for responses from CPPE...
#
$watchCPPEid = fork();
if( $watchCPPEid ){
return; # back to Tk MainLoop
}
else{ # Watch the CPPE filehandle for data...
$capWin -> insert( 'end', "CPPE readback info...\n" );
while( <CPPE> ){
print $_;
$capWin -> insert( 'end', $_ );
}
#
# When we get here, the external process has terminated
# (I think). So what to do here...?
#
kill( $watchCPPEid ); # ???
}
}
else{
#
# Launch the external program, passing some args as required.
#
#### exec( "cppe", "/s /r", "bias15scan.prc", $incVal );
exec( "prnwait", @ARGV ); # simpler offline testbed...
# We never get here....
}
}
sub abortScan(){
kill( 9, $cppeId );
kill( 9, $watchCPPEid );
exit();
}
------------------< prnwait.c >-----------------
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv[] ){
int i;
for( i = 0; i < atoi(argv[1]); i++ ){
printf( "This is line %d\n", i );
fflush( stdout );
sleep( atoi(argv[2]) );
}
exit(0);
}
================< console output >=======================
This is line 0
This is line 1
This is line 2
This is line 3
This is line 4
Xlib: unexpected async reply (sequence 0x103)!
Warning: unable to close filehandle CPPE properly.
This is line 0
This is line 1
This is line 2
This is line 3
This is line 4
Xlib: unexpected async reply (sequence 0x161)!
X Error of failed request: BadIDChoice (invalid resource ID chosen for this
connection)
Major opcode of failed request: 53 (X_CreatePixmap)
Resource id in failed request: 0x3000017
Serial number of failed request: 357
Current serial number in output stream: 320
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rod Nussbaumer, Programmer/Technologist E-mail: bomr@triumf.ca
TRIUMF --- University of British Columbia, Phone: (604)222-7449
Vancouver, BC, Canada. FAX: (604)222-7307
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: 15 Dec 2000 11:29:59 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: Re: basic code -- why won't it work??!!
Message-Id: <1r66klwq20.fsf@video.bsd.uchicago.edu>
>>>>> "John" == John W <jwmsng@greatNOSPAMwebsolutions.com> writes:
John> Folks, what am I doing wrong here -- why does the following
John> not generate any output? What I'm looking for, obviously,
John> is:
Your code produces the desired output on my terminal. It looks like
your default output is set to something funky.
John Hunter
------------------------------
Date: Fri, 15 Dec 2000 13:10:44 -0500
From: "John W" <jwmsng@greatNOSPAMwebsolutions.com>
Subject: Re: basic code -- why won't it work??!!
Message-Id: <3a3a5e2d_5@goliath2.newsfeeds.com>
Huh. Absolute most bizarre thing I've seen this week.
Thanks for the help, John. I wondered whether I was going crazy.
Your post did lead to a solution, though not one I'm entirely satisfied
with. I tried similar code using a new file, and it worked.
I tried modifying the previous code to be virtually identical to the new
file, and -- it DIDN'T work.
Nothing I could discover wrong with the file. Maybe there was a wierd,
invisible character in there somewhere, but that's about the only thing I
can think of. Permissions were all the same, everything.
Now here's another thought. A unix question, more. I wonder whether...
BINGO! I think I found it.
I renamed file2 to file1. It no longer works.
Appears Unix is executing some other file, somewhere else, by the same name
as file1. No visible output.
Great.
Anyway, thanks for your help that enabled me to solve the problem!!!!!
John
>
> John> Folks, what am I doing wrong here -- why does the following
> John> not generate any output? What I'm looking for, obviously,
> John> is:
>
> Your code produces the desired output on my terminal. It looks like
> your default output is set to something funky.
>
> John Hunter
>
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Fri, 15 Dec 2000 10:52:40 -0700
From: Andy Cantrell <cantrela@agcs.com>
To: John W <jwmsng@greatNOSPAMwebsolutions.com>
Subject: Re: basic code -- why won't it work??!!
Message-Id: <3A3A5A68.3978074D@agcs.com>
foreach $usr (@users) { print ...
John W wrote:
>
> Folks, what am I doing wrong here -- why does the following not generate any
> output? What I'm looking for, obviously, is:
>
> bob
> jane
> tim
> sue
>
> =================
> #!/usr/local/bin/perl
> @users = ( 'bob', 'jane', 'tim', 'sue' );
> for my $usr (@users) {
> print "$usr \n";
> }
>
--
Andy Cantrell - cantrela@agcs.com
AG Communication Systems
------------------------------
Date: 15 Dec 2000 17:22:45 +0000
From: nobull@mail.com
Subject: Re: cookies
Message-Id: <u94s054n16.fsf@wcl-l.bham.ac.uk>
"Claus" <brasen@email.dk> writes:
> I save it as test.cgi, upload it and chmod 755.
I would definitely recommend inserting "syntax check" and probably
"run at the command line" between those steps.
> Then I call it with:
> <a href=/cgi-bin/test.cgi>test cookie</a>
> but it doesn't work :(
>
> anyone know why?
Has "anyone" run your script though the Perl syntax checker?
Has "anyone" looked in the server error log?
If so then "anyone" would know there's a semicolon missing at the end
of one of the lines.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 15 Dec 2000 11:29:48 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Errors in HTTP/Response & LWP/Response
Message-Id: <6976-3A3A550C-15@storefull-245.iap.bryant.webtv.net>
Are there errors in HTTP/Response
and LWP/Response? The below snippet of code gives the same errors
whether I use the server's modules or install my own locally. I even
installed the entire libwww library, and tried different versions. Both
versions 5.46 and 5.48 still give the errors listed below. [Looks like
this is the real reason that none of those scripts people suggested
worked]
#!/usr/bin/perl -wd
print "Content-type: text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use LWP::Simple;
$URL = "http://downtowndisco.hypermart.net/email2.gif";
$file = "temp/storage";
getstore($URL, $file);
ERRORS RETURNED after processing....
No alias for back No alias for cut No alias for cut No alias for cut No
alias for back No alias for cut Content-type: text/html Software error:
Missing right curly or square bracket at
/usr/local/lib/perl5/site_perl/5.6.0/HTTP/Response.pm line 330, at end
of line syntax error at
/usr/local/lib/perl5/site_perl/5.6.0/HTTP/Response.pm line 330, at EOF
Compilation failed in require at
/usr/local/lib/perl5/site_perl/5.6.0/LWP/UserAgent.pm line 98.
Please help. I've been trying to grab and store a URL for 2 weeks now,
and am getting nowhere.
Regards,
Dennis
------------------------------
Date: 15 Dec 2000 09:11:25 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: FAQ 5.11: How can I translate tildes (~) in a filename?
Message-Id: <3a3a42ad@cs.colorado.edu>
In article <91c091$chh@netnews.hinet.net>,
John Lin <johnlin@chttl.com.tw> wrote:
>> Use the <> (glob()) operator, documented in the perlfunc manpage. This
>> requires that you have a shell installed that groks tildes, meaning
>csh
>> or tcsh or (some versions of) ksh, and thus may have portability
>> problems.
>
>This documentation is out of date, right?
Yes, it is.
--tom
------------------------------
Date: Fri, 15 Dec 2000 12:22:02 -0500
From: "Vladimir Silyaev" <cbah@chez.com>
Subject: Re: File limit to save on HDD
Message-Id: <91djuk$dj1$1@slb7.atl.mindspring.net>
<bakha_ma@my-deja.com> wrote in message news:911pok$jm6$1@nnrp1.deja.com...
> I have a very newbie question for you all! I am working on developing
> a Perl script to run as a cgi-bin script on a web server under Windows
> 98 and am having a problem. When I try to save text from a web form,
> it appears that only 1.5Kb of text is getting saved. I paste in 4Kb of
> information, but only 1.5Kb make it to the file. Here is the script
> itself:
You have consider to use CGI.pm module at first priroty. And looks below
about your problem.
[skiped]
> #Get parametrs from query-string
> if ($ENV{'REQUEST_METHOD'} eq 'GET'){$query = $ENV{'QUERY_STRING'};}
> elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
> {sysread(STDIN, $query, $ENV{'CONTENT_LENGTH'});}
Here You have to read data in the loop untill you get error or receive
exactly amount of data.
--
Vladimir Silyaev
Brainbench MVP for Perl
http://www.brainbench.com
------------------------------
Date: Fri, 15 Dec 2000 08:53:43 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: flat text file or MySQL
Message-Id: <3A3A4C97.5AE0D20D@vpservices.com>
bababozorg@aol.com wrote:
>
> i am about to write this Advertising program, but i am not sure about
> one thing... whether or not use MySQL or flat text files as my
> database...
>
> I would like to use MySQL, but i am worried if it will work fast enough
> since everytime a banner is requested a connection have to be made to
> the database
As others have said, there are ways around the slow connection time.
OTOH, if you use Perl DBI and the DBD::RAM driver then you can write a
script that will access almost any type of flat file (CSV,XML,Tab or
Pipe "delimited", Fixed-wdith,...) with essentially no connection time.
The trade-off will be in a speed of access which won't matter until your
database gets large. One advantage of doing it this way is that you can
use the same script with MySQL just by changing the connection line of
the script. That way you can test speeds using both backends or switch
to the MySQL backend at any point.
--
Jeff
------------------------------
Date: Fri, 15 Dec 2000 13:17:01 -0500
From: "_14k4" <webmaster@860.org>
Subject: Re: flat text file or MySQL
Message-Id: <hft_5.7298$OD.3097782@typhoon.snet.net>
> ###############################
> Take care of your shoes...jay
Mmm .. primal soup.
------------------------------
Date: 15 Dec 2000 17:42:15 +0000
From: nobull@mail.com
Subject: Re: Function from string
Message-Id: <u91yv94myq.fsf@wcl-l.bham.ac.uk>
"Daniel W. Burke" <dwb1@home.com> writes:
> %CUSTOM_FUNCTION = (
> "NEW_AND_UPDATED","GetNewAndUpdated",
> "AVG_TO_CLOSURE","GetAvgToCLosure",
> "AGENT_ACTIVITY","GetAgentActivity",
> <---- code snipped ---->
> );
>
> my $CustomFunction = $CUSTOM_FUNCTION{$in{'REPORT_TYPE'}};
> &$CustomFunction;
> Is there a way we can work around this without removing strict
> from that module?
Quick workround: remove strict only from the one statement.
{ no strict 'refs'; &$CustomFunction; }
Weird workround: Call them as methods (method calls are exempt from
strict refs):
__PACKAGE__->$CustomFunction();
Real solution: replace symbolic refs by real refs.
%CUSTOM_FUNCTION = (
"NEW_AND_UPDATED",\&GetNewAndUpdated,
"AVG_TO_CLOSURE",\&GetAvgToCLosure,
"AGENT_ACTIVITY",\&GetAgentActivity,
More conventionally written as:
%CUSTOM_FUNCTION = (
NEW_AND_UPDATED => \&GetNewAndUpdated,
AVG_TO_CLOSURE => \&GetAvgToCLosure,
AGENT_ACTIVITY => \&GetAgentActivity,
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 15 Dec 2000 16:25:28 GMT
From: andre_sanchez@my-deja.com
Subject: Re: Help!!!!
Message-Id: <91dgld$3ri$1@nnrp1.deja.com>
In article <91d1n2$o8f$1@talia.mad.ttd.net>,
"Juan Salvador" <salva.perez@ctv-jet.com> wrote:
> Anybody knows if exists a tool for indenting Perl sources (like
indent
> by example).
>
Go to www.google.com and search for emacs.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 15 Dec 2000 18:48:45 GMT
From: Ryan Travis Tate <ryantate@OCF.Berkeley.EDU>
Subject: Re: How do I get the last day of a month??
Message-Id: <91dp2d$jq1$1@agate.berkeley.edu>
| o Years greater than 999 are interpreted as being the
| actual year, rather than the offset from 1900. Thus,
| 1963 would indicate the year Martin Luther King won the
| Nobel prize, not the year 2863.
perl's y3k bug!
of course, perl will be on at least 5.7 by then, right?
------------------------------
Date: Fri, 15 Dec 2000 12:31:54 -0500
From: "Vladimir Silyaev" <cbah@chez.com>
Subject: Re: IO::Select::select not blocking on a filehandle
Message-Id: <91dkig$3bd$1@slb1.atl.mindspring.net>
"Freddie" <freddie@ns1.nowait.net> wrote in message
news:9ll63tge5qatg3b5rkfih4dgnr7gtsvuee@4ax.com...
> Hi,
>
> I seem to be having a rather annoying problem with
> IO::Select::select... here's some code:
>
> sub main_loop {
> open(LOG, "< $c{'logfile'}") || die $!;
> seek(LOG, 0, 2);
>
[skipped]
> $logfh is ALWAYS in @$rh_set, so the select call is always returning
> straight away, making a nice spinlock = 100% CPU usage :-( I've tried
> it with can_read() too, same problem... anyone have any ideas?
Select nor Poll doesn't works with regular files. In your case if you are
looking to follow up to the log file you
have to consider the next possibilities:
1. Open log file in the other way: open(LOG, "tail -f $c{'logfile'}|")
2. Use sysread functions and wait some time when sysread returned '0' (end
of file reached)
--
Vladimir Silyaev
Brainbench MVP for Perl
http://www.brainbench.com
------------------------------
Date: 15 Dec 2000 09:12:17 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is a Hash of Arrays possible?
Message-Id: <3a3a42e1$1@cs.colorado.edu>
In article <3a39e95c@news-uk.onetel.net.uk>, Edd <edd@texscene.com> wrote:
>Is it possible to have hash of arrays.
What part of the perlref, perldsc, or perllol manpages was it
that you didn't understand? :-(
--tom
------------------------------
Date: Fri, 15 Dec 2000 17:49:02 +0100
From: "tim allen" <timallen449@coldmail.com>
Subject: Re: Is a Hash of Arrays possible?
Message-Id: <91dhe3$ff6$1@diana.bcn.ttd.net>
I've only been hanging around this NG for a little while, but I have to say
that I'm well impressed by the level of participation of perl heroes such as
yourself and Randal Schwartz. Even if it *is* to hand out RTFM. It's all
very good. Thanks.
--
unmunge?cold=hot
@q=unpack('U*',"Tim Allen");@l=unpack('U*',"Geeky Hackers Grok Perl!\n"
);@w=(61,113,107,191,88,-11,74,107,105,127,97,119,115,47,64,120,118,29,
20,72,91,189,144,39,-88);foreach(@w){push(@g,($_-$l[$x]));$x++}foreach(
@g){print chr($_+$q[$z]);$z++;$z%=@q}
"Tom Christiansen" <tchrist@perl.com> wrote in message
news:3a3a42e1$1@cs.colorado.edu...
In article <3a39e95c@news-uk.onetel.net.uk>, Edd <edd@texscene.com> wrote:
>Is it possible to have hash of arrays.
What part of the perlref, perldsc, or perllol manpages was it
that you didn't understand? :-(
--tom
------------------------------
Date: 15 Dec 2000 09:08:17 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <3a3a41f1$1@cs.colorado.edu>
In article <3A3990C2.7D6E35A6@rochester.rr.com>,
Bob Walton <bwalton@rochester.rr.com> wrote:
>In Perl, I would expect that the length of a variable's name would make
>a difference in execution time, since the variable must be looked up in
>the symbol table each time it is used (Perl isn't like a language in
>which compilation is followed by linking).
This is actually wrong, because the compiler looks up all the symbols
available to it at compile-time. From the Camel:
Most variable name lookups happen at compile-time, but run-time
lookups happen when symbolic references are dereferenced, and
also when new bits of code are parsed under C<eval>.
Furthermore, even if it *didn't* do so, this would be the 2nd-most
most idiotic programming advice known to man, following only behind
the one to "use no comments, and it'll be faster".
--tom
------------------------------
Date: 15 Dec 2000 09:10:33 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <3a3a4279@cs.colorado.edu>
In article <91c9sn$e8f$1@boomer.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>Can't you measure compile time of some code by doing something
>like the following?
That assumes you can get to within the margin of error caused
by quantum fluctuation. Which is highly unclear.
--tom
------------------------------
Date: 15 Dec 2000 09:09:09 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <3a3a4225@cs.colorado.edu>
In article <3a373715.67126743@news.grnet.gr>,
Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>Is there any significant time overhead when using long variable names?
>
>e.g. $name_in_old_and_obsolete_database versus $old_name
No.
--tom
------------------------------
Date: 15 Dec 2000 10:54:28 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <91dic4$jt8$1@boomer.cs.utexas.edu>
In article <3a3a4279@cs.colorado.edu>,
Tom Christiansen <tchrist@perl.com> wrote:
>In article <91c9sn$e8f$1@boomer.cs.utexas.edu>,
>Logan Shaw <logan@cs.utexas.edu> wrote:
>>Can't you measure compile time of some code by doing something
>>like the following?
>
>That assumes you can get to within the margin of error caused
>by quantum fluctuation. Which is highly unclear.
Huh? Are you saying that you expect the variation to be so small
that it would be hard to ensure one tests enough iterations to
find a difference?
I did see a difference when I ran that benchmark. The ones with the
print statement took about 20% longer than the ones without. Granted,
this difference is probably much larger than the difference for
examining symbols of two different sizes. But then, while it may not
ultimately answer the question of whether there is an overhead for
using long variable names, if the difference is so small that it's
difficult to measure, then that does give sort of a practical answer.
Of course, you could always exaggerate the difference by using
obscenely long variable names. (Is there a maximum?)
- Logan
------------------------------
Date: 15 Dec 2000 10:12:00 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <3a3a50e0@cs.colorado.edu>
In article <91dic4$jt8$1@boomer.cs.utexas.edu>,
Logan Shaw <logan@cs.utexas.edu> wrote:
>Huh? Are you saying that you expect the variation to be so small
>that it would be hard to ensure one tests enough iterations to
>find a difference?
Yes, very much so.
>I did see a difference when I ran that benchmark. The ones with the
>print statement took about 20% longer than the ones without.
20%? I am dubious.
In any event, this is FALSE EFFICIENCY. Efficiency-chasing is often
a sign of a mis-directed novice programmer. There's thinking about
the absolute wrong thing.
Stop chasing microseconds. Duh.
In any event, the apparent difference between any of these in utterly
meaningless, because the variation between separate runs is almost
always greater than the apparent difference in execution speeds. And
even if it isn't, this means NOTHING.
It would be faster not the check return codes, so don't do that.
It would be faster not to use whitespace, so don't do that.
It would be faster not to use comments, so don't do that.
It would be faster not to write the program, so don't do that.
It would be faster to write in assembler, so have a nice day.
I think not.
Efficiency is the hobgoblin of little programmers. Rule 1 of
optimization is: Don't!
% perl /tmp/ab
Benchmark: running q first, q null, q second, q third, each for at least 3 CPU seconds...
q first: 3 wallclock secs ( 3.22 usr + 0.00 sys = 3.22 CPU) @ 3414.91/s (n=10996)
q null: 3 wallclock secs ( 3.21 usr + 0.00 sys = 3.21 CPU) @ 4118.38/s (n=13220)
q second: 3 wallclock secs ( 3.18 usr + 0.00 sys = 3.18 CPU) @ 3434.91/s (n=10923)
q third: 3 wallclock secs ( 3.25 usr + 0.00 sys = 3.25 CPU) @ 3486.15/s (n=11330)
Benchmark: running sub first, sub null, sub second, sub third, each for at least 3 CPU seconds...
sub first: 3 wallclock secs ( 3.11 usr + 0.00 sys = 3.11 CPU) @ 3299.36/s (n=10261)
sub null: 3 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 4025.24/s (n=12599)
sub second: 3 wallclock secs ( 3.25 usr + 0.01 sys = 3.26 CPU) @ 3350.61/s (n=10923)
sub third: 3 wallclock secs ( 3.16 usr + 0.00 sys = 3.16 CPU) @ 3348.73/s (n=10582)
Benchmark: running var 0, var 1, var 2, each for at least 3 CPU seconds...
var 0: 3 wallclock secs ( 3.14 usr + 0.00 sys = 3.14 CPU) @ 7000.96/s (n=21983)
var 1: 4 wallclock secs ( 3.13 usr + 0.00 sys = 3.13 CPU) @ 6337.06/s (n=19835)
var 2: 4 wallclock secs ( 3.21 usr + 0.00 sys = 3.21 CPU) @ 6378.19/s (n=20474)
% perl /tmp/ab
Benchmark: running q first, q null, q second, q third, each for at least 3 CPU seconds...
q first: 3 wallclock secs ( 3.18 usr + 0.00 sys = 3.18 CPU) @ 3457.86/s (n=10996)
q null: 3 wallclock secs ( 3.19 usr + 0.00 sys = 3.19 CPU) @ 4144.20/s (n=13220)
q second: 3 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @ 3450.81/s (n=10663)
q third: 3 wallclock secs ( 3.19 usr + 0.00 sys = 3.19 CPU) @ 3447.02/s (n=10996)
Benchmark: running sub first, sub null, sub second, sub third, each for at least 3 CPU seconds...
sub first: 3 wallclock secs ( 3.10 usr + 0.00 sys = 3.10 CPU) @ 3341.61/s (n=10359)
sub null: 3 wallclock secs ( 3.07 usr + 0.00 sys = 3.07 CPU) @ 4052.77/s (n=12442)
sub second: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 3385.08/s (n=10663)
sub third: 3 wallclock secs ( 3.11 usr + 0.00 sys = 3.11 CPU) @ 3402.57/s (n=10582)
Benchmark: running var 0, var 1, var 2, each for at least 3 CPU seconds...
var 0: 3 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @ 7112.00/s (n=21336)
var 1: 3 wallclock secs ( 3.11 usr + 0.00 sys = 3.11 CPU) @ 6380.71/s (n=19844)
var 2: 3 wallclock secs ( 3.10 usr + 0.00 sys = 3.10 CPU) @ 6401.29/s (n=19844)
% cat /tmp/ab
use Benchmark;
$code1 = "print 'How long will this take to compile?';";
$code2 = "print 'What about this?';";
$code3 = "print '';";
timethese (0, {
'q first' => q { eval qq{sub { $code1 } } },
'q second' => q { eval qq{sub { $code2 } } },
'q third' => q { eval qq{sub { $code3 } } },
'q null' => q { eval qq{sub { } } },
});
timethese (0, {
'sub first' => sub { eval qq{sub { $code1 } } },
'sub second' => sub { eval qq{sub { $code2 } } },
'sub third' => sub { eval qq{sub { $code3 } } },
'sub null' => sub { eval qq{sub { } } },
});
timethese(0, {
'var 0' => q { eval qq{ } },
'var 1' => q { eval qq{ $x = 1 } },
'var 2' => q { eval qq{ $abcabcabcd = 1 } },
});
--tom
------------------------------
Date: 15 Dec 2000 18:14:17 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Is there an overhead using long variable names?
Message-Id: <91dn1p$obd$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x74s06i8v4.fsf@home.sysarch.com>:
> >>>>> "BW" == Bob Walton <bwalton@rochester.rr.com> writes:
>
> BW> In Perl, I would expect that the length of a variable's name would
> BW> make a difference in execution time, since the variable must be
> BW> looked up in the symbol table each time it is used (Perl isn't
> BW> like a language in which compilation is followed by linking).
> you expect incorrectly. if all the vars are my'ed (as most of them
> should be) then there are no symbol table entries to look up at run
> time.
With non-lexical variables there *are* entries, but they are used *only*
if you use symbolic references
$name = 'long_name_of_a_variable';
$$name = 12;
Otherwise access to non-lexicals may be even (slightly) quickier than
to lexicals (though I saw no water-tight explanation why this may be
so: there is one less C indirection for lexicals).
Ilya
------------------------------
Date: Fri, 15 Dec 2000 17:04:08 GMT
From: eggrock@my-deja.com
Subject: Re: Parsing files backwards
Message-Id: <91diu2$5nk$1@nnrp1.deja.com>
In article <87n1dyjzfx.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Thu, 14 Dec 2000 17:50:37 GMT,
> >> eggrock@my-deja.com said:
> > [snip code]
>
> you didn't actually say what you're trying to do in any
> detail beyond the subject. I'll assume you want to
> reverse a file (last line first...first line last) to
> stdout.
>
> The simplest solution is the module:
>
>
http://search.cpan.org/doc/URI/File-ReadBackwards-0.94/ReadBackwards.pm
That's cool. I think in this case I'd like to "reinvent the wheel"
though, in order to more fully understand the workings of this. I'll
take a look at this module though, and thank you.
I found one problem with the script I wrote--It doesn't check for empty
files and endlessly loops if it tries to read one. That shouldn't be a
problem to fix though.
What I want to do exactly is grab the last x number of lines without
having to push the whole file into an array, and do it faster than
parsing a whole file (if it's huge) using push/shift with an array (or
unshift/pop depending on how I want to do it).
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5123
**************************************