[6680] in Perl-Users-Digest
Perl-Users Digest, Issue: 305 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 15 12:07:27 1997
Date: Tue, 15 Apr 97 09:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 15 Apr 1997 Volume: 8 Number: 305
Today's topics:
[Q] Returning an array of hashes <vegardb@knoll.hibu.no>
Re: [Q] Returning an array of hashes (RHS Linux User)
Re: [Q] Returning an array of hashes <tchrist@mox.perl.com>
[Q]about typeglobs and filehandles (Keiji yonezawa)
Re: [Q]about typeglobs and filehandles <tchrist@mox.perl.com>
Re: [Q]about typeglobs and filehandles (RHS Linux User)
Re: A simple substitution <tchrist@mox.perl.com>
AccessSeControl MS developer studio from perl p (Jingsong Li)
An extended e-mail parser <jast@ms.com>
Re: An extended e-mail parser (Eric D. Friedman)
formatting large numbers (David Waters)
Re: Get a week number from a file (Petr Prikryl)
Re: Limiting system use - Perl bombing system (Mik Firestone)
Re: limits of hashes/scalar? <tchrist@mox.perl.com>
Re: MailFolder installation problem (Kevin Johnson)
Re: Need a math program (Nathan V. Patwardhan)
Re: Need a math program <tchrist@mox.perl.com>
Re: OraPErl , DBD0.44 (John D Groenveld)
Re: Oraperl (John D Groenveld)
Passing How Do I Send Parseable values via the Command <richard.schlief@telops.gte.com>
Re: Passing How Do I Send Parseable values via the Comm <tchrist@mox.perl.com>
Re: Perl -e switch <tchrist@mox.perl.com>
Re: Perl -e switch <dorman@s3i.com.anti-spam>
Re: perl pattern matching (David Alan Black)
Re: POP3 perl script (Nathan V. Patwardhan)
Re: reading in password file (Eric D. Friedman)
Re: Reply to Ousterhout's reply (was Re: Ousterhout and (Brad Spencer)
Re: Reply to Ousterhout's reply (was Re: Ousterhout and <erik@naggum.no>
Sendmail Help <scsREMOVE@huron.net>
Serial Port and WIN32 <rhempel@log.on.ca>
Re: sorting a *file* (yeah, I know, it's a mainframe co <tchrist@mox.perl.com>
Re: sorting a *file* (yeah, I know, it's a mainframe co <seay@absyss.fr>
Re: uninitialized value warning? (David Alan Black)
Re: Unix and ease of use (WAS: Who makes more ...) (Steve Mading)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Apr 1997 16:40:07 +0200
From: Vegard Bakke <vegardb@knoll.hibu.no>
Subject: [Q] Returning an array of hashes
Message-Id: <33539347.3815@knoll.hibu.no>
I'm having problem with an array of hashes.
This example illustrates my problem.
Can someone tell me what's wrong?
-------------------------------
#!/opt/local/bin/perl -w
use strict;
use diagnostics;
sub Func ()
{
my(@A, %H, $I);
for($I=0; $I < 5; $I++) {
$H{'pos'} = $I;
$H{'neg'} = -$I;
$A[$I] = \%H;
print "Func: $I $A[$I]->{'pos'}\n";
}
return @A;
}
my(@Ar, $I);
@Ar = Func();
for ($I=0; $I <= $#Ar; $I++) {
print "main: $I $Ar[$I]->{'neg'}\n";
}
Running the script:
$ ./test.pl
Func: 0 0
Func: 1 1
Func: 2 2
Func: 3 3
Func: 4 4
main: 0 -4
main: 1 -4
main: 2 -4
main: 3 -4
main: 4 -4
Why is every tuppel in the array @Ar equal to the
last tuppel of @A? It gets the number of tupples right.
--
Vegard Bakke,
vegard.bakke@hibu.no
Kirkegata 9, 3600 Kongsberg, Norway
"My spelling is Wobbly. It's good spelling but it Wobbles,
and the letters get in the wrong places." -- Winnie the Pooh
------------------------------
Date: 15 Apr 1997 11:29:54 -0400
From: mike@localhost.localdomain (RHS Linux User)
Subject: Re: [Q] Returning an array of hashes
Message-Id: <5j06ti$217@localhost.localdomain>
In article <33539347.3815@knoll.hibu.no>,
Vegard Bakke <vegardb@knoll.hibu.no> wrote:
>I'm having problem with an array of hashes.
>This example illustrates my problem.
>Can someone tell me what's wrong?
>Why is every tuppel in the array @Ar equal to the
>last tuppel of @A? It gets the number of tupples right.
Because each time you say
$A[$I] = \%H;
you're putting a reference to the same hash into the element of @A, so all
of the elements refer to the same hash which contains the last values.
You can use the {} anonymous hash constructor to build a unique copy
of the contents of %H e.g.
$A[$I] = {%H};
or you could rewrite the function like this:
sub Func ()
{
my(@A, $I);
for ($I = 0; $I < 5; $I++) {
push @A, {'pos' => $I,
'neg' => -$I,
};
}
return @A;
}
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 15 Apr 1997 15:34:08 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: [Q] Returning an array of hashes
Message-Id: <5j075g$1ul$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Vegard Bakke <vegardb@knoll.hibu.no> writes:
:I'm having problem with an array of hashes.
:This example illustrates my problem.
:Can someone tell me what's wrong?
:{
: my(@A, %H, $I);
:
: for($I=0; $I < 5; $I++) {
: $H{'pos'} = $I;
: $H{'neg'} = -$I;
: $A[$I] = \%H;
: print "Func: $I $A[$I]->{'pos'}\n";
: }
:
Yes, the perldsc man page or Chapter 5 of the Camel would
have told you what's wrong with that:
Here's the case of taking a reference to the same memory location
again and again:
for $i (1..10) {
@list = somefunc($i);
$LoL[$i] = \@list; # WRONG!
}
So, what's the big problem with that? It looks right, doesn't it?
After all, I just told you that you need an array of references, so
by golly, you've made me one!
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Don't wear rollerskates to a tug-of-war." --Larry Wall
------------------------------
Date: 15 Apr 1997 09:42:12 GMT
From: keiji-y@is.aist-nara.ac.jp (Keiji yonezawa)
Subject: [Q]about typeglobs and filehandles
Message-Id: <5ivihk$b5f@fse3.aist-nara.ac.jp>
Page 51 of the new camel shows one example of opening a file
and returning its refelence of filehandle. But I don't know
how to dereference it. Following code doesn't work:
print while(<$fh>);
Would someone tell me the collect code?
Forgive my poor English. Thank you.
=========================================================
Keiji Yonezawa, NAIST
http://cactus.aist-nara.ac.jp/~keiji-y/
mailto:keiji-y@is.aist-nara.ac.jp
------------------------------
Date: 15 Apr 1997 14:34:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: [Q]about typeglobs and filehandles
Message-Id: <5j03m4$ck$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
keiji-y@is.aist-nara.ac.jp (Keiji yonezawa) writes:
:
: Page 51 of the new camel shows one example of opening a file
:and returning its refelence of filehandle. But I don't know
:how to dereference it. Following code doesn't work:
:
:print while(<$fh>);
:
:Would someone tell me the collect code?
Probably you said
return \*FH;
instead of
return *FH;
Which has been fixed in a recent printing.
It's probably best to use
use FileHandle;
$fh = FileHandle->new();
however.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
I've got plenty of inputs and outputs. I don't need the video. --Andrew Hume
------------------------------
Date: 15 Apr 1997 10:38:09 -0400
From: mike@localhost.localdomain (RHS Linux User)
Subject: Re: [Q]about typeglobs and filehandles
Message-Id: <5j03sh$1r3@localhost.localdomain>
In article <5ivihk$b5f@fse3.aist-nara.ac.jp>,
Keiji yonezawa <keiji-y@is.aist-nara.ac.jp> wrote:
>
> Page 51 of the new camel shows one example of opening a file
>and returning its refelence of filehandle. But I don't know
>how to dereference it. Following code doesn't work:
>
>print while(<$fh>);
>
>Would someone tell me the collect code?
There is a set of camel errata at
http://www.perl.com/perl/critiques/camelrata/
and in
http://www.perl.com/perl/critiques/camelrata/ch02.err
it says:
[*51*] Change
return \*FH;
to
return *FH;
Otherwise it's broken.
This works in recent perl 5.003xx versions.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 15 Apr 1997 13:53:24 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: A simple substitution
Message-Id: <5j018k$r3p$4@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
jeff@yoak.com (Jeff Yoak) writes:
:What is a good way to change the first letter of each word in a string
:to uppercase? I found my self sufficiently confused with s/// and
:tr/// that I ended up with:
:
:@lower = (a..z);
:foreach $letter (@lower) {
: $upper = $letter;
: $upper =~ tr/a-z/A-Z/;
: $line =~ s/\b$letter/$upper/g;
:}
:
:Somehow, this just seems morally wrong. There must be a better way.
Yup, that's nuts. Remember you can use tr on a whole line:
$line =~ tr/a-z/A-Z/;
or more nicely written
$line =~ tr[a-z][A-Z];
Although this isn't just the first letter, so that's not quite
what you want either.
You know something, USING tr/// FOR CASE TRANSLATION IS WRONG!
To see this kind of thing written really annoys me. And it doesn't
make my cousin Renie or the Caqon City Chamber of Commerce very happy.
Face it, anything that's seven-bit only is a naove fagade that won't
hold up in the real world of even writing English properly, and you
don't have to be an ilitist with a learnhd bent to realize this.
This will do what you want better, I believe:
s/\b(\w)/\u$1/g;
and won't screw up on the words that aren't 7-bit only. (You may
need 'use locale' in 5.004, though it works fine currently.)
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
You know, by the time you get done with all this, the "Swiss Army
Chainsaw" is going to be more like a Swiss Army Tactical Nuke.... :-)
--Brandon Allbery on perl in <1991Feb21.002412.20045@NCoast.ORG>
------------------------------
Date: 14 Apr 1997 19:16:58 -0400
From: li@xl.home.office (Jingsong Li)
Subject: AccessSeControl MS developer studio from perl possible? By oOLE or others?
Message-Id: <5iudta$8qj$1@xl.home.office>
Hi,
I am not sure I ask right question:
Can we use oleauto or other method in perl to control MS Developer Studio?
What I want to do is similar to what VB script can do.
Thanks.
Jingsong Li
PS: is there any command line version of MS Developer Studio? If yes, how?
------------------------------
Date: Tue, 15 Apr 1997 10:48:30 -0400
From: Peter Jastreboff <jast@ms.com>
Subject: An extended e-mail parser
Message-Id: <3353953E.41C67EA6@ms.com>
Hi,
I am trying to write an e-mail parser which will take emails sent to
an predefined id and do the following.
1. separate and sort the subject information.
2. take the main message body and post it in an HTML file.
3. Allow differnt parameters to sort the Subject information.
I have a good handle on how to Subject informatin, however, I am having
trouble parsing out the message body and then sending it to and HTML
file. Any ideas or example scripts I could follow?
Thanks,
Hut
------------------------------
Date: 15 Apr 1997 15:31:32 GMT
From: friedman@medusa.acs.uci.edu (Eric D. Friedman)
Subject: Re: An extended e-mail parser
Message-Id: <5j070k$knu@news.service.uci.edu>
[mailed, posted]
In article <3353953E.41C67EA6@ms.com>, Peter Jastreboff <jast@ms.com> wrote:
>
>I have a good handle on how to Subject informatin, however, I am having
>trouble parsing out the message body and then sending it to and HTML
>file. Any ideas or example scripts I could follow?
Look into MHonArc.
http://www.oac.uci.edu/indiv/ehood/
See the section "Earl's perls" and find the link to MHonArc.
--
Eric D. Friedman
friedman@uci.edu
------------------------------
Date: 15 Apr 1997 15:13:03 GMT
From: przec@westminster.ac.uk (David Waters)
Subject: formatting large numbers
Message-Id: <5j05tv$b3s@badger.wmin.ac.uk>
Hello all,
If I have a price say over 999 , e.g.
1000.87 or 1345.65 or 5467.00 how do I format so -
1,000.87 1,345.65 and 5,467.00 .
Thanx alot
David
--
\\\|///
\\ - - //
( @ @ )
+----------------oOOo-(_)-oOOo----------------------+
| David Waters Email: d.w.waters@wmin.ac.uk |
| |
| World Wide Web: http://www.wmin.ac.uk/~przec |
+-------------------------Oooo----------------------+
oooO ( )
( ) ) /
\ ( (_/
\_)
------------------------------
Date: 15 Apr 1997 06:48:50 GMT
From: prikryl@dcse.fee.vutbr.cz (Petr Prikryl)
Subject: Re: Get a week number from a file
Message-Id: <5iv8ci$4va$1@boco.fee.vutbr.cz>
Nathan V. Patwardhan (nvp@shore.net) wrote:
>John Jiang (jiangj@bnr.ca) wrote:
>: How can I get a week number of the time when a file is
>: created. The week number would be something like what we got from
>: shell "date -u +%W". Thanks.
>You can't get the creation date of a file, but you can get last-modified,
>date, etc., which are explained in perlfunc.pod in the section dealing
>with stat().
...and then you can convert using localtime(). You will obtain also the
day in the week as 0..6 number and the day in the year. You have to calculate
week number yourself (probably some package does this).
--
Petr Prikryl (prikryl@dcse.fee.vutbr.cz) http://www.fee.vutbr.cz/~prikryl/
TU of Brno, Dept. of Computer Sci. & Engineering; tel. +420-(0)5-7275 218
------------------------------
Date: 15 Apr 1997 14:09:42 GMT
From: mfiresto@vnet.ibm.com (Mik Firestone)
Subject: Re: Limiting system use - Perl bombing system
Message-Id: <5j0276$lla$1@mail.lexington.ibm.com>
In article <5iu443$rmb$1@nntp.ucs.ubc.ca>,
Andrew Daviel <andrew@andrew.triumf.ca> wrote:
[snip]
>on a Linux system. When the logfile got too large before being reset
>at the end of the week, the system bombed (every night at 04:26-ish)
[snip]
(Cross posts trimmed).
The behaviour you describe sounds like a problem I have had. There is a
snippet of code that is in the FAQ, and gets posted frequently that uses
_bm_build, bm_and and bm_or ( as I remember ). Are you using these
functions? If you are, I would suggest starting with those. I ground a
few servers to a halt before I figured it out. It is a result of the
closure tricks these programs use.
As a closure "pretends to run in that context" [Camel, pg 253], I assume (
and please note, this is mainly guessing from behaviour and reading a great
deal into a few lines ) that it is saving large portions of the program
state in memory. Which is okay if you use closure a few times in a given
program. But once you start using it many times ( I found my threshold to
be around 1000 times ), and each time you are saving state information, it
will take an impressive amount of memory.
To give any more help, it would be nice to see the code. Post it, or email
it to me and I will be happy to help.
Htth,
-----
Mik Firestone mfiresto@mindspring.com
Evil Overlord Rule #36: My pet monster will be kept in a secure cage
from which it cannot escape and into which I could not accidentally
stumble.
------------------------------
Date: 15 Apr 1997 15:10:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: limits of hashes/scalar?
Message-Id: <5j05pa$1ul$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Hans.Suijkerbuijk@SD.BE writes:
:Are there limits to the size of hashes/scalars?
No, but there may be limits in the database.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Perl5, surprisingly, makes it very easy to do OO programming. I suspect
that it does this much better than Larry ever intended."
--Dean Roehrich in <1994Oct5.140720.1511@driftwood.cray.com>
------------------------------
Date: 15 Apr 1997 07:22:01 -0700
From: kjj@primenet.com (Kevin Johnson)
Subject: Re: MailFolder installation problem
Message-Id: <5j02u9$jms$1@nnrp01.primenet.com>
Santiago Alvarez Rojo <santiago@gambito.com> wrote:
>Hi, I'm trying to install MailFolder0.06 and when I do 'make test', it
>complains about a MIME method: header (see log below). I've previously
>installed MIME-parser-1.13, isn't this the last version?
>Ps. email reply will be appreciated
[test output snipped]
I'm posting something because several folks have reported this
problem to me via email.
I forgot to put a dependancy in the Makefile.PL for MIME-tools-3.204.
Installing MIME-tools-3.204 will rectify the problem.
The next version of MailFolder will have the dependancy listed.
--
thx,
kjj@pobox.com http://www.pobox.com/~kjj/
------------------------------
Date: 15 Apr 1997 13:43:02 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Need a math program
Message-Id: <5j00l6$2fb@fridge-nf0.shore.net>
netwatch@ix.netcom.com wrote:
: I need a perl program that will add.sub, multi, amd div. numbers.
: It must have 3 levels of difficulty. Level 1 use numbers from 1 to 5,
: level 2 use numbers from 1 to 20, and level 3 use numbers from 1 to
: 50.
Okay, I need a commitment of $500 (level 1), 20 easy payments of $100
(level 2), and 3 final payments of $100 (level 3). :-)
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 15 Apr 1997 15:05:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Need a math program
Message-Id: <5j05gm$1ul$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
netwatch@ix.netcom.com writes:
:I need a perl program that will add.sub, multi, amd div. numbers.
:It must have 3 levels of difficulty. Level 1 use numbers from 1 to 5,
:level 2 use numbers from 1 to 20, and level 3 use numbers from 1 to
:50.
:I also need a perl program that can be use as a address book. It must
:have name and phone number fields
Why do I feel like I'm being accosted by a streetperson trying to
get spare change out of me plus a hitched ride to San Diego?
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"... an initial underscore already conveys strong feelings of
magicalness to a C programmer."
--Larry Wall in <1992Nov9.195250.23584@netlabs.com>
------------------------------
Date: 15 Apr 1997 11:08:19 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: OraPErl , DBD0.44
Message-Id: <5j05l3$ihk$1@tholian.cse.psu.edu>
In article <natarajE8M3o5.7J3@netcom.com>, nataraj <nataraj@netcom.com> wrote:
>I am trying to use OraPerl/DBD0.44 stuff to access
>an ORACLE database.
Cool.
>Can experts let me know whether the above modules
>support stored procedure calls with IN & OUT
>parameters.
Yes. See test.pl in the distribution. This is FAQ, so take a look at the
dbi-users archive at
http://www.rosat.mpe-garching.mpg.de/mailing-lists/PerlDB-Interest/
>A quick repsonse to me email acct(nataraj@netcom.com)
>would be greatly appreciated.
Usenet is not a very fast medium. In general, if you want emailed replies
then you should do your fair share to save the world and offer to summarize.
I've CC'd you.
Happy Perl'ng
John
groenvel@cse.psu.edu
------------------------------
Date: 15 Apr 1997 11:20:30 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Oraperl
Message-Id: <5j06bu$o21$1@tholian.cse.psu.edu>
Oh no. You need to upgrade to Perl5, DBI/DBD-Oracle with the Oraperl emulation
module. You wont find much support for Perl4 or any of its extensions.
See http://www.perl.com/perl/ for details about Perl5. See the archive of this
newsgroup at http://www.dejanews.com/ for similar posts.
> if (($address) = &ora_fetch($csr))
This returns one row from your cursor. You need to use a while loop instead.
Good luck,
John
groenvel@cse.psu.edu
------------------------------
Date: Tue, 15 Apr 1997 10:37:54 -0400
From: Richard Schlief <richard.schlief@telops.gte.com>
Subject: Passing How Do I Send Parseable values via the Command Line
Message-Id: <335392C2.6915@telops.gte.com>
Whenever I write pl scripts I always have the HTML form already
developed. I have a need where I will have the script before the HTML
form and I need to be able to pass the standard HTML STDIN info on the
command line. What is the syntax for that?
--
------------------------------------<><---
-- Richard Schlief
-- richard.schlief@telops.gte.com
-- GTE Data Services (813) 978-4457
------------------------------
Date: 15 Apr 1997 15:27:37 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Passing How Do I Send Parseable values via the Command Line
Message-Id: <5j06p9$1ul$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
richard.schlief@telops.gte.com writes:
:Whenever I write pl scripts I always have the HTML form already
:developed. I have a need where I will have the script before the HTML
:form and I need to be able to pass the standard HTML STDIN info on the
:command line. What is the syntax for that?
What does this have to do with Perl? Perl != CGI. Are you aware that
there are newsgroups for CGI and HTML issues? I can't swear that your
question isn't Perl-related, but it sure smells like a CGI question,
which quite frankly, are seldom well-received in these parts.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
#define NULL 0 /* silly thing is, we don't even use this */
--Larry Wall in perl.c from the v4.0 perl source code
------------------------------
Date: 15 Apr 1997 13:36:31 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl -e switch
Message-Id: <5j008v$r3p$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Chris Andrew <earl@bell.us> writes:
:Where do I find *larger* examples of the use of the -e (command-line)
:switch in Perl?
:
:The most extensive explanation I have found (1 line long) is in Learning
:Perl side 191 and does not help me much.
I don't know how big you want it.
# run contents of "my_file" as a program
perl my_file
# run debugger "stand-alone"
perl -d -e 42
# run program, but with warnings
perl -w my_file
# run program under debugger
perl -d my_file
# just check syntax, with warnings
perl -wc my_file
# useful at end of "find foo -print"
perl -nle unlink
# simplest one-liner program
perl -e 'print "hello world!\n"'
# add first and penultimate columns
perl -lane 'print $F[0] + $F[-2]'
# just lines 15 to 17
perl -ne 'print if 15 .. 17' *.pod
# in-place edit of *.c files changing all foo to bar
perl -p -i.bak -e 's/\bfoo\b/bar/g' *.c
# command-line that prints the first 50 lines (cheaply)
perl -pe 'exit if $. > 50' f1 f2 f3 ...
# delete first 10 lines
perl -i.old -ne 'print unless 1 .. 10' foo.txt
# change all the isolated oldvar occurrences to newvar
perl -i.old -pe 's{\boldvar\b}{newvar}g' *.[chy]
# command-line that reverses the whole file by lines
perl -e 'print reverse <>' file1 file2 file3 ....
# find palindromes
perl -lne 'print if $_ eq reverse' /usr/dict/words
# command-line that reverse all the bytes in a file
perl -0777e 'print scalar reverse <>' f1 f2 f3 ...
# command-line that reverses the whole file by paragraphs
perl -00 -e 'print reverse <>' file1 file2 file3 ....
# increment all numbers found in these files
perl i.tiny -pe 's/(\d+)/ 1 + $1 /ge' file1 file2 ....
# command-line that shows each line with its characters backwards
perl -nle 'print scalar reverse $_' file1 file2 file3 ....
# delete all but lines beween START and END
perl -i.old -ne 'print unless /^START$/ .. /^END$/' foo.txt
# binary edit (careful!)
perl -i.bak -pe 's/Mozilla/Slopoke/g' /usr/local/bin/netscape
# look for dup words
perl -0777 -ne 'print "$.: doubled $_\n" while /\b(\w+)\b\s+\b\1\b/gi'
# command-line that prints the last 50 lines (expensively)
perl -e '@lines = <>; print @lines[ $#lines .. $#lines-50' f1 f2 f3 ...
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
There are probably better ways to do that, but it would make the parser
more complex. I do, occasionally, struggle feebly against complexity... :-)
--Larry Wall in <7886@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 15 Apr 1997 09:35:28 -0400
From: Clark Dorman <dorman@s3i.com.anti-spam>
Subject: Re: Perl -e switch
Message-Id: <dohbg1k9r.fsf@s3i.com>
Chris Andrew <earl@bell.us> writes:
> I have a nagging question that has been on my mind for quite some time,
> but that the man pages and FAQ do not seem to address.
>
> Where do I find *larger* examples of the use of the -e (command-line)
> switch in Perl?
>
> The most extensive explanation I have found (1 line long) is in Learning
> Perl side 191 and does not help me much.
-e commandline
may be used to enter one line of script. If -e is given, Perl will
not look for a script filename in the argument list. Multiple -e
commands may be given to build up a multi-line script. Make sure to
use semicolons where you would in a normal program.
I've only used -e during single line things. Why would you want to
have it be more than one line long? Ok, maybe two, and then you use -e
more than once. If it's more than one line, just fire up vi (blech)
or pop up emacs and save it for posterity.
--
Clark Dorman "Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html -Francis Crick
------------------------------
Date: 15 Apr 1997 14:27:28 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: perl pattern matching
Message-Id: <5j038g$mbe@pirate.shu.edu>
dblack@icarus.shu.edu (David Alan Black) writes:
>sub string { "<ARTTIT>title-1</ARTTIT><LID>text1<LIST> ...
...
>{'one' => '$a = &string; $a =~ s|<LID>.+?</LID>||g;',
Ummm, slight overkill on the cutesy syntax there.... A case
of starting out too complicated and never quite recovering. Feel
free to make it sane :-)
David Black
dblack@icarus.shu.edu
------------------------------
Date: 15 Apr 1997 13:40:18 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: POP3 perl script
Message-Id: <5j00g2$2fb@fridge-nf0.shore.net>
Generic Blues (root@gblues.grey.org) wrote:
: I want to write a perl script that will make a connection to a POP3
: server, login, etc. and grab any new mail I have and move it to
: /var/spool/mail. While I can handle most of this, what I don't know how to
Ah, then you're looking for Net::POP3 or Mail::POPClient available
at a CPAN near you! From my experience, you'll have to do a bit
more client-wise to get Net::POP3 working for your tastes, but it's
not all very difficult if you read the POD for the return values
of each function.
--
Nathan V. Patwardhan
nvp@shore.net
------------------------------
Date: 15 Apr 1997 14:39:01 GMT
From: friedman@medusa.acs.uci.edu (Eric D. Friedman)
Subject: Re: reading in password file
Message-Id: <5j03u5$j6r@news.service.uci.edu>
[mailed, posted]
In article <5iu3r4$7jg@news.fsu.edu>, Justin C Lloyd <lloyd@cs.fsu.edu> wrote:
>Anyway, to make a long story short, here is the function I came up with:
>sub read_password_file {
> my @entry = ();
> my @pwfile = ();
> while (@entry = getpwent) {
> my @pwent = @entry; # Why is this here? - edf
> push @pwfile, \@pwent;
> }
> return @pwfile;
>}
>
>Is there a way to make it more efficient? Also, would it be better to return
>the array or a reference to the array?
return a reference to the array. That said, I don't see why you need
@pwent in your code at all:
sub read_password_file {
my @entry = ();
my @pwfile = ();
while (@entry = getpwent) {
push @pwfile, \@entry;
}
return \@pwfile;
}
Getting rid of @pwent is small potatoes, but returning a reference instead
of a giant list from your function should make a significant difference.
HTH,
Eric
--
Eric D. Friedman
friedman@uci.edu
------------------------------
Date: 15 Apr 1997 13:46:39 GMT
From: bspencer@bassun.perfect.att.com (Brad Spencer)
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <BSPENCER.97Apr15094639@bassun.perfect.att.com>
On Thu, 10 Apr 1997 09:08:06 +1000, Graham Matthews
<graham.matthews@maths.anu.edu.au> wrote:
>What rubbish. You can train people to use a modern language just like
>you can and do train them to use an older language. The "oh these new
>languages are too hard to learn for Joe average programmer" just doesn't
>stand up. How can a language with no pointers, no explicit memory
>alloc/dealloc, etc be harder to learn than one where you have to do all
>that yourself ...
Remember LOGO; a LISP derivative used for teaching youngsters to
program...
ABW
--
"Plug and Play support: WfEWAD will autodetect any installed
Nuclear Arsenals, Laser Satellites, Battlefield Control Networks,
Radar Installations, Fighter Squadrons, and other WfEWAD compliant
devices, including the new Macrosoft Unnatural Keyboard, with
full support for the now-famous Big Red Buttom(tm)."
(Windows for Early Warning and Defence User's manual P26)
Alaric B. Williams Internet : alaric@abwillms.demon.co.uk
<A HREF="http://www.abwillms.demon.co.uk/">Hello :-)</A>
Hmmmm...
I think that this was later. I seem to recall that the original goal
of LOGO was to control a robot arm [at, I believe, MIT].
Brad Spencer - bspencer@bassun.netminder.lucent.com [work]
bspencer@lucent.com [more work]
brad@anduin.eldar.org http://anduin.eldar.org [home]
------------------------------
Date: 15 Apr 1997 14:32:39 +0000
From: Erik Naggum <erik@naggum.no>
Subject: Re: Reply to Ousterhout's reply (was Re: Ousterhout and Tcl ...)
Message-Id: <3070103559376281@naggum.no>
* John Ousterhout
| Unfortunately, it isn't really possible to sustain a coherent debate on a
| hot topic via unmoderated newsgroups. The discussion very quickly
| fragments into dozens of sub-topics that drift off the main thread of
| discussion.
it might be instructive to consider which measures are used in "real life"
to maintain coherent debates in a cacophony of protests and more or less
valid arguments. in my experience, the primary measure is for those who
wish to maintain the coherent debates to focus _only_ on the best parts of
the discussion. those who do not wish to maintain any coherent debates are
the first to complain that _others_ don't and that they, therefore, can't
reign in the crowds or just speak their minds without some authority figure
like a moderator. if you complain about the noise, you _are_ the noise.
life in general _is_ noise. intelligence is filtering out the information
from the plethora of irrelevancies that bombards us. USENET is an amazing
experiment in how people choose to think when they have to _recreate_ the
opinions and arguments of others by _reading_ and _interpreting_ them in
their own minds. some see only ad hominem arguments (and most of those who
do seem to be ignorant of what "argumentum ad hominem" actually means),
while others see technical debates with lots of emotions in the argumetns,
and focus on the technical issues. e.g., if one writes "you'd have to an
idiot to argue that point", some will read this as "he called him an idiot"
while others will read it as "he's fed up with ignorant spluts who can't
even bother to do their homework", while yet others will read it as "in his
mind, that point is an absolute" and decide how to read his other points
based on whether it really is a settled issue or not. there's an old adage
that goes something like this: "be careful of whom you allow to insult you".
of course, there are also liars and frauds on the Net, like everywhere
else. I think this is a relevant character issue insofar as one points out
that people do not argue truthfully. if someone has a hidden agenda, it
should be brought out in the open for others to see. untruthfulness is not
an argumentum ad hominem if it is the _arguments_ that are untruthful.
| I'm too swamped to respond to each of the hundreds of arguments that have
| been made (many of which do have merit), and if I did, each of those
| responses would generate 30 more counter-responses that would be even
| harder to respond to.
no wonder you're swamped -- you choose to be! most of us learn to deal
with noise-makers pretty fast and to ignore them. if you don't, of course
you're going to run into all sorts of problems. this is what focus and
concentration is all about. barring, of course, the reduced cognitive
abilities of mild schizophrenia or attention deficit disorder, but there's
no reason to expect such in somebody who can focus long enough to get _any_
product out the door and complete a serious academic carreer.
I've seen you respond with ridicule to lots of arguments. that would be OK
only if one was in a well-established position of superiority. such has
_not_ been established by you. ridiculing an opponent is a very dangerous
rhetorical technique -- if the opponent is proven right and ignores the
ridicule to continue to hammer down his points, he who has committed the
ridicule is left as the laughing stock. right now, I'm having the distinct
impression that you have left yourself in a very unenviable position by
ridiculing only the most incoherent of your critics, ignoring lots of
coherent arguments, and then arguing that you're swamped! by not answering
technical points and instead turning to rhetorical tricks, you have
yourself contributed to the voluminous flow of irrelevancy.
| Or, look at it this way: if I don't respond then you get the last word :-)
I wish you could be serious a little more than you seem to want to be. if
you were as superior to your critics as you seem to think you are, it would
not have been a problem to debunk the serious arguments without smileys or
ridicule. of course, it is possible to be superior to one's critics and
use smileys and ridicule, but then it would not behoove one to complain
that others aren't presenting serious technical arguments.
#\Erik
--
I'm no longer young enough to know everything.
------------------------------
Date: 15 Apr 1997 14:40:08 GMT
From: "Stephen Hill" <scsREMOVE@huron.net>
Subject: Sendmail Help
Message-Id: <01bc49aa$3f29c020$1791e9cd@garcia.huron.net>
I want to be able to force Sendmail to accept the headers I specify, it
will accept some of them but not the return-path and From.
Anyone know where I can find Help on this?
Thanks.
--
Stephen Hill
scsREMOVE@huron.net
To email me just take the REMOVE outta the line above.
Getting really ticked at these Spammers!!!
------------------------------
Date: Tue, 15 Apr 1997 10:18:59 -0500
From: Ralph Hempel <rhempel@log.on.ca>
Subject: Serial Port and WIN32
Message-Id: <33539C63.66AD@log.on.ca>
I know, I know.....
How do I get my PC running WIN32 to talk to the serial port?
The suggestions in the FAQ do not work. COM1 is reserved and
opened, but nothing is received by the PERL program.
Please don't answer with "You should get a real operating system" :-)
I have looked through DejaNews for answers but can't find them.
Cheers, Ralph
------------------------------
Date: 15 Apr 1997 14:38:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: sorting a *file* (yeah, I know, it's a mainframe concept)
Message-Id: <5j03sf$ck$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
dblack@icarus.shu.edu (David Alan Black) writes:
:sub namesort {
: my ($an, $al, $af) = split /\s+/, $a;
: my ($bn, $bl, $bf) = split /\s+/, $b;
: ($al cmp $bl) or ($af cmp $bf) or ($an <=> $bn); # for identical names :-)
:}
Try it on a thousand records, and you'll see why that should be
a Schwartzian Transform or equivalent. You want 2*n*log(n) splits,
or just n of them?
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
Every program has at least one bug and can be shortened by at least one
instruction --from which, by induction, one can deduce that every
program can be reduced to one instruction which doesn't work.
------------------------------
Date: Tue, 15 Apr 1997 17:30:35 +0100
From: Douglas Seay <seay@absyss.fr>
To: Michael <dbambw@panther.gsu.edu>
Subject: Re: sorting a *file* (yeah, I know, it's a mainframe concept)
Message-Id: <3353AD2B.541A@absyss.fr>
Michael wrote:
>
> Hi all,
>
> I am in the process of re-writing some of our COBOL programs in
> perl. In one of these, I need to sort a file of records. Each
> rec might have 10 or 12 fields in it, the fist three being a 5 digit
> workorder number, followed by a last name then a first name.
>
> The records come in in workorder number, and I need to sort them to
> an outfile in lastname/firstname sort order.
>
> All the sorting methods in perl seem to be set up to handle associative
> arrays (ie ONE key field, ONE data field). I don't see how a *record*
> (in the mainframe meaning) could be set up as an assoc array, but I
> can't figure out how to *sort a file* (again in the mainframe concept).
You don't say what platform you're on. If it is some flavor of unix,
try "man sort" because it is a standard tool for sorting files.
> So how 'bout it, any other ex-COBOLers out there?:-)
What makes this so COBOL specific? I did it all the time in VM/CMS by
having REXX call sortfile. I use the unix sort from time to time with
shell scripts. I'd say that a sorted file is a valid technique in any
language.
- doug
------------------------------
Date: 15 Apr 1997 14:09:44 GMT
From: dblack@icarus.shu.edu (David Alan Black)
Subject: Re: uninitialized value warning?
Message-Id: <5j0278$jtu@pirate.shu.edu>
lloyd@cs.fsu.edu (Justin C Lloyd) writes:
>I am receiving the following warning 1648 times (when using the -w option):
> Use of uninitialized value at ROSTERS.pm line 122, <FP> chunk 7.
>$pwref is a reference to an array containing 849 (1/2 of 1648) password file
>entries. The code works fine, all it does is look through the password file
Well, for what it's worth, 1648/2 == 824, not 849. I would guess
that it all has something to do with people who don't have middle
initials, especially if there are 824 of them....
David Black
dblack@icarus.shu.edu
------------------------------
Date: 15 Apr 1997 10:32:11 -0500
From: madings@earth.execpc.com (Steve Mading)
Subject: Re: Unix and ease of use (WAS: Who makes more ...)
Message-Id: <5j071r$530$1@earth.execpc.com>
Tim Behrendsen (tim@a-sis.com) wrote:
: Steve Mading <madings@earth.execpc.com> wrote in article
: <5ishq7$slr$1@earth.execpc.com>...
: > Tim Behrendsen (tim@a-sis.com) wrote:
: >
: > : Hm; compare PKZIP and gzip (PKZIP includes the gzip algorithm, I
: > : believe). PKZIP includes support for multiple files, spanning
: > : multiple floppies, and a zillion other features.
: >
: > All of which are unnessacery on the Unix systems for which gzip
: > was intended. That's "tar"'s job.
: I understand that, and it's a lot less flexible that way. Can
: "tar | gzip" span multiple floppies? No, unless you tar it
: again after you make the file (assuming your tar supports the
: feature). Can I replace files within an archive? Can I extract
: one file without having to stream the whole silly file?
Use 'split' to cut up any one file into pieces. Therefore something
like 'tar | gzip | split' gives you multiple disk spanning (yes, I
have done this) The inverse operation is 'cat | gunzip | tar'.
Admittedly, this is not as easy as PKzip's way - but the advantage is
that the tools involved ('split') can be used for other stuff too.
Replace files in an archive: - I don't know because I've never had to
try to do this. (Pkzip or Gzip).
Extract one file without streaming the whole thing: How do you know
that pkzip does this? all you know is that you ask for a particular
file and pkzip finds it in the archive - you don't know whether or
not it reads from the beginning of the archive to do this (unless
you worked for Pkware and wrote it.) I do know that 'tar' can extract
just one file, or just one 'tree' of directories from a certain root,
but it has to scan from the beginning of the tar file to find it (this
is very quick unless the tar file is on a tape).
Oh, and can pkzip archive to tape or other non-disk devices? With
Unix's everything-is-a-file sytesm, 'tar' can. I even remember
once using tar + gzip to send a large directory tree from one
linux machine to another via a null modem cable on the parallel
ports. On the sender I did a 'tar | gzip > the_parallel_device',
and on the receiver I did a 'cat the_parallel_device | gunzip | tar'
: And it's also extremely fragile. One corrupted byte and the
: rest of the file is trash. With a reasonable tool like pkzip,
This I admit is true. Never had it happen though. But to be fair,
the messed up bit has to be in just the right spot. Otherwise
you only corrupt that file in the extraction. The real problem comes
when bytes are missing or extra bytes are added. This is what
hoses a tar file, because the tar format uses the filesize in bytes
to determine where the next file in the archive starts.
: you can often access files even if part of it is corrupt, and
: sometimes even rebuild the directory structure.
: Or how about self-extracting archives?
A nice thing if you don't mind limiting yourself to one machine
archetecture. (Imagine trying to run a self-extracting exe on
Windows NT on a non-intel box like Alpha.) The Unix community
does not want this feature since the Unix community has zillions
of different archetectures to pass files between. Since gzip
came from Unixy people - it has no self-extracting exe format.
This has nothing to do with it being free and everything to do
with it being from Unix.
: Don't get me wrong; I use the tar-gzip combination quite often,
: but it's inferior as a tool compared to archive tools, particularly
: in combination with something like WinZip.
I admit that pkzip has advantages over tar/gzip.
I showed you many ways that tar/gzip has advantages over pkzip too.
This is yet another example of why it is impossible to come up
with a tool that is 'better than the rest, bar none'. Regardless
of whether a tool is commercial or not. It's like trying to ask
someone, "What's better, a Porsche or a dump truck?" Depends on
what you are using it for, doesn't it?
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 305
*************************************