[10832] in Perl-Users-Digest
Perl-Users Digest, Issue: 4433 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 15 22:07:32 1998
Date: Tue, 15 Dec 98 19:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 15 Dec 1998 Volume: 8 Number: 4433
Today's topics:
Re: 'pipe' an 8-bit file (Tad McClellan)
Re: Can standard Perl functions be overloaded ? <zenin@bawdycaste.org>
Re: Can standard Perl functions be overloaded ? <perl@nullspace.com>
can't write file under NT (need help) <jbon@hotmail.com>
Re: Complicated sorting problem <uri@sysarch.com>
Re: Decent Editor <schuette@umr.edu>
Re: Eval vs. Subroutine? (Matthew Bafford)
Re: Formatting Numbers <ajohnson@gatewest.net>
Re: Hashref Compatibility with Perl 4.0 -- TIA <andy@focus-consulting.co.uk>
Re: Hashref Compatibility with Perl 4.0 -- TIA (Martien Verbruggen)
Help: File size weirdness with db's (Perry Friedman)
Re: How can I compare files? (muzo)
Re: how do I do this common text import task? (Tad McClellan)
Re: how do I do this common text import task? (Larry Rosler)
Re: How to extract emails from HTML page dturley@pobox.com
Re: How to extract emails from HTML page <schuette@umr.edu>
Re: How to extract emails from HTML page (Larry Rosler)
Re: Need some speed tips on this script.. (Tad McClellan)
Re: Need some speed tips on this script.. <uri@sysarch.com>
Re: NEWBIE! - need help with sar output on UNIX and per (Tad McClellan)
Re: Origin of 'local'? (Mark-Jason Dominus)
Re: Pipe docs (basic) (Tad McClellan)
Re: problem with grep and readdir for subdirectories (Martien Verbruggen)
Re: problem with grep and readdir for subdirectories <perl@nullspace.com>
Problem with script "... cgi-bin\signup.pl' script prod (CareerMngr)
Re: Question about NT (newbie) <perl@nullspace.com>
Re: Question about NT (newbie) (Larry Rosler)
Re: Trying to get all directories recursively (Tad McClellan)
Re: Trying to get all directories recursively (Christopher Parent)
Re: Trying to get all directories recursively (Martien Verbruggen)
Re: Trying to get all directories recursively <kprice@cardinal.co.nz>
Re: Why Is Perl not a Language? <perl@nullspace.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 15 Dec 1998 18:17:45 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: 'pipe' an 8-bit file
Message-Id: <97u657.n0e.ln@magna.metronet.com>
Earl Childers (childers@acns.fsu.edu) wrote:
: I asked around locally about the following:
You should strive to expand your circle of Perl advisors somewhat ;-)
: Using PERL, how can I 'pipe' a binary (8-bit) file to standard out?
^^^^
^^^^
Perl is used to refer to the language proper
perl is used to refer to the compiler/interpreter
PERL is not used ;-)
I dunno what you mean by that 'pipe' part.
Did you meant to say:
"how can I output a binary file to standard out?"
??
: ********
: Here's the answer I got:
: open(FILE, "location/of/file");
The open() might fail.
Better to stop gracefully rather than plow on and try to
read the unopened filehandle:
open(FILE, 'location/of/file') ||
die "could not open 'location/of/file' $!";
I don't like to use double quotes when I don't need/want the
extra things that double quotes give you (variable interpolation
and backslash escapes)
: while($line = <FILE>) {
: print $line;
: }
: The only thing you would change in that example is the location of the file
: (leave in the " ").
I would change the " " to ' ' ;-)
I would also check the return value from all open() calls.
: **********
: I'd like to know if that's how I'd do it with a plain text file
That will work fine, unless you cannot open the input file
for some reason.
: and is it
: also a good way to do it for a
: binary (8-bit) file that may not have any end-of-line (CRLF) markers?
It is Not So Good for that.
Will perhaps work, but may suck in the entire file and execute
the loop only once. That would be a problem if the file is
truly large (compared to available virtual memory).
Have a look at read() or even sysread() in the perlfunc man
page.
If you are on M$ then see also binmode().
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Dec 1998 02:31:10 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Can standard Perl functions be overloaded ?
Message-Id: <913775594.164580@thrush.omix.com>
Sean McAfee <mcafee@pacman.rs.itd.umich.edu> wrote:
: In article <913686321.510810@thrush.omix.com>,
: Zenin <zenin@bawdycaste.org> wrote:
: > use subs 'open(*$)';
: > sub open (*$) { ... }
:
: It's nice that this works, but how the heck *does* it work?
I have no idea actually. I tried it once on a whim, it worked, and
so I never questioned the "how". What's the quote again, "Perl did
the magic, I just waved the wand"?
: use subs 'open(*$)';
: should be essentially equivalent to
: BEGIN {
: my $import = 'open(*$)';
: *{"main::$import"} = \&{"main::$import"};
: }
Hmm, yes, that makes no sense. But it works, so I don't really care
all that much, just like a lot of perl. ;-)
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Tue, 15 Dec 1998 18:42:10 -0800
From: Steve Harris <perl@nullspace.com>
Subject: Re: Can standard Perl functions be overloaded ?
Message-Id: <36771E02.B56C7A4B@nullspace.com>
You are messing with the symbol table, that's why it
works. Check out Camel Chapter 5.
*pkg::sym{CODE} # same as \&pkg::sym
--Steve
Zenin wrote:
>
> Sean McAfee <mcafee@pacman.rs.itd.umich.edu> wrote:
> : In article <913686321.510810@thrush.omix.com>,
> : Zenin <zenin@bawdycaste.org> wrote:
> : > use subs 'open(*$)';
> : > sub open (*$) { ... }
> :
> : It's nice that this works, but how the heck *does* it work?
>
> I have no idea actually. I tried it once on a whim, it worked, and
> so I never questioned the "how". What's the quote again, "Perl did
> the magic, I just waved the wand"?
>
> : use subs 'open(*$)';
> : should be essentially equivalent to
> : BEGIN {
> : my $import = 'open(*$)';
> : *{"main::$import"} = \&{"main::$import"};
> : }
>
> Hmm, yes, that makes no sense. But it works, so I don't really care
> all that much, just like a lot of perl. ;-)
>
> --
> -Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
> BSD: A psychoactive drug, popular in the 80s, probably developed at UC
> Berkeley or thereabouts. Similar in many ways to the prescription-only
> medication called "System V", but infinitely more useful. (Or, at least,
> more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Wed, 16 Dec 1998 01:02:37 GMT
From: Joe <jbon@hotmail.com>
Subject: can't write file under NT (need help)
Message-Id: <3677066E.6E139292@hotmail.com>
Does anyone know why using the following bit of code will not write to
the file "eaddress.txt" in the following bit of code? This code works
fine under UNIX but it will not write the file under NT.
Thanks.
--
Joe Bongiorno
Owner/General Manager
MEDIAFORCE Website Management Services
AMERICA SAVE 30% ON WEB DEVELOPMENT WORK
155 Queen Street, Suite 200
Ottawa, ON
K1P 6L1
Tel: (613) 751-4437; Fax: (613) 724-9915
e-mail: sales@mediaforce1.com
Internet: http://www.mediaforce1.com
------------------------------
Date: 15 Dec 1998 21:53:09 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Complicated sorting problem
Message-Id: <x7n24opzl6.fsf@sysarch.com>
>>>>> "BM" == Bill Moseley <moseley@best.com> writes:
BM> my @sorted = sort {
BM> my @a = $a =~ /^(\D+)(\d+)/;
BM> my @b = $b =~ /^(\D+)(\d+)/;
BM> $a[0] cmp $b[0] or
BM> $a[1] <=> $b[1];
BM> } @lines;
because this does the regex match for each comparison which will lead to
cpu death. ST and orcian manouever save the work per compare by either
precomputing it or saving it in a hash on the fly. either way uses more
memory and will save your cpu from premature burnout. it is the classic
memory vs. speed tradeoff. these days memory is much cheaper than cpu
speed so speed algorithms are more popular. if you have a severe memory
shortage (e.g. embedded system) then you would use more cpu to conserve
ram.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 15 Dec 1998 19:37:38 -0600
From: Matt Schuette <schuette@umr.edu>
Subject: Re: Decent Editor
Message-Id: <36770EE2.2A06691B@umr.edu>
Can't we all just get along? The only descent editor for Person X
is the one that Person X writes from scratch. No doubt everyone has a
gripe with their favorite editor, no matter what it is. THERE IS NO
PERFECT EDITOR!! If you are dissatisfied with the ones available, write
your own that does what you would expect an editor to do and you will
love it =)
Matt Schuette
------------------------------
Date: Tue, 15 Dec 1998 21:41:13 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Eval vs. Subroutine?
Message-Id: <MPG.10e0e7d1a7a1fd9a989764@news.scescape.net>
In article <756via$k91$1@shell1.ncal.verio.com>,
syran@shell1.ncal.verio.com says...
=> If I have a little snipped of code, that say, sets a few variables and i
=> have that iterated many times over in my program ... which is faster,
=> creating a subroutine, copy/pasting everywhere (yuck), or assigning the
=> snippet to a (global) variable and eval'ing it everytime?
[snip]
There's this really cool module known as 'Benchmark'. You _should_ check
it out.
Does this answer your question?
#!/usr/bin/perl -w
use Benchmark;
sub a {
$_ = "foobar";
}
$code = '$_ = "foobar";';
timethese(100_000, {
'eval' => sub { eval $code },
'sub' => sub { a(); }
});
__END__
Benchmark: timing 100000 iterations of sub, eval...
eval: 51 wallclock secs (49.97 usr + 0.00 sys = 49.97 CPU)
sub: 1 wallclock secs ( 1.50 usr + 0.00 sys = 1.50 CPU)
HTH!
:-)
--Matthew
------------------------------
Date: Tue, 15 Dec 1998 19:15:33 -0600
From: Andrew Johnson <ajohnson@gatewest.net>
Subject: Re: Formatting Numbers
Message-Id: <367709B5.1BEDD425@gatewest.net>
Scott Phillips wrote:
>
> Lets say I have:
>
> $amount = "100230.00";
>
> how can I format it so that it places a "," after every third digit to the
> left of the decimal point.....so it would like this:
>
> 100,230.00
>
> Thanks, its been stumping me.
the FAQ's are great de-stumpers ... see for example:
perlfaq5: How can I output my numbers with commas added?
(you can view that faq and more with the perldoc utility
ala 'perldoc perlfaq5')
regards
andrew
------------------------------
Date: Wed, 16 Dec 1998 01:03:11 +0000
From: Andy Mendelsohn <andy@focus-consulting.co.uk>
Subject: Re: Hashref Compatibility with Perl 4.0 -- TIA
Message-Id: <367706CF.6B41A47@focus-consulting.co.uk>
Christian M. Aranda wrote:
>
> Folks -
>
> I have the need to write perl scripts using only verion 4.0. There
> are many reasons that I can not use a current version. Here is the
> exact version of perl I'm using --
> ----------
> This is perl, version 4.0
>
> $RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
> Patch level: 36
> ---------
>
> I need to use a hashref which I've grown to know and love lately, but
> can't seem to get it to work with 4.0. Here is the hashref I'm
> initializing:
>
> %how_found_map = (
> "code review" => $phase_intro[0],
> "customer use" => $phase_intro[1],
> "doc review" => $phase_intro[0],
> "functional test" => $phase_intro[0],
> "integration test" => $phase_intro[0],
> "internal use" => $phase_intro[2],
> "metric validation" => $phase_intro[0],
> "new requirement" => $phase_intro[3],
> "new functionality" => $phase_intro[4],
> "regression test" => $phase_intro[0],
> "unit test" => $phase_intro[0]
> );
>
> @phase_intro is an array (obv.). Here is the exact error message I
> receive when trying to execute my script:
> ------------
> syntax error in file migrate_ddts_delim.pl at line 44, next 2 tokens
> "=>"
> -----------
>
> Any insight into this at all is appreciated. There must be a
> "correct" way to initialize a hashref with perl 4.0, but I have
> exhausted my resources.
>
> TIA -
>
> Christian Aranda
> christian.aranda@iiginc.com
> Impact Innovations Group
change them good old (or in this case new) => to ,
which as the error message says, perl 4 doesn't understand.
%how_found_map = (
"code review" , $phase_intro[0],
"customer use" , $phase_intro[1],
"doc review" , $phase_intro[0],
etc....
andy
------------------------------
Date: Wed, 16 Dec 1998 02:04:39 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Hashref Compatibility with Perl 4.0 -- TIA
Message-Id: <XyEd2.104$595.81@nsw.nnrp.telstra.net>
In article <756qjt$gfn$1@news-1.news.gte.net>,
christian.aranda@iiginc.com (Christian M. Aranda) writes:
> I have the need to write perl scripts using only verion 4.0. There
> are many reasons that I can not use a current version. Here is the
> exact version of perl I'm using --
you may say that, but I cannot think of one single reason that you
cannot upgrade to perl 5. I can think of many many reasons why you
should.
> I need to use a hashref which I've grown to know and love lately, but
> can't seem to get it to work with 4.0. Here is the hashref I'm
> initializing:
hashrefs don't exist in perl 4. No hard references exist in perl 4.
> %how_found_map = (
This is a hash. Not a hash ref.
> "code review" => $phase_intro[0],
I don't know for certain anymore, after all perl 4 has been dead for a
few years now, but I don't think '=>' existed in perl 4. As far as I
can remember it first appeared in some perl 5 version.
Use a comma (,) instead.
> Any insight into this at all is appreciated. There must be a
> "correct" way to initialize a hashref with perl 4.0, but I have
> exhausted my resources.
If you _have_ to use perl 4, you should consult the perl 4
documentation, and maybe see if you can find a book about it. You'll
find fewer and fewer people here who remember enough about perl4 to
assist you beyond simple questions like this.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | That's funny, that plane's dustin'
Commercial Dynamics Pty. Ltd. | crops where there ain't no crops.
NSW, Australia |
------------------------------
Date: 16 Dec 1998 01:55:59 GMT
From: friedman@Xenon.Stanford.EDU (Perry Friedman)
Subject: Help: File size weirdness with db's
Message-Id: <7573vf$ojl$1@nntp.Stanford.EDU>
I have tested this on PC Solaris and Sparc Solaris with various versions
of Perl 5, and all have shown the same symptoms:
I create a DB (either using tie or dbmopen). It doesn't matter whether
it is NDBM_File, GDBM_File, SDBM_File, etc. The symptoms are always the same.
In a nut shell, the file size reported by "ls -l" for the individual file
does not jive with the file size reported by "du" or "df -k" or even the
total for the directory using ls.
Furthermore, if I "cp" the file, the new file behaves normally wrt to du
and df -k.
Here is an example of what I mean:
I create an NDBM db. Here is an ls -l on the directory:
total 16392
-rw------- 1 pickem staff 4096 Dec 15 17:45 NEW.dir
-rw------- 1 pickem staff 33230848 Dec 15 17:45 NEW.pag
Here is a du -k on the directory:
8197
Now, the file looks to be about four times as big as is reported by du or
even the directory total.
Now I do a "cp NEW.pag N"
ls -l reports:
total 81352
-rw------- 1 pickem staff 33230848 Dec 15 17:49 N
-rw------- 1 pickem staff 4096 Dec 15 17:45 NEW.dir
-rw------- 1 pickem staff 33230848 Dec 15 17:45 NEW.pag
and du -k reports:
40677
The amount of K added jives with the individual file size, as does the number
of blocks added. But the total is still off.
This is really weird.
Anyone know why this would be? Is this a bug in Perl? In Solaris? In ls?
Actually, it is not just Solaris. I just tested this with SDBM_File on BSD
and also experienced the same symptoms.
It is very odd.
Perry
------------------------------
Date: 15 Dec 1998 18:56:11 PST
From: muzok@nospam.pacbell.net (muzo)
Subject: Re: How can I compare files?
Message-Id: <3677063f.524859548@news.concentric.net>
Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, Pep Mico <pep_mico@hp.com> writes:
>:I'm using Perl under Windows NT. How can I compare two files? I haven't
>:found this file function in Perl Manuals. I just only need to know if
>:files are Equals or differents.
>:
>:Should I invoke COMP command from Windows NT?
>
>If you were on a real system, you'd just call the cmp program,
>possibly only after checking that the respective st_size fields differ.
>Since you're not, you get to have much more fun.
>
you mean system("cmp -s foo bar") doesn't work on NT ? It does on my system. I
guess this is a real system after all. OBTW, if you are going to say cmp doesn't
exist on NT don't bother; I know. If you are limited to an out of the box NT, you
can try system("fc foo bar 1> out") and look at the output. As the inquirer has
Perl, I am assuming it is possible to get the cygnus toolset.
>It is distressing to see how many people who, abused by Microsoft and
>deprived of proper tools, feel compelled to recreate the wheel in Perl.
>If you want Unix (read: a programmer-friendly environment), you know
>where you find it. If you don't want a programmer-friendly environment,
>well, then you are welcome to pay as much money as you'd like not to
>get your job done easily.
>
>--tom
Why are these people deprived of power tools ? All the tools necessary exist on
the Net. Instead of making these snide comments when asked a question, I think
you would be using your time and ours more productively if you tried to answer
it.
PS Alas fc doesn't set exit code based on the result of comparison so you have to
look at the output generated by it. Sometimes I do agree that MS is full of
idiots.
muzo
WDM & NT Kernel Driver Development Consulting <muzok@pacbell.net>
------------------------------
Date: Tue, 15 Dec 1998 19:02:13 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how do I do this common text import task?
Message-Id: <lq0757.07e.ln@magna.metronet.com>
Terry Haroldson (tharold@portal.ca) wrote:
: I'm new at this and am sure this is a easy question. I have data in a
: text file similar to the following (retrieved from a Informix d/b). I
: would like to transpose it into a csv format, so I can stick it into
: Excel. (I don't care about the field names.)
: This must be a common
: task.
Which should make you think that maybe there is a module
that would help?
I see that there is one named: Text::CSV
Looks promising, though I have not used it.
: I would like to get this:
: 11,1,876,1,909576453,7,0,0,7
: 2,CT003A,76,1,912859221,0,0,0,0
: 2,CT003A,51,1,912859221,0,0,0,0
----------------------------
#!/usr/bin/perl -w
{ local $/ = ''; # paragraph mode
while (<DATA>) {
chomp;
s/^.{20}//gm; # discard the field names
tr/\n/,/; # newlines become commas
print "$_\n";
}
}
__DATA__
wire_center_id 11
cable_name 1
first_pair 876
sequence_num 1
date_analyzed 909576453
all_fault_weight 7
weight_fault_count 0
all_fault_count 0
bad_pair_count 7
wire_center_id 2
cable_name CT003A
first_pair 76
sequence_num 1
date_analyzed 912859221
all_fault_weight 0
weight_fault_count 0
all_fault_count 0
bad_pair_count 0
wire_center_id 2
cable_name CT003A
first_pair 51
sequence_num 1
date_analyzed 912859221
all_fault_weight 0
weight_fault_count 0
all_fault_count 0
bad_pair_count 0
----------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 15 Dec 1998 17:59:36 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: how do I do this common text import task?
Message-Id: <MPG.10e0b3e4818658ee9898cb@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36770063.9871B481@home.com> on Wed, 16 Dec 1998 00:28:34
GMT, Rick Delaney <rick.delaney@home.com> says...
> Larry Rosler wrote:
...
> > print join(',', /\d+/g), "\n" while <DATA>;
>
> Some of the original sample data had letters in it. Perhaps:
>
> print join(',', / (\w+)/g), "\n" while <DATA>;
Yes. I didn't notice the letters in the data or the missing letters in
the output from my test.
Perhaps for generality the leading space in the regex should be "[ \t]".
It can't be "\s" because of the newlines in each record.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 16 Dec 1998 01:09:10 GMT
From: dturley@pobox.com
Subject: Re: How to extract emails from HTML page
Message-Id: <75717l$a3c$1@nnrp1.dejanews.com>
In article <3676C929.5EB677F9@popcorn-studio.ch>,
Philip Class <philip.class@popcorn-studio.ch> wrote:
> Dear Friends ;-)
>
> To be honest - The main purpose for collecting emails is a commercial one.
> Contancting potential customers in a discrete way (inculding our own personal
> address data as sender and offering a 'REMOVE ME' feature) is not what I call
> usual cheap spam.
But extracting email addresses from web pages is such a trivial perl script.
Could we actually trust your programming on the "REMOVE ME" program part of
it? ____________________________________ David Turley dturley@pobox.com
http://www.binary.net/dturley/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 15 Dec 1998 19:23:50 -0600
From: Matt Schuette <schuette@umr.edu>
Subject: Re: How to extract emails from HTML page
Message-Id: <36770BA6.9FF0A3EE@umr.edu>
Philip,
If you truly have a legitamate reason to want these addresses, you
probably wouldn't mind spending the time to email your potential
customers individually and tell them about your
product/service/whatever. If you don't have the time to do that, maybe
you shouldn't take up their time with unsoliceted email. The "REMOVE
ME" feature is a wonderful service to those who have expressly
registered for something and no longer wish to receive it. Another
quick solution would be to make a web page and register it with the
popular search engines. There are some wonderful threads on this topic
in "alt.html.tags" and elsewhere I'm sure. If all of these methods are
too time consuming, perhaps you need to rethink your market strategy.
If your customers aren't interested, unsolicited mail will certainly not
help.
Matt Schuette
------------------------------
Date: Tue, 15 Dec 1998 18:27:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to extract emails from HTML page
Message-Id: <MPG.10e0ba53d17dd629898cd@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36770BA6.9FF0A3EE@umr.edu> on Tue, 15 Dec 1998 19:23:50 -
0600, Matt Schuette <schuette@umr.edu> says...
...
> ... The "REMOVE
> ME" feature is a wonderful service to those who have expressly
> registered for something and no longer wish to receive it.
<OFFTOPIC -- but so is this whole thread by now>
The "REMOVE ME" feature is a wonderful service to those who want to
verify that the address they are spamming is indeed a live, functioning
email user. Using this feature *immediately* promotes your email
address to extra-attention extra-value lists, leading to a higher level
of spam.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 15 Dec 1998 18:46:08 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Need some speed tips on this script..
Message-Id: <gsv657.n0e.ln@magna.metronet.com>
Chris Beatson (cbeatson@mail.ci.lubbock.tx.us) wrote:
: This script works fine, but it runs a bit slow. Any advice to speed it up
: would be appreciated. Please explain any suggestions.
: ## script to pull unique IP's from a log file
^^^^^^
^^^^^^
Whenever you see this word in the problem description, your
Perlified brain should immediately say repeatedly:
hash
hash
hash
Looking things up in a hash is always going to be *way* faster
than looking things up in an array.
: print "what's the log file name?\n";
: chomp($logfile=<stdin>);
^^^^^
Bad, though it works.
You should be using the -w switch on *all* of your Perl programs.
(and it should generate no warnings)
Really.
All of them.
: $count=0;
: $ips[0]="0"; ## array to store ip's in
Store then in %ips for quick lookup.
: open (file, "<$logfile") || die "can't open the logfile: $logfile\n";
^^^^
Your script will suddenly and mysteriously stop working when
Perl version 7.5 adds a 'file' keyword...
-w would have pointed that out...
: OUTER: while (<file>) {
: chomp;
: if ($_=~ /(^\d+?\.\d+?\.\d+?\.\d+?)\,.*$/) {
The non-greedy quantifiers do nothing there, since each is
followed by a required non \d anyway.
Try it with greedy quantifiers.
Since you don't do anything with the trailing chars, why
bother matching them?
Take the .*$ out too.
The comma is not a metacharacter, and therefore does not
need to be escaped.
: foreach $i (@ips)
: {
: if ($1 eq $i)
: {
: next OUTER;
: }
: }
: $ips[$count]="$1";
: $count++;
: }
: }
So, you can replace the whole if statement with:
if ( /(^\d+\.\d+\.\d+\.\d+),/) {
$ips{$1}++;
}
: open (results, ">ips");
^^^^^^^
Trouble when 'results' becomes a Perl keyword...
You should check the return value from *every* open() call.
It might fail, and you should recover gracefully rather than
plow on and try to write to the unopened file:
open(RESULTS, '>ips') || die "could not open 'ips' $!";
: foreach $i (sort(@ips))
: {
: $ipcount++;
: print results "$i\n";
: }
: close (results);
foreach (sort keys %ips) {
print RESULTS "$_\n";
}
: close (file);
: print "there were $ipcount different ips\n";
print 'there were ', scalar(keys %ips), " different ips\n";
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Dec 1998 21:58:27 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Need some speed tips on this script..
Message-Id: <x7k8zspzcc.fsf@sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> I looked back at my submission to see what cool stuff you are referring
LR> to. I agree that the one-liner mapped hash slice *is* cool, and have
LR> thanked Uri Guttman several times for pushing hash slices on me in my
LR> infancy, many months ago. But I also found the following (essentially
LR> copied from the original code):
thanx.
>> print RESULTS map "$_\n", sort keys %ips;
i would use a join here rather than map.
print RESULTS join( "\n"m sort keys %ips ), "\n";
join is one of the fastest complex perl funcs and is underused by many
folks.
LR> This one was a no-brainer. Nothing to learn from comparing O(n**2) to
LR> O(n). Maybe some other time when it is more interesting.
too true.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 15 Dec 1998 19:11:53 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: NEWBIE! - need help with sar output on UNIX and perl
Message-Id: <pc1757.07e.ln@magna.metronet.com>
jdennis@alldata.net wrote:
: Help!
OK!
: sar -d gives output for each disk and tape device on a separate line, with
: only the first line giving the timestamp.
: I need to duplicate the timestamp for all disks in my output file.
-------------------------------
#!/usr/bin/perl -w
while (<DATA>) {
if (/^(\S+)/) { # if line starts with non-space chars
$time = $1; # save time in case we need it for subsequent lines
}
else {
substr($_, 0, 8) = $time; # insert the time
}
print;
}
__DATA__
00:10:01 c0t1d0 0.07 0.51 1 7 3.12 1.88
c0t1d3 0.04 0.50 0 1 3.42 2.07
00:20:01 c0t1d0 0.26 0.50 1 8 3.41 3.30
c2t0d0 0.00 0.50 0 0 4.76 0.79
c0t1d3 0.03 0.50 0 1 3.49 1.76
00:30:01 c0t1d0 0.22 0.50 1 5 3.23 3.91
c2t0d0 0.00 0.50 0 0 4.84 0.78
c0t1d3 0.03 0.50 0 2 3.32 1.71
-------------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 15 Dec 1998 16:08:58 -0500
From: mjd@Op.Net (Mark-Jason Dominus)
Subject: Re: Origin of 'local'?
Message-Id: <756j5a$50m$1@monet.op.net>
In article <3676A0E1.1B36EC14@kasey.umkc.edu>,
David L Nicol <david@kasey.umkc.edu> wrote:
>This is a feature which is completely absent from C/C++/Java/Basic
>but is present in Pascal. Don't know about *ol, not that old.
How could you not be old enough to remember yourself?
------------------------------
Date: Tue, 15 Dec 1998 19:13:38 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Pipe docs (basic)
Message-Id: <2g1757.07e.ln@magna.metronet.com>
Forrest Reynolds (dropzone@mail.utexas.edu) wrote:
: I'm lookling for a place to read about pipes " from the beginning." The
: Llama doesn't have it and the Camel assumes more than I know. I understand how
: this statement works:
: ls -l | more
: but not much more.
A pipe connects the STDOUT of the left side to the STDIN
of the right side.
That's it!
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 16 Dec 1998 01:39:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: problem with grep and readdir for subdirectories
Message-Id: <xbEd2.99$595.86@nsw.nnrp.telstra.net>
In article <3676ED2F.2DC37F06@carleton.edu>,
Dane Miller <millerd@carleton.edu> writes:
> I am trying to get a list of subdirectories for a given directory path
> but am having problems. I can only retrieve subdirectories if I have
> run the script from the parent-level of these directories.
It's in the documentation:
# perldoc -f readdir
[snip]
If you're planning to filetest the return values out of a C<readdir()>, you'd
better prepend the directory in question. Otherwise, because we didn't
C<chdir()> there, it would have been testing the wrong file.
[snip]
Please, please, please, always consult the documentation first if you
have a problem with a certain function.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | 75% of the people make up 3/4 of the
Commercial Dynamics Pty. Ltd. | population.
NSW, Australia |
------------------------------
Date: Tue, 15 Dec 1998 18:58:49 -0800
From: Steve Harris <perl@nullspace.com>
Subject: Re: problem with grep and readdir for subdirectories
Message-Id: <367721E9.6AC28B75@nullspace.com>
As well as reading the docs on the function, it also
helpful to examine the values you are testing. You
would notice the error had you printed what you were
trying to test...you'd see that you were dealing with
a file.
Trial and error can sometimes be faster than docs, but
it'll rarely be as comprehensive. I understand that some
of us are better at reading docs than others ;-)
You might note that I've run into some problems with
renaming some file operations "across" file systems,
but I beilieve this is documented as well. I've also
had problems doing 'stat' on NFS, which I believe is
ALSO in the docs. I've never had file system issues
beyond UMASK and those listed here on UNIX systems.
--Steve
Dane Miller wrote:
>
> I am trying to get a list of subdirectories for a given directory path
> but am having problems. I can only retrieve subdirectories if I have
> run the script from the parent-level of these directories.
>
> For example, when I run the following code from /export/home1/netweb, I
> get a list of subdirectories as I expected. But if I run it from
> another location, say /export/home1/, I only get the two relative
> directories '.' and '..'
>
> opendir TEST, "/export/home1/netweb" or die "cannot open directory $!";
> @subs = grep -d, readdir(TEST);
> close TEST;
> for (@subs){print "$_\n";}
>
> Am I making a perl error or is this an issue with my the unix file
> system?
>
> thanks,
> Dane
------------------------------
Date: 16 Dec 1998 02:22:34 GMT
From: careermngr@aol.com (CareerMngr)
Subject: Problem with script "... cgi-bin\signup.pl' script produced no output "
Message-Id: <19981215212234.15592.00003761@ng-fi1.aol.com>
Problem with script "... cgi-bin\signup.pl' script produced no output "
Any ideas why a perl script installed to a NT server might produce the above
error message (or know someone who can help me)? I've installed the scripts
more than a dozen times to UNIX and freebsd servers without a problem.
I know NT wants everything it's own way so I:
- changed *.cgi extensions to *.pl
- Replaced all instances of #!/usr/bin/perl with [print "HTTP/1.0 200 OK\n";]
- Removed all instance of [print "Content-type: text/html\n\n";]
- Changed all required references to something like [$lib =
"d:\\inetpub\\users\\mysite\\cgi-bin\\";]
- Moved cgi's to /cgi-bin, since the NT server I'm installing to prohibits cgi
applications to run anywhere other than /cgi-bin.
Before I made the last change only blank pages were loading, now I get the
following error message: 'd:\inetpub\users\ledscc\cgi-bin\signup.pl' script
produced no output' :(
Any ideas how I go about fixing this?
Thanks for your help!
Andre'
------------------------------
Date: Tue, 15 Dec 1998 17:35:33 -0800
From: Steve Harris <perl@nullspace.com>
Subject: Re: Question about NT (newbie)
Message-Id: <36770E65.6BB7BD8@nullspace.com>
Basic, but a good question...especially if you are
concerned. It should not logically affect your usage
because 0 and NULL are logically equivalent (as is the
empty string ''). Perl will do automatic conversion in
most cases, and will warn you of unusual usage if you
use -w and 'use strict' when writing your programs.
There should be no expectation of zero or any other value
in "false" cases, simply a false result. 'cmp' returns
zero(0) because it is specified as having a return value
of -1, 0, or 1 depending on the evaluation of the
comparison. Contrast that to <=> which is a true-false
operator.
You've obviously done your homework, keep it up!
--Steve Harris
ixb9142@rit.edu wrote:
>
> Okay,
>
> I now just noticed that if I use the string comparison operator 'cmp'
> and the two strings are identical, then it really does return a zero,
> but all other comparison operators I've used both numeric and string
> don't seem to be returning zeros when they should.
>
> Ian Blake
> ixb9142@rit.edu
>
> On Tue, 15 Dec 1998 16:16:56 GMT, ixb9142@rit.edu wrote:
>
> >Hi,
> >I just started to teach myself PERL yesterday. I am using a book that
> >was designed for Unix but I am on NT. For the most part things have
> >been the same with a few minor differences. One thing I am wondering
> >about though. It seems that If you compare two values and the result
> >is false, then instead of returning a zero, NT will return a null
> >character. Is this true? Will this really affect anything I am
> >trying to do in the future. Does a null character mean false in NT?
> >Any info would be certainly helpful. This is also my first time
> >posting to this group. Could people please e-mail because I'm not
> >sure how often I'll be checking here, although I could become a
> >regular reader. Thanks
> >
> >Ian Blake
> >ixb9142@rit.edu
------------------------------
Date: Tue, 15 Dec 1998 18:20:49 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Question about NT (newbie)
Message-Id: <MPG.10e0b8df21d2f4449898cc@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36770E65.6BB7BD8@nullspace.com> on Tue, 15 Dec 1998 17:35:33
-0800, Steve Harris <perl@nullspace.com> says...
...
> ... 'cmp' returns
> zero(0) because it is specified as having a return value
> of -1, 0, or 1 depending on the evaluation of the
> comparison. Contrast that to <=> which is a true-false
> operator.
>
> You've obviously done your homework, keep it up!
Have you? :-)
>From perlop:
Binary ``<=>'' returns -1, 0, or 1 depending on whether the left
argument is numerically less than, equal to, or greater than the right
argument.
It *has* to return three values in order for 'sort' to work correctly.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 15 Dec 1998 18:54:57 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Trying to get all directories recursively
Message-Id: <1d0757.07e.ln@magna.metronet.com>
Christopher Parent (parenc@rpi.edu) wrote:
: I'm trying to write a perl script that goes through each directory and
: subdirectory, and returns all the files that match a mask that I set.
: If anyone has written something like this
: and can help, I'd appreciate it.
use File::Find;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 16 Dec 1998 02:05:47 GMT
From: parenc@rpi.edu (Christopher Parent)
Subject: Re: Trying to get all directories recursively
Message-Id: <3677151e.9665451@news.ntplx.net>
On Tue, 15 Dec 1998 18:54:57 -0600, tadmc@metronet.com (Tad McClellan)
wrote:
>
> use File::Find;
>
>
>--
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
I can't use the FInd command. Eventually I'll be using the algorithm
to parse through some files, which would contain a similar structure.
I need to write my own from scratch.
Chris
------------------------------
Date: Wed, 16 Dec 1998 02:18:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Trying to get all directories recursively
Message-Id: <ELEd2.105$595.81@nsw.nnrp.telstra.net>
In article <3677151e.9665451@news.ntplx.net>,
parenc@rpi.edu (Christopher Parent) writes:
> On Tue, 15 Dec 1998 18:54:57 -0600, tadmc@metronet.com (Tad McClellan)
> wrote:
>
>>
>> use File::Find;
[snip of quoted sig. Bad, bad, bad]
> I can't use the FInd command. Eventually I'll be using the algorithm
Are you saying you can't use the File::Find module? Why not? Every
recent perl ships with it. If you have an older perl, you should
upgrade, if not for this reason, then for many others.
If you don't have that option, you can at least download the sources
for the module, and use those to see how it's done.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | I'm just very selective about what I
Commercial Dynamics Pty. Ltd. | accept as reality - Calvin
NSW, Australia |
------------------------------
Date: Wed, 16 Dec 1998 15:51:56 +1300
From: Kelvin Price <kprice@cardinal.co.nz>
Subject: Re: Trying to get all directories recursively
Message-Id: <3677204C.4918E1C6@cardinal.co.nz>
Christopher Parent wrote:
>
> Here's my resulting perl code that I didn't include in my original
> message:
>
> #!/usr/local/bin/perl
>
> sub isDir {
> if ($_[0]=~/^d/) {
> /(\w*)$/;
> $currentDir = $&;
> @dir = (@dir, $currentDir);
> return 1;
> }
> else { return 0; }
> }
>
> @allfiles = `ls -l`;
>
> sub findImage {
> if (isDir($_[0])) {
> chdir ($currentDir);
> @test = `ls`;
> findImage(`ls -l`);
> }
>
> }
>
> foreach (@allfiles) {
> findImage($_);
> }
> ----------------------------------------------------------------------
>
> So you're saying that I have to chdir back up? to which one? Should I
> have say a $prevDir and $nextDir ?
Given that chdir ($currentDir) is changing down 1 directory level, then
chdir('..') will change back up (.. is a special directory which takes
you to the parent directory of the current directory ).
HTH
------------------------------
Date: Tue, 15 Dec 1998 18:46:50 -0800
From: Steve Harris <perl@nullspace.com>
Subject: Re: Why Is Perl not a Language?
Message-Id: <36771F1A.E326AC24@nullspace.com>
Off topic of the group, maybe, but not off mark. This is
a very good example of how Microsoft has subtly changed
(purposefully or not) our language in such a way that
terms like Operating System or User Interface or
Application or Protocol or Fairness seem to lose their
original meaning and fall into the realm of ambiguity.
I believe this is the "uncertainty" portion of FUD.
Fearlessness, Unity, Confidence, Knowledge. That is
our antidote.
The antidote for FUD is...well you figure it out.
--Steve
Thomas Brian Holdren wrote:
>
> In article <m3btl5kbau.fsf@moiraine.dimensional.com>,
> dgris@moiraine.dimensional.com says...
> >
> >bart.lateur@skynet.be (Bart Lateur) writes:
> >
> >> "Interactive" means that the programs stops in situations like:
> >>
> >> Well here's the data I've got so far, now tell me what to do with it.
> >>
> >> Programs without an interface don't stop and ask. They go from start to
> >> finish in one go.
> >
> >So an http server (make one request, receive one reply) is not
> >interactive, while an ftp server is? Seems strange to me.
>
> I'm not too experienced, but I wrestled with this concept not too long ago
> myslef. I believe the kind of user interface Mr. Lateur is referring to as a
> user interface is event driven programming (a la Visual Basic), and Mr.
> Grisinger is referring to it as linear programming (a la command line). I'm
> not sure which one is really considered a user interface, but the VB kind is
> definitely more user-friendly.
>
> Or maybe I'm way off the mark *again*.
>
> tbholdren
> --
> Thomas Brian Holdren irc_addict@hotmail.com
> "My mind is drawing a "", a '', and a //." -Me
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 4433
**************************************