[8467] in Perl-Users-Digest
Perl-Users Digest, Issue: 2084 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 12 14:07:53 1998
Date: Thu, 12 Mar 98 11:00:36 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 12 Mar 1998 Volume: 8 Number: 2084
Today's topics:
Re: Brand new and completely bewildered!!! <camerond@mail.uca.edu>
cookies? <miller@bigsky.net>
garbage collecting <david.gallone@innet.lu>
How to keep an FTP session alive? jli@neurocrine.com
Re: How to read whole HTML content from Web pages? (I R A Aggie)
Re: HTTP_USER_AGENT - any others? (Michael J Gebis)
Re: mkdir() and umask <chasecreek.systemhouse@usa.net>
Need help importing an external function (Rob Wilson)
Re: Need help. Which DB for perl/cgi ? <agraham@usa.net>
Re: Newbie: Degugging Regexps? (Douglas Wilson)
Perl4 vs Perl 5 (User)
Re: Perl4 vs Perl 5 <jim.michael@gecm.com>
Running perl scripts in the background (Paul Wilson)
Re: Speed of sort routine vs. one-by-one compare (123 (Bart Lateur)
Re: Speed of sort routine vs. one-by-one compare (123 (Bart Lateur)
Re: splice -- useful uses? (Michael W Peterson)
Re: You have 1 message(s) - how to print plurals? (Craig Berry)
Re: You have 1 message(s) - how to print plurals? <ajohnson@gpu.srv.ualberta.ca>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Mar 1998 11:41:26 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Bjoern Guenzel <guenzel.p1@usa.net>
Subject: Re: Brand new and completely bewildered!!!
Message-Id: <35081E46.F89E2008@mail.uca.edu>
[cc'd to BG]
Bjoern Guenzel wrote:
>
> [snip]
> I admit that I haven't got CGI.pm yet, I promise it's the next thing
> I'll get.
Have you got perl5? Then you've got CGI.pm - it's part of the standard
distribution.
Cameron
camerond@mail.uca.edu
------------------------------
Date: Thu, 12 Mar 1998 11:00:42 -0700
From: "Keith L. Miller" <miller@bigsky.net>
Subject: cookies?
Message-Id: <350822CA.8B77C383@bigsky.net>
Can anyone tell me how to use cookie's to bring information into my
forms? I have seen some things on this, but really would like more
details.
Thanks,
Miller
------------------------------
Date: Thu, 12 Mar 1998 18:21:09 -0500
From: David Gallone <david.gallone@innet.lu>
Subject: garbage collecting
Message-Id: <35086DE4.58F3@offis.lu>
Hi there,
Could someone confirm that garbage collecting for scalars, arrays or
hashes when reference count goes to zero is not working with a regular
perl interpreter (compiled without special options). In this case, could
you tell me what exact compilation option to use in order to get the
right "destruct level".
I am using perl5.004 on a SINIX platform.
Thanks in advance.
T.Conrad
------------------------------
Date: Thu, 12 Mar 1998 11:33:27 -0600
From: jli@neurocrine.com
Subject: How to keep an FTP session alive?
Message-Id: <6e966g$msh$1@nnrp1.dejanews.com>
Hi, friends.
I am in the process of learning perl and try to use what I have learned to
solve some real problem. I am doing data mining and sometime need to download
huge database files from a remote server using ftp. However the ftp connection
frequently breaks. I tried to write a perl script to monitor the ftp
connection and if it detects break it will automaticaly reconnect and continue
the download. I got the Net::FTP module installed and read its documents. But
I still stack at how to write perl script to determine if the connection is
broken or not, and how to reconnect and continue the downloading. I don't
think there is a reget (like reget on Unix) function with Net::FTP. Any help
would be appreciated.
Jay Li
E-mail: jli@neurocrine.com
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Thu, 12 Mar 1998 13:29:38 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: How to read whole HTML content from Web pages?
Message-Id: <fl_aggie-1203981329380001@aggie.coaps.fsu.edu>
In article <3507fe4a.7748986@news.cedep.com>, gstamant@cedep.com (Guy
St-Amant) wrote:
+ I'm not talking about submiting a form here, I mean, how to grab the
+ content of any page from the Web?
Go look at the LWP module. The docs will explain it, and the working
utils should provide good examples.
James
--
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: 12 Mar 1998 18:27:00 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: HTTP_USER_AGENT - any others?
Message-Id: <6e99dk$br4@mozo.cc.purdue.edu>
"Ben" <ben@wallroyds.demon.co.uk> writes:
}I wonder if any1 know whereabout you can find ... For ALL ones you can have
Ben, I'll pay you a dollar if you refrain from using words like "any1"
and "cuz" in this newsgroup.
}HTTP referer - $ENV{'HTTP_REFERER'}
}Remote addr - $ENV{'REMOTE_ADDR'}
}Remote host - $ENV{'REMOTE_HOST'}
}Remote ident - $ENV{'REMOTE_IDENT'}
}I wonder if any1 know the one for ... HTTP_REFERER or something? When I run
}the program, it didn't show where I came from .... And, what about the one
}"TZ" or something? But, can any1 show me where to find, for ALL of them?
}A-Z!
This is at heart a CGI question, and you could find the answer in various
CGI newsgroups and FAQs. The meaning and origin of all these
environment variables would be found there, too.
If your question was "How can I print the contents of %ENV" the answer
might be something like
foreach $var (keys %ENV) { print "$var: $ENV{$var}\n";}
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Thu, 12 Mar 1998 18:10:27 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: mkdir() and umask
Message-Id: <350823C8.DE2664F2@usa.net>
UMASK Man Page:
umask(1) User Commands umask(1)
NAME
umask - get or set the file mode creation mask
SYNOPSIS
/usr/bin/umask [ -S ] [ _m_a_s_k ]
sh
umask [ _o_o_o ]
csh
umask [ _o_o_o ]
ksh
umask [ -S ] [ _m_a_s_k ]
AVAILABILITY
SUNWcsu
DESCRIPTION
/usr/bin/umask
The umask utility sets the file mode creation mask of the
current shell execution environment to the value specified
by the _m_a_s_k operand. This mask affects the initial value of
the file permission bits of subsequently created files. If
umask is called in a subshell or separate utility execution
environment, such as one of the following:
(umask 002)
nohup umask ...
find . -exec umask ...
it does not affect the file mode creation mask of the
caller's environment.
If the _m_a_s_k operand is not specified, the umask utility
writes the value of the invoking process's file mode crea-
tion mask to standard output.
sh
The user file-creation mode mask is set to _o_o_o. The three
octal digits refer to read/write/execute permissions for
owner, group, and other, respectively (see chmod(1),
chmod(2), and umask(2)). The value of each specified digit
is subtracted from the corresponding ``digit'' specified by
the system for the creation of a file (see creat(2)). For
example, umask 022 removes write permission for group and
other (files normally created with mode 777 become mode 755;
files created with mode 666 become mode 644).
If _o_o_o is omitted, the current value of the mask is
printed.
umask is recognized and executed by the shell.
SunOS 5.5.1 Last change: 28 Mar 1995 1
umask(1) User Commands umask(1)
umask can be included in the user's .profile (see pro-
file(4) ) and invoked at login to automatically set the
user's permissions on files or directories created.
csh
See the description above for the Bourne shell (sh) umask
built-in.
ksh
The user file-creation mask is set to _m_a_s_k. _m_a_s_k can
either
be an octal number or a symbolic value as described in
chmod(1). If a symbolic value is given, the new umask value
is the complement of the result of applying _m_a_s_k to the com-
plement of the previous umask value. If _m_a_s_k is omitted,
the current value of the mask is printed.
OPTIONS
The following option is supported:
-S Produce symbolic output.
The default output style is unspecified, but will be recog-
nised on a subsequent invocation of umask on the same system
as a _m_a_s_k operand to restore the previous file mode creation
mask.
OPERANDS
The following operand is supported:
_m_a_s_k A string specifying the new file mode creation mask.
The string is treated in the same way as the _m_o_d_e
operand described in the chmod(1) manual page.
For a _s_y_m_b_o_l_i_c__m_o_d_e value, the new
value of the file
mode creation mask is the logical complement of the
file permission bits portion of the file mode speci-
fied by the _s_y_m_b_o_l_i_c__m_o_d_e string.
In a _s_y_m_b_o_l_i_c__m_o_d_e value, the
permissions _o_p charac-
ters + and - are interpreted relative to the current
file mode creation mask; + causes the of for the
indicated permissions to be cleared in the mask; -
causes the bits of the indicated permissions to be
set in the mask.
The interpretation of _m_o_d_e values that specify file
mode bits other than the file permission bits is
unspecified.
The file mode creation mask is set to the resulting
numeric value.
SunOS 5.5.1 Last change: 28 Mar 1995 2
umask(1) User Commands umask(1)
The default output of a prior invocation of umask on
the same system with no operand will also be recog-
nized as a _m_a_s_k operand. The use of an operand
obtained in this way is not obsolescent, even if it
is an octal number.
OUTPUT
When the _m_a_s_k operand is not specified, the umask utility
will write a message to standard output that can later be
used as a umask _m_a_s_k operand.
If -S is specified, the message will be in the following
format:
"u=%s,g=%s,o=%s\n", <_o_w_n_e_r
_p_e_r_m_i_s_s_i_o_n_s>, <_g_r_o_u_p
_p_e_r_m_i_s_-
_s_i_o_n_s>, <_o_t_h_e_r
_p_e_r_m_i_s_s_i_o_n_s>
where the three values will be combinations of letters from
the set {r, w, x}; the presence of a letter will indicate
that the corresponding bit is clear in the file mode crea-
tion mask.
If a _m_a_s_k operand is specified, there will be no output
written to standard output.
EXAMPLES
Either of the commands:
umask a=rx,ug+w
umask 002
sets the mode mask so that subsequently created files have
their S_IWOTH bit cleared.
After setting the mode mask with either of the above com-
mands, the umask command can be used to write the current
value of the mode mask:
$ umask
0002
(The output format is unspecified, but historical implemen-
tations use the obsolescent octal integer mode format.)
$ umask -S 1
u=rwx,g=rwx,o=rx
Either of these outputs can be used as the mask operand to a
subsequent invocation of the umask utility.
Assuming the mode mask is set as above, the command:
umask g-w
sets the mode mask so that subsequently created files have
their S_IWGRP, and S_IWOTH bits cleared.
The command:
umask -- -w
sets the mode mask so that subsequently created files have
SunOS 5.5.1 Last change: 28 Mar 1995 3
umask(1) User Commands umask(1)
all their write bits cleared. Note that _m_a_s_k operands r , w
, x or anything beginning with a hyphen, must be preceded by
-- to keep it from being interpreted as an option.
ENVIRONMENT
See environ(5) for descriptions of the following environment
variables that affect the execution of umask: LC_CTYPE,
LC_MESSAGES, and NLSPATH.
EXIT STATUS
The following exit values are returned:
0 The file mode creation mask was successfully changed, or
no _m_a_s_k operand was supplied.
>0 An error occurred.
SEE ALSO
chmod(1), csh(1), ksh(1), sh(1), chmod(2), creat(2), pro-
file(4), environ(5)
HTH,
Sneex :-)
Jeff Stewart wrote:
> Perl's mkdir() function requires a directory name and a "mode," which
> the manual says is modified with the umask() function. The mans for
> umask() just say, "Sets the umask for the process and returns the old
> one. If EXPR is omitted, merely returns current umask."
>
> So what's a umask? What process?
>
> I tried executing mkdir (testing, 777) and got a testing directory with
> or gx wx permissions set.
>
> ???
>
> I tried executing print umask(); and got 18.
>
> ???
>
> Please forgive my ignorance, but what are the man pages leaving out?
>
> --
> Jeff S.
------------------------------
Date: 12 Mar 98 12:40:25 -0500
From: rwilson@cs.muohio.edu (Rob Wilson)
Subject: Need help importing an external function
Message-Id: <1998Mar12.124025.771@nntp.muohio.edu>
I have looked in the Camel book and a few others as well as read every web page
that might be able to help, but I am stumped. I am trying to load a function
into my script that will be re-evaluated each time a certain line is
executed. The function is a text filter, but the format of the strings coming
in changes frequently and the script itself is a long-running one. I would like
to be able to change the filter without having to reload the script every time.
Also, I need to be able to pass arguments to it and include it in an object.
Thanks in advance.
--
Rob Wilson
EH.Net Systems Administrator
rwilson@eh.net
------------------------------
Date: Thu, 12 Mar 1998 13:20:54 -0500
From: "Adam C. Graham" <agraham@usa.net>
Subject: Re: Need help. Which DB for perl/cgi ?
Message-Id: <35082786.EA84BB8E@usa.net>
I wrote a record manager module for Xbase/DBF files using Berkeley DB for indexes.
http://www.erinbay.com/public_source
Good luck,
ACG
Kim Chen wrote:
> Hi All,
>
> I am going to use perl to build a large amount of members base Web
> application, which may be up to over 100 thousand members record.
> However, I am not familiar with perl interface Database system nor the
> Database. I gusses text-file type database is not good enough. Other
> choice are :
>
> DBM : SDBM, GDBM...I just know their name .What's the actual diff ? Are
> they good enough ?
>
> Berkeley DB : any good ?
>
> freeware RDBMS : something like Postgre and PostgreSQL. But is it very
> hard to install/learn/use ? Since I have no real experience with
> RDBMS. However, it seems it is the most powerful and complete one.
>
> Another question is : I don't own the web site. I will put the web
> application on a ISP. So I don't have any superuser access right. Can I
> still install/use the package ?
>
> Or any better solution ?
>
> Thanks a lot for your help anyway.
>
> regards,
>
> Kim
> Please reply to kim@glink.net.hk
------------------------------
Date: Thu, 12 Mar 1998 18:42:00 GMT
From: dgwilson@gte.net (Douglas Wilson)
Subject: Re: Newbie: Degugging Regexps?
Message-Id: <6e9a5s$2dj$1@gte2.gte.net>
On Wed, 11 Mar 1998 11:20:23 -0500, mpleone@ma.ultranet.com wrote:
>$line = '171-0190 Type A Line Guard Rope Screw $1.75';
>
>
>if ($line =~ m/^\s+([d\-\]*)\s+(.*)(\b|\))\s+\$([\d.]+)\s$/)
Let's take this a piece at a time:
m/^\s+
#^ You have no spaces at the beginning of the string in the above
# sample data(therefore no match);
# you could change this to '^\s*'
([d\-\]*)
#^ You mean '[\d\-]' not '[d\-\]' right?
#And are you sure that the '*' shouldn't be a '+'? (Which
#I guess might be the case if you have parts w/o part #'s).
\s+
#Ok
(.*)(\b|\))\s+
#The above line could probably be '(.*?)\s+' since the next match
#is a literal '$'
\$([\d.]+)\s$/x
#Ok except you have no spaces at the end of the string
#in the above sample data, maybe you mean '\s*$'?
Hope that helps,
Douglas Wilson
------------------------------
Date: Thu, 12 Mar 1998 18:21:51 GMT
From: you@somehost.somedomain (User)
Subject: Perl4 vs Perl 5
Message-Id: <3508272a.261783665@news.btinternet.com>
Ok I've looked in the FAQ
RTFM'd some books, and I still cant find what I want.
I am currently working on a project, my team say that we should be
programming in Perl 5, another Team Perl 4.
Can suggest any reasons not to go with Perl 4, specific cases of code
not working, or any pointers to such info would be great.
Thanks in Advance
Ian
------------------------------
Date: Thu, 12 Mar 1998 13:32:28 -0500
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: Perl4 vs Perl 5
Message-Id: <35082A3C.325D@gecm.com>
User wrote:
>
> Ok I've looked in the FAQ
How about dejanews, where I think this topic might have come up before.
> RTFM'd some books, and I still cant find what I want.
dejanews usually works pretty well. You think you have a question that's
never been asked before on Usenet?
>
> I am currently working on a project, my team say that we should be
> programming in Perl 5, another Team Perl 4.
Why don't you just call yourselves Team Perl?
>
> Can suggest any reasons not to go with Perl 4, specific cases of code
> not working, or any pointers to such info would be great.
Perl 4 is not Y2K compliant. Is that a good reason?
Cheers,
Jim
--
To email, rot(13) the part of the From: address before the @, and join
with the rot(8) of the part after the @. Then subtract 1 from any
numeric characters, mapping 0 to 9. Now bitwise AND with
president@whitehouse.gov and use the result as the email address.
Looking forward to hearing from you!
------------------------------
Date: Thu, 12 Mar 1998 18:13:33 GMT
From: prw@god.I.hate.spam.vanitydomain.net (Paul Wilson)
Subject: Running perl scripts in the background
Message-Id: <350824f1.90751993@news.bestweb.net>
This may sound like a stupid question, but how do I get a perl script
to run itself in the background on a UNIX (BSD) system? I've tried all
kinds of fork stuff but the script just hangs on and never dumps me
back to the UNIX prompt unless I hit ^Z bg.
Paul.
prw at vanitydomain dot net
(yes, this is my real address)
------------------------------
Date: Thu, 12 Mar 1998 17:43:28 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Speed of sort routine vs. one-by-one compare (123)
Message-Id: <35091a7e.2140537@news.tornado.be>
Nick Halloway <snowe@rain.org> wrote:
>What I need to do is to update a file that might have say 50,000 records,
>with new records occasionally. So it would be on disk, then either
>read in record-by-record, or all of it would be read into memory.
>
>By binary insertion,
>I mean a program that does something like this: Reads the file
>into memory, looks for the middle of the file, figures out whether the
>new record belongs above or below the middle of the file, looks for the
>middle of that half of the file, figures out where the record belongs
>relative to that middle, etc. If anyone has such a program, I'd
>appreciate hearing about it.
Poor guy. He's asking for a practical solution, and all he gets is
people throwing software theory at his head.
Anyway, here's my contyribution. I think that in practice, this will be
a hard one to beat. It does so by reducing the amount of file I/O to the
bare minimum.
I assume that you have a text file containing the records, and that each
record is one line (plus line end).
Then you need an index file. This is a binary file containing only
packed longs (4 byte integers). Each of these is an index, where in the
data file the associated record starts (seek value).
In my implementation, it's the INDEX file that gets sorted: a new record
is always APPENDED to the end of the data file. In laymen's terms: you
don't rewrite the book, you just add addenda, and rewrite the index.
In a database of 50000 records of about 40 bytes each (estimate), the
data file would be 2Mb, while the index file would be 200kb. That would
save you a factor of 10 in file I/O.
What I would do is:
* read the whole index file into memory
* do a binary search, with for each step:
+ retrieve the seek value for the current entry, seek in the data
file, and read in the record.
* append the new record to the data file, and insert the new seek value
into the index
* save the updated index to the index file.
Note that if you desperately need multiline records, that can be delt
with, by using another control character as your record delimiter, ex.
"\r". Set $/ accordingly. (Careful on Wintel boxes. Using binmode on the
datafile might do the trick.)
Assuming you're not starting from an empty database, here 's how you
could initialize it:
open(DATA,">records.txt");
open(INDEX,">records.idx"); binmode INDEX;
local $\ = $/; # usually "\n";
foreach (sort @data) {
my $seek = tell(DATA);
print DATA;
syswrite INDEX,pack("N",$seek),4;
}
So you start with a presorted dB.
Here's how to do a binary search and insertion:
open(DATA,"+<records.txt");
open(INDEX,"+<records.idx"); binmode INDEX;
$filelength = -s 'records.idx';
$records= sysread(INDEX, $index, $filelength)>>2;
# Find the largest power of two less than $records:
my $i = 1;
while(($i<<1)<$records) {
$i<<=1;
}
print STDERR "$records records, i = $i\n";
# now find the closest match equal or smaller than the new one:
my $j = 0;
while($i) {
my $ij = $i+$j; #for debugging
next if $i+$j >= $records;
my $seek = unpack("N",substr($index,($i+$j)<<2,4));
seek DATA,$seek,0;
chomp($record = <DATA>);
print STDERR "Testing record $ij, seek = $seek,
$record\n";
unless ($new lt $record) {
$j += $i;
last if $new eq $record;
}
} continue {
$i>>=1;
}
print STDERR "Match: $j -> $record\n";
local $\ = $/;
unless ($new eq $record) {
$j++ if $new gt $record;
print STDERR "Inserting record at $j\n";
seek DATA,0,2;
my $seek = tell DATA;
print DATA $new;
substr($index, $j<<2 , 4) = pack("N",$seek);
sysseek INDEX,0,0;
syswrite INDEX, $index, length $index;
} else {
print STDERR "Exact match\n";
}
Note that it contains some debugging aiding messages. Also note that
it's not thoroughly tested, but only superficially.
HTH,
Bart.
------------------------------
Date: Thu, 12 Mar 1998 18:18:30 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Speed of sort routine vs. one-by-one compare (123)
Message-Id: <350825d2.219150@news.tornado.be>
Well, damned, I've posted this just a few minutes ago, and I've tought
of a bufg already, and that is that the last record read is not
nbecessarily the record at the current $j position.
This can be fixed by either:
- repeating the seek/read combination for the last value, or
- leave the loop for $i=0 only AFTER this has been done.
The second approach would lead to:
my $j = 0;
while(1) {
my $ij = $i+$j; #for debugging
next if $i+$j >= $records;
my $seek = unpack("N",substr($index,($i+$j)<<2,4));
seek DATA,$seek,0;
chomp($record = <DATA>);
print STDERR "Testing record $ij, seek = $seek,
$record\n";
last if $i==0; # this is it!
unless ($new lt $record) {
$j += $i;
last if $new eq $record;
}
} continue {
$i>>=1;
}
Bart.
------------------------------
Date: 12 Mar 1998 18:02:53 GMT
From: michael@flash.net (Michael W Peterson)
Subject: Re: splice -- useful uses?
Message-Id: <6e980d$64$1@excalibur.flash.net>
[cc of this posting sent via email to avoid PSI.net]
On 12 Mar 1998 11:09:39 GMT, <abigail@fnx.com> wrote:
>[Cut & pasted from Dejanews, neither of Michaels articles arrived
> at my site. PSI.net continues to show to be by far the worst newsserver
> I've ever seen in the 10 years I've been around on Usenet. If you
> ever get the chance to use PSI.net as your newsfeed, think twice.]
>
>
>Michael W Peterson wrote:
>
>++ On 12 Mar 1998 02:12:40 GMT, <tchrist@mox.perl.com> wrote:
>++ > [courtesy cc of this posting sent to cited authors via email]
>++ >
>++ >certainly have a situation where a quadratic algorithm (with low overhead)
>++ >can beat a linear one (with high overhead). That's what's going on
>++ >here -- in the tiny cases, the more native way wins. But keep doubling
>++ >your data size and you'll see what I mean. Hers eventually pulls ahead,
>++ >as it inevitably must.
>++
>++ But, as it appears from my results, not because the linear is faster.
>++ The native quadratic algorithm continues be optimized to run faster, at
>++ the cost of huge memory usage. The quadratic version slows down as the OS
>++ thrashes about more and more trying to satisfy the ever-increasing memory
>++ demands.
>
>You are not making any sense at all here.
But I have data to support my nonsense. ;)
>++ >Using just 10,000 iterations so things can get done in my lifetime,
>++ >at $N == 32, here's what happened:
>++ >
>++ > Benchmark: timing 10000 iterations of c, perl...
>++ > c: 55 secs (54.59 usr 0.00 sys = 54.59 cpu)
>++ > perl: 70 secs (41.60 usr 2.67 sys = 44.27 cpu)
>++ >
>++
>++ When I ran it on my workstation, I got 'Out of Memory!' errors on the
>++ quadratic algorithm at $N == 32. Bells went off at this point, so I threw
>++ it on a bigger box where I could watch it easier and got the following:
>
>Eh? Something must be majorly wrong. (0 .. 9) x 32 is only an array
>of 320 elements. Knuths algorithm is in situ; only needs constant
>memory more, and the splice() variant needs linear extra storage.
>
>I ran the algorithms with 50000 elements, in just over 7 Mb.
I was able to get the test code in your other post to run as expected.
>++ Memory stays at 68M while 'c' runs again and then grows to 234M while
>++ 'perl' runs again.
>
>For 640 elements? *boggle*
Crazy stuff. I'll have to poke at our two code samples and see where mine
is breaking down. They're substantially the same; maybe I've got a bit in
mine that Benchmark is tripping over. *shrug*
--
Michael W Peterson <http://www.flash.net/~michael/>
Chief System Administrator FlashNet Communications
Unix: more than enough rope...
------------------------------
Date: 12 Mar 1998 17:56:06 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: You have 1 message(s) - how to print plurals?
Message-Id: <6e97jm$1th$1@marina.cinenet.net>
Dave Bushong (spamfree@yahoo.com) wrote:
: I have a pet peeve about having a ten thousand dollar computer telling
: me "1 file(s) copied", when it's a matter of checking whether or not the
: count is one. In 'C', there is usually something in the printf that
: uses the ternary operator, e.g., prinf ("%d file%s\n", count,
: count==1?"":"s");
:
: That works if you know that you will be using the word "file", for
: example, but is not a general solution. I looked for a "pluralize"
: function in the Text modules (#11), but not exhaustively.
Common Lisp has some really nice support for this sort of thing...but
Perl doesn't, that I know of. Might make a nice CPAN module, if you want
to do that.
: I came up with this, and would like comments about my implementation.
: Specifically, it seems a little clumsy to say
:
: print ("I have ", pluralize($quantity, $nouns), "\n");
:
: but I can't think of a more elegant way.
Unfortunately, that seems the best way.
: Here is the code; please followup here, and/or to my email address (yes,
: it's really spamfree@yahoo.com). I hope my cut and paste worked.....
:
: ################### first line in source file
: %endings = qw(
: loaf loaves
[snip]
: appendix appendices
: );
I might suggest putting this mapping into an external data file which is
slurped into the hash at runtime. That way you can add mappings without
editing program source, which is safer.
: # add singular and plural forms there
: # that are different from predictable
: # formats
:
: sub pluralize
: {
: my ($quan, $word) = @_;
: my ($pluralform, $lastletter, $lastletters);
Stylistically, I prefer defining 'my' variables at the point they're
needed/initialized, rather than in a C-ish top-of-func group. This is
purely an esthetic issue, of course.
: return ("1 " . $word) if $quan == 1;
Why not interpolate? return "1 $word" if $quan == 1;
: return ($quan . ' ' . $word . '\'s') if $word =~ /\d+/;
Not sure what you're after here -- why is a word containing any numerals
a special case? However, leaving that aside, you can again interpolate
for brevity: return "$quan ${word}s" if $word =~ /\d+/;
: if($endings{$word}) {
'exists $endings{$word}' is prefered, but should work identically in your
case.
: $pluralform = $endings{$word};
: } else {
: $lastletter = substr($word, -1);
: $penultimateletter = substr($word, -2, 1);
: if(($lastletter eq 's')||($lastletter eq 'x') ||
: (($lastletter eq 'h') && ($penultimateletter =~
: /[cs]/))) {
Equivalent test: $word =~ /(?:[xs]|[cs]h)$/
: $pluralform = $word . "es";
Or: $pluralform = "${word}es";
: } elsif(($lastletter eq 'y') && ($penultimateletter =~
: /[^aeiou]/)) {
Equivalent test: $word =~ /[^aeiou]y$/
: $pluralform = $word;
: substr($pluralform, -1) = "ies";
Equivalent transformation: $word =~ s/y$/ies/;
: } else {
: $pluralform = $word . 's';
Or: $pluralform = "${word}s";
: }
: }
: return ($quan . " " . $pluralform);
Or: return "$quan $pluralform";
: }
Hope this helps!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 12 Mar 1998 11:38:22 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: You have 1 message(s) - how to print plurals?
Message-Id: <35081D8E.3F2C9029@gpu.srv.ualberta.ca>
Dave Bushong wrote:
>
> I have a pet peeve about having a ten thousand dollar computer telling
> me "1 file(s) copied", when it's a matter of checking whether or not the
> count is one. In 'C', there is usually something in the printf that
> uses the ternary operator, e.g., prinf ("%d file%s\n", count,
> count==1?"":"s");
>
> That works if you know that you will be using the word "file", for
> example, but is not a general solution. I looked for a "pluralize"
> function in the Text modules (#11), but not exhaustively.
what's the matter with using printf() in perl and passing the
noun as well?
$noun='idea';
$quantity=1;
printf("I have %d %s%s\n",$quantity,$noun,$quantity==1?'':'s');
regards
andrew
------------------------------
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 2084
**************************************