[13833] in Perl-Users-Digest
Perl-Users Digest, Issue: 1243 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 1 12:10:38 1999
Date: Mon, 1 Nov 1999 09:10:16 -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: <941476215-v9-i1243@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 1 Nov 1999 Volume: 9 Number: 1243
Today's topics:
New Modules: Conversion of C-structs to Perl <rhomberg@ife.ee.ethz.ch>
Re: New Modules: Conversion of C-structs to Perl <vantrinh@lucent.com>
New posters to comp.lang.perl.misc <gbacon@cs.uah.edu>
Non-ASCII report output <dthomson@zack.fammed.wisc.edu>
Re: Perl4 and Y2K (Kragen Sitaker)
Re: Perl4 and Y2K (Randal L. Schwartz)
Please Perl, do what I ask !! <ralawrence@my-deja.com>
Problems with mirror 2.9 on NT ( wrong date, and permis <Martin.Pfeilsticker@Informatik.Uni-Oldenburg.DE>
reading the DATA filehandle in a loop (Eric Smith)
Re: reading the DATA filehandle in a loop (Randal L. Schwartz)
Re: Reinventing the wheel <csaba.raduly@sophos.com>
Re: Reinventing the wheel <david.laneNOdaSPAM@mantech.com.invalid>
Re: sendmail question <js@saltmine.radix.net>
Re: sendmail question <_ncc1701d@storage2000.com_>
Statistics for comp.lang.perl.misc <gbacon@cs.uah.edu>
Re: Stored procedure with parameters. mpeppler@mbay.net
Survey form, return multiple checkboxes sleepernyc@my-deja.com
Re: Survey form, return multiple checkboxes <lr@hpl.hp.com>
Thanks and Follow-up (was: RFC: Making array using rang lou@visca.com
Thanks and Follow-up (was: RFC: Making array using rang lou@visca.com
Re: Thanks and Follow-up (was: RFC: Making array using <lr@hpl.hp.com>
Re: Thanks and Follow-up (was: RFC: Making array using <uri@sysarch.com>
Re: What makes the web go? mpeppler@mbay.net
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 01 Nov 1999 12:49:26 +0100
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: New Modules: Conversion of C-structs to Perl
Message-Id: <381D7E46.42C37F29@ife.ee.ethz.ch>
Hi
I did not find any documented method to convert a C/C++ struct to Perl.
I therefore wrote something of my own. Here is the pod I came up with so
far.
What should I do with it?
- Alex
=head1 NAME
B<C_To_SV> - generate functions that convert C-structs to Perl
structures
=head1 SYNOPSIS
use Mytest;
$C_conversion_function = gen_C_To_SV(name1=>\@desc1, name2=>\@desc2);
$header = header();
$stub = c_entry_stub();
=head1 ABSTRACT
The lone function in this module generates a C++ function that can
convert C-structures into complex perl data structures.
=head1 DESCRIPTION
Given a description of a C structure in Perl, B<gen_C_To_SV> returns a
C++ function which generates recursively a complex perl data structure
containing the same data as the original structure.
The Perl-description of a C struct is an array containing the
description of the struct fields that should be converted. The
description of struct fields is a ref to a hash:
$fielddesc = {name => 'name',
array=>[arraydesc],
access => 'access'};
=head2 Possible Keys
=over 4
=item B<name> (mandatory)
The name that will be used as hash key to store the data of this
struct member
=item B<array> (optional)
Gives the dimensions of the array that this member points to. This can
be any C-code that will evaluate to an integer at runtime. The B<self>
variable will hold the structure, so its members can be used to
determine the size of the array.
=item B<access> (optional)
Give some C code to access the data here. Default is "self.<name>".
This is usefull to enter methods that retrieve data. The B<self>
variable holds the currently processed structure.
=back
No type information is needed. The C++ compiler does that with
overloading.
=head2 EXAMPLE
An example C++ struct:
struct exa1 {
char *s1; /* generic type */
double d1[4][2]; /* two dimensional double array */
struct exa1 *next; /* beware of recursion */
struct exa1 **peers; /* an array of struct pointers */
int num_peers; /* the size of above array */
myclass *obj; /* class with special access function */
}
is used with the following descriptor, each of which is explained
below.
@exa1 = (
{name => 's1'},
{name => 'd1', array =>[4,2]},
{name => 'next'},
{name => 'peers', array => [self.num_peers]},
# {name => 'num_peers'} omitted, information is in peers
{name => 'obj'}
);
@myclass = (
{name => 'perlname', access => 'self.data()'}
);
=over 4
=item B<s1>
This calls one of the generic conversion functions which exist for
char*, double and int.
=item B<d1>
This converts a two dimensional array. The array dimensions are given
in the B<array> key.
=item B<next>
A pointer to a similar structure. This will call the conversion
function recursively. If an already converted structure is encountered
(like in a circular buffer), an additional reference to the already
translated entity will be inserted.
=item B<peers>
An array of similar structures. The dimensions are given in the
structure member B<num_peers> which is accessed through B<self>.
=item B<num_peers>
This is needed for C to know how many peers there are. In Perl, array
sizes can be determined easily, so this is not converted (but could
be).
=item B<obj>
a class that needs a special conversion function
=item B<perlname>
Use the data() method to get at the data of this class.
=back
The B<standard.cc> that must be included provides conversion functions
for generic data types and for an recursive templates for arrays of
any dimension.
Non-array pointers (of any depth) are handled like embedded
structures. An embedded structure is represented by a ref to that
structure, and so is a pointer (and a pointer to a pointer).
If a class is convoluted enough, no conversion function can be
generated. In this case take the generated code as an example on how
to write a conversion function.
=head1 POINTERS CAVEAT
With this method, the (rare) pointer to array cannot be converted. If
you have a deep pointer and less array sizes, the arrays are applied
first and and the remaining pointers are omitted. Example
int **ddpointer; with description C<{name => ddpointer, array => [3]}>
is interpreted as an array of 3 pointers to integer. these integers
are dereferenced automatically, so I'll get a ref of an array
containing the three ints directly.
If I want to access it as a pointer to an array of 3 integers (say 1,
4 and 7), I have to give an additional array size of one: C<{name =>
ddpointer, array =>[1,3]}>. I will then get a an array ref containing
one arrayref containing the data as reqested C<[[1,4,7]]>
=head1 OUTLOOK
One could write a simple parses that looks for structures in
preprocessor output (e.g. gcc -E) and generetas the descriptors. This
could only handle simple name=> only stuff, for special access
functions and arrays, a hand written description is still necessary.
=head1 AUTHOR
A. Rhomberg, alex.rhomberg@schweiz.org
=head1 SEE ALSO
Look at the generated code and at standard.cc.
=cut
------------------------------
Date: 01 Nov 1999 07:48:12 -0800
From: Vtrinh <vantrinh@lucent.com>
Subject: Re: New Modules: Conversion of C-structs to Perl
Message-Id: <uzowydxhf.fsf@lucent.com>
Alex Rhomberg <rhomberg@ife.ee.ethz.ch> writes:
> Hi
>
> I did not find any documented method to convert a C/C++ struct to Perl.
> I therefore wrote something of my own. Here is the pod I came up with so
> far.
>
> What should I do with it?
>.....
I'm curious whether your module would take care of the internal padding
behavior by a C-compiler? It's not clear to me when i read your pod. Thanks.
....
------------------------------
Date: 1 Nov 1999 15:08:41 GMT
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: New posters to comp.lang.perl.misc
Message-Id: <7vkadp$3pa$2@info2.uah.edu>
Following is a summary of articles from new posters spanning a 7 day
period, beginning at 25 Oct 1999 16:02:24 GMT and ending at
01 Nov 1999 08:00:18 GMT.
Notes
=====
- A line in the body of a post is considered to be original if it
does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
- All text after the last cut line (/^-- $/) in the body is
considered to be the author's signature.
- The scanner prefers the Reply-To: header over the From: header
in determining the "real" email address and name.
- Original Content Rating (OCR) is the ratio of the original content
volume to the total body volume.
- Find the News-Scan distribution on the CPAN!
<URL:http://www.perl.com/CPAN/modules/by-module/News/>
- Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
- Copyright (c) 1999 Greg Bacon.
Verbatim copying and redistribution is permitted without royalty;
alteration is not permitted. Redistribution and/or use for any
commercial purpose is prohibited.
Totals
======
Posters: 184 (37.9% of all posters)
Articles: 281 (17.4% of all articles)
Volume generated: 466.5 kb (15.9% of total volume)
- headers: 210.7 kb (4,349 lines)
- bodies: 253.2 kb (8,653 lines)
- original: 198.3 kb (7,052 lines)
- signatures: 2.3 kb (53 lines)
Original Content Rating: 0.783
Averages
========
Posts per poster: 1.5
median: 1.0 post
mode: 1 post - 131 posters
s: 1.3 posts
Message size: 1700.0 bytes
- header: 768.0 bytes (15.5 lines)
- body: 922.8 bytes (30.8 lines)
- original: 722.6 bytes (25.1 lines)
- signature: 8.3 bytes (0.2 lines)
Top 10 Posters by Number of Posts
=================================
(kb) (kb) (kb) (kb)
Posts Volume ( hdr/ body/ orig) Address
----- -------------------------- -------
7 8.2 ( 4.7/ 3.6/ 3.4) * Tong * <sun_tong@geocities.com>
6 7.2 ( 5.0/ 2.1/ 1.7) oneill78 <oneillNOonSPAM@cs.uregina.ca.invalid>
6 9.5 ( 5.0/ 4.5/ 4.0) jgivensXX@adelphiaXX.netXX (Jeff Givens)
5 10.1 ( 3.9/ 6.2/ 2.5) andersjk@sol-invictus.org (kevin anderson)
5 11.5 ( 4.8/ 6.7/ 4.1) jmonroe.easystreet@com.spam.sucks.my.ass.com (Jon)
4 7.0 ( 3.2/ 3.8/ 1.5) greg@mccarroll.demon.co.uk
4 10.1 ( 3.3/ 6.7/ 5.5) "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
4 10.0 ( 3.5/ 6.5/ 2.7) jkuhnert@bellatlantic.net
4 7.4 ( 2.8/ 4.6/ 3.1) richardstands@my-deja.com
4 5.9 ( 3.6/ 2.3/ 1.3) "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
These posters accounted for 3.0% of all articles.
Top 10 Posters by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Address
-------------------------- ----- -------
24.2 ( 1.7/ 22.5/ 22.1) 2 scottlm@visi.com
13.7 ( 3.0/ 9.8/ 6.9) 4 dfoster@panix.com (David Foster)
11.5 ( 0.9/ 10.7/ 10.3) 1 Paone <Paone@mediaone.net>
11.5 ( 4.8/ 6.7/ 4.1) 5 jmonroe.easystreet@com.spam.sucks.my.ass.com (Jon)
10.1 ( 3.9/ 6.2/ 2.5) 5 andersjk@sol-invictus.org (kevin anderson)
10.1 ( 3.3/ 6.7/ 5.5) 4 "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
10.0 ( 3.5/ 6.5/ 2.7) 4 jkuhnert@bellatlantic.net
10.0 ( 3.1/ 6.8/ 2.7) 4 "Jason D" <_ncc1701d@storage2000.com_>
9.5 ( 5.0/ 4.5/ 4.0) 6 jgivensXX@adelphiaXX.netXX (Jeff Givens)
9.2 ( 1.1/ 8.0/ 8.0) 2 moya <moya@dreamhouse.co.kr>
These posters accounted for 4.1% of the total volume.
Top 10 Posters by OCR (minimum of three posts)
==============================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
1.000 ( 2.1 / 2.1) 3 adm@ipat.com (Alan Mead)
0.974 ( 4.9 / 5.1) 3 blakem@world.std.com (Blake Meike)
0.947 ( 3.4 / 3.6) 7 * Tong * <sun_tong@geocities.com>
0.947 ( 0.7 / 0.7) 3 "Joachim Pimiskern" <Joachim.Pimiskern@de.bosch.com>
0.882 ( 4.0 / 4.5) 6 jgivensXX@adelphiaXX.netXX (Jeff Givens)
0.827 ( 5.5 / 6.7) 4 "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
0.816 ( 3.3 / 4.1) 4 Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
0.802 ( 2.3 / 2.9) 3 mr_geek <shon@mad.scientist.com>
0.778 ( 1.7 / 2.1) 6 oneill78 <oneillNOonSPAM@cs.uregina.ca.invalid>
0.750 ( 1.3 / 1.8) 4 "XeoN" <xeon@g-em.com>
Bottom 10 Posters by OCR (minimum of three posts)
=================================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.705 ( 6.9 / 9.8) 4 dfoster@panix.com (David Foster)
0.680 ( 3.1 / 4.6) 4 richardstands@my-deja.com
0.650 ( 1.3 / 2.0) 3 "Jon Frisby" <jfrisby@NOSPAM.megapathdsl.net>
0.608 ( 4.1 / 6.7) 5 jmonroe.easystreet@com.spam.sucks.my.ass.com (Jon)
0.550 ( 0.4 / 0.8) 3 Ralf Beckers <bexxx@hasiland.com>
0.548 ( 1.3 / 2.3) 4 "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
0.409 ( 2.5 / 6.2) 5 andersjk@sol-invictus.org (kevin anderson)
0.409 ( 2.7 / 6.5) 4 jkuhnert@bellatlantic.net
0.402 ( 1.5 / 3.8) 4 greg@mccarroll.demon.co.uk
0.396 ( 2.7 / 6.8) 4 "Jason D" <_ncc1701d@storage2000.com_>
21 posters (11%) had at least three posts.
Top 10 Crossposters
===================
Articles Address
-------- -------
6 Alla Gribov <alla.gribov@metatel.com>
5 "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
4 "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
3 andreyNOSPAM@bookexchange.net
3 mpthompson@home.net
2 Darin McGrew <mcgrew@stanfordalumni.org>
2 "Ryan" <ryan_richards_2000[NOSPAM]@yahoo.com>
2 nobody@this.location (Nobody)
2 Paone <Paone@mediaone.net>
2 Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
------------------------------
Date: 01 Nov 1999 10:03:05 -0600
From: Don Thomson <dthomson@zack.fammed.wisc.edu>
Subject: Non-ASCII report output
Message-Id: <m3aeoyci86.fsf@zack.fammed.wisc.edu>
I'm in the process of replacing a Microsoft Access application with a
Perl script running on a UNIX box. The end users are used to report
output that looks a bit fancier than the plain ASCII output that I
already know how to produce. Any suggestions for modules that would
allow me to produce graphical lines/boxes/etc. while writing a report?
Thanks....
--
----- Don Thomson -------------------- Department of Family Medicine -----
dthomson@fammed.wisc.edu 265-0589 777 S. Mills Street Madison, WI 53715
------------------------------
Date: Mon, 01 Nov 1999 14:43:52 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Perl4 and Y2K
Message-Id: <IGhT3.16278$23.910997@typ11.nn.bcandid.com>
In article <m1iu3mwtcg.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Kragen" == Kragen Sitaker <kragen@dnaco.net> writes:
>
>Kragen> But what's wrong with Perl4 Y2K-wise?
>
>See Deja for "perl4" and "y2k" posted by me.
>
>Hint: the warning I posted has two meanings. You may have misread it.
>That's deliberately so. :)
I just did see Deja for perl4 and y2k posted by you, and found two
postings -- the ones in this thread. Searching for just y2k posted by
you yields lots of stuff, but nothing interesting, except an earlier
statement of your perl4 warning and some referrals to the FAQ.
It almost looks as if you're deliberately trying to mislead people into
thinking perl4 has Y2K bugs in it so they will upgrade, but I can't
imagine you'd stoop to that kind of manipulative dishonesty.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 01 Nov 1999 08:26:01 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Perl4 and Y2K
Message-Id: <m1u2n6uqjq.fsf@halfdome.holdit.com>
>>>>> "Kragen" == Kragen Sitaker <kragen@dnaco.net> writes:
Kragen> I just did see Deja for perl4 and y2k posted by you, and found two
Kragen> postings -- the ones in this thread. Searching for just y2k posted by
Kragen> you yields lots of stuff, but nothing interesting, except an earlier
Kragen> statement of your perl4 warning and some referrals to the FAQ.
You have to search "older postings". This was last year and the year
before.
Kragen> It almost looks as if you're deliberately trying to mislead people into
Kragen> thinking perl4 has Y2K bugs in it so they will upgrade, but I can't
Kragen> imagine you'd stoop to that kind of manipulative dishonesty.
You must read the sentence carefully. Why would someone have
"no plans" to fix y2k problems in Perl4? Do I need to spell it out?
And I didn't come up with that particular gem. I don't recall who did.
It's just a meme, and here's a sample explanation:
http://www.deja.com/getdoc.xp?AN=333749071
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 01 Nov 1999 15:47:14 GMT
From: Richard Lawrence <ralawrence@my-deja.com>
Subject: Please Perl, do what I ask !!
Message-Id: <7vkcm0$5ne$1@nnrp1.deja.com>
Hello all!
I seem to have a few problems with perl and with it not doing what I
want it to do. Could someone please put me back on the right track?
Firstly I'm trying to open an ftp connection with the following:
sub connect_to_ftp_site
{
my ($result, $ftp);
# attempt to connect
$ftp = Net::FTP->new($_[0], Timeout => 10, Port => $_[1]);
return 0 if (!$ftp);
As you can see the timeout value is set to 10. However the line
actually timeouts after 2 minutes (which according to the man page is
the default). So as far as I can see, its ignoring my value totally.
Can anyone give me swift kick and point me to what I'm doing wrong?
Secondly I have some code like this (please excuse the horrible perl -
i am only just learning):
eval
{
local $SIG{ALRM} = sub { die "timeout\n" };
alarm 10;
my $browser = LWP::UserAgent->new();
my $webdoc = $browser->request(HTTP::Request->new(GET => $wanted));
if ($webdoc->is_success && $webdoc->content_type eq 'text/html')
{
my $webbase = $webdoc->base;
foreach (HTML::LinkExtor->new->parse($webdoc->content)->eof-
>links)
{
my ($webtag, %weblinks) = @$_;
next unless $webtag eq "a";
my $weblink;
foreach $weblink (values %weblinks)
{
$field = url($weblink, $webbase)->abs->as_string;
$field =~ tr/+/ /;
$field =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if ($field =~ m%(ftp://.+\.mp3)%)
{
if (instring($1)) # does this match our search?
{
$real_url = $1;
$real_url =~ tr/+/ /;
$real_url =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex
($1))/eg;
push (@urls, $real_url);
$added++;
}
}
}
}
}
alarm(0);
};
if ($@)
{
die unless $@ eq "timeout\n";
print "alarm called!\n";
$added = 0;
}
The internals are working fine (if not written particulary well), what
isn't however is the alarm (lifted straight from the perldoc). It just
doesn't trigger at all, even if I set the value to something stupid
like 2 seconds.
Can anyone shed any light on these please?
Thanks
Rich
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 1 Nov 1999 13:02:31 GMT
From: "Martin Pfeilsticker" <Martin.Pfeilsticker@Informatik.Uni-Oldenburg.DE>
Subject: Problems with mirror 2.9 on NT ( wrong date, and permissions)
Message-Id: <7vk317$ht3@news.Informatik.Uni-Oldenburg.DE>
Hello all!
I have problems with mirroring a ftp-server with perl.
I'm using mirror 2.9 on Windows NT 4.0 SP 5 with Active Perl 519.
Remote Server is Windows NT with IIS.
Everything is working fine, I only have one problem:
Neither the file-permissions nor the date is transmitted correctly, ie the
ftp-ed file has the current date of the transfer and new permissions.
This is bad for me, since we are mirroring in both directions, so every
file is transfered with every run of mirror. I can work around the
permission-bits with fixed mask but not the date problem.
Does anybody has any idea or better a fix ?
regards
Martin Pfeilsticker
--
-----------------------------------------------------------------------------
| Martin.Pfeilsticker@arbi.informatik.uni-oldenburg.de |
| In god we trust, all other pay cash |
----------------------------------------------------------------------------
------------------------------
Date: 1 Nov 1999 12:10:14 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: reading the DATA filehandle in a loop
Message-Id: <slrn81r0p5.lr2.eric@plum.fruitcom.com>
Here is the code ..
#!/usr/bin/perl -w
$sleeptime = 3;
chdir "/d/e/lz/";
while (){
print "\nI woke and did ..\n";
#open DATA; #bitches when uncomemnted if DATA file handle else not
while (<DATA>){
print "entered while (<DATA>)";
print;
}
sleep $sleeptime;
}
__END__
#dir,fileid,pumkinholder,comment
lz,,,Landing Zone
palmast,Palmast,leon,
report,Report,johann,
createb,CreateBase,leon, sql Create Scripts
createu,CreateUpdate,leon, sql Update Scripts
sqo,SQO,Other sql scripts
Here is the problem ..
The DATA is read only once i.e. during the first iteration of the while
and never again. The same happens if you use a conventional filehandle
that reads a disk file like /etc/passwd. But in the latter case one may
put the open FILHANDLE just above the while (<FILHANDLE>) and voila it
works as required. Try that with the DATA special filehandle and it
complains of a read on a closed filehandle.
What to do ?
--
Eric Smith
eric@fruitcom.com
www.fruitcom.com
Press every key to continue.
------------------------------
Date: 01 Nov 1999 08:28:59 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: reading the DATA filehandle in a loop
Message-Id: <m1n1syuqes.fsf@halfdome.holdit.com>
>>>>> "Eric" == Eric Smith <eric@fruitcom.com> writes:
Eric> The DATA is read only once i.e. during the first iteration of the while
Eric> and never again. The same happens if you use a conventional filehandle
Eric> that reads a disk file like /etc/passwd. But in the latter case one may
Eric> put the open FILHANDLE just above the while (<FILHANDLE>) and voila it
Eric> works as required. Try that with the DATA special filehandle and it
Eric> complains of a read on a closed filehandle.
You need to save and restore the fileposition:
while () {
$where = tell DATA;
while (<DATA>) {
## process $_
}
seek DATA, $where, 0;
}
__END__
data, goes, here
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 01 Nov 1999 10:45:34 +0000
From: Csaba Raduly <csaba.raduly@sophos.com>
Subject: Re: Reinventing the wheel
Message-Id: <381D6F4E.C9932FDD@sophos.com>
"david.lane@mantech.com" wrote:
>
> Greetings,
>
> I suspect someone out there has already done this and can help me out.
>
> I am trying to take a directory output (from NetWare's NDIR command) and
> transpose it so that I can shove it into a database. Once I get it
> transposed, I can easily upload it. The problem is getting it
> transposed.
>
> What I have is this:
>
> CORP_02/SHARES:SPC\PROJECTS\MARKETI0\NUTRIVIL\*.*
> Files Size Last Update Owner
> ----------------- ------------- ---------------
> -------------------------
> MANUAL6.DOC o 477,696 4/03/98 12:04p
> MScott.Alexandria.ISDN...
> NUORDERF.DOC o 12,288 3/17/98 10:53a
> MScott.Alexandria.ISDN...
> MANUAL.DOC o 484,864 4/03/98 12:05p
> MScott.Alexandria.ISDN...
> NUTACTIV.DOC 527,360 2/26/98 8:49a
> MScott.Alexandria.ISDN...
>
> What I want to get rid of is the formating crap (Files, size and the
> underline) between the directory name and the files. I also want to
> tack on the directory name to the files listing so that in general I
> have:
>
> file, size, date, user, directory
>
> I can get as far as the regex to pull out the directory name and put
> that in a variable for appending, but I cannot skip or get rid of the
> next two lines. With 500 pages of this stuff to sort through, I really
> want to do this in an automated fashion.
>
Since the format is fixed, this _should_ be easy.
Process the dirname and the two superfluous lines OUTSIDE the loop.
$directory = <>;
$directory =~ s/(.*)\\\*\.\*$/$1/; # try to lose the *.* at the end
$_=<>; # lose the header
$_=<>; # lose the lines
while(<>)
{
... do whatever necessary
}
WARNING ! This is completely untested.
Csaba
--
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/>GMU d- s:- a30 C++$ UL+ P+>+++ L++ E- W+ N++ o? K? w++>$ O++$ M-
V- PS PE Y PGP- t+ 5 X++ R* tv++ b++ DI+++ D++ G- e+++ h-- r-- !y+
-----END GEEK CODE BLOCK-----
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com http://www.sophos.com/
US Support +1 888 SOPHOS 9 UK Support +44 1235 559933
Life is complex, with real and imaginary parts.
------------------------------
Date: Mon, 01 Nov 1999 04:37:49 -0800
From: david.lane@mantech.com <david.laneNOdaSPAM@mantech.com.invalid>
Subject: Re: Reinventing the wheel
Message-Id: <11f733ec.227103e0@usw-ex0101-002.remarq.com>
Thanks for the pointers. I was actually quite simple once I figured
out how to do NOT statements in my IF loops when searching on the regex.
DAVID
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Mon, 1 Nov 1999 09:26:56 -0500
From: John Schmidt <js@saltmine.radix.net>
Subject: Re: sendmail question
Message-Id: <Pine.SV4.3.96.991101092151.17853A-100000@saltmine.radix.net>
On Mon, 1 Nov 1999, Kragen Sitaker wrote:
> But I'm perfectly mystified by the actual problem. Is it possible the
> subject and from headers are actually blank, so sendmail makes the from
> say 'nobody'?
Dunno about the problem with the "Subject: " header, but the "From: "
being changed makes it look as if the script is being run from CGI,
with httpd running as user nobody. Check the full headers of a
message that is sent with the wierdness.
A couple of other things to check: make sure that sendmail is
setuid root, and see if the problem continues if you use the
-oi -t as flags to sendmail instead of just -t.
JS
------------------------------
Date: Mon, 1 Nov 1999 09:48:27 -0600
From: "Jason D" <_ncc1701d@storage2000.com_>
Subject: Re: sendmail question
Message-Id: <sEiT3.1815$bi6.1200@news2.randori.com>
The otherway that your could do this would be to use the mail command Unix..
(This is off the top of my head)
$x="$content|mail $email -s Subject";
system($x);
If you run it as the user you want the mail sent from then mail should take
care of the rest. Although I'm sure you can specify who the mail is from in
the command line. Use the proper technique to capture return errors if that
is needed.
Jason
John Schmidt <js@saltmine.radix.net> wrote in message
news:Pine.SV4.3.96.991101092151.17853A-100000@saltmine.radix.net...
>
> On Mon, 1 Nov 1999, Kragen Sitaker wrote:
>
> > But I'm perfectly mystified by the actual problem. Is it possible the
> > subject and from headers are actually blank, so sendmail makes the from
> > say 'nobody'?
>
> Dunno about the problem with the "Subject: " header, but the "From: "
> being changed makes it look as if the script is being run from CGI,
> with httpd running as user nobody. Check the full headers of a
> message that is sent with the wierdness.
>
> A couple of other things to check: make sure that sendmail is
> setuid root, and see if the problem continues if you use the
> -oi -t as flags to sendmail instead of just -t.
>
> JS
>
------------------------------
Date: 1 Nov 1999 15:08:41 GMT
From: Greg Bacon <gbacon@cs.uah.edu>
Subject: Statistics for comp.lang.perl.misc
Message-Id: <7vkadp$3pa$1@info2.uah.edu>
Following is a summary of articles spanning a 7 day period,
beginning at 25 Oct 1999 16:02:24 GMT and ending at
01 Nov 1999 08:00:18 GMT.
Notes
=====
- A line in the body of a post is considered to be original if it
does *not* match the regular expression /^\s{0,3}(?:>|:|\S+>|\+\+)/.
- All text after the last cut line (/^-- $/) in the body is
considered to be the author's signature.
- The scanner prefers the Reply-To: header over the From: header
in determining the "real" email address and name.
- Original Content Rating (OCR) is the ratio of the original content
volume to the total body volume.
- Find the News-Scan distribution on the CPAN!
<URL:http://www.perl.com/CPAN/modules/by-module/News/>
- Please send all comments to Greg Bacon <gbacon@cs.uah.edu>.
- Copyright (c) 1999 Greg Bacon.
Verbatim copying and redistribution is permitted without royalty;
alteration is not permitted. Redistribution and/or use for any
commercial purpose is prohibited.
Excluded Posters
================
perlfaq-suggestions\@(?:.*\.)?perl\.com
Totals
======
Posters: 485
Articles: 1612 (772 with cutlined signatures)
Threads: 453
Volume generated: 2937.3 kb
- headers: 1253.4 kb (25,029 lines)
- bodies: 1549.8 kb (49,492 lines)
- original: 1085.9 kb (37,083 lines)
- signatures: 132.5 kb (2,866 lines)
Original Content Rating: 0.701
Averages
========
Posts per poster: 3.3
median: 1 post
mode: 1 post - 277 posters
s: 8.6 posts
Posts per thread: 3.6
median: 2 posts
mode: 1 post - 134 threads
s: 4.8 posts
Message size: 1865.9 bytes
- header: 796.2 bytes (15.5 lines)
- body: 984.5 bytes (30.7 lines)
- original: 689.8 bytes (23.0 lines)
- signature: 84.2 bytes (1.8 lines)
Top 10 Posters by Number of Posts
=================================
(kb) (kb) (kb) (kb)
Posts Volume ( hdr/ body/ orig) Address
----- -------------------------- -------
95 157.4 ( 71.0/ 75.2/ 36.7) Jonathan Stowe <gellyfish@gellyfish.com>
86 210.7 ( 95.9/ 78.3/ 73.2) abigail@delanet.com
74 125.6 ( 47.5/ 69.7/ 40.1) Larry Rosler <lr@hpl.hp.com>
66 109.7 ( 63.7/ 38.1/ 23.2) Tom Phoenix <rootbeer@redcat.com>
49 87.6 ( 39.9/ 42.0/ 22.1) David Cassell <cassell@mail.cor.epa.gov>
33 75.4 ( 25.2/ 43.8/ 29.2) mgjv@comdyn.com.au
31 53.8 ( 18.1/ 35.7/ 22.3) tadmc@metronet.com (Tad McClellan)
22 31.6 ( 18.5/ 12.9/ 7.7) bart.lateur@skynet.be (Bart Lateur)
22 30.4 ( 13.6/ 16.8/ 8.4) mjtg@cus.cam.ac.uk (M.J.T. Guy)
22 34.4 ( 14.2/ 15.7/ 9.9) cberry@cinenet.net (Craig Berry)
These posters accounted for 31.0% of all articles.
Top 10 Posters by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Address
-------------------------- ----- -------
210.7 ( 95.9/ 78.3/ 73.2) 86 abigail@delanet.com
157.4 ( 71.0/ 75.2/ 36.7) 95 Jonathan Stowe <gellyfish@gellyfish.com>
149.3 ( 5.8/142.4/141.9) 8 tchrist@mox.perl.com (Tom Christiansen)
125.6 ( 47.5/ 69.7/ 40.1) 74 Larry Rosler <lr@hpl.hp.com>
109.7 ( 63.7/ 38.1/ 23.2) 66 Tom Phoenix <rootbeer@redcat.com>
87.6 ( 39.9/ 42.0/ 22.1) 49 David Cassell <cassell@mail.cor.epa.gov>
75.4 ( 25.2/ 43.8/ 29.2) 33 mgjv@comdyn.com.au
53.8 ( 18.1/ 35.7/ 22.3) 31 tadmc@metronet.com (Tad McClellan)
40.6 ( 15.0/ 21.5/ 13.6) 20 kragen@dnaco.net (Kragen Sitaker)
36.5 ( 13.5/ 19.9/ 11.1) 15 lee.lindley@bigfoot.com
These posters accounted for 35.6% of the total volume.
Top 10 Posters by OCR (minimum of five posts)
==============================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.997 (141.9 /142.4) 8 tchrist@mox.perl.com (Tom Christiansen)
0.947 ( 3.4 / 3.6) 7 * Tong * <sun_tong@geocities.com>
0.935 ( 73.2 / 78.3) 86 abigail@delanet.com
0.911 ( 18.5 / 20.3) 11 Greg Bacon <gbacon@cs.uah.edu>
0.882 ( 4.0 / 4.5) 6 jgivensXX@adelphiaXX.netXX (Jeff Givens)
0.817 ( 7.3 / 9.0) 8 cpierce1@ford.com (Clinton Pierce)
0.794 ( 17.3 / 21.8) 7 bblishA@TblackbeltDO.Tcom
0.778 ( 1.7 / 2.1) 6 oneill78 <oneillNOonSPAM@cs.uregina.ca.invalid>
0.761 ( 5.3 / 6.9) 8 scott@aravis.softbase.com (Scott McMahan)
0.723 ( 3.5 / 4.8) 6 *@dragons.duesouth.net
Bottom 10 Posters by OCR (minimum of five posts)
=================================================
(kb) (kb)
OCR orig / body Posts Address
----- -------------- ----- -------
0.500 ( 8.4 / 16.8) 22 mjtg@cus.cam.ac.uk (M.J.T. Guy)
0.496 ( 3.4 / 6.8) 15 bmccoy@foiservices.com
0.488 ( 36.7 / 75.2) 95 Jonathan Stowe <gellyfish@gellyfish.com>
0.433 ( 1.8 / 4.2) 5 c_j_marshall@my-deja.com
0.414 ( 1.8 / 4.3) 5 "jan smit" <duthler@tebenet.nl>
0.409 ( 2.5 / 6.2) 5 andersjk@sol-invictus.org (kevin anderson)
0.409 ( 1.4 / 3.5) 5 catfood@apk.net (Mark W. Schumann)
0.397 ( 3.9 / 9.9) 5 Bob Walton <bwalton@rochester.rr.com>
0.377 ( 3.1 / 8.3) 13 mbudash@wcws.com (Michael Budash)
0.320 ( 1.5 / 4.6) 5 ncherry@home.net
60 posters (12%) had at least five posts.
Top 10 Threads by Number of Posts
=================================
Posts Subject
----- -------
41 It is always like this here?
35 Q: digit-wise number comparisons ?
32 length (number of items) of an array
28 simplifying a script
20 offtopic: DFA backreferences?
17 Quoting Strategies and the Jeopardy Game
17 adding data to beginning of file
16 Banner Rotation Theory
16 What makes the web go?
15 comparing text with words
These threads accounted for 14.7% of all articles.
Top 10 Threads by Volume
========================
(kb) (kb) (kb) (kb)
Volume ( hdr/ body/ orig) Posts Subject
-------------------------- ----- -------
106.8 ( 33.3/ 68.6/ 45.2) 41 It is always like this here?
65.6 ( 28.9/ 35.5/ 22.4) 35 Q: digit-wise number comparisons ?
58.0 ( 0.7/ 57.1/ 57.1) 1 FM: managing class data in OO
57.1 ( 24.8/ 28.4/ 18.3) 28 simplifying a script
53.8 ( 15.2/ 37.8/ 27.8) 17 Quoting Strategies and the Jeopardy Game
43.7 ( 23.7/ 15.6/ 10.1) 32 length (number of items) of an array
40.6 ( 12.1/ 27.7/ 20.4) 12 Scripts that invoke one another via Location: and/or URI: - environment persistence?
40.3 ( 17.0/ 21.5/ 13.7) 20 offtopic: DFA backreferences?
36.3 ( 0.8/ 35.5/ 35.5) 1 FM: how to open stuff
35.5 ( 14.9/ 17.9/ 12.8) 15 comparing text with words
These threads accounted for 18.3% of the total volume.
Top 10 Threads by OCR (minimum of five posts)
==============================================
(kb) (kb)
OCR orig / body Posts Subject
----- -------------- ----- -------
0.931 ( 7.4/ 7.9) 6 Is this a bug?
0.902 ( 6.9/ 7.7) 5 Review request! Does this module seem useful/correct?
0.846 ( 8.7/ 10.3) 6 a newbie and his DOS
0.831 ( 4.7/ 5.7) 7 several questions about perl
0.825 ( 5.3/ 6.4) 9 Perl disallowed at ACM programming contests?
0.810 ( 3.3/ 4.1) 5 linking to perl script to html page.
0.794 ( 1.5/ 1.9) 8 $formdata=~s/\s+$//; ?
0.787 ( 5.2/ 6.7) 7 Hex to binary?
0.786 ( 5.2/ 6.6) 8 How the heck does this regex match?
0.785 ( 1.0/ 1.3) 5 does file exist
Bottom 10 Threads by OCR (minimum of five posts)
=================================================
(kb) (kb)
OCR orig / body Posts Subject
----- -------------- ----- -------
0.482 ( 1.2 / 2.5) 5 waking from sleep()
0.477 ( 3.9 / 8.1) 6 to Alan Flavell
0.475 ( 3.2 / 6.7) 7 Submit button thwarted by Reload
0.447 ( 4.2 / 9.4) 7 EPOCH'S Halloween?
0.432 ( 2.4 / 5.5) 10 How di I join a string together?
0.418 ( 3.4 / 8.2) 6 Newbie: graphic counter:shes-a no work!
0.371 ( 0.6 / 1.6) 5 How to convert a a single char (from a string) to a int (decimal)???
0.370 ( 2.4 / 6.4) 5 messy DOS, winDoze, and the great bit bucket in the sky
0.283 ( 1.4 / 4.9) 7 [offtopic] English
0.215 ( 1.7 / 8.0) 7 Unpacking modules on <cough> Windows ... ?
98 threads (21%) had at least five posts.
Top 10 Targets for Crossposts
=============================
Articles Newsgroup
-------- ---------
60 comp.lang.perl.modules
34 alt.perl
10 comp.lang.perl
6 comp.infosystems.www.authoring.html
6 comp.lang.java
4 de.comp.lang.misc
3 comp.databases.oracle.server
3 relcom.comp.dbms.oracle
3 cop.database.oracle.tools
2 comp.unix.programmer
Top 10 Crossposters
===================
Articles Address
-------- -------
7 Jonathan Stowe <gellyfish@gellyfish.com>
6 mjtg@cus.cam.ac.uk (M.J.T. Guy)
6 Alla Gribov <alla.gribov@metatel.com>
6 "William" <bivey@teamdev.com>
5 "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
5 ilya@math.ohio-state.edu (Ilya Zakharevich)
5 abigail@delanet.com
5 Larry Rosler <lr@hpl.hp.com>
4 Tye McQueen <tye@metronet.com>
4 "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
------------------------------
Date: Mon, 01 Nov 1999 14:50:56 GMT
From: mpeppler@mbay.net
Subject: Re: Stored procedure with parameters.
Message-Id: <7vk9cf$33m$1@nnrp1.deja.com>
In article <3818878C.1BB9823@midwal.ca>,
SG <sg@midwal.ca> wrote:
> Sorry... It was typing error at my message, not in my script. The
actual
> codes look like the following:
>
> use DBD::Sybase;
> $first = "N";
> $second = "";
> $dbh = DBI->connect ("dbi:Sybase:server=name", $user, $pass,
> {RaiseError=>1,AutoCommit=>1});
> $sth = $dbh->prepare ("BEGIN sp_name(:1,:2); END;") or die "Error";
> $sth->bind_param (1, $first);
> $sth->bind_param_inout (2, \$second, 10);
> $rv = $sth->execute();
That's invalid syntax with DBD::Sybase. It might work with DBD::Oracle.
You can't use placeholders for parameters to stored procs with
DBD::Sybase (yet)
Michael
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 01 Nov 1999 14:18:46 GMT
From: sleepernyc@my-deja.com
Subject: Survey form, return multiple checkboxes
Message-Id: <7vk7g3$1oa$1@nnrp1.deja.com>
I have a survey form where I would like to have people check off five
hobbies out of ten, and return all answers to my form.log. Any idea how
to do this? the radio fields work well because you can only pick one.
<input type="CHECKBOX" name="hobby" value="dineout">Dining Out
<input type="CHECKBOX" name="hobby" value="cooking">Cooking
<input type="CHECKBOX" name="hobby" value="wine">Wine
<input type="CHECKBOX" name="hobby" value="cookbooks">Cookbooks
<input type="CHECKBOX" name="hobby" value="travel">Travel
<input type="CHECKBOX" name="hobby" value="garden">Gardening
<input type="CHECKBOX" name="hobby" value="hiking">Hiking/Biking/Outdoors
<input type="CHECKBOX" name="hobby" value="sports">Sports
<input type="CHECKBOX" name="hobby" value="concerts">Live Music/Concerts
<input type="CHECKBOX" name="hobby" value="theater">Theater
Thanks!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 1 Nov 1999 07:24:02 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Survey form, return multiple checkboxes
Message-Id: <MPG.1287505a53a5099798a16d@nntp.hpl.hp.com>
In article <7vk7g3$1oa$1@nnrp1.deja.com> on Mon, 01 Nov 1999 14:18:46
GMT, sleepernyc@my-deja.com <sleepernyc@my-deja.com> says...
> I have a survey form where I would like to have people check off five
> hobbies out of ten, and return all answers to my form.log. Any idea how
> to do this? the radio fields work well because you can only pick one.
>
> <input type="CHECKBOX" name="hobby" value="dineout">Dining Out
> <input type="CHECKBOX" name="hobby" value="cooking">Cooking
> <input type="CHECKBOX" name="hobby" value="wine">Wine
> <input type="CHECKBOX" name="hobby" value="cookbooks">Cookbooks
> <input type="CHECKBOX" name="hobby" value="travel">Travel
> <input type="CHECKBOX" name="hobby" value="garden">Gardening
> <input type="CHECKBOX" name="hobby" value="hiking">Hiking/Biking/Outdoors
> <input type="CHECKBOX" name="hobby" value="sports">Sports
> <input type="CHECKBOX" name="hobby" value="concerts">Live Music/Concerts
> <input type="CHECKBOX" name="hobby" value="theater">Theater
The CGI module makes his very easy to handle. Use the param() function
in list context.
for (param 'hobby') { use the values in $_ }
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 01 Nov 1999 11:10:39 GMT
From: lou@visca.com
Subject: Thanks and Follow-up (was: RFC: Making array using range op and map)
Message-Id: <7vjsfd$q89$1@nnrp1.deja.com>
Greetings:
Many thanks to Uri, Matthew, Larry and Kragen for helping me with my
problem. I've learned a lot trying to 'grok' the improvements.
Just for fun I did a benchmark on the different solutions. I was
surprised to see there was such a penalty for using Data Dumper (though
perhaps my benchmarking is faulty?). Unsurprisingly, to me, at least,
Uri's simple C loop is fastest.
#!/usr/bin/perl -w
use strict;
use Benchmark;
use Data::Dumper;
sub lou {
my @price = ( [5..19], [20..60] );
@{$price[0]} = map {$_ * 10} @{$price[0]};
@{$price[1]} = grep /[50]$/, @{$price[1]};
@{$price[1]} = map {$_*10, $_*10+25} @{$price[1]};
pop @{$price[1]};
my @final = map { map {$_*1000} @{$_} } @price;
}
sub uri {
my ($price, @prices);
for ( $price = 50_000 ; $price < 200_000 ; $price += 10_000 ) {
push @prices, $price ;
}
for ( ; $price <= 600_000 ; $price += 25_000 ) {
push @prices, $price ;
}
}
sub matthew {
sub make_range {
my @a;
for my $range ( @_ ) {
my($min, $max, $step) = @{$range};
push @a, $_ * $step + $min for 0 .. ($max - $min)/$step;
}
@a;
}
my @final = Dumper make_range([50_000, 200_000, 10_000],
[225_000, 600_000, 25_000]);
}
sub larry {
my ($incr1, $incr2) = (10_000, 25_000);
$_ = '1';
my @final = ( map($incr1 * $_ => 50_000/$incr1 ..
200_000/$incr1),
map($incr2 * $_ => 225_000/$incr2 ..
600_000/$incr2) );
}
sub kragen {
sub range {
my ($min, $max, $step) = @_;
return map {$min + $step * $_} (0..($max-$min)/$step);
}
#
my @final = (range (50_000, 200_000, 10_000),
range (225_000, 600_000, 25_000));
}
timethese(10000,{
Uri => \&uri,
Matthew => \&matthew,
Larry => \&larry,
Kragen => \&kragen,
Lou => \&lou
}
);
RESULTS:
C:\>perl D:\perl\clpm\zz-postings\BM_range_op_map_prices.pl
Benchmark: timing 10000 iterations of Kragen, Larry, Lou, Matthew,
Uri...
Kragen: 3 wallclock secs ( 2.42 usr + 0.00 sys = 2.42 CPU)
Larry: 2 wallclock secs ( 2.09 usr + 0.00 sys = 2.09 CPU)
Lou: 7 wallclock secs ( 7.25 usr + 0.00 sys = 7.25 CPU)
Matthew: 98 wallclock secs (97.44 usr + 0.00 sys = 97.44 CPU)
Uri: 1 wallclock secs ( 1.48 usr + 0.00 sys = 1.48 CPU)
Once again, thanks.
--
JAPHW
Lou Hevly
lou@visca.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 01 Nov 1999 11:14:40 GMT
From: lou@visca.com
Subject: Thanks and Follow-up (was: RFC: Making array using range op and map)
Message-Id: <7vjsmt$qgr$1@nnrp1.deja.com>
Greetings (Sorry if this is repeated, but Deja.com gave me an unknown
error: E_POST_BUILD_ERROR the first time I posted it):
Many thanks to Uri, Matthew, Larry and Kragen for helping me with my
problem. I've learned a lot trying to 'grok' the improvements.
Just for fun I did a benchmark on the different solutions. I was
surprised to see there was such a penalty for using Data Dumper (though
perhaps my benchmarking is faulty?). Unsurprisingly, to me, at least,
Uri's simple C loop is fastest.
#!/usr/bin/perl -w
use strict;
use Benchmark;
use Data::Dumper;
sub lou {
my @price = ( [5..19], [20..60] );
@{$price[0]} = map {$_ * 10} @{$price[0]};
@{$price[1]} = grep /[50]$/, @{$price[1]};
@{$price[1]} = map {$_*10, $_*10+25} @{$price[1]};
pop @{$price[1]};
my @final = map { map {$_*1000} @{$_} } @price;
}
sub uri {
my ($price, @prices);
for ( $price = 50_000 ; $price < 200_000 ; $price += 10_000 ) {
push @prices, $price ;
}
for ( ; $price <= 600_000 ; $price += 25_000 ) {
push @prices, $price ;
}
}
sub matthew {
sub make_range {
my @a;
for my $range ( @_ ) {
my($min, $max, $step) = @{$range};
push @a, $_ * $step + $min for 0 .. ($max - $min)/$step;
}
@a;
}
my @final = Dumper make_range([50_000, 200_000, 10_000],
[225_000, 600_000, 25_000]);
}
sub larry {
my ($incr1, $incr2) = (10_000, 25_000);
$_ = '1';
my @final = ( map($incr1 * $_ => 50_000/$incr1 ..
200_000/$incr1),
map($incr2 * $_ => 225_000/$incr2 ..
600_000/$incr2) );
}
sub kragen {
sub range {
my ($min, $max, $step) = @_;
return map {$min + $step * $_} (0..($max-$min)/$step);
}
#
my @final = (range (50_000, 200_000, 10_000),
range (225_000, 600_000, 25_000));
}
timethese(10000,{
Uri => \&uri,
Matthew => \&matthew,
Larry => \&larry,
Kragen => \&kragen,
Lou => \&lou
}
);
RESULTS:
C:\>perl D:\perl\clpm\zz-postings\BM_range_op_map_prices.pl
Benchmark: timing 10000 iterations of Kragen, Larry, Lou, Matthew,
Uri...
Kragen: 3 wallclock secs ( 2.42 usr + 0.00 sys = 2.42 CPU)
Larry: 2 wallclock secs ( 2.09 usr + 0.00 sys = 2.09 CPU)
Lou: 7 wallclock secs ( 7.25 usr + 0.00 sys = 7.25 CPU)
Matthew: 98 wallclock secs (97.44 usr + 0.00 sys = 97.44 CPU)
Uri: 1 wallclock secs ( 1.48 usr + 0.00 sys = 1.48 CPU)
Once again, thanks.
--
JAPHW
Lou Hevly
lou@visca.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 1 Nov 1999 07:04:43 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Thanks and Follow-up (was: RFC: Making array using range op and map)
Message-Id: <MPG.12874a1a12e8ab1e98a16c@nntp.hpl.hp.com>
In article <7vjsmt$qgr$1@nnrp1.deja.com> on Mon, 01 Nov 1999 11:14:40
GMT, lou@visca.com <lou@visca.com> says...
> Many thanks to Uri, Matthew, Larry and Kragen for helping me with my
> problem. I've learned a lot trying to 'grok' the improvements.
>
> Just for fun I did a benchmark on the different solutions. I was
> surprised to see there was such a penalty for using Data Dumper (though
> perhaps my benchmarking is faulty?). Unsurprisingly, to me, at least,
> Uri's simple C loop is fastest.
Surprising to me, because it does many more perl ops than a functional
solution. However, this is because the benchmark is bogus. See below.
Benchmarking is hard to do!
> #!/usr/bin/perl -w
> use strict;
> use Benchmark;
> use Data::Dumper;
...
> sub uri {
> my ($price, @prices);
> for ( $price = 50_000 ; $price < 200_000 ; $price += 10_000 ) {
> push @prices, $price ;
> }
> for ( ; $price <= 600_000 ; $price += 25_000 ) {
> push @prices, $price ;
> }
> }
...
> sub larry {
> my ($incr1, $incr2) = (10_000, 25_000);
> $_ = '1';
> my @final = ( map($incr1 * $_ => 50_000/$incr1 ..
> 200_000/$incr1),
> map($incr2 * $_ => 225_000/$incr2 ..
> 600_000/$incr2) );
> }
...
> timethese(10000,{
> Uri => \&uri,
> Matthew => \&matthew,
> Larry => \&larry,
> Kragen => \&kragen,
> Lou => \&lou
> }
> );
>
> RESULTS:
> C:\>perl D:\perl\clpm\zz-postings\BM_range_op_map_prices.pl
> Benchmark: timing 10000 iterations of Kragen, Larry, Lou, Matthew,
> Uri...
> Kragen: 3 wallclock secs ( 2.42 usr + 0.00 sys = 2.42 CPU)
> Larry: 2 wallclock secs ( 2.09 usr + 0.00 sys = 2.09 CPU)
> Lou: 7 wallclock secs ( 7.25 usr + 0.00 sys = 7.25 CPU)
> Matthew: 98 wallclock secs (97.44 usr + 0.00 sys = 97.44 CPU)
> Uri: 1 wallclock secs ( 1.48 usr + 0.00 sys = 1.48 CPU)
Them's fightin' words, buddy! You are comparing apples with lemons.
Let's try once again, this time interpolating the constants so that the
compiler can fold them, instead of redoing the divisions every time.
That was done for pedagogic purposes only; no one said anything about
benchmarks.
Here is the function I added to your benchmark:
sub larry1 {
$_ = '1';
my @final = ( map(10_000 * $_ => 50_000/10_000 .. 200_000/10_000),
map(25_000 * $_ => 225_000/25_000 .. 600_000/25_000));
}
Benchmark: timing 10000 iterations of Larry, Larry1, Uri...
Larry: 5 wallclock secs ( 4.62 usr + 0.00 sys = 4.62 CPU)
Larry1: 2 wallclock secs ( 2.41 usr + 0.00 sys = 2.41 CPU)
Uri: 4 wallclock secs ( 3.41 usr + 0.00 sys = 3.41 CPU)
There, that feels better! Sorry, Uri [NOT!].
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 01 Nov 1999 11:09:02 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Thanks and Follow-up (was: RFC: Making array using range op and map)
Message-Id: <x7bt9eb3dt.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> Benchmark: timing 10000 iterations of Larry, Larry1, Uri...
LR> Larry: 5 wallclock secs ( 4.62 usr + 0.00 sys = 4.62 CPU)
LR> Larry1: 2 wallclock secs ( 2.41 usr + 0.00 sys = 2.41 CPU)
LR> Uri: 4 wallclock secs ( 3.41 usr + 0.00 sys = 3.41 CPU)
LR> There, that feels better! Sorry, Uri [NOT!].
i never claimed the fastest. i just wrote a very clear answer to someone
who might not grok maps yet. and if the starting/ending vals and
increments are not constant, a loop should (i ain't testing it) be about
the same as map as you would have to do the divisions.
also if the starting/ending values were not multiples of the increment,
then the loop wins easy over the map.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 01 Nov 1999 14:48:41 GMT
From: mpeppler@mbay.net
Subject: Re: What makes the web go?
Message-Id: <7vk988$317$1@nnrp1.deja.com>
In article <slrn81g2ih.66b.abigail@alexandra.delanet.com>,
abigail@delanet.com wrote:
> Martien Verbruggen (mgjv@comdyn.com.au) wrote on MMCCXLIX September
> MCMXCIII in <URL:news:gUOR3.184$z73.4674@nsw.nnrp.telstra.net>:
> __
> __ *nod* They may be able to handle Yahoo. I don't know whether, given
> __ enough hardware, MS SQL could perform well enough. But I know a few
> __ things: The system would not be nearly as stable as Sybase on
Solaris,
> __ for example. And given the same investment, the latter would
probably
> __ outperform the MS solution by far. And if you then look at ASE on
> __ Linux, which is a possibility as well nowadays,
>
> *cough* On _Linux_? No, thanks.
>
> To run a database in a large production environment, you need several
> things. Good support for many processors. Technical support for your
> server. And in the case of Sybase, raw devices.
>
> AFAIK, Sybase 11.9.x isn't available on Linux yet - and for the
11.0.3.3
> version, you cannot get support. Support that'll be dropped on other
> platforms next year anyway (except VMS - they get another 4 years).
11.9.2 *is* available for linux. Free for development, and can
be downloaded from http://linux.sybase.com.
As for raw devices - in general I agree (although you also
want async IO, which linux also lacks). However, depending on how
you setup your backup strategy you can very often make do with
filesystem devices.
This of course has nothing to do with perl...
Michael
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1243
**************************************