[18211] in Perl-Users-Digest
Perl-Users Digest, Issue: 379 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 28 18:12:16 2001
Date: Wed, 28 Feb 2001 15:10:19 -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: <983401819-v10-i379@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Feb 2001 Volume: 10 Number: 379
Today's topics:
Re: Newbie question re: Perl on RedHat 7 mwhyte_@_pmds.com
Re: Newbie question re: Perl on RedHat 7 (Danny C.)
not sure to post it here <www0028@garnet.acns.fsu.edu>
Re: Perl CGI.pm RESET problem (BUCK NAKED1)
Re: Perl CGI.pm RESET problem (BUCK NAKED1)
Re: Perl comments ?? <shanem@ll.mit.edu>
Re: Perl comments ?? <peter.sundstrom-eds@eds.com>
Re: Perl string (Anno Siegel)
Re: print "</tr><tr>" vs. print $tr (Abigail)
Re: print "</tr><tr>" vs. print $tr <stan_no_spam_for_me@alamo.nmsu.edu>
Re: print "</tr><tr>" vs. print $tr <stan_no_spam_for_me@alamo.nmsu.edu>
Re: print "</tr><tr>" vs. print $tr <joe+usenet@sunstarsys.com>
Re: print "</tr><tr>" vs. print $tr (Ilya Zakharevich)
Re: print "</tr><tr>" vs. print $tr <bernie@fantasyfarm.com>
Re: print "</tr><tr>" vs. print $tr (Ben Okopnik)
Re: print "</tr><tr>" vs. print $tr <stan_no_spam_for_me@alamo.nmsu.edu>
Re: print "</tr><tr>" vs. print $tr <flavell@mail.cern.ch>
Re: print "</tr><tr>" vs. print $tr <godzilla@stomp.stomp.tokyo>
Re: print "</tr><tr>" vs. print $tr <stan_no_spam_for_me@alamo.nmsu.edu>
Re: problem with {q}? <mjcarman@home.com>
Re: problem with {q}? (Rudolf Polzer)
Re: problem with {q}? <ddunham@redwood.taos.com>
Re: problem with {q}? <bernie@fantasyfarm.com>
Re: problem with {q}? <micah@cowanbox.com>
QUE: Reading and Writing to Serial Port <mtsouk@freemail.gr>
Re: Reading and Writing to Serial Port <um@no.com>
Re: regex help please (The Mosquito ScriptKiddiot)
Re: regex help please (The Mosquito ScriptKiddiot)
Re: Secret planned perl feature revealed <lmoran@wtsg.com>
Win32::API question. <Nicholas.Hoelz@BestBuy.com>
Re: XML modules <bertilow@chello.se>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Feb 2001 19:36:14 GMT
From: mwhyte_@_pmds.com
Subject: Re: Newbie question re: Perl on RedHat 7
Message-Id: <97jjve$5c9$1@news.netmar.com>
In article <97j8fi$esp$1@news.netmar.com>, <mwhyte_@_pmds.com> writes:
>
>I was hoping someone can help me with is probably a simple issue. I'm
>running
>RedHat 7 and my version of perl is 5.6 - the version that ships with RedHat
>7. I've written my very first perl scrip, called test.pl naturally. When I
>run "perl test.pl", everything works just fine (the script simply
>prints 3
>lines of test to the screen). However, after making test.pl executable
>(chmod +x test.pl), I cannot run it just by typing "test" at the
>command
>line. The first line of the script is "#!/usr/bin/perl", just like all
>the
>examples I've seen. When I type "test", nothing happens - no error
>messages
>or anything, I simply return to a command prompt.
>
DOH! I figured out the obvious problem about the command /usr/bin/test
already existing. So I wrote another little script called "hello.pl", here
it is in it's glory:
#!/usr/bin/perl -w
use strict;
use diagnostics;
print "Hello World\n";
print `ls`;
When I run "perl hello.pl", everything is fine. However, after making it
executable, I can't run it simply by typing "hello". Am I missing a step in
making it executable (the book I'm reading said all that was necessary was to
add the "#!/usr/bin/perl -w" line at the beginning and run a simple chmod)?
Once again, I appreciate any and all help :)
Mark
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Wed, 28 Feb 2001 22:16:58 GMT
From: no@thanks.moo (Danny C.)
Subject: Re: Newbie question re: Perl on RedHat 7
Message-Id: <Xns9056A3F5BH07C0W5@205.152.0.143>
mwhyte_@_pmds.com spluttered this in <97jjve$5c9$1@news.netmar.com>:
>When I run "perl hello.pl", everything is fine. However, after making
>it executable, I can't run it simply by typing "hello". Am I missing a
>step in making it executable (the book I'm reading said all that was
>necessary was to add the "#!/usr/bin/perl -w" line at the beginning and
>run a simple chmod)?
The file is not named "hello", it's named "hello.pl".
Try running "hello.pl" (no quotes, of course)
Danny
--
,=================================================================,
/ "Mr. Potato Head's on a boner" - Tomo \
\ "DANNY = SUPARHER0j" - James /
`=================================================================`
------------------------------
Date: Wed, 28 Feb 2001 16:23:51 -0500
From: Bill Wang <www0028@garnet.acns.fsu.edu>
Subject: not sure to post it here
Message-Id: <3A9D6C67.CE2C0308@garnet.acns.fsu.edu>
i am pulling out a data from sql server, this data is a string with
'enter' in it, I means, for example,
1.welcome
2.bybye
when I want to set this data to a textarea, "unterminal string" fault.
I tried txtarea.value="1.welcome \n2bybye", it works, but why the data
from database can not work?
when debug,
txtarea="1.welcome
2.bybye", of cause, it is wrong. How can I do?
wei wang
------------------------------
Date: Wed, 28 Feb 2001 13:39:29 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Perl CGI.pm RESET problem
Message-Id: <23575-3A9D53F1-26@storefull-243.iap.bryant.webtv.net>
Thanks, Joe. I tried both of your suggestions ( defaults() and override
). I think I'm making some progress; but now my revised script changes
the textbox to the URL of the script when I hit RESET... instead of
clearing it. Can you tell me what I'm doing wrong?
[apologies for any newsreader wrapping or odd AO characters]
#!/usr/local/bin/perl -wd
use CGI qw(fatalsToBrowser);
use CGI qw(:standard);
print header;
print "<HTML><BODY bgcolor=99CCFF topmargin=0>
<CENTER>
$query = new CGI;
print $query->start_multipart_form(-method=>$method,
-action=>$action,
-enctype=>$encoding);
print $query->textfield(-name=>'url',
-value=>"$ENV{HTTP_REFERER}",
-override=>1,
-size=>60,
-maxlength=>300);
print "<BR>";
print $query->defaults(-name=>'url',
-value=>'RESET',
-default=>'url');
print " ";
print $query->submit(-name=>'submit',
-value=>'SUBMIT');
print "</CENTER></BODY></HTML>";
print $query->endform;
Regards,
Dennis
------------------------------
Date: Wed, 28 Feb 2001 14:11:25 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Perl CGI.pm RESET problem
Message-Id: <1064-3A9D5B6D-9@storefull-244.iap.bryant.webtv.net>
Oops... I have a "; after my CENTER tag. I just CC&P'd it wrong when I
removed something before pasting it.
--Dennis
------------------------------
Date: Wed, 28 Feb 2001 15:00:17 -0500
From: Shane McDaniel <shanem@ll.mit.edu>
Subject: Re: Perl comments ??
Message-Id: <3A9D58D1.4504F6C8@ll.mit.edu>
Is the server a unix machine or PC? The path at the top of the code
would say a unix box, but editing it in notepad says you're on a PC.
If you are editing it on a pc and ftping it to a unix box then make sure
you are doing an ascii ftp transfer.
Otherwise, is the entire script being printed out also? If so you may
have the wrong path to the perl binary.
"deborah.knight1" wrote:
>
> Hello,
>
> I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
> the # and /*..*/ for comments but none work, with the comments showing up in
> both netscape and IE from home and my server.
>
> This is the code:
>
> #!/usr/local/bin/perl
>
> /*comment see if it works*/
> #this perhaps
>
> print "content-type:text/html\n\n";
>
> <HTML><HEAD><TITLE>Hiya there</TITLE></HEAD>
> <BODY><H1>Web page</H1></BODY></HTML>
>
> Any hints gratefully recieved.
>
> Debbie Knight
------------------------------
Date: Thu, 1 Mar 2001 10:12:56 +1300
From: "Peter Sundstrom" <peter.sundstrom-eds@eds.com>
Subject: Re: Perl comments ??
Message-Id: <97jpko$kd$1@hermes.nz.eds.com>
"deborah.knight1" <debbie.knight@ntlworld.com> wrote in message
news:c8an6.216$_4.159123@news6-win.server.ntlworld.com...
> Hello,
>
> I've edited a cgi scrpit using notepad, wordpad and ultraedit, using both
> the # and /*..*/ for comments but none work, with the comments showing up
in
> both netscape and IE from home and my server.
Perl comments start with #
>
> This is the code:
>
> #!/usr/local/bin/perl
>
> /*comment see if it works*/
> #this perhaps
>
> print "content-type:text/html\n\n";
>
> <HTML><HEAD><TITLE>Hiya there</TITLE></HEAD>
> <BODY><H1>Web page</H1></BODY></HTML>
This code produces the following perl error:
/*comment see if it works*/: ?+*{} follows nothing in regexp at /tmp/foo
line 3.
Your problem is a web server configuration issue. Nothing to do with Perl.
------------------------------
Date: 28 Feb 2001 19:05:58 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl string
Message-Id: <97ji6m$6s7$2@mamenchi.zrz.TU-Berlin.DE>
According to Tad McClellan <tadmc@augustmail.com>:
> Peter Søgaard <peter.s@tjgroup.dk> wrote:
> >> What are "inverted commas"?
> >
> >I think he means back ticks ``
> >...not sure tho'
>
>
> But there were not any backtick characters in his post...
Uh... "inverted commas" is a britishism for "double quotes".
Anno
------------------------------
Date: 28 Feb 2001 19:11:00 GMT
From: abigail@foad.org (Abigail)
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <slrn99qja4.h8r.abigail@tsathoggua.rlyeh.net>
Stan McCann (stan_no_spam_for_me@alamo.nmsu.edu) wrote on MMDCCXXXVIII
September MCMXCIII in <URL:news:3A9D1E81.C2182300@alamo.nmsu.edu>:
<> I've been writing some scripts that displays data in tables and it
<> becomes cumbersome to keep using print "</tr><tr>" every time I need to
<> start a new row in the table. I thought of doing it as a small function
<> and calling the funtion but I'm pretty sure that is going to involve
<> some slowdown of program execution. I finally thought of defining a
<> variable my ($tr) = "</tr><tr>" and then just printing the variable when
<> needed. This works pretty well but I'm wondering if there is a better
<> way. I thought about a define or an inline function as in C but don't
<> know how to do this in perl. I've tried looking at perldocs but can't
<> find anything suitable.
<>
<> Which is more efficent? Is there a better way?
<>
<> Thanks.
<> Stan McCann
sub print_table {
local ($" => $,) = qw <</td><td> </td></tr><tr><td>>;
print "<table><tr><td>";
print map {"@$_"} @{$_[0]};
print "</td></tr></table>\n";
}
And pass the table to be printed as a reference.
Abigail
--
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'
------------------------------
Date: Wed, 28 Feb 2001 11:59:29 -0700
From: Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D4A91.E2E6D95F@alamo.nmsu.edu>
"Alan J. Flavell" wrote:
>
> On Wed, 28 Feb 2001, Stan McCann wrote:
>
> > I've been writing some scripts that displays data in tables and it
> > becomes cumbersome to keep using print "</tr><tr>" every time I need to
> > start a new row in the table.
>
> I'd recommend a more structured thought. Each table row is a complete
> HTML "element", starting with <tr> and ending with </tr> and
> containing, well, whatever it contains (td and th elements, if you
> want to be specific). If you wish, you can print a tr element using
> CGI.pm's Tr() function. If you don't wish, then that's fine too, but
> I'd still recommend getting the structure right.
Yes, I know this. In coding it though, each time I want a new row in my
table, I first must end a row </tr>, then start a new row <tr>. Are you
trying to say that I'm doing something wrong by combining the two when I
want to start a new row?
print "<tr><td>cell 1</td><td>cell 2></tr>" is difficult to read and see
the table structure so I have gone to using something more like for easy
reading and clarity in my code:
print "<tr>";
print "<td>cell 1</td>";
print "<td>cell 2</td>";
print "</tr>";
At the beginning of a table, I place the <tr> next to the <table>, then
I place a </tr> before </table> handling the start row and end row
tags. I just though it would be easier when going to a new row to
simplify the above code to:
print "<td>cell 1</td>";
print "<td>cell 2</td>$tr";
or something like:
print "<td>cell 1</td>";
print "<td>cell 2</td>";
printrow();
>
> > I thought of doing it as a small function
> > and calling the funtion but I'm pretty sure that is going to involve
> > some slowdown of program execution.
>
> Rule 1 of program optimisation is "don't optimise yet". (that's also
> rule 2, and possibly rule 3 also).
>
Sorry, I don't follow this philosophy of re-writing code. I'd rather do
it right the first time than to have to spend time later rewriting a
program to optimize it.
> The first priority is to engineer it right. That in itself is a form
> of optimisation: but don't think of it in those terms. Just don't
> optimise yet,
>
> > Which is more efficent?
>
> Frankly, you'd have to be generating an unreasonably vast amount of
> HTML per invocation before this mattered. In reality the dominant
> time and resource consumption of what you're discussing is likely to
> be the process startup. Stop worrying about the detailed efficiency
> of what you're coding, and start worrying about its robustness,
> correctness, but most of all about the overall organisation of what
> you're doing.
>
That's what I thought but I wanted some verification from the
"experts". What I am doing is partly dealing with the organisation by
making my code easier for me to read.
> Good luck.
Thanks for the reply.
Stan McCann
------------------------------
Date: Wed, 28 Feb 2001 12:02:19 -0700
From: Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D4B3B.CE01E44@alamo.nmsu.edu>
brian d foy wrote:
>
> In article <3A9D1E81.C2182300@alamo.nmsu.edu>,
> stan_no_spam_for_me@alamo.nmsu.edu wrote:
>
> > Which is more efficent? Is there a better way?
>
> how about:
>
> use CGI qw(:standard);
>
> print Tr( ... );
Where do I find *good* documentation on using the cgi.pm module? I am
using cgi but couldn't find anyplace that documented table use. I had
tried things like start_table, start_row, end_table, end_row, etc. but
they don't work. I just figured that the cgi mod only had routines for
forms.
>
> --
> brian d foy <comdog@panix.com>
------------------------------
Date: 28 Feb 2001 14:42:47 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <m3k86a1tmw.fsf@mumonkan.sunstarsys.com>
Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu> writes:
> I've been writing some scripts that displays data in tables and it
> becomes cumbersome to keep using print "</tr><tr>" every time I need to
> start a new row in the table. I thought of doing it as a small function
> and calling the funtion but I'm pretty sure that is going to involve
> some slowdown of program execution.
Well you should test that theory then, because it's usually
an irrelevant difference unless you are in a very tight loop.
> I finally thought of defining a
> variable my ($tr) = "</tr><tr>" and then just printing the variable when
> needed. This works pretty well but I'm wondering if there is a better
> way.
% man CGI
> I thought about a define or an inline function as in C but don't
> know how to do this in perl.
Don't bother- data manipulation is what Perl does best.
> I've tried looking at perldocs but can't
> find anything suitable.
>
> Which is more efficent? Is there a better way?
CGI.pm offers functions (Tr, td) that work great with map(), but
if that's all you want to do, you could roll your own in the same way.
Here's a few (assuming your table is stored as a lol):
my @table = ( [qw(row one)], [qw(row two)], [qw(row three)] );
Either use CGI
use CGI qw( Tr td table );
print table( {-border=>0}, map { Tr td($_) } @table );
or inline it
{
local ($", $,) = ("</td> <td>", "</td></tr>\n\t<tr><td>");
print qq{<table border="0">\n\t<tr><td>};
print map { "@{$_}" } @table;
print qq{</td></tr>\n</table>\n};
}
or make your own sub
sub print_html_table (@) {
print qq{<table border="0">\n\t<tr><td>},
join (
"</td></tr>\n\t<tr><td>",
map { join "</td> <td>", @{$_} } @_
),
qq{</td></tr>\n</table>};
}
If really speed matters, the sub is probably the quickest of
these.
--
Joe Schaefer "Language is the dress of thought."
-- Samuel Johnson
------------------------------
Date: 28 Feb 2001 20:16:14 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <97jmae$no5$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Ilmari Karonen
<usenet11381@itz.pp.sci.fi>],
who wrote in article <983383233.335@itz.pp.sci.fi>:
> In article <3A9D1E81.C2182300@alamo.nmsu.edu>, Stan McCann wrote:
> >
> >I thought of doing it as a small function and calling the funtion but
> >I'm pretty sure that is going to involve some slowdown of program
> >execution.
>
> Yes. About 5 microseconds per call, according to my measurements.
>
> That's not a very reliable measurement, however, since the overhead of
> timing the call is about 10 times larger. In other words, the slowdown
> is about as significant as a fly's piss in the pacific ocean.
What reliable measurements show is that calling a Perl function is a
*very significant overhead*, close to dispatching 20 Perl opcodes.
Given that $c = $a + $b is 5 opcodes, you got the picture. Wrapping
it in a function will slow it down 5 times.
Ilya
------------------------------
Date: Wed, 28 Feb 2001 15:33:43 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <j5nq9t445bbosaqib5bq7tah0bq84n4e1c@news.supernews.net>
Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu> wrote:
} ... In coding it though, each time I want a new row in my
} table, I first must end a row </tr>, then start a new row <tr>. Are you
} trying to say that I'm doing something wrong by combining the two when I
} want to start a new row?
}
} print "<tr><td>cell 1</td><td>cell 2></tr>" is difficult to read and see
} the table structure so I have gone to using something more like for easy
} reading and clarity in my code:
}
} print "<tr>";
} print "<td>cell 1</td>";
} print "<td>cell 2</td>";
} print "</tr>";
Actually, I end up looking at the HTML output a fair bit, also, and so I've
gone to:
print "<tr>\n" ;
print " <td>cell 1</td>\n" ;
print " <td>cell 2</td>\n" ;
print "</tr>\n";
If something goes awry and I need to 'view source' I *HATE* it if I have to
sort out a single 800-char-long line of stuff, so I line-break and indent
the HTML as carefully as I do the same for my Perl code. different
compulsions for different folks..:o)
} At the beginning of a table, I place the <tr> next to the <table>, then
} I place a </tr> before </table> handling the start row and end row
} tags.
I *never* do that. I always have the table laid out and indented [and with
lots of newlines] so that the HTML ends up looking like:
TABLE
ROW
COL
COL
COL
/ROW
NEXTROW
COL
COL
/NEXTROW
/TABLE
[with further formatting of the HTML if the 'col' stuff won't comfortably
fit on a line].
} > > I thought of doing it as a small function
} > > and calling the funtion but I'm pretty sure that is going to involve
} > > some slowdown of program execution.
} >
} > Rule 1 of program optimisation is "don't optimise yet". (that's also
} > rule 2, and possibly rule 3 also).
And beyond that, Axiom 1 is "if you've already optimized, you almost
certainly optimized the wrong thing"...:o)
} Sorry, I don't follow this philosophy of re-writing code. I'd rather do
} it right the first time than to have to spend time later rewriting a
} program to optimize it.
Which philosophy? There are two problems with the approach you seem to be
espousing:
1) until you've written, tested and benchmarked the code, how do you know
what *parts* (if any) need optimizing? And how to optimize it [will it be
more important to save CPU cycles, disk accesses, process size, etc, and
how *much* to optimize it... as a rule, for almost anything more
complicated than adding a column of numbers there aren't just two possible
solutions [the slow and the fast] but usually dozens of things (each
getting more and more obscure and tricky) that you can do to squeeze out a
little bit more. Unless the program is done and benchmarked [see (2)
below] you don't know which to use and when to stop.
2) as a rule, "optimized" code is less clear and more fragile than are
more straightforward programming styles and so should be avoided whenever
possible [lest you end up with a program that is difficult to debug and
difficult to maintain -- for most applications fast-but-broken or
fast-but-wrong isn't a good combination].
Generally, I try to write the most robust, clear, clean, easy-to-apprehend
code that I can, get the program debugged and rock-solid, and THEN and
_only_then_, if [and that's a _big_ if!] the program has performance
problems I'll profile/analyze it and fix *just* what needs fixing.
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: 28 Feb 2001 20:48:03 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <slrn99qp04.po3.ben-fuzzybear@Odin.Thor>
The ancient archives of Wed, 28 Feb 2001 12:02:19 -0700 showed
Stan McCann of comp.lang.perl.misc speaking thus:
>brian d foy wrote:
>>
>> In article <3A9D1E81.C2182300@alamo.nmsu.edu>,
>> stan_no_spam_for_me@alamo.nmsu.edu wrote:
>>
>> > Which is more efficent? Is there a better way?
>>
>> how about:
>>
>> use CGI qw(:standard);
>>
>> print Tr( ... );
>
>Where do I find *good* documentation on using the cgi.pm module? I am
>using cgi but couldn't find anyplace that documented table use. I had
>tried things like start_table, start_row, end_table, end_row, etc. but
>they don't work. I just figured that the cgi mod only had routines for
>forms.
It's not "cgi.pm", it's "CGI.pm" - that makes a difference. Try
perldoc CGI
The things you mention above will make good search terms. :)
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
If you put an infinite amount of monkeys in front of an infinite amount of
typewriters, they'd eventually produce the entire works of Shakespeare. Do
the same with humans and computers and you get Windows NT. Score: Monkeys
1, Humans 0. -- Jordan Hardgrove
------------------------------
Date: Wed, 28 Feb 2001 13:58:57 -0700
From: Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D6691.1CDA77AA@alamo.nmsu.edu>
Ilya Zakharevich wrote:
>
> What reliable measurements show is that calling a Perl function is a
> *very significant overhead*, close to dispatching 20 Perl opcodes.
> Given that $c = $a + $b is 5 opcodes, you got the picture. Wrapping
> it in a function will slow it down 5 times.
>
Thanks Ilya, that's what I was thinking is that the function would use
more overhead than using a variable but I was curious about how much.
This kind of clears it up for me.
Some others suggested some ways that may be even more efficient, but I'm
still too new to perl to really understand. I haven't looked into
mapping at all yet and do not understand what Abigail and others were
trying to show me. Joe's post was also helpful as I kept looking for
information about CGI.pm in perldoc and not finding it. Duh! It never
occurred to me to man CGI.
Thanks all, I feel I'm on the right track now with my print $tr.
Stan McCann
------------------------------
Date: Wed, 28 Feb 2001 22:36:33 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <Pine.LNX.4.30.0102282219340.18159-100000@lxplus003.cern.ch>
On Wed, 28 Feb 2001, Stan McCann wrote:
> Where do I find *good* documentation on using the cgi.pm module?
Did you even try? Although "cgi.pm" isn't really correct, suppose we
feed that into Google, then the number 1 hit is
http://stein.cshl.org/WWW/software/CGI/
which also happens to be the author's own HTML-format documentation
for the CGI.pm (note the capitalisation) module.
If we confine ourselves to the Perl documentation, then it's true that
typing 'perldoc cgi,pm' or 'perldoc -q cgi.pm' produced nothing when I
tried it, but 'perldoc -q cgi' offered, among other things,
Where can I learn about CGI or Web programming in Perl?
which surely wouldn't be far off finding the answer.
perldoc CGI (or perldoc CGI.pm) would bring you another version of the
documentation that would have adequately answered your questions
(though for the time being I'd say the author's HTML version is better
- I believe this is being worked on for future releases).
It's a normal courtesy to the regulars on any usenet group to
familiarise yourself with their FAQs first. Nobody minds if you
missed something that you needed, but at least if you show some
evidence of having tried, you'll command a lot more sympathy.
> using cgi but couldn't find anyplace that documented table use. I had
> tried things like start_table, start_row, end_table, end_row, etc. but
> they don't work.
Didn't I already propose to you to think in terms of complete
elements, rather than in these kind of fragmentary actions?
> I just figured that the cgi mod only had routines for
> forms.
Far from it, though you don't _have_ to use CGI.pm for writing all
your HTML if you don't want to.
But, as it happens, its table calls can be particularly convenient, as
its documentation shows.
------------------------------
Date: Wed, 28 Feb 2001 13:50:51 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D72BB.C7DC5FD3@stomp.stomp.tokyo>
Stan McCann wrote:
> I've been writing some scripts that displays data in tables
> and it becomes cumbersome to keep using print "</tr><tr>"
> every time I need to start a new row in the table.
(snipped)
As a word of caution, you need to know extensive use of
table tags is strongly discouraged by Microsoft, Mozilla
and professional web page designers.
Two years back, maybe a little more, both Microsoft and
Mozilla issued warning statements about nested table tags
causing their browsers to crash. More specifically, overuse
of nested table tags, or a mistake in use of nested table
tags, can instantly consume all available RAM memory causing
a machine to freeze, curable only by a forced reboot.
Certainly you have visited pages where an author has overused
table tags and, have noted brief periods of 'browser hang' at
these sites. Those incidents reflect internal machine events
which come very close to a CPU freeze.
One single mistake in nested table tags, just a kitten's hair
over the line demarcating too much nested table use, and you
will crash your visitor's system.
There are better ways to display your information without
use of memory gobbling, CPU time consuming nested table tags.
Godzilla!
------------------------------
Date: Wed, 28 Feb 2001 15:17:40 -0700
From: Stan McCann <stan_no_spam_for_me@alamo.nmsu.edu>
Subject: Re: print "</tr><tr>" vs. print $tr
Message-Id: <3A9D7904.4141881A@alamo.nmsu.edu>
Bernie Cosell wrote:
>
>
> Actually, I end up looking at the HTML output a fair bit, also, and so I've
> gone to:
> print "<tr>\n" ;
> print " <td>cell 1</td>\n" ;
> print " <td>cell 2</td>\n" ;
> print "</tr>\n";
That looks like a pretty good idea for viewing source. I may adopt that
when I'm working on static pages. But for dynamic pages, I rarely ever
look at the source from the browser, only in the coding. And there, I
just leave a blank line between blocks to indicate the end of one row
and the begin of another.
>
> } Sorry, I don't follow this philosophy of re-writing code. I'd rather do
> } it right the first time than to have to spend time later rewriting a
> } program to optimize it.
>
I agree with what you are saying below. The above is probably just poor
wording on my part. I was attempting to speak to the idea that deciding
whether to use print "<tr></tr>" or print $tr is better. I'd rather
figure that out now and write the code than figure out later that it
would have been better to do it the other way and then have to go
through my code and change it. So maybe find and replace isn't that
hard to do, but still . . .
> Which philosophy? There are two problems with the approach you seem to be
> espousing:
> 1) until you've written, tested and benchmarked the code, how do you know
> what *parts* (if any) need optimizing? And how to optimize it [will it be
> more important to save CPU cycles, disk accesses, process size, etc, and
> how *much* to optimize it... as a rule, for almost anything more
> complicated than adding a column of numbers there aren't just two possible
> solutions [the slow and the fast] but usually dozens of things (each
> getting more and more obscure and tricky) that you can do to squeeze out a
> little bit more. Unless the program is done and benchmarked [see (2)
> below] you don't know which to use and when to stop.
> 2) as a rule, "optimized" code is less clear and more fragile than are
> more straightforward programming styles and so should be avoided whenever
> possible [lest you end up with a program that is difficult to debug and
> difficult to maintain -- for most applications fast-but-broken or
> fast-but-wrong isn't a good combination].
>
> Generally, I try to write the most robust, clear, clean, easy-to-apprehend
> code that I can, get the program debugged and rock-solid, and THEN and
> _only_then_, if [and that's a _big_ if!] the program has performance
> problems I'll profile/analyze it and fix *just* what needs fixing.
>
Yes! That's what I am trying to do, write clear, clean, easy to read
code that works reliably without sacrificing speed.
Stan McCann
------------------------------
Date: Wed, 28 Feb 2001 12:14:46 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: problem with {q}?
Message-Id: <3A9D4016.14F4E9D5@home.com>
Bernie Cosell wrote:
>
> } { print @_ unless $opts{q} ; }
>
> I don't exactly understand why [...] I get
> >>> Ambiguous use of {q} resolved to {"q"}
>
> What was 'q' ambiguous with?
The alternative single quote syntax, e.g.
my $string = q(Some string with '' in it);
Perl DWYM'd it (correctly) to a literal 'q'. If you replace $opts{q}
with $opts{'q'} you won't get the warning anymore.
-mjc
------------------------------
Date: Wed, 28 Feb 2001 20:34:19 +0100
From: rpolzer@web.de (Rudolf Polzer)
Subject: Re: problem with {q}?
Message-Id: <slrn99qklr.52e.rpolzer@rebounce.rpolzer-lx>
Bernie Cosell <bernie@fantasyfarm.com> schrieb Folgendes:
> In a program I'm playing with [Perl 5.004_004], I do
>
> } my %opts ;
> } getopts("a:p:q", \%opts) ;
>
> and then I play with the hash in the program. In one place I do:
> if ($opts{a})
> { $acct = $opts{a} ; }
> else
> { print...dostuff..etc..
>
> and down later in the program I do
>
> } sub say
> } { print @_ unless $opts{q} ; }
>
> I don't exactly understand why the reference to $opts{a} [and {p}] seem to
> be OK, but for that last one, I get
>
> >>> Ambiguous use of {q} resolved to {"q"}
>
> What was 'q' ambiguous with? I just looked through my program and I
> for-sure don't have a symbol named 'q'.. why would just that one hash-key
> be ambiguous but the others not? In case it is some package messing with
> me, the program includes only:
q is ambigous with the q// operator. See perldoc perlop.
--
#!/usr/bin/perl
eval($0=q{$0="\neval(\$0=q{$0});\n";for(<*.pl>){open X,">>$_";print X
$0;close X;}print''.reverse"\nsuriv lreP trohs rehtona tsuJ>RH<\n"});
####################### http://learn.to/quote #######################
------------------------------
Date: Wed, 28 Feb 2001 19:42:28 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: problem with {q}?
Message-Id: <Ewcn6.111$bG5.39114@news.pacbell.net>
Bernie Cosell <bernie@fantasyfarm.com> wrote:
>>>> Ambiguous use of {q} resolved to {"q"}
> What was 'q' ambiguous with? I just looked through my program and I
> for-sure don't have a symbol named 'q'.. why would just that one hash-key
> be ambiguous but the others not? In case it is some package messing with
> me, the program includes only:
It is ambiguous because there is a function called 'q'.
It assumed (and told you) that you wanted %hash{"q"} rather than
%hash{q()}.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Wed, 28 Feb 2001 15:35:30 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: problem with {q}?
Message-Id: <a6oq9t86h9ppdncema2tfft6dn4lfa3hn1@news.supernews.net>
Michael Carman <mjcarman@home.com> wrote:
} Bernie Cosell wrote:
} >
} > } { print @_ unless $opts{q} ; }
} >
} > I don't exactly understand why [...] I get
} > >>> Ambiguous use of {q} resolved to {"q"}
} >
} > What was 'q' ambiguous with?
}
} The alternative single quote syntax, e.g.
}
} my $string = q(Some string with '' in it);
DRAT!! I completely forgot about that guy... sigh... It is all crystal
clear.. DUH... so I guess I shouldn't change the hash key to qq
either..:o)
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: 28 Feb 2001 14:53:37 -0800
From: Micah Cowan <micah@cowanbox.com>
Subject: Re: problem with {q}?
Message-Id: <yu8k86amnbi.fsf@mcowan-linux.transmeta.com>
Michael Carman <mjcarman@home.com> writes:
> Bernie Cosell wrote:
> >
> > } { print @_ unless $opts{q} ; }
> >
> > I don't exactly understand why [...] I get
> > >>> Ambiguous use of {q} resolved to {"q"}
> >
> > What was 'q' ambiguous with?
>
> The alternative single quote syntax, e.g.
>
> my $string = q(Some string with '' in it);
>
> Perl DWYM'd it (correctly) to a literal 'q'. If you replace $opts{q}
> with $opts{'q'} you won't get the warning anymore.
>
> -mjc
<To OT:>
And if you'd been using "use strict" on a regular basis, you'd have
written it like this anyway...
<To Mr. Carman:>
Hm... I guess I can't now sign this with /my/ initials, now can I? Oh
/wait/! I know, I'll use caps:
-MJC
;)
------------------------------
Date: Wed, 28 Feb 2001 22:26:24 +0200
From: "Mihalis Tsoukalos" <mtsouk@freemail.gr>
Subject: QUE: Reading and Writing to Serial Port
Message-Id: <97jn7j$1bn9$1@ulysses.noc.ntua.gr>
Hello to everyone.
If anyone has used the serial port with Perl, I would like to ask a couple
of questions:
What I really need is two routines, one for reading and one for writing.
I already have something but I get garbage with it and I don't know why. Is
there any chance that ôçå ãáñâáãå would be the start and stop bits of the
serial port?
Can you please help me?
Has anyone have the two routines that I want?
many thanks in advance,
Mihalis
mtsouk@freemail.gr
PS. Please reply to my email (mtsouk@freemail.gr) as well as to the
newsgroup.
------------------------------
Date: Wed, 28 Feb 2001 16:43:00 -0800
From: "Ben L." <um@no.com>
Subject: Re: Reading and Writing to Serial Port
Message-Id: <3a9d732c$1_1@news2.one.net>
What platform are you using?
------------------------------
Date: 28 Feb 2001 22:17:28 GMT
From: anotherway83@aol.com (The Mosquito ScriptKiddiot)
Subject: Re: regex help please
Message-Id: <20010228171728.19100.00001161@ng-mq1.aol.com>
first off...
thanks for replying.
but this is not a homework problem, i'm not in college/engineering school (im
in HS), i'm learning perl from an online tutorial (i think its a SAMS one, r
they any good??) and this is a pet-project of my own, i wanna put it up on my
own website...this problem needs to be solved, because it will be used in a
larger program that solves derivatives in calculus
thanks
peace
The Mosquito ScriptKiddiot
Championing the Cause of Mosquitoes in Technology
------------------------------
Date: 28 Feb 2001 22:39:12 GMT
From: anotherway83@aol.com (The Mosquito ScriptKiddiot)
Subject: Re: regex help please
Message-Id: <20010228173912.19100.00001171@ng-mq1.aol.com>
holy cow, that works awesumly well
thank u, thank u thank u...
thanks also to all those who replied
this has solved my problem:)
peace
The Mosquito ScriptKiddiot
Championing the Cause of Mosquitoes in Technology
------------------------------
Date: Wed, 28 Feb 2001 17:05:46 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: Secret planned perl feature revealed
Message-Id: <3htq9t808o2q1vop4q9q0q2djl7f4hd37b@4ax.com>
On Tue, 27 Feb 2001 23:30:52 -0600, cdh <cdh@ala.net> wrote wonderful
things about sparkplugs:
>perl -e 'print "Perl, please automatically write the program I am thinking of right now!\n"; $perl = sub { print "Yes Master, here
>is what I need...\n" }; do &$perl()'
>
>Yes, I know there's an error... therein lies the funny part;)
>
>Later,
>Chris Hickman
>
>P.S. this works on 5.6.0, I don't know if it's present in other versions.
#!/usr/bin/perl -w
#use strict;
my $insaneramblings = 1;
print "\nWhy did you post this here?\n\n"
unless $insaneramblings eq "0";
>
--
"> thanks in advance !!!
If you are going to do anything 'in advance' it should be RTFM."
--swiped from a nobull clp.misc post
Lou Moran <lmoran@wtsg.com>
------------------------------
Date: 28 Feb 2001 14:51:12 -0600
From: "Nicholas" <Nicholas.Hoelz@BestBuy.com>
Subject: Win32::API question.
Message-Id: <3a9d640d$0$1288$45beb828@newscene.com>
Does anybody know of a way to halt PERL's execution until an API call
returns?
All the necessary logic is in place, except for this one little hiccup.
I ran into the same trouble with a global services check script, but
that was easily circumvented using a do..until loop, and checking the status
as well as any errors that mighgt be thrown.
Without the return value, the rest of the script is useless, as the
handle returned is absolutely necessary for the reading of the page and the
parsing of the header.
------------------------------
Date: Wed, 28 Feb 2001 21:14:52 GMT
From: "Bertilo Wennergren" <bertilow@chello.se>
Subject: Re: XML modules
Message-Id: <gTdn6.1846$bX.27731@nntp1.chello.se>
Tom Kralidis:
> Is anyone aware of any XML::Parser documentation, other than perldoc
I'm also trying to wrap my head around XML parsing with Perl.
These articles helped me a lot:
<http://www.perlmonth.com/columns/perl_xml/perl_xml.html?issue=4>
<http://www.perlmonth.com/columns/perl_xml/perl_xml.html?issue=5>
<http://www.perlmonth.com/columns/perl_xml/perl_xml.html?issue=6>
Good luck!
--
#####################################################################
Bertilo Wennergren
<http://purl.oclc.org/net/bertilo>
<bertilow@chello.se>
#####################################################################
------------------------------
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 V10 Issue 379
**************************************