[18676] in Perl-Users-Digest
Perl-Users Digest, Issue: 844 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 00:07:43 2001
Date: Sun, 6 May 2001 21:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989208308-v10-i844@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 6 May 2001 Volume: 10 Number: 844
Today's topics:
Re: [OT: language religion ] Re: Should Perl be first? <tom.beer@btfinancialgroup.spamfilter.com>
ANNOUNCE: Bleach 1.10Approved: damian@conway.org (per m (Damian Conway)
ANNOUNCE: Data::Denter 0.12 <ingy@ActiveState.com>
automating ftp download using perl <dkohli@san.rr.com>
Change URL to directory and file name (BUCK NAKED1)
Re: Change URL to directory and file name <tony_curtis32@yahoo.com>
Re: Change URL to directory and file name (BUCK NAKED1)
Re: Change URL to directory and file name <tony_curtis32@yahoo.com>
Re: Command not found when opening "-|" <abe@ztreet.demon.nl>
DBI and fetch <troyr@vicnet.net.au>
Re: DBI and fetch <joe+usenet@sunstarsys.com>
Re: DBI and fetch <bwalton@rochester.rr.com>
RE: Good editor for perl <perlNO-SPAM@NO-SPAMprogramacionweb.com>
Re: Good editor for perl <mikecook@cigarpool.com>
Re: Help on optimization wanted <Juha.Laiho@iki.fi>
Re: Help on optimization wanted (Abigail)
Re: Help on optimization wanted (Anno Siegel)
Re: Help slim down Perl code (Anno Siegel)
Re: Passing references via recursion <skilchen@swissonline.ch>
RE: Perl & ODBC <perlNO-SPAM@NO-SPAMprogramacionweb.com>
Re: Perl & ODBC <jtjohnston@courrier.usherb.ca>
Re: reverse of perlcc (Anno Siegel)
Re: sessions and closures <admin@bestwebscripts.com>
Re: Simple Script Needed <bwalton@rochester.rr.com>
Re: sub z {return } print ((($x,$y)=z) ? "yes:$x,$y\n" (Anno Siegel)
Re: The Canonical Program (was Re: I remember someone m <nospam@kremvax.su>
Re: Trying to fill in a Pager Web page. (Abigail)
Re: UPPERCASE to "Sentence Case" (Anno Siegel)
Re: UPPERCASE to "Sentence Case" (Abigail)
Re: UPPERCASE to "Sentence Case" (Anno Siegel)
Re: UPPERCASE to "Sentence Case" (Abigail)
Re: UPPERCASE to "Sentence Case" (Anno Siegel)
Re: UPPERCASE to <nospam@newsranger.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 7 May 2001 13:43:02 +1000
From: "Tom Beer" <tom.beer@btfinancialgroup.spamfilter.com>
Subject: Re: [OT: language religion ] Re: Should Perl be first?
Message-Id: <9d55jd$cg1$1@merki.connect.com.au>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
>
> [2] because a) I loathe Java, and b) we employ people who enjoy writing
> in it.
>
I'm interested - why do you loathe Java? (This is strictly curiosity, I
don't know or use Java).
Tom.
------------------------------
Date: 6 May 2001 22:13:39 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: ANNOUNCE: Bleach 1.10Approved: damian@conway.org (per merlyn@stonehenge.com standing approval)
Message-Id: <9d4iaj$330$1@towncrier.cc.monash.edu.au>
Keywords: perl, module, release
==============================================================================
Release of version 1.10 of Bleach
==============================================================================
NAME
Bleach - For *really* clean programs
SYNOPSIS
use Bleach;
print "Hello world";
DESCRIPTION
The first time you run a program under `use Bleach', the module removes
all the unsightly printable characters from your source file. The code
continues to work exactly as it did before, but now it looks like this:
use Bleach;
INSTALLATION
It's all pure Perl, so just put the .pm file in its appropriate
local Perl subdirectory.
AUTHOR
Damian Conway (as if you couldn't guess)
COPYRIGHT
Copyright (c) 2001, Damian Conway. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the terms of the Perl Artistic License
(see http://www.perl.com/perl/misc/Artistic.html)
==============================================================================
CHANGES IN VERSION 1.10
- Add demo_bleach.* examples in other languages
- Added DWIM.pm (at dha's implicit request)
==============================================================================
AVAILABILITY
Bleach has been uploaded to the CPAN
and is also available from:
http://www.csse.monash.edu.au/~damian/CPAN/Bleach.tar.gz
==============================================================================
------------------------------
Date: Mon, 07 May 2001 01:25:32 GMT
From: Brian Ingerson <ingy@ActiveState.com>
Subject: ANNOUNCE: Data::Denter 0.12
Message-Id: <tfc1hoev2hamf3@corp.supernews.com>
Data::Denter - An alternative to Data::Dumper and Storable.
INTRODUCTION:
Data::Denter is yet another Perl data serializer/deserializer. It
formats nested data structures in an indented fashion. It is optimized
for human readability/editability, safe deserialization, and
(eventually) speed.
NOTE: It may be optimized for Python programmers too, but please don't
hold that against me ;)
It exports 2 functions: C<Indent()> and C<Undent()> for serialization
and deserialization respectively. It handles all of the commonly
serializable Perl data types, including: scalars, hash refs, array
refs, scalar refs, ref refs, undef, and blessed references. It can
even properly handle circular and duplicate references.
SAMPLE:
use Data::Denter;
print Indent bless {foo => 42,
bar => [ 'happy', undef, [], 'sad' ],
baz => "Bozo the Clown",
}, "Small::Example";
yields:
%Small::Example
bar => @
happy
?
@
sad
baz => Bozo the Clown
foo => 42
CHANGES:
(version 0.12)
- URI style escaping for binary data.
- Hash keys are sorted by default for the Indent()
function. Controlled by the "Sort" option.
- Added "HashMode" option for creating quick and easy config files.
- Added "MaxLines" option for limiting the output of very long string
values.
- Fixed bug. Now works with 5.7.0+.
INFORMATION:
For more information on Data::Denter, see 'perldoc Data::Denter'.
Please send questions and comments to "Brian Ingerson" <INGY@cpan.org>
Copyright (c) 2001, Brian Ingerson. All Rights Reserved.
------------------------------
Date: Mon, 07 May 2001 03:51:13 GMT
From: "Dilmeet Kohli" <dkohli@san.rr.com>
Subject: automating ftp download using perl
Message-Id: <RYoJ6.1340$Tl2.915897@typhoon.san.rr.com>
Hi everyone:
I want to write a perl script to automatically down load files from ftp
sites. I am sure I am not the first one. Wondering if similar scripts are
available on the Internet. Please help me with some reference material.
Thanks
Dilmeet
------------------------------
Date: Sun, 6 May 2001 19:02:44 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Change URL to directory and file name
Message-Id: <5827-3AF5E624-149@storefull-248.iap.bryant.webtv.net>
How do I change a URL to a directory and file name? EX: I want to change
something similar to "http://user.hypermart.net/image/bg.gif" to
"wkdir/bg.gif".
I can't find anything about this in the FAQ, and I've tried split and
regex's to no avail.
Please help.
Thanks,
Dennis
------------------------------
Date: 06 May 2001 19:25:34 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Change URL to directory and file name
Message-Id: <878zka3szl.fsf@limey.hpcc.uh.edu>
>> On Sun, 6 May 2001 19:02:44 -0500 (CDT),
>> dennis100@webtv.net (BUCK NAKED1) said:
> How do I change a URL to a directory and file name? EX:
> I want to change something similar to
> "http://user.hypermart.net/image/bg.gif" to
> "wkdir/bg.gif".
> I can't find anything about this in the FAQ, and I've
> tried split and regex's to no avail.
It's not possible. The way a remote server implements its
underlying representation space is (should be) completely
opaque to its clients.
If it's *your* server and *your* filespace (i.e. the http
part of the URL can be ignored) then you could use the URI
module to construct a URL and extract the path section.
You'd then need to know the root of the web-filespace, and
the rest is an exercise for the reader.
perldoc URI
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Sun, 6 May 2001 20:07:21 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Change URL to directory and file name
Message-Id: <5827-3AF5F549-160@storefull-248.iap.bryant.webtv.net>
Thanks, Tony. I don't think I'm doing this correctly anyway. I'm using
LWP::Simple to download a file and store it, such as
getstore("$url", "$file")...
$url will be unknown, but $file is defined: $file =
">wkdir/tempfile007".
..and then I use Net::FTP to...
$ftp->put("$file", "$file").... but it names the remote file
"tempfile007" instead of the filename(pathname of the URL), which is
what I want.
Maybe I need to forget LWP and just use Net::FTP for the entire
operation??? I guess I should open a connection for $ftp->get("$url),
save it; and then do another connection for storage to the other server
to save it. I dunno.
Regards,
--Dennis
------------------------------
Date: 06 May 2001 20:35:58 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Change URL to directory and file name
Message-Id: <874ruy3pq9.fsf@limey.hpcc.uh.edu>
>> On Sun, 6 May 2001 20:07:21 -0500 (CDT),
>> dennis100@webtv.net (BUCK NAKED1) said:
> Thanks, Tony. I don't think I'm doing this correctly
> anyway. I'm using LWP::Simple to download a file and
Not quite: you're downloading a URL and storing it to a
file. The underlying representation (which might or might
not be a file, e.g. dynamically scripted output) is hidden
behind the http URL.
> ..and then I use Net::FTP to... $ftp->put("$file",
> "$file").... but it names the remote file "tempfile007"
That's now the *local* file which is a copy of *the
content* of the remote URL.
> Maybe I need to forget LWP and just use Net::FTP for the
> entire operation??? I guess I should open a connection
But how will Net::FTP talk to an HTTP server?
> for $ftp->get("$url), save it; and then do another
> connection for storage to the other server to save it. I
> dunno.
Are you trying to mirror a remote site by any chance?
There are better ways, e.g. "wget", if I may digress into
a non-perl solution :-) or http://sunsite.org.uk/packages/mirror/
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Mon, 07 May 2001 01:28:01 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Command not found when opening "-|"
Message-Id: <eanbftsvkuifq5tdgiitiv22jgvcftkick@4ax.com>
On Sat, 05 May 2001 15:23:59 GMT, "Hans de Bruin"
<Hans.de.Bruin@chello.nl> wrote:
>
> When I try to open "-|" or "|-" my os responses that "-" is not a command or
> batch file which it can run. Is there a solution to this, or an other sane
> way to let two processes talk to one another?
>
> (WinNT4SP6 / ActivePerl 5.6.1)
From perlfork.pod:
Forking pipe open() not yet implemented
The "open(FOO, "|-")" and "open(BAR, "-|")" constructs are not
yet implemented. This limitation can be easily worked around in
new code by creating a pipe explicitly. The following example
shows how to write to a forked child:
--
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'
------------------------------
Date: Mon, 7 May 2001 12:15:21 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: DBI and fetch
Message-Id: <aCnJ6.2182$ZJ.81782@ozemail.com.au>
Hi i was wondering if anyone knew how to get a returned recordset using DBI
in a different order from what it was returned
eg if i do a sql query and get 15 records returned i use fetch->() to get
the next row. However..i do not know how to jump straight to row 13 without
having to fetch->() the first 12 rows.
The DBI manpage says that non sequential record reads are not supported..but
i was wondering if anyone had a work around
Thanks in advance
--
----------------------------------------------------------------
Troy Rasiah
Melbourne, Aus
------------------------------
Date: 06 May 2001 22:54:07 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: DBI and fetch
Message-Id: <m366fd3m40.fsf@mumonkan.sunstarsys.com>
"Troy Boy" <troyr@vicnet.net.au> writes:
> Hi i was wondering if anyone knew how to get a returned recordset using DBI
> in a different order from what it was returned
If you want to fetch the rows in an arbitrary order, then I think the
answer is no. However, you might try using one of DBI's "fetchall"
variants and work with the recordset as a Perl structure.
> eg if i do a sql query and get 15 records returned i use fetch->() to get
> the next row. However..i do not know how to jump straight to row 13 without
> having to fetch->() the first 12 rows.
>
> The DBI manpage says that non sequential record reads are not supported..but
> i was wondering if anyone had a work around
Maybe not on the Perl/DBI side, but perhaps your database can skip the
first 12 rows if it supports the LIMIT clause.
my $sql = "SELECT * FROM table LIMIT 13, 100"; # pulls rows 13-100
HTH
--
Joe Schaefer "I never think of the future. It comes soon enough."
--Albert Einstein
------------------------------
Date: Mon, 07 May 2001 02:59:31 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: DBI and fetch
Message-Id: <3AF60FDC.CB899A82@rochester.rr.com>
Troy Boy wrote:
>
> Hi i was wondering if anyone knew how to get a returned recordset using DBI
> in a different order from what it was returned
>
> eg if i do a sql query and get 15 records returned i use fetch->() to get
> the next row. However..i do not know how to jump straight to row 13 without
> having to fetch->() the first 12 rows.
>
> The DBI manpage says that non sequential record reads are not supported..but
> i was wondering if anyone had a work around
...
> Troy Rasiah
> Melbourne, Aus
Well, my understanding of SQL says this isn't directly possible (maybe
some databases have extensions for this?). If, though, the row number
were stored as a column of the table, then you could add a 'where'
clause to your SQL to pick out row 13, which would then be the only row
returned. That would be the proper "SQL-ish" way -- let SQL do the
selection work, rather than doing it yourself. Note also that (unless
an 'order by' clause is present), SQL may not always return rows in the
same order, so the meaning of "row 13" may be nebulous.
--
Bob Walton
------------------------------
Date: Mon, 7 May 2001 01:34:55 +0200
From: "Fermín" <perlNO-SPAM@NO-SPAMprogramacionweb.com>
Subject: RE: Good editor for perl
Message-Id: <3af5df41$1@news>
Also WinEdit (Shareware)
www.winedit.com
and UltraEdit (Shareware)
www.ultraedit.com
"dave turner" <dt@area.com> escribió en el mensaje
news:MPG.155e98c6f91645dd989696@news.area.com...
| In article <9cpnd202p78@enews3.newsguy.com>, rcranberry@hotmail.com
| says...
|
| You might also look at DZ Soft's Perl editor.
|
| www.dzsoft.com
|
|
| > www.editplus.com
| >
| > Excellent editor!
| >
| > "Super-Simon" <simon@super-simon.com> wrote in message
| > news:9c1csm$loh$1@news1.xs4all.nl...
| > > Hi all,
| > >
| > > I'm searching for a good, fast editor with syntax highlighting
for perl
| > > (CGI) for use under Windows 2000 / Windows 98 (I use windowz
only for
| > > editing scripts, scripts runs on Linux-server). It has to be
free (I'm a
| > > poor student ;-)
| > >
| > > Grtz,
| > >
| > > Super-Simon
| > >
| > >
| >
| >
| >
------------------------------
Date: Sun, 6 May 2001 18:19:25 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Re: Good editor for perl
Message-Id: <PKmJ6.851$fU2.376052@news.uswest.net>
Try cygwin (a UNIX emulator for windoze - link below) and use vim - cygwin
is free & you can do a lot more than text editing (with syntax coloring of
course)...
Michael
http://sources.redhat.com/cygwin/
--
== CigarPool ==
http://www.cigarpool.com
"dave turner" <dt@area.com> wrote in message
news:MPG.155e98c6f91645dd989696@news.area.com...
> In article <9cpnd202p78@enews3.newsguy.com>, rcranberry@hotmail.com
> says...
>
> You might also look at DZ Soft's Perl editor.
>
> www.dzsoft.com
>
>
> > www.editplus.com
> >
> > Excellent editor!
> >
> > "Super-Simon" <simon@super-simon.com> wrote in message
> > news:9c1csm$loh$1@news1.xs4all.nl...
> > > Hi all,
> > >
> > > I'm searching for a good, fast editor with syntax highlighting for
perl
> > > (CGI) for use under Windows 2000 / Windows 98 (I use windowz only for
> > > editing scripts, scripts runs on Linux-server). It has to be free (I'm
a
> > > poor student ;-)
> > >
> > > Grtz,
> > >
> > > Super-Simon
> > >
> > >
> >
> >
> >
------------------------------
Date: 6 May 2001 10:19:55 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: Help on optimization wanted
Message-Id: <9d38gb$5cn$1@ichaos.ichaos-int>
"Michael Ströck" <michael@stroeck.com> said:
>One of our CS teachers at school told me to write a
>script that finds all primes from 1 - n.
>
>Writing that script was easy, but as I'm very new to
>Perl, I'd really appreciate any comments on how to
>make the following script run faster.
As others have written, testing against primes only less or equal than
the square root of the number you're testing for primeness is a good
speedup.
Another is that by increasing the number to test alternatively by two
and by four will skip all numbers divisible by three in addition to all
numbers divisible by two. The adjustment needed for this to work properly
is to start your loop at five, so you'll check 5,7,11,13,17,... .
So, this reduces the numbers to test by 1/3 with a negligible overhead.
It would be possible to extend this "skip sequence" to also cover
everything divisible by five, but in my opinion that wouldn't be cost-
effective, especially when five is the first divisor against which to
test (after you proof that this technique reliably skips everything
divisible by two or three there's no need to try to divide with these).
With the 2-4 -skip sequence the amount of numbers to test is 2 out of
6, which already is a good ratio; growing the sequence to cover numbers
divisible by 5 would only lower this ratio by 2/30, from 10/30 to 8/30.
But this isn't perl, this is maths. Off to sci.math with you (where this
is bound to be a FAQ).. :-)
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
!M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: Sun, 6 May 2001 22:46:39 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Help on optimization wanted
Message-Id: <slrn9fbl2f.ti0.abigail@tsathoggua.rlyeh.net>
Craig Berry (cberry@cinenet.net) wrote on MMDCCCV September MCMXCIII in
<URL:news:tfb5nd19910l1d@corp.supernews.com>:
}}
}} #!/usr/bin/perl -w
}} # sieve - find primes using a sieve
}} # Craig Berry (20010506)
}}
}} use strict;
}}
}} my $max = shift || 100;
}} my $limit = int sqrt($max);
}} my @sieve = (0, 0, (1) x ($max - 1));
That takes a lot of memory.
Here's a sieve that uses approx. 1 byte/20 numbers:
#!/opt/perl/bin/perl -l
use strict;
use warnings 'all';
sub scrub ($);
sub findnext ($);
my $max = $ARGV [0] || 1000;
my $bits = 4 * int ($max / 10) + ($max % 10 ? 4 : 0);
my $bytes = int ($bits / 8) + ($bits % 8 ? 1 : 0);
my $sieve = "\xFF" x $bytes;
# Note that with the exception of 2 and 5, all prime numbers end in
# 1, 3, 7 or 9. We will use a bitvector as sieve, and only keep track
# of numbers ending in 1, 3, 7, and 9; hence 4 bits per 10 numbers.
# So, we store the bit belonging to a number 10 * k + l (0 <= l < 10)
# in bit 4 * k + {1 => 0, 3 => 1, 7 => 2, 9 => 3} -> {l}.
# Also, bit m belongs to number 10 * (int (m / 4)) + [1, 3, 7, 9] -> [m % 4].
# Numbers less than 10 are "special".
print 2;
print 3; scrub 3;
print 5;
print 7; scrub 7;
for (my $i = findnext 9; $i; $i = findnext $i) {
print $i;
scrub $i;
}
exit;
my ($offset1, $offset2);
INIT {
$offset1 = [undef, 0, undef, 1, undef, undef, undef, 2, undef, 3];
$offset2 = [1, 3, 7, 9];
}
# Scrub out all multiples of the given argument. It's easy to see that
# all multiples less than the square already have been crossed out, and
# we only have to scrub out the odd multiples. Furthermore, multiples of
# 5 should not be scrubbed out.
# This can be made faster, some loop unrolling makes it that
# 1) we don't need $offset1, 2) we don't need the test % 5.
# This is left as an exercise to the reader.
sub scrub ($) {
use integer;
my $n = shift;
for (my $i = $n * $n; $i <= $max; $i += ($n << 1)) {
next if (($i % 5) == 0);
vec ($sieve, 4 * ($i / 10) + $offset1 -> [$i % 10], 1) = 0;
}
}
# Find the next prime number after the given number.
sub findnext ($) {
use integer;
my $n = shift;
my $i = 4 * ($n / 10) + $offset1 -> [$n % 10] + 1;
while ($i <= $bits) {
if (vec ($sieve, $i, 1)) {
return 10 * ($i / 4) + $offset2 -> [$i % 4]
}
$i ++
}
undef;
}
__END__
This might print up to 2 primes more than the given maximum.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: 7 May 2001 02:44:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help on optimization wanted
Message-Id: <9d5275$879$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Craig Berry (cberry@cinenet.net) wrote on MMDCCCV September MCMXCIII in
> <URL:news:tfb5nd19910l1d@corp.supernews.com>:
> }}
> }} #!/usr/bin/perl -w
> }} # sieve - find primes using a sieve
> }} # Craig Berry (20010506)
> }}
> }} use strict;
> }}
> }} my $max = shift || 100;
> }} my $limit = int sqrt($max);
> }} my @sieve = (0, 0, (1) x ($max - 1));
>
> That takes a lot of memory.
>
> Here's a sieve that uses approx. 1 byte/20 numbers:
[delightful code snipped]
Thanks for the thorough analysis. I like the way to save space
by skipping the numbers in each decade that can't be primes.
This particular method seems to be inspired by the decimal number
system. Could a different base inspire a system that saves even
more? A base that is the product of the first few primes looks
promising, but I get the distinct feeling I'm re-inventing some
wheel here. Off to the literature I go, instead of perpetrating
more off-topic ruminations.
Anno
------------------------------
Date: 7 May 2001 01:22:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Help slim down Perl code
Message-Id: <9d4tda$5fk$1@mamenchi.zrz.TU-Berlin.DE>
According to Uri Guttman <uri@sysarch.com>:
[...]
> read( FH, $buf, -s FH ) ;
> return $buf ;
>
> # older slow way
> # local( $/ ) unless wantarray ;
> # <FH>
> }
Is it known to be slower? I do like the read() method because it's
actually clearer than the time-honored way of undef'ing $/. It has
the disadvantage that it fails if -s isn't applicable to FH as with
terminals, sockets and their ilk.
Anno
------------------------------
Date: Mon, 7 May 2001 02:05:00 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Passing references via recursion
Message-Id: <9d4oui$ged7g$1@ID-13368.news.dfncis.de>
"Arvin Portlock" <temp133@hotmail.com> schrieb im Newsbeitrag
news:9d41jp$h6j$1@agate.berkeley.edu...
>
> As for Mr. Kilchenmann's code, [...]
> The problem with your code though, is that it customizes
> recurse to do a specific thing: append lines. I have too many
> instance in older code of subroutines like recurse1, recurse2,
> recurse3, and such. I never want to have to do that again.
>
You are right. But then you might want to try out the famous closures.
See the higher order functions "make_location_appender" and
"make_list_pusher" below. Both return a list of two closures. The
first one does the desired work, the second one returns the
accumulated result of the work done so far.
#!/usr/bin/perl -w
use strict;
sub print_locations {
my $root = shift;
my ($do_append, $get_locations) = make_location_appender(' ');
recurse ($root, $do_append);
print $get_locations->(), "\n";
}
sub get_location_list {
my $root = shift;
my ($list_push, $get_list) = make_list_pusher();
recurse($root, $list_push);
return $get_list->();
}
sub recurse {
my ($node, $subref) = @_;
if (defined($node)) {
$subref->($node);
recurse($node->{sub}, $subref);
recurse($node->{next}, $subref);
}
}
sub make_location_appender {
my $separator = shift || '';
my $locations = '';
my $do_append = sub {
my $node = shift;
if ($locations) {
$locations .= ($separator . $node->{place});
}
else {
$locations = $node->{place};
}
};
my $get_locations = sub {
return $locations;
};
return ($do_append, $get_locations);
}
sub make_list_pusher {
my @list = ();
my $list_push = sub {
my $node = shift;
push(@list, $node->{place});
};
my $get_list = sub {
return \@list;
};
return ($list_push, $get_list);
}
my $root = {
place => "first",
sub => {
place => "second",
sub => undef,
next => {
place => "third",
sub => {
place => "third_sub",
sub => undef,
next => {
place => "third_sub_next",
sub => undef,
next => undef,
},
},
next => {
place => "third_next",
sub => {
place => "third_next_sub",
sub => undef,
next => undef,
},
next => undef,
}
},
},
next => {
place => "fourth",
sub => {
place => "fifth",
sub => undef,
next => undef,
},
next => undef,
},
};
print_locations($root);
print "\n";
print join("\n", @{get_location_list($root)});
__END__
output:
first second third third_sub third_sub_next third_next third_next_sub
fourth fifth
first
second
third
third_sub
third_sub_next
third_next
third_next_sub
fourth
fifth
------------------------------
Date: Mon, 7 May 2001 01:29:25 +0200
From: "Fermín" <perlNO-SPAM@NO-SPAMprogramacionweb.com>
Subject: RE: Perl & ODBC
Message-Id: <3af5df3f$1@news>
Hello,
Yes, of course you can use Access.
Read carefully the link you've posted.
In this link, it is used a SQL query in an Access database.
It is not mentioned SQL server, nor necessary, but I recommend you to
use a SQL server (MySQL, SQLServer, ...) if you are going to have many
connections in your database.
Note the difference between SQL Server and SQL query. You can make SQL
querys in your Access, because SQL is a "language".
Fermín Palacios
P.S. You post to the news, so you have to consult the news, that´s
what I think.
Good luck!
"jtjohnston" <jtjohnston@courrier.usherb.ca> escribió en el mensaje
news:3AF5C01B.35C3C11D@courrier.usherb.ca...
| Can I use and access Microsoft Access *.mdb files without having a
sql
| server?
| For example, I was consulting this:
| http://www.geocities.com/Area51/Cavern/4503/perl_odbc.htm
| But it talks about a SQL server acting as an intermediary. I'm sure
I've
| seen this done without a SQL server?
|
| (My ISP won't give me access to a SQL server; nor do I want one. I
| normally database with *.text files, but want a new challenge.)
|
| John
| (P.S. an email post and reply would eb appreciated.)
|
------------------------------
Date: Sun, 06 May 2001 21:34:39 -0400
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Re: Perl & ODBC
Message-Id: <3AF5FBAF.996F0200@courrier.usherb.ca>
> > Read carefully the link you've posted.
> > In this link, it is used a SQL query in an Access database.
> > It is not mentioned SQL server, nor necessary, but I recommend you to
> > use a SQL server
I guess I don't understand the code or the SQL call.
http://www.geocities.com/Area51/Cavern/4503/perl_odbc.htm
The link says create a db called MyDatabase.mdb. OK, done.
Then it says you are working from a web server ... ??? I don't have one.
"Now you have to specify the location of your database. In the Data Source
Name: box, type a name that will identify your database from your perl
script. For this example, we'll use MyData - Remember this, it's
important!"
How can I do that if I don't have a SQL db? I guess I should ask, how do I
modify this code to open MyDatabase.mdb and not "MyData"? What do I do
here:
$sql = "SELECT * FROM table1 WHERE this_field='criteria';";
$dsn = "MyData";
I just want to read this table called "table1"
| name | text |
| address | text |
sub searchDatabase
{
$sql = "SELECT * FROM table1 WHERE this_field='criteria';";
$dsn = "MyData";
$db = new Win32::ODBC($dsn);
$db->Sql($sql);
while ($db->FetchRow())
{
($rec1, $rec2, $rec3) = $db->Data("rec1", "rec2", "rec3");
print "Record 1 = $rec1\n";
print "Record 2 = $rec2\n";
print "Record 3 = $rec3\n";
}
$db->Close();
}
Thanks,
john
>
------------------------------
Date: 7 May 2001 02:57:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: reverse of perlcc
Message-Id: <9d52u6$879$2@mamenchi.zrz.TU-Berlin.DE>
According to flash <bop@mypad.com>, who top-posted:
> I have already started.
> and im almost done.
Programmers say "I'm almost done" all the time. It's safe to assume
they're wrong.
Anno
------------------------------
Date: Mon, 07 May 2001 03:35:37 +0400
From: Serge <admin@bestwebscripts.com>
Subject: Re: sessions and closures
Message-Id: <3AF5DFC9.D9BDEC60@bestwebscripts.com>
"F. Xavier Noria" wrote:
> behavior. If you understand about continuations, one way
> to explain what we did would be to say that we wrote our
> software in continuation-passing style. [...]
>
> Sounds elegant! Have any of you tried this approach with Perl?
> Could you please comment a bit on this?
either inserting some additional data into documents being served... or
using plain cookies :-)
--
CGI Scripts and Services
http://bestwebscripts.com
------------------------------
Date: Mon, 07 May 2001 03:18:35 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Simple Script Needed
Message-Id: <3AF61454.C63B6767@rochester.rr.com>
Cut Throat wrote:
...
> Say I have 2 pages,
> On EACH of those pages i a line of text,
> For example : Page 1 has : Hello and welcome to the old page,
> And page 2 had : Hello and welcome to the new page.
>
> Every day I have to change those pages > by changing the line of text on
> them,
> Now at the moment I am having to modify them manually,
> What I need to do is relate the lines of text on each page to a single text
> file,
> So page 1s line of text will read it off line 1 of the single text file,
> And page 2s line of text (which is different) will read it off line 2 of the
> single text file,.
>
> So what i would have now in this example > is 2 blank pages with something
> like a script on it pointing to a text file or script, ANd a text file or
> script saying :
>
> Hello and welcome to the old page,
> Hello and welcome to the new page,
>
> Then say I wanted to change page one to say Hello and welcome to the NEW
> page and page 2 saying Hello and welcome to the OLD page. Then all I would
> need to do is open the one single text or script file and just change the
> lines,
>
> NOw that was a simple example because as you can tell it is hard to explain,
> The only adaptions I would make is that it is about 14 pages i need to
> change,
>
> Now how would i do this?
>
> ANY HELP AT ALL WILL HELP ! ! :0)
...
> Chris
...
Well, if you only want to update the pages once per day, the pages
should be static HTML, updated daily. I would recommend making a
template page for each page with the location for the data to be
inserted represented by a special tag that will never occur elsewhere in
the template, like maybe <%subhere%>, for example. Then once a day, run
a simple Perl program to read the template files and the file with your
revised lines, copying each template file to the real HTML file with the
data substituting for the special tag. Maybe something like [WARNING:
UNTESTED]:
@files=('file1','file2',...);
open IN,"data.file" or die "Oops, $!";
while(<IN>){
chomp;
$line=$_; #the data to be substituted for the next file
$file=shift @files; #base name of file
open TEMPLATE,"$file.template" or
die "Oops, couldn't open $file.template, $!";
open HTML,"$file.html" or
die "Oops, couldn't open $file.html for write, $!";
while(<TEMPLATE>){
s/<%subhere%>/$line;
print HTML $_;
}
close TEMPLATE;
close HTML;
}
Using this method, there would be a once per day possibility of serving
a partial web page, unless the web server is temporarily suspended
during this operation. Depending on your application, that might or
might not be a potential problem.
There are probably some more elegant ways of doing this, perhaps using a
module like Text::Template.
--
Bob Walton
------------------------------
Date: 6 May 2001 23:18:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sub z {return } print ((($x,$y)=z) ? "yes:$x,$y\n" : "no\n")
Message-Id: <9d4m4j$13c$1@mamenchi.zrz.TU-Berlin.DE>
According to Rick Delaney <rick.delaney@home.com>:
> Anno Siegel wrote:
> >
> > According to Ilmari Karonen <usenet11446@itz.pp.sci.fi>:
>
> > Yes, that's one of the tenets of the Perl Order. I wonder how slices
> > used like
> >
> > $x = @y[ 0 .. 3];
> >
> > fit in. Unless we decide to postulate a list context to the right
> > of "=" for the slice all by itself, I wouldn't know how to call the
> > right side of the assignment, except a list in scalar context.
>
> Why not "an array slice in scalar context". It is the operation
> (slicing) that is put in context. There is no need to postulate a list
> context for the slice by itself since that presupposes that the
> operation will produce a list (which you then want to say is in scalar
> context).
[...]
Ah, this puts things into perspective. Context would be something
that modifies an operation, not the result of a somehow context-free
operation. Seen that way, a "list in scalar context" is indeed an
oxymoron, because no operation in scalar context returns a list (duh).
Thanks, I've seen the light.
Anno
------------------------------
Date: 6 May 2001 23:31:47 GMT
From: Billy Chambless <nospam@kremvax.su>
Subject: Re: The Canonical Program (was Re: I remember someone made a perl parser.)
Message-Id: <9d4mt3$144$1@news.datasync.com>
Keywords: troll, troll, troll
In article <9d27ec$dum$1@sloth.swcp.com>, Tramm Hudson <hudson@swcp.com> wrote:
>flash <bop@mypad.com> wrote:
>> ... read the file and do stuff ...
>Ah -- the canonical program:
>
> int main( int argc, char *argv[] )
> {
> read_input();
> do_stuff();
> write_output();
> }
>The Perl version is similar:
>
> #!/usr/bin/perl -w
> use strict;
> read_input();
> do_stuff();
> write_output();
> __END__
Depending on the input and output, this can often be written as:
#!/usr/bin/perl -wp
do_stuff();
or if you want to be really verbose, make that:
do_stuff($_);
I'm still waiting for
#!/bin/dwim
------------------------------
Date: Sun, 6 May 2001 22:47:22 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Trying to fill in a Pager Web page.
Message-Id: <slrn9fbl3q.ti0.abigail@tsathoggua.rlyeh.net>
Kathy Ramsey (ramseyk@home.com) wrote on MMDCCCV September MCMXCIII in
<URL:news:3AF5B214.12231392@home.com>:
<> I am trying to feed a pager # and message to www.arch.com - a pager web
<> site.
<> where do I begin!
By installing LWP.
Abigail
------------------------------
Date: 6 May 2001 23:35:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: UPPERCASE to "Sentence Case"
Message-Id: <9d4n4p$1l8$1@mamenchi.zrz.TU-Berlin.DE>
According to Andras Malatinszky <andras@mortgagestats.com>:
> Anno Siegel wrote:
> > According to Abigail <abigail@foad.org>:
> > > How you can parse sentences out of a text is a different matter, and
> > > beyond the scope of this group. Try alt.usage.english.
> >
> > ...who will be delighted to explain that there is no way to do that.
> >
> > Anno
>
> Actually, alt.usage.english is quite inappropriate for the "how do I recognize a
> sentence?" question because it has nothing to do with usage and very
> little to do with
> English. You may have more luck in sci.lang.
Quite true, and I'm sorry if I appeared to invite an off topic posting
to aue. On the other hand, I stand by the prediction that the regulars
there would tear to shreds the idea that you can automatically parse
sentences from an English text. Some might even show delight in doing
so :).
Anno
------------------------------
Date: Sun, 6 May 2001 23:39:11 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: UPPERCASE to "Sentence Case"
Message-Id: <slrn9fbo4v.fl.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCV September
MCMXCIII in <URL:news:9d4n4p$1l8$1@mamenchi.zrz.TU-Berlin.DE>:
-:
-: Quite true, and I'm sorry if I appeared to invite an off topic posting
-: to aue. On the other hand, I stand by the prediction that the regulars
-: there would tear to shreds the idea that you can automatically parse
-: sentences from an English text. Some might even show delight in doing
-: so :).
Then let me point out that the algorithm Knuth uses in TeX seldomly fails.
I've written entire articles without having to correct (La)TeX once on
determining end of sentences.
Abigail
--
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];
------------------------------
Date: 6 May 2001 23:59:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: UPPERCASE to "Sentence Case"
Message-Id: <9d4og8$2bu$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCV September
> MCMXCIII in <URL:news:9d4n4p$1l8$1@mamenchi.zrz.TU-Berlin.DE>:
> -:
> -: Quite true, and I'm sorry if I appeared to invite an off topic posting
> -: to aue. On the other hand, I stand by the prediction that the regulars
> -: there would tear to shreds the idea that you can automatically parse
> -: sentences from an English text. Some might even show delight in doing
> -: so :).
>
>
> Then let me point out that the algorithm Knuth uses in TeX seldomly fails.
> I've written entire articles without having to correct (La)TeX once on
> determining end of sentences.
I'll take your word. I suppose the algorithm makes use of the fact that
TeX is more structured than plain English text. I'm certain it profits
from the fact that Knuth's mind is more structured than average. This
is not something you do with a regex or two. For plain text the notion
of sentence breaks isn't always well defined, nor are the rules of
capitalization that apply.
Anno
------------------------------
Date: Mon, 7 May 2001 00:50:47 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: UPPERCASE to "Sentence Case"
Message-Id: <slrn9fbsb7.fl.abigail@tsathoggua.rlyeh.net>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCV September
MCMXCIII in <URL:news:9d4og8$2bu$1@mamenchi.zrz.TU-Berlin.DE>:
!! According to Abigail <abigail@foad.org>:
!! > Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCV September
!! > MCMXCIII in <URL:news:9d4n4p$1l8$1@mamenchi.zrz.TU-Berlin.DE>:
!! > -:
!! > -: Quite true, and I'm sorry if I appeared to invite an off topic posting
!! > -: to aue. On the other hand, I stand by the prediction that the regulars
!! > -: there would tear to shreds the idea that you can automatically parse
!! > -: sentences from an English text. Some might even show delight in doing
!! > -: so :).
!! >
!! >
!! > Then let me point out that the algorithm Knuth uses in TeX seldomly fails.
!! > I've written entire articles without having to correct (La)TeX once on
!! > determining end of sentences.
!!
!! I'll take your word. I suppose the algorithm makes use of the fact that
!! TeX is more structured than plain English text.
Since TeX is a system for typesetting (English) text, I do not understand
what you mean by this.
!! I'm certain it profits
!! from the fact that Knuth's mind is more structured than average. This
!! is not something you do with a regex or two. For plain text the notion
!! of sentence breaks isn't always well defined, nor are the rules of
!! capitalization that apply.
Granted, anything a bit more complicated than a regex or two is beyond the
capabilities of the far majority of the Perl programmers; but that doesn't
mean one cannot write an algorithm that is almost all the time right.
TeX proves such an algorithm exists. The TeX sources are freely available,
under one of the most free licenses you can imagine (basically "distribute
freely, don't change if you keep the name TeX, do whatever you fancy if
you call the result TeX"). So, I leave the translation of TeX's algorithm
to Perl as an exercise to the reader. ;-)
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: 7 May 2001 01:43:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: UPPERCASE to "Sentence Case"
Message-Id: <9d4ujo$673$1@mamenchi.zrz.TU-Berlin.DE>
According to Abigail <abigail@foad.org>:
> Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMDCCCV September
> MCMXCIII in <URL:news:9d4og8$2bu$1@mamenchi.zrz.TU-Berlin.DE>:
> !! According to Abigail <abigail@foad.org>:
[...]
> !! > Then let me point out that the algorithm Knuth uses in TeX seldomly fails.
> !! > I've written entire articles without having to correct (La)TeX once on
> !! > determining end of sentences.
> !!
> !! I'll take your word. I suppose the algorithm makes use of the fact that
> !! TeX is more structured than plain English text.
>
> Since TeX is a system for typesetting (English) text, I do not understand
> what you mean by this.
It wouldn't run unawares into pages containing a table of contents
and try to parse a sentence structure into that. It would know where
formulas are embedded and ignore punctuation inside. It knows a bit
(probably a crucial bit) about context that isn't available from a plain
ASCII representation[1].
[rest agreed to and snipped]
Anno
[1] You wouldn't stoop to pointing out that TeX is ASCII, would you?
------------------------------
Date: Mon, 07 May 2001 01:06:28 GMT
From: Dan <nospam@newsranger.com>
Subject: Re: UPPERCASE to
Message-Id: <oymJ6.3916$vg1.301213@www.newsranger.com>
In article <tf6e7c4n7aet56@corp.supernews.com>, Craig Berry says...
>
>This is very very *very* hard to do in the general case, given the
>potential vagaries of punctuation. If you're willing to accept the rule
>that any character other than one following start-of-file or a period (and
>whitespace) should be lowercase, this will work (assuming a read from
>standard input):
>
> my $text = lc do { local $/; <>; };
> $text =~ s/((^|\.)\s*\w)/\U$1/g;
This works relatively well, however, I don't want each new line to start
capitalized. Let's say I have this for my data:
---
348 PM CDT SUN MAY 6 2001
A STATIONARY FRONT...EXTENDING ACROSS ILLINOIS INTO
SOUTHERN INDIANA AND KENTUCKY...WILL TRIGGER SCATTERED SHOWERS
AND THUNDERSTORMS THIS EVENING.
---
I want the first A to remain capitalized, but I don't want the "s" in Southern
and the "a" in and to be capitalized. How could I modify the code to make this
work?
Thanks,
Dan
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 844
**************************************