[8880] in Perl-Users-Digest
Perl-Users Digest, Issue: 2497 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 4 23:06:45 1998
Date: Mon, 4 May 98 20: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 Mon, 4 May 1998 Volume: 8 Number: 2497
Today's topics:
Re: #PERL the IRC Channel on Efnet. <webmaster@fccjmail.fccj.org>
Re: cgi-lib.pl or CGI.pm? (brian d foy)
CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm? <ljz@asfast.com>
Re: CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI (brian d foy)
Checking for Ping reply??? <andrew@iaccess.com.au>
Re: condition to subroutine (Charles DeRykus)
Re: condition to subroutine <sowmaster@juicepigs.com>
Re: Directory usage in Perl for win32 <davidc@selectst.com>
Re: Ever Wonder Why Not Everyone Uses Modules? (I R A Aggie)
Re: Ever Wonder Why Not Everyone Uses Modules? (Andre L.)
Help with DBM files <tgough@ols.net>
HELP: Can someone help me with this problem ?? <nl@medex.anhb.uwa.edu.au>
how to use eval and-or $@ (Michael Shavel)
Re: Image Cache (Martien Verbruggen)
Re: Padding a string to be a fixed length <danboo@negia.net>
Re: Padding a string to be a fixed length <lr@hpl.hp.com>
Re: Perl Conference (brian d foy)
Re: Personal Web Server <sowmaster@juicepigs.com>
Re: Personal Web Server (Martien Verbruggen)
Printing in Perl indhiraa@hotmail.com
Re: visual basic replacement <davidc@selectst.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 May 1998 00:59:01 GMT
From: Bill 'Sneex' Jones <webmaster@fccjmail.fccj.org>
Subject: Re: #PERL the IRC Channel on Efnet.
Message-Id: <354E6299.B93AC23@fccjmail.fccj.org>
Excession wrote:
> But there is the inevitable pitfall of IRC to contend with -- the trigger
> happy Operators of the channel.
>
> you have been kicked off #perl by x ( whoomp! there it is!)
>
> <Dac> Amagosa got upset when I said that he was a #perl godlet :-)
My favorite line from FF7 is 'Knights of the Round'...
Or, a more down to earth approach - Nuke'em all.
(Sound of neutron bomb) "Ooops! There it is :-)"
-Sneex-
____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
mailto:webmaster@fccjmail.fccj.org | http://webmaster.fccj.org/Webmaster
------------------------------
Date: Mon, 04 May 1998 22:24:19 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: cgi-lib.pl or CGI.pm?
Message-Id: <comdog-ya02408000R0405982224190001@news.panix.com>
Keywords: from just another new york perl hacker
In article <6ilc9n$dr$2@flotsam.uits.indiana.edu>, bdwheele@indiana.edu (Brian Wheeler) posted:
CGI.pm is hideously bloated and combines CGI, HTML, cookies, etc in
>one module...which I think is a mistake (Print works very well for HTML
>generation...Do I really need an anchor object?)
but then, you only have to export what you want, if even that. :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: 04 May 1998 21:40:19 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?)
Message-Id: <ltyawh5wcc.fsf_-_@asfast.com>
[ Followups set to comp.lang.perl.modules ]
mgjv@comdyn.com.au (Martien Verbruggen) writes:
> In article <354E293A.DBC1FFE@shell.com>,
> Yong Huang <yong@shell.com> writes:
> > Thanks, Sir. I wonder if you could give me a more specific example or reason
> > why CGI.pm is better than cgi-lib.pl. That is, I don't seme to be fully
> > convinced yet.
>
> What is unconvincing about CGI.pm being more reliable, less buggy,
> still supported, part of the standard distribution, having better
> debugging capabilities, being more flexible? What is unconvincing of
> CGI.pm even having a cgi-lib 'compatibility' mode which allows you to
> still use your old code? I don't get it. Did you read any of responses
> you got?
All these things are true about CGI.pm, but I just ran a quick
benchmark, and CGI.pm is quite a bit slower than cgi-lib.pl (results
discussed below). If speed and web server load are issues, and if all
that's needed is basic functionality, then cgi-lib.pl might be a more
desirable alternative.
What I did was to post identical <FORM> data to a simple CGI script
that loaded either CGI.pm or cgi-lib.pl, depending on the contents of
the PATH_INFO enviroment variable (which is set via the URL in the
`action' clause of each of the <FORM> tags -- see below). The script
then retrieved the variable values from the form and listed them on
the returned web page.
I used Time::HiRes to capture the total elapsed time of the script
(until HTML printing) and also to calculate the elapsed time after
the initial load of the module (CGI.pm or cgi-lib.pl) had taken place.
In both cases, CGI.pm was quite a bit slower.
This is by no means an exhaustive benchmark. I'm sure that those of
you who might be interested in pursuing this further could come up
with many more comparison scenarios. However, this benchmark does
illustrate the relative efficiencies of the two modules.
All my benchmark code is attached at the bottom of this post. But
first, here are the benchmark results (averages are computed over 10
iterations):
Avg. total elapsed time Avg. elapsed time
Module including load time after initial load
---------- ----------------------- ------------------
cgi-lib.pl 0.0189837 sec 0.0019999 sec
CGI.pm 0.1935548 sec 0.0752660 sec
As you can see, CGI.pm is much slower than cgi-lib.pl for the simple
processing perfomed in this test.
These results were computed using a Pentium Pro 200 MHz box running
RedHat Linux 5.0 and Perl 5.004_04. The web server is Apache 1.3b6.
Here's the main CGI benchmark script (named `test' in my CGI directory):
------------------------------------------------------------------------
#!/usr/bin/perl
# -*- perl -*-
use Time::HiRes;
$startTime = [Time::HiRes::gettimeofday];
@variables = qw( aaa bbb ccc ddd eee fff ggg hhh );
%results = ();
($program = $0) =~ s:.*/::;
($pathInfo = $ENV{'PATH_INFO'}) =~ s:^/::;
# Load the variable values into the %results hash in both cases, for
# the purpose of uniformity.
if ($pathInfo eq "CGI") {
require "./test-CGI.pl"; # (see below)
$loadedTime = [Time::HiRes::gettimeofday];
$q = new CGI;
foreach $item (@variables) {
$results{$item} = $q->param($item);
}
}
else {
require "./test-cgi-lib.pl"; # (see below)
$loadedTime = [Time::HiRes::gettimeofday];
ReadParse();
foreach $item (@variables) {
$results{$item} = $in{$item};
}
}
print <<EOD;
Content-type: text/html
<html>
<head>
<title>Test of CGI vs. cgi-lib</title>
</head>
<body>
<b>Test of $pathInfo</b><br><br>
<table>
EOD
foreach $item (sort keys %results) {
print <<EOD;
<tr>
<td align="left"><b>Key: $item</b></td>
<td align="left"><b>Value: $item</b></td>
</tr>
EOD
}
print <<EOD;
</table>
<br>
EOD
$totalElapsed = Time::HiRes::tv_interval($startTime);
$sinceLoading = Time::HiRes::tv_interval($loadedTime);
print <<EOD;
<b>Total elapsed time:
$totalElapsed seconds</b><br>
<b>Elapsed time since loading of <i>$pathInfo</i>:
$sinceLoading seconds</b><br>
</body>
</html>
EOD
exit(0);
__END__
Here are the contents of the `test-CGI.pl' include file:
--------------------------------------------------------
use CGI;
1;
Here are the contents of the `test-cgi-lib.pl' include file:
------------------------------------------------------------
require 'cgi-lib.pl';
1;
Here's the web page for invoking the main CGI benchmark script:
---------------------------------------------------------------
<html>
<head>
<title>Form Test</title>
</head>
<body>
<b>This is a timing test of <i>CGI.pm</i> versus <i>cgi-lib.pl</i>.<br><br>
For the most accurate results, please don't change any of the values in
the input fields. Just click on one or the other of the submit buttons.</b>
<br><hr><br>
<form action="/cgi/test/cgi-lib" method="post">
<input name="aaa" value="aaa">
<input name="bbb" value="bbb">
<input name="ccc" value="ccc">
<input name="ddd" value="ddd">
<input name="eee" value="eee">
<input name="fff" value="fff">
<input name="ggg" value="ggg">
<input name="hhh" value="hhh">
<input type="submit" value="Test cgi-lib.pl">
</form>
<hr><br>
<form action="/cgi/test/CGI" method="post">
<input name="aaa" value="aaa">
<input name="bbb" value="bbb">
<input name="ccc" value="ccc">
<input name="ddd" value="ddd">
<input name="eee" value="eee">
<input name="fff" value="fff">
<input name="ggg" value="ggg">
<input name="hhh" value="hhh">
<input type="submit" value="Test CGI.pm">
</form>
<br>
</body>
</html>
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Mon, 04 May 1998 22:23:12 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: CGI.pm/cgi-lib.pl benchmark (Was: cgi-lib.pl or CGI.pm?)
Message-Id: <comdog-ya02408000R0405982223120001@news.panix.com>
Keywords: from just another new york perl hacker
In article <ltyawh5wcc.fsf_-_@asfast.com>, Lloyd Zusman <ljz@asfast.com> posted:
>[ Followups set to comp.lang.perl.modules ]
[ Follow-up ignored ]
>mgjv@comdyn.com.au (Martien Verbruggen) writes:
>
>> In article <354E293A.DBC1FFE@shell.com>,
>> Yong Huang <yong@shell.com> writes:
>> > Thanks, Sir. I wonder if you could give me a more specific example or reason
>> > why CGI.pm is better than cgi-lib.pl. That is, I don't seme to be fully
>> > convinced yet.
>>
>> What is unconvincing about CGI.pm being more reliable, less buggy,
>> still supported, part of the standard distribution, having better
>> debugging capabilities, being more flexible? What is unconvincing of
>> CGI.pm even having a cgi-lib 'compatibility' mode which allows you to
>> still use your old code? I don't get it. Did you read any of responses
>> you got?
>
>All these things are true about CGI.pm, but I just ran a quick
>benchmark, and CGI.pm is quite a bit slower than cgi-lib.pl (results
>discussed below). If speed and web server load are issues, and if all
>that's needed is basic functionality, then cgi-lib.pl might be a more
>desirable alternative.
if speed and load are issues, use mod_perl [1] or fast-cgi [2].
[1] <URL:http://perl.apache.org>, or <URL:http://apache.perl.org>
[2] <URL:http://www.fastcgi.com>
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: Tue, 5 May 1998 11:18:56 +1000
From: "Andrew Specht" <andrew@iaccess.com.au>
Subject: Checking for Ping reply???
Message-Id: <6ilp9v$fjt@sleipnir.iaccess.com.au>
Hi,
I was wondering if there is an option in perl to ping a host and then to
check for a reply. And if there is a reply, then do something else and so
on
Basically i would like to check every 10 minutes if one of my servers is
still up.
Thanks in advance for any help :)
Andrew Specht
System Administrator
Internet Access Australia
andrew@iaccess.com.au
------------------------------
Date: Tue, 5 May 1998 01:12:16 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: condition to subroutine
Message-Id: <EsGM0G.3s0@news.boeing.com>
In article <354E4F4D.2D12@juicepigs.com>,
Bob Trieger <sowmaster@juicepigs.com> wrote:
>Graham Wallace wrote:
>>
>> [ omit... ]
>
>A statement just isn't a statement without the great taste of semicolon.
>
>if (...) { &sub(); } or &sub() if (...);
>
^
You know, of course, a real epicure will never garnish a curly
with a semicolon if it's not necessary :)
--
Charles DeRykus
------------------------------
Date: Mon, 04 May 1998 21:49:17 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
Subject: Re: condition to subroutine
Message-Id: <354E701D.76CD@juicepigs.com>
Charles DeRykus wrote:
>
> In article <354E4F4D.2D12@juicepigs.com>,
> Bob Trieger <sowmaster@juicepigs.com> wrote:
> >Graham Wallace wrote:
> >>
> >> [ omit... ]
> >
> >A statement just isn't a statement without the great taste of semicolon.
> >
> >if (...) { &sub(); } or &sub() if (...);
> >
> ^
> You know, of course, a real epicure will never garnish a curly
> with a semicolon if it's not necessary :)
Thanks, I never realized that.
I also learned empty parens aren't needed when ampersand is used.
--
Bob Trieger | Titanic: big boat, bigger
sowmaster@juicepigs.com | iceberg, big deal
------------------------------
Date: Tue, 05 May 1998 12:01:28 +1000
From: David Coldrick <davidc@selectst.com>
To: Mike Marziani <marz@tamu.edu>
Subject: Re: Directory usage in Perl for win32
Message-Id: <354E72F7.9B719F19@selectst.com>
Below is an NT example that takes a root directory as a command line
parameter, and executes the "process" routine for each file found.
The basic code comes from Nigel Chapman's book, which has gotta the most
enjoyable, well-targetted book for an experienced programmer learning Perl. I
dunno why it isn't referenced more often in this newsgroup.
Regards,
David
PS Chapman's book is at
http://www.amazon.com/exec/obidos/ats-query/002-4979561-5285421
Example (pls excuse indentation if it's flakey):
use English;
my $pathsep = "\\";
sub lookin {
my ($dir, $function_ref) = @ARG;
opendir DIR, $dir or die "Can't open $dir: $OS_ERROR\n";
my @files = readdir DIR;
foreach $f (@files) {
next if ($f eq '.' or $f eq '..'); # ignore the DOS weirdness
my $p = $dir . $pathsep . $f;
if (-d $p) { lookin($p, $function_ref); }
else {
&$function_ref($f, $p, $dir) if defined($f);
}
}
}
sub process {
my ($file, $fullfile, $dir) = @ARG;
# do some processing here
}
$root = join(' ', @ARGV);
lookin($root, \&process);
Mike Marziani wrote:
> I have a mail server (running under windows NT) with roughly 200 user
> directories. I want a quick and easy way to generate a report that will
> show me everyone who is using over a certain amount of space so that I can
> keep disk usage down. I have a bit of code that will get me the file size
> for any directory tree I give it:
>
> use File::Find;
> @ARGV = ('.') unless @ARGV;
> my $sum = 0;
> find sub { $sum += -s }, @ARGV;
> print "@ARGV contains $sum bytes\n";
>
> But what is the best way to read in the list of directories and apply this
> function to each directory in turn? I am sort of new to perl (but not to
> programming) so if this is some info readily available in the docs, please
> point me to it.
>
> Thanks in advance,
> Mike
------------------------------
Date: Mon, 04 May 1998 21:51:16 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <fl_aggie-0405982151170001@aggie.coaps.fsu.edu>
In article <6ilddd$344$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
(Tom Christiansen) wrote:
+ Another problem with that is if it goes on forever, no one will
+ ever learn how to make wheels.
Ah, so, someday I'll create perl?
James - unless I'm mistaken, 'wheel-making' is the child of Necessity
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Mon, 04 May 1998 22:28:03 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Ever Wonder Why Not Everyone Uses Modules?
Message-Id: <alecler-0405982228030001@dialup-392.hip.cam.org>
In article <6ilddd$344$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
(Tom Christiansen) wrote:
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> Art Cohen <upsetter@shore.net> writes:
> :People on this newsgroup are quick to say "Don't re-invent the wheel;
> :there's a module that already does that"...
>
> Another problem with that is if it goes on forever, no one will
> ever learn how to make wheels.
>
> There are lessons to be learned on both sides here, folks.
>
> --tom
That's refreshing to hear!
Mister C., your wisdom brings me a great deal of relief.
There's been plenty of UAMS ('use a module, stupid') comments in here. I
got the feeling that not using every module available for every possible
task was some kind of a sin.
I rather think that blindly using ready-made routines is not the best way
to get to know what you're doing. Studying them, on the other hand, is a
great way to learn, and to figure out the best way to do it.
And sometimes, a few lines of plain old perl is the best way, period.
A.L.
------------------------------
Date: Mon, 4 May 1998 21:41:31 -0700
From: "Tracy J. Gough" <tgough@ols.net>
Subject: Help with DBM files
Message-Id: <674850C9AB00D204.14C3195D640C4AD4.376CDB40ECCEFCC6@library-proxy.airnews.net>
I am somewhat new with Perl and I am using DBM files with a project. The
problem I am having is trying to store scalar values to the DBM file hash. I
don't having any problems storing values to the DBM hash if they are from
another hash. In this example $fields{'keyvalue'} and $fields{'formvalue'}
represents values from the HTML form data that called the Perl script.
dbmopen(%itemrecs, "catalog", 0644) || die "Can't open orders database
file\n";
$somevalue = "Hello world";
$itemrecs{$fields{'keyvalue'}} = "$fields{'formvalue'}::$somevalue";
The key and first field, $fields{'formvalue'}, will be stored. The
$somevalue field will not be stored. The '::' isn't even stored. How do I
store the scalar $somevalue?
Thanks in advance for any help.
Tracy J. Gough
------------------------------
Date: Tue, 05 May 1998 10:33:19 -0700
From: Nguyen LY <nl@medex.anhb.uwa.edu.au>
Subject: HELP: Can someone help me with this problem ??
Message-Id: <354F4D5F.102840D@medex.anhb.uwa.edu.au>
Can anyone help me out with this problem ???
I'm trying to write a script that will filter an imported text file
which has the following format:
------------File begin--------------
<1>
TI File title
AU File author
AB File abstract
RE References
<2>
TI
AU
.
.
.
<n>
-----------File end------------------
The algorithm I'm trying to come up with will read the file in line by
line
and do the following:
Search for the number in the <x> field; #something like: if (/^<(.)>/m)
...???
if found, push number to an array;
then search for string following TI; #something like: if
(/^TI(.*?)$/) ...???
if found, then push string to an array;
then search for string following AU;
if found, push string to array;
then search.... etc for all the fields...
else error
else error;
else error
So basically, what I want to come up with is an @array with
$array[0] = 1, [1] = string in TI, [2] = string in AU... etc..
I'm just starting to learn Perl, so I find that the regular expressions
are a
bit overwhelming...
Anyway, the problem that I have is I can't seem to figure out how to
search for one
field then starting at that field search for the next, and so on...
I can write the script with subroutines searching for each field
separately but that would
mean the file must be process 5 or so times ........
Any help or pointers would be greatly appreciated..
Thanks....
Nguyen Ly (nl@iaaf.anhb.uwa.edu.au)
------------------------------
Date: Mon, 04 May 1998 22:35:17 -0400
From: mshavel@erols.com (Michael Shavel)
Subject: how to use eval and-or $@
Message-Id: <mshavel-0405982235170001@130.9.16.207>
This is a snip of what I am using to connect to a remote server.
The problem I am having is that if the connection fails the whole
script quits. I need to generate an error message to a log file
before it quits.
I believe using eval is the way but I have tried it in different
places and have had no success.
#eval does not work this way
eval{
$ftp = Net::FTP->new($host) or warn "Could not connect to host: $!\n";
};
if ($@) {print LOG "Danger will robinson!!\n";}
Also, if I print out $@ I am able to see what my error is so I am wondering if
all I need to do is something like this:
$ftp = Net::FTP->new($host) or warn "Could not connect to host: $!\n";
if (defined $@)
{ print LOG "Was not able to connect to remote server\n";}
In this case it looks like I do not need an eval.
In any case.. if someone could give me some help on how to use eval in
this situation I would appreciate it a great deal.
Thanks.
Mike Shavel
mshavel@erols.com
------------------------------
Date: 5 May 1998 00:59:21 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Image Cache
Message-Id: <6ilo99$1jm$1@comdyn.comdyn.com.au>
In article <6iklhi$tm$1@nnrp1.dejanews.com>,
angelok@usa.net writes:
[ Please, next time format your post so it's readable. I'll do it for
you this time]
> Here is the problem...I would like to force the browser to read
> images that have been stored in the cache. A user hits my site and
What cache? Are you going to keep a cache?
> has 3 images on the page. They fill out this form, the data gets
> posted form the server with the same images returned but they repeat
> 5 times. The browser however, instead of reading the images from the
> cache downloads them again when the form is returned form the
> server.
That is the browser's problem. This has nothing to do at all with
perl. Why do you think it has? Please, ask this question on one of the
groups that talk about this stuff:
comp.infosystems.www.*
> Make sense?
Not much, especially not if you expect perl questions.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Mon, 04 May 1998 20:40:56 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: Re: Padding a string to be a fixed length
Message-Id: <354E6018.39E792DD@negia.net>
Mad Max wrote:
>
> I am new to perl and am trying to figure out how to pad a string with spaces
> to be a fixed length. I.E.
>
> $data = "My test String";
> $leftOver = length($data) - $maxLength
>
> I then want to add $leftOver number of spaces to the string.
umm, which end? or should they be sprinkled about randomly? ;-)
here are some hints:
1. "$spaces = ' ' x $leftOver;" will get you a string of $leftOver
number of spaces.
2. this of course depends on the proper logic and mathematics which is
currently not in place. i think you want to subtract your string's
length from your $maxLength.
3. then you can (pre|ap)pend the $spaces as you see fit.
4. you could also use the handy 'sprintf' function which can be
researched in your favorite set of perl documentation.
hope this helps,
--
Dan Boorstein home: danboo@negia.net work: danboo@y-dna.com
"THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
- Cosmic AC
------------------------------
Date: Mon, 4 May 1998 18:50:09 -0700
From: "Larry Rosler" <lr@hpl.hp.com>
Subject: Re: Padding a string to be a fixed length
Message-Id: <6ilra2$88m@hplntx.hpl.hp.com>
Mad Max wrote in message <6ill3o$oov@news-central.tiac.net>...
>I am new to perl and am trying to figure out how to pad a string with
spaces
>to be a fixed length. I.E.
>
>
>$data = "My test String";
>$leftOver = length($data) - $maxLength
I think you want this:
$leftOver = $maxLength - length($data);
>
>
>I then want to add $leftOver number of spaces to the string.
...
Saveral ways. Here's a few of them:
$data .= ' ' x $leftOver;
$data = sprintf "%-${maxLength}s", $data;
$data = pack "A$maxLength", $data;
Understanding each one should be instructive for future problems.
Benchmarking yields these comparisons:
#!/usr/local/bin/perl -w
use strict;
use Benchmark;
use vars qw( $maxLength );
$maxLength = 20;
timethese (100000, {
'x' => q{
my $data = "My test String";
my $leftOver = $maxLength - length($data);
$data .= ' ' x $leftOver;
},
'sprintf' => q{
my $data = "My test String";
$data = sprintf "%-${maxLength}s", $data;
},
'pack' => q{
my $data = "My test String";
$data = pack "A$maxLength", $data;
},
} );
Benchmark: timing 100000 iterations of pack, sprintf, x...
pack: 2 secs ( 2.70 usr -0.01 sys = 2.69 cpu)
sprintf: 3 secs ( 3.09 usr 0.00 sys = 3.09 cpu)
x: 4 secs ( 2.77 usr 0.01 sys = 2.78 cpu)
These results may vary with computer architecture, of course.
--
Larry Rosler
Hewlett-Packard Laboratories
lr@hpl.hp.com
------------------------------
Date: Mon, 04 May 1998 22:30:45 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl Conference
Message-Id: <comdog-ya02408000R0405982230450001@news.panix.com>
Keywords: from just another new york perl hacker
In article <354E2F54.B57F2813@tribune.com>, wsanchez@tribune.com posted:
>Can someone provide me with an ~ cost of attending the Perl Conference
>last year.
do you plan on the Buying-Randal-Drinks package or the Alone-In-My-Room
package? one costs significantly more...
do you want the conference fee? last year it was around $900US. of
course, you still need to figure in your travel costs.
keep watching <URL:http://conference.perl.com> though.
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>
------------------------------
Date: Mon, 04 May 1998 21:14:24 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: Nervick <nervick@bewellnet.com>
Subject: Re: Personal Web Server
Message-Id: <354E67F0.1B6B@juicepigs.com>
[posted & mailed]
Nervick wrote:
> cannot locate cgi-lib.pl in @INC.
>
> The file is in the correct directory and the file is called "cgi-lib.pl" not
> "CGI-lib.pl" or "Cgi-Lib.pl". I looked at @INC and it is as it should be. I
> don't know what's wrong! Please help!
Obligatory cgi-lib.pl putdown:
Use CGI.pm and you won't have this problem.
Or if you must use that ancient crap, try putting it in your cgi-bin
directory.
--
Bob Trieger | Titanic: big boat, bigger
sowmaster@juicepigs.com | iceberg, big deal
------------------------------
Date: 5 May 1998 01:05:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Personal Web Server
Message-Id: <6ilokl$1jm$2@comdyn.comdyn.com.au>
In article <354e5fd5.0@news.bewellnet.com>,
"Nervick" <nervick@bewellnet.com> writes:
> I'm using MS Personal Web Server on my computer at home. I have made the
> correct associations is the "Script Map" part of the registry, and have
> execute permissions in the correct directories. The problem is that
> 'require( "cgi-lib.pl" )' doesn't work! the following message appears:
Questions like this have most of the time nothing to do with perl,
but are problems with CGI or the setup of your server. Please read
the following documents. If you still have problems, and you are
certain it has something to do with perl, please ask again:
Perl CGI FAQ and (no offense) Idiot's guide:
http://www.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html
http://www.perl.com/CPAN/doc/FAQs/cgi/perl-cgi-faq.html
Section 9 of the perl FAQ:
# perldoc perlfaq9
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | A Freudian slip is when you say one
Commercial Dynamics Pty. Ltd. | thing but mean your mother.
NSW, Australia |
------------------------------
Date: Mon, 04 May 1998 21:21:09 -0600
From: indhiraa@hotmail.com
Subject: Printing in Perl
Message-Id: <6ilt2l$ivu$1@nnrp1.dejanews.com>
Hi:
here is my code:
use FileHandle;
my $helpMsg = "help\n";
my $pfh = new FileHandle "| /usr/openwin/bin/filep -l";
(defined $pfh) or return "Can't print.: $!\n";
print $pfh "$helpMsg";
undef $pfh;
I am invoking this subroutine at the press of a button.
I get this error:
Tk::Error: (in cleanup) Not a GLOB reference
Am I missing anything.
Thanks,
Indira.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Tue, 05 May 1998 11:36:17 +1000
From: David Coldrick <davidc@selectst.com>
To: lvirden@cas.org
Subject: Re: visual basic replacement
Message-Id: <354E6D10.246AB9DA@selectst.com>
I'd like to get this beta (preferably binaries for x86 NT), but I can't find it
(or any other beta) on CPAN.
Could you give me a direct pointer?
Thanks and regards,
David
lvirden@cas.org wrote:
> . . .
> Or you could get the beta version of Perl/Tk which connects to Tk 8.0.
>
> Just sign up for the Perl/TK mailing list to learn all about it - or
> download the latest beta from CPAN.
> --
> <URL:mailto:lvirden@cas.org> Quote: In heaven, there is no panic,
> <*> O- <URL:http://www.teraform.com/%7Elvirden/> only planning.
> Unless explicitly stated to the contrary, nothing in this posting
> should be construed as representing my employer's opinions.
------------------------------
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 2497
**************************************