[7829] in Perl-Users-Digest
Perl-Users Digest, Issue: 1454 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 11 11:07:22 1997
Date: Thu, 11 Dec 97 08:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 11 Dec 1997 Volume: 8 Number: 1454
Today's topics:
Re: a certain bug...!!! <Christian.Khoury@inria.fr>
Re: awk to perl (Keith Willis)
DBM's + Associative Arrays <dead@visitweb.com>
Re: DBM's + Associative Arrays <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Re: Download Question - Yes Please <dtlgc@deletethisstringanddot.flash.net>
Re: getting list of directories, returned as an array <merlyn@stonehenge.com>
Hard and symbolic references to subs (Jason Gloudon)
help with win32::process (David J. Boyd)
Re: how to pre-allocate memory chunk <tchrist@mox.perl.com>
Re: Install Perl on Win95 (Jeffrey R. Drumm)
Re: is there anyway around this ssi problem with "query <dboorstein@ixl.com>
Re: Need documentation on WORD_BASIC ole module <jjfink@searle.monsanto.com>
Re: need help with regexp (Brock Sides)
Re: need to know what browser the client is using <justinb@cray.com>
Re: newbie: compact an array (Jason Gloudon)
perl compilation problem on hpux-10.10 <erik@ecom.be>
Perl support for the long long type <vincent.joseph@usa.net>
Re: Please advise. Fastest way to line-count files <steve.tolkin@fmr.com>
Re: Please advise. Fastest way to line-count files <tchrist@mox.perl.com>
Re: removing duplicate entries from the PATH variable <tchrist@mox.perl.com>
Re: removing duplicate entries from the PATH variable <merlyn@stonehenge.com>
Re: Socket I/O in Perl5 <merlyn@stonehenge.com>
Re: sorting a hash of hashes??? (Andrew M. Langmead)
Re: using PERL with Personal Web server under 95 <jefpin@bergen.org>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 11 Dec 1997 14:33:30 +0100
From: Christian Khoury <Christian.Khoury@inria.fr>
To: khoury
Subject: Re: a certain bug...!!!
Message-Id: <348FEBAA.4157246F@inria.fr>
> Require file Retain data
> Yes Yes +<
> No Yes +>>
> No No +>
>
> There's no obvious way to require a file whose data you don't want.
> Fortunately, that's not likely to be needed. :-)
>
> Hope this helps!
Certainely it did....:-)..thanx for your help...
But then, i wouldn't call it (+>) Read-Write mode...it's
Read-Write-Create mode...:-)
Christian
--
Christian Khoury
INRIA - Projet SOR - B.P. 105 - 78153 Le Chesnay Cedex - FRANCE
Tel : +33 1 39 63 51 33 e-mail : Christian.Khoury@inria.fr
------------------------------
Date: Thu, 11 Dec 1997 14:12:31 GMT
From: keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com (Keith Willis)
Subject: Re: awk to perl
Message-Id: <3490f498.98853714@elf.bri.hp.com>
On Fri, 5 Dec 1997 17:25:37 +0000, Tim Pagden <tim@doulos.co.uk>
wrote:
>I've tried search engines, browsing (and text-searching) the key Web
>pages (anything linked to from www.perl.com) and the FAQs - just about
>everything in fact - but can I find the ftp site or URL for downloading
>the awk2perl utility? Nope.
Don't know about 'awk2perl', but there is a 'a2p' utility which is
part of the normal Perl distribution....
----------------------------------------------------------------------
The above message reflects my own views, not those of Hewlett Packard.
When emailing me, please note that there is no '.junk' in my address.
------------------------------
Date: Thu, 11 Dec 1997 13:47:16 +0000
From: CJ <dead@visitweb.com>
Subject: DBM's + Associative Arrays
Message-Id: <348FEEE4.4FA6@visitweb.com>
HELP!
If I use a dbm file with perl, what is the largest size that
the dbm can be and still be workable under perl. e.g. are
there any limits on associative arrays/dbm files?
I'm thinking of creating a simple db and using something like
dbmopen(%MYDB,"mydata",0666);
$MYDB{$key}=$data;
dbmclose(%MYDB);
but I'm concerned that if the DB was to grow to any significant
levels, then would dbm/perl associative arrays be able to
handle such.
Also if I perform a sort against such an array, how does perl handle
such e.g. is it sorted in memory and therefore a memory sizing limit
or does it use a memory/disk base sorting method such as per
the Unix sort command.
Any help or pointers appreciated.
------------------------------
Date: Thu, 11 Dec 1997 06:23:56 -0800
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: DBM's + Associative Arrays
Message-Id: <66ot1q$p75@mtinsc03.worldnet.att.net>
I don't pretend to be an expert and may get shot down for this, but . . .
>From everything I've read, the only constraint on the amount of data Perl
can handle is the size of your memory. I've never heard that qualified as to
type of data. In fact, Larry states one of his aims in designing Perl was to
have "no built-in limits."
This would mean that you could make a dbm that would fill your available
memory. I can only assume that means physical memory plus virtual memory
(although this may be different for a Mac -- I don't know whether it will
just eat unused memory or whether it limits itself to the amount of memory
you set aside for the program). Would such a file be wieldy? I don't know.
I've never tried.
Someone who has practical experience creating gigabyte associative arrays
may have a differing opinion. :D
CJ wrote in message <348FEEE4.4FA6@visitweb.com>...
>HELP!
>
>If I use a dbm file with perl, what is the largest size that
>the dbm can be and still be workable under perl. e.g. are
>there any limits on associative arrays/dbm files?
>
>I'm thinking of creating a simple db and using something like
>
> dbmopen(%MYDB,"mydata",0666);
> $MYDB{$key}=$data;
> dbmclose(%MYDB);
>
>but I'm concerned that if the DB was to grow to any significant
>levels, then would dbm/perl associative arrays be able to
>handle such.
>
>Also if I perform a sort against such an array, how does perl handle
>such e.g. is it sorted in memory and therefore a memory sizing limit
>or does it use a memory/disk base sorting method such as per
>the Unix sort command.
>
>Any help or pointers appreciated.
------------------------------
Date: Thu, 11 Dec 1997 08:29:28 -0800
From: Steve <dtlgc@deletethisstringanddot.flash.net>
Subject: Re: Download Question - Yes Please
Message-Id: <349014E8.2CF6@deletethisstringanddot.flash.net>
I have the excat same question.
I have been looking at MIME Headers, Content-type
Content-ID, Content-Description
but have not found a way yet.
Must be something simple, eh?
Nash Weber wrote:
>
> I've written a CGI script in PERL 4 that allows users to browse an image
> database and select images they want to download. Once they've made
------------------------------
Date: 11 Dec 1997 08:28:37 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: jkugler@inreach.com (Joshua J. Kugler)
Subject: Re: getting list of directories, returned as an array
Message-Id: <8cvhwvkifu.fsf@gadget.cscaper.com>
>>>>> "Joshua" == Joshua J Kugler <jkugler@inreach.com> writes:
Joshua> On 9 Dec 1997 01:54:19 GMT, mgjv@comdyn.com.au (Martien Verbruggen)
Joshua> Ok, I have been able to write a little munge that does what I want,
Joshua> but there has to be a better way. Here is what I have so far.
Joshua> use File::Find;
Joshua> find(\&get_dir_list, '/win');
Joshua> @dirlist = (sort keys %dirlist);
Joshua> print "@dirlist";
Joshua> sub get_dir_list {$main::dirlist{$File::Find::dir} = 1;}
You're trying too hard.
use File::Find;
find ( {
push @dirlist, $File::Find::name if -d;
}, '/win' );
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 264 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Thu, 11 Dec 1997 13:01:07 GMT
From: jgloudon@bbn.subtleantispam.com (Jason Gloudon)
Subject: Hard and symbolic references to subs
Message-Id: <nuRj.96$ea2.3830469@cam-news-reader1.bbnplanet.com>
Is the following behaviour intended ?
$ perl -we 'use strict "refs"; $foo = "foo"; my $ref = \${"foo"}'
Can't use string ("foo") as a SCALAR ref while "strict refs" in use at -e line 1
$ perl -we 'use strict "refs"; @ary = "foo"; my $ref = \@{"ary"}'
Can't use string ("ary") as an ARRAY ref while "strict refs" in use at -e line 1
$ perl -we 'use strict "refs"; %hash = "foo"; my $ref = \%{"hash"}'
Can't use string ("hash") as a HASH ref while "strict refs" in use at -e line 1.
And yet:
$ perl -e 'use strict "refs"; sub foo { print "foo\n" }; my $ref = \&{"foo"}'
These examples are from some email I've exchanged with a coworker.
He wonders (and so do I) if \&{"foo"} is not making use of a symbolic reference
and should be complained about my use strict.
Jason Gloudon
------------------------------
Date: Thu, 11 Dec 1997 14:49:53 GMT
From: djboyd@nospam.sam.on-net.net (David J. Boyd)
Subject: help with win32::process
Message-Id: <348ffd8b.74505280@news.on-net.net>
I am running perl5 build 110 on win NT 4.0 and Win 95. I have been given the
task to create a perl script that will build a sorted directory tree of a source
server and compare it to a target server. I have completed this part and it
works fine. The problem is that it takes over 24 hours to run the compare of
all the server pairs. A solution I came up with is to create some process that
will run to help speed up this process. Now the problem is that I have had to
hard code the server pairs into the process. I have created a driver which will
kick off 4 sub drivers which will then start the compare process.
What I would like to do is set up something so that each of these sub process
gets the server info from a common file. Say sub process 1 grabs the server.txt
file, locks it so the other process have to wait, read in the contents of the
file into an array, pop an item off the array, write the array back to the file,
and then release the file for the next process. This way I don't have to worry
about any load balancing and that all process will run until there is nothing in
the file. Now, I have create a sub that does the above but, I am unable to lock
the file.
So, the question is how does one go about locking a file? And if someone has a
better solution then the above please let me know.
...
TIA
To reply remove nospam from the address: djboyd@sam.on-net.net
------------------------------
Date: 11 Dec 1997 13:47:35 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how to pre-allocate memory chunk
Message-Id: <66oqtn$oh2$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Arvind N V <upendra1@hotmail.com> writes:
:I am using associative arrays where I store more than 100,000 keys. Is
:there a way I can preallocate a memory chunk for this associative array?
$ man perldelta
will reveal that 5.004 supports an lvaluable version of keys.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"I think the pod should be the master...."
--Larry Wall in <9410072305.AA03994@scalpel.netlabs.com>
------------------------------
Date: Thu, 11 Dec 1997 12:46:19 GMT
From: drummj@mail.mmc.org (Jeffrey R. Drumm)
Subject: Re: Install Perl on Win95
Message-Id: <348fde21.2401394723@news.mmc.org>
On Thu, 11 Dec 1997 00:16:12 +0000, Nathan Stanford <nathan@cyberservices.com>
wrote - WAAAAAAAYYYY too many times:
> If you haven't figured it out or gotten an answer email me
Nathan, if your offer of help can't be something constructive to the general
Perl public on c.l.p.m, PLEASE don't post. I'm sure the original posters of the
problems you've responded to appreciate the offer, but there are other ways to
contact them that don't make the noise level here any higher than it already
is.
Thank you.
[posted (sorry, but it had to be said) and mailed]
PS. It would be darn nice of you to cancel those posts . . .
--
Jeffrey R. Drumm, Systems Integration Specialist
Maine Medical Center - Medical Information Systems Group
420 Cumberland Ave, Portland, Maine 04101
Voice: 207-871-2150 Fax: 207-871-6501 Email: drummj@mail.mmc.org
------------------------------
Date: Thu, 11 Dec 1997 09:51:13 -0500
From: Dan Boorstein <dboorstein@ixl.com>
Subject: Re: is there anyway around this ssi problem with "query_String?
Message-Id: <348FFDE1.2A29A986@ixl.com>
this is really not a perl question, and would make more
sense in a cgi or server group, but i'll take a stab anyway.
if you look at what you are doing in the cmd="", you will notice
that it looks an awful lot like a command line statement. lo and
behold, if you treat it as such, you will get your parameters in
@ARGV.
just remove the '?' and take a look at ARGV[0] or as many elements
of it as you like. you could even assign to $ENV{QUERY_STRING}, if
you want to pretend.
<!--#exec cmd="/home/user/go/html/cgi-bin/perl.pl miscinfo"-->
$ENV{QUERY_STRING} = $ARGV[0];
good luck!
dan
283492834 wrote:
>
> i have an ssi
> <!--#exec cmd="/home/user/go/html/cgi-bin/perl.pl?miscinfo"-->
>
> if i use QUERY_STRING in the perl script, the query after the ? is
> ignored. the query string only works if i enter it by hand in the url
> box of my browser. is tehre anyway around this? i need the query
> string in the ssi, or some other method of putting miscinfo into a log
> file.
------------------------------
Date: 11 Dec 1997 14:39:06 GMT
From: "Joel Finkle" <jjfink@searle.monsanto.com>
Subject: Re: Need documentation on WORD_BASIC ole module
Message-Id: <01bd0642$83409d60$12322389@Joel.monsanto.com>
grega <grega9@mail.idt.net> wrote in article
<grega9-1112970243520001@ppp-5.ts-4.lax.idt.net>...
> In article <MPG.ef73ce98514b30c989680@moose.webworks.ca>,
> graham@webworks.ca (Graham Wile) wrote:
> > The problem is, I cannot find real documentation, with examples.
> > I found some examples for the Excel part, but I need something
> > for Word to get me started.
...
> I'm also new to OLE and perl. I once asked the same question to a
> Microsoft employee at a trade show. His response is that all ole
> automation info about their various ole automation server apps (ie;
excel,
> etc...) can be found somewhere at microsoft's www site. If you find the
> exact location, please let me know.
If you're using Office '97, then Word.Basic is not the OLE object
you want to talk to (except in rare instances), but rather just Word
(I think). WordBasic is the Office '95 almost-but-not-quite-VBA
language present only in Word '95 (7.0).
The documentation for Visual Basic for Applications for each of the
office apps comes on the Office CD's in MS Help (.HLP) format. But
the default installation doesn't ordinarily install them :^P. You've
got to do a Custom install to get them.
Microsoft does publish a Visual Basic for Applications reference, but
it's worse than useless: It's a dump of the Help files, sans index. There
is not one word of additional text, except for the indicia at the beginning
of the books :^P
I haven't tried any OLE from Perl, so I can't give specifics. But if you
need to know how to do something in Word, I can give you the right VBA
('97) or WordBasic ('95) syntax.
Joel
------------------------------
Date: Thu, 11 Dec 1997 09:04:10 -0600
From: cbks@NOSPAM.magibox.net (Brock Sides)
Subject: Re: need help with regexp
Message-Id: <cbks-1112970904110001@demeter-39.magibox.net>
In article <349011c6.46237746@news.a1.nl>, jvgorkum@dds.nl (Jeroen van
Gorkum) wrote:
> I'm working on a big html document tree where I need to replace the
> ".html" extensions of all _local_ links with ".htm". I'm looking for
> one regular expression to pass as a command line option to H.
> Churchyard's html search & replace (perl) script. It accepts two
> options:
> old="..." where ... is a regular expression,
> new="..." where ... is a statement to be evaluated.
> I'm looking for the regexp that goes in old="...".
>
> To distinguish between local and external links that use a http, ftp,
> gopher or other protocol I planned on matching a pattern that contains
> ".html", preceded by any characters that aren't colons. (like in
> "http://", I'm not using "file://" - all local links are relative.)
>
> When it contains a colon, I don't want a match, but when it doesn't
> contain a colon, I'd like the ".html" part memorized to be able to
> replace it by reference in new="...".
>
> I can't seem to get this to work:
>
> ====
>
> $_ = "A href=\"http://www.somewhere.com/directory/filename.html\"";
> /[^:]+(\.html)/;
>
> ====
>
> $` is now: A href="http:
> $& is now: //www.somewhere.com/directory/filename.html
> $' is now: "
>
> While I need the string as a whole in $` or $' or not matched at all
> in this case.
>
> Any suggestions?
Put an beginning-of-line anchor at the beginning of your regex, i.e.
/^[^:]+(\.html)/;
--
Carl Brock Sides cbks@NOSPAM.magibox.net (remove NOSPAM to reply) http://www.magibox.net/~brock/
for(0..4){$humps="."x($_*2+1);$camel.="($humps)"}
"Jtsutona reP reh\nrekcah l"=~/$camel/s;
for(1..5){eval"print scalar reverse \"\$$_\""};
------------------------------
Date: 11 Dec 1997 08:08:57 -0600
From: Justin Banks <justinb@cray.com>
Subject: Re: need to know what browser the client is using
Message-Id: <o8ng1o0ug3q.fsf@ebony.cray.com>
Tom Phoenix <rootbeer@teleport.com> writes:
>
> Yep, not a Perl question. The key is, if the answer is the same whether
> you're programming in Perl, C, or Visual Modula 17++ with JavaBeans and
> Digital Satellite TV Support, then it's not a Perl-specific question.
Ooooh, I may have just found a new ~/.signature
--
Justin Banks \
Silicon Graphics \ Polar bear: a Cartesian bear after a coordinate transform.
Eagan, Minnesota \
------------------------------
Date: Thu, 11 Dec 1997 13:41:07 GMT
From: jgloudon@bbn.subtleantispam.com (Jason Gloudon)
Subject: Re: newbie: compact an array
Message-Id: <T3Sj.97$ea2.3843956@cam-news-reader1.bbnplanet.com>
Tom Phoenix (rootbeer@teleport.com) wrote:
: On Thu, 11 Dec 1997, Jason Gloudon wrote:
: > Xah (xah@best.com) wrote:
: > : Suppose @a is an array of integers. I want to compact @a, so that elements
: > : that are 0 get deleted. How can I do this without declaring another array @b
: > : such as:
: >
: > Something like this:
: >
: > for($i=0;$i<@a;$i++){
: > if($a[$i] eq '0'){
: > splice (@a,$i,1);
redo; # Fixes the bug Tom pointed out
: > }
: > }
Jason Gloudon
------------------------------
Date: Thu, 11 Dec 1997 16:16:29 +0000
From: erik mannens <erik@ecom.be>
Subject: perl compilation problem on hpux-10.10
Message-Id: <349011DD.5DF95FF8@ecom.be>
'make test' gives the following error :
'pragma/locale.t Failed at test 102'
if I go and look in the ./perl5.004_04/t/pragma/locale.t
this is the code-part that causes the problem
397# Test for read-onlys.
398
399 {
400 no locale;
401 $a = "qwerty";
402 {
403 use locale;
404 print "not " if $a cmp "qwerty";
405 }
406 }
407 print "ok 102\n";
initially I ignored this (only 1 subtest failed out of 4607) and I
installed perl5.004_04 anyhow
.... but during the 'make test' of the libwww-perl-5.16 module, I got
the following error :
'uri/heuristic.t Failed 14/14 subtests'
I looked at ./libwww-perl-5.16/t/uri/heuristic.t and it was the first
line
"use URI::Heuristic qw(uf_urlstr uf_url);" that gave the problem.
Then looked to ./libwww-perl-5.16/lib/URI/Heuristic.pm which mentions
"L<Locale::Country>"
somewhere, which brings me back to the first problem I guess
Any help appreciated,
erik
--
**********************************************************************
Erik Mannens e-COM Interactive Expertise
Software Engineer Innovatie & Incubatiecentrum
e-mail:erik@ecom.be Technologiepark 3
http://www.ecom.be/cverik.htm B-9052 Zwijnaarde
tel:+32-9-2415600
fax:+32-9-2451814
**********************************************************************
------------------------------
Date: Thu, 11 Dec 1997 14:56:36 GMT
From: Vincent Joseph <vincent.joseph@usa.net>
Subject: Perl support for the long long type
Message-Id: <348FFF51.D2D4B1B@usa.net>
Hi,
Does perl provide support for the long long type (64 bit)?
(I am using 5.002 on AIX 3.2.5)
I need to constrcut a 5 byte integer. I have the individual bytes, but
need to put them together.
$byte0 (most significant)
$byte1
$byte2
$byte3
$byte4
Is there a quick way to do this in Perl? It should be fairly efficient
in terms of execution time.
(In C, I use the long long type and some pointer manipulations to get it
working.)
TIA,
Vincent
------------------------------
Date: Thu, 11 Dec 1997 10:19:11 -0500
From: Steven Tolkin <steve.tolkin@fmr.com>
To: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Please advise. Fastest way to line-count files
Message-Id: <3490046F.2A52@fmr.com>
> Ravi Kumar <ravi@centtech.com> writes:
... I need to line-count
...
> Try this:
>
> (undef) = <FH> ;
> $count = $. ;
...
> Tom Christiansen tchrist@jhereg.perl.com
...
This is great! But if the file does not end in a newline, perl reports
one more line than wc -l. Adding a chomp and a test would fix that.
--
Steven Tolkin steve.tolkin@fmr.com 617-563-0516
Fidelity Investments 82 Devonshire St. R27C Boston MA 02109
There is nothing so practical as a good theory. Remarks are mine.
------------------------------
Date: 11 Dec 1997 15:46:14 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Please advise. Fastest way to line-count files
Message-Id: <66p1s6$1hf$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author, who
naughtily stealth cc'd via email]
In comp.lang.perl.misc, steve.tolkin@fmr.com writes:
:This is great! But if the file does not end in a newline, perl reports
:one more line than wc -l. Adding a chomp and a test would fix that.
You realize, I hope, that that's not a proper text file! Text files
contain 0 or more newline-terminated records.
He who confuses the terms "terminated", "separated", and "delimited",
will eventually become unhappy, especially using split() and <readline>.
text file: newline *terminated* ==> data\ndata\n
path variable: colon *separated* ==> data:data:data
strings: quote *delimited* ==> "data"
substitutes: whatever *delimited* ==> s/foo/bar/, s!foo!bar!
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"The purpose of most computer languages is to lengthen your resume by
a word and a comma." --Larry Wall
------------------------------
Date: 11 Dec 1997 13:46:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: removing duplicate entries from the PATH variable
Message-Id: <66oqs7$oh2$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, alester@bfsec.bt.co.uk writes:
:Does anyone have any suggestions on how I can check the directories
:listed on $PATH and, if any are duplicated, remove the first occurrence
:of it?
I once wrote a someone obfuscated program called manpath that infers a man
path based on a bin path. It removes duplicates, but preserves ordering.
CODE_0: for (split(/:/, $ENV{PATH})) {
next if /^\.?$/;
s![^/]*$!man!
&& -d
&& !$seen{$_}++
&& do {
($dev,$ino) = stat(_);
! $seen{$dev,$ino}++;
}
&& push(@manpath,$_);
}
print join(":", @manpath), "\n";
Let's use the essential techniques from that to implement
various versions of your request.
The following code retains only the first occurrence of a directory in
the path, mapping null elements to '.' as is proper. This would render:
/usr/bin:/bin/:/usr/bin:/usr/ucb => /usr/bin:/bin/:/usr/ucb
CODE_1: for $dir (split /:/, $path, -1) {
$dir = '.' unless length $dir;
push @outpath, $dir unless $seen{$dir}++;
}
print join(":", @outpath), "\n";
But if /usr/bin and /usr/ucb are really the same directory? Or /bin
and /usr/../bin? How can you tell this? That's what the device-inode
pair returned from stat are for. Then you'd like this answer
/usr/bin:/bin/:/usr/bin:/usr/ucb => /usr/bin:/bin/
This code takes care of that:
CODE_2: for $dir (split /:/, $path, -1) {
$dir = '.' unless length $dir;
next unless ($dev,$ino) = stat($dir);
next unless -d _;
push @outpath, $dir unless $seen{$dev,$ino}++;
}
print join(":", @outpath), "\n";
The following code retains only the last occurrence of a directory in
the path. Well, it retains the position of the first occurrence, but the
name of the last. Thus if /usr/bin and /usr/ucb are the same directory,
/usr/bin:/bin/:/usr/bin:/usr/ucb => /usr/ucb:/bin/
CODE_3: for $dir (split /:/, $path, -1) {
$dir = '.' unless length $dir;
next unless ($dev,$ino) = stat($dir);
next unless -d _;
push @{$files{$dev,$ino}}, $dir;
push @inodes, $files{$dev,$ino} unless $seen{$dev,$ino}++;
}
print join(":", map { pop @$_ } @inodes), "\n";
Your question asked to suppress only the first one,
not all but the last. This would do so:
CODE_4: @dirs = grep { -d }
map { /^$/ ? '.' : $_ }
split /:/, $path, -1;
for $dir (@dirs) { $seen{$dir}++ }
for $dir (@dirs) {
push(@outpath, $dir)
unless $seen{$dir} > 1 && !$printed{$dir}++;
}
print join(":", @outpath), "\n";
But I don't like the fact that it can't discern identical
directories with different names. Here, this one does:
CODE_5: @dirs = grep { -d }
map { /^$/ ? '.' : $_ }
split /:/, $path, -1;
for $dir (@dirs) {
($dev,$ino) = stat($dir);
$file2inode{$dir} = $dev . $; . $ino;
$seen{$dev,$ino}++;
}
for $dir (@dirs) {
$pair = $file2inode{$dir};
push(@outpath, $dir)
unless $seen{$pair} > 1 && !$printed{$pair}++;
}
print join(":", @outpath), "\n";
Hope this provides some insight into your problem.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Just because you're into control doesn't mean you're in control."
--Larry Wall
------------------------------
Date: 11 Dec 1997 08:31:21 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: alester@bfsec.bt.co.uk
Subject: Re: removing duplicate entries from the PATH variable
Message-Id: <8cra7jkiba.fsf@gadget.cscaper.com>
>>>>> "Adrian" == Adrian Lester <alester@bfsec.bt.co.uk> writes:
Adrian> Does anyone have any suggestions on how I can check the directories
Adrian> listed on $PATH and, if any are duplicated, reomve the first occurance
Adrian> of it?
I presume you mean "later occurances", not "first occurance". :-)
print "PATH=", join ":", grep !$seen{$_}++, split ":", $ENV{PATH};
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 264 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 11 Dec 1997 08:39:23 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Erik D. Jones" <erikdj@cyberjunkie.com>
Subject: Re: Socket I/O in Perl5
Message-Id: <8cn2i7khxw.fsf@gadget.cscaper.com>
comp.lang.perl is dead. Has been for over two years.
>>>>> "Erik" == Erik D Jones <erikdj@cyberjunkie.com> writes:
Erik> I am working with PERL5.003 and I'm writing a program that scans a range
Erik> of IP addresses. For each IP address it attempts a socket connection to
Erik> a particular PORT. Everything works great and I am able to process the
Erik> errors properly and all that (set by errno from the connect() function
Erik> call), but the connection timeout value is set so high that without
Erik> creating a multithreaded program, this scan is going to take a million
Erik> years.
My spider sense is tingling.
Erik> get/setsockopt does not seem to have a value that specifically
Erik> relates to connection timeouts.
Right. These timeouts are set by TCP standards, and not by mere
mortal users.
Erik> What do I do??? ARgh!!
Fork a lot. There's no other way. Fork 15 children, keep them
all busy, and you'll be probing at least every 2 seconds.
But I'm still curious as to the *legitmate* usage of so many probes.
Please tell me you're a good guy, a white hat, and why you are doing
this. I'll sleep better at night if you do.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 264 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Thu, 11 Dec 1997 15:19:15 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: sorting a hash of hashes???
Message-Id: <EL16K3.Mvq@world.std.com>
ljwobker@eos.ncsu.edu (Lawrence J. Wobker) writes:
[with various parts cut out.]
>I have a hash or hashes, set up like so:
>%USERDATA= ();
>$USERDATA{$emailaddress}{current} = x;
>$USERDATA{$emailaddress}{cumulative} = y;
>What I'm looking to do is sort the elements of the
>hash by either the current or overall values.
for $address (sort { $USERDATA{$a}{current} <=> $USERDATA{$b}{current} }
keys %USERDATA) {
print "$USERDATA{$address}{current} $USERDATA{$address}{cumulative}\n";
}
For more information, you might want to look at the perl data
structure cookbook? (the perldsc man page.) and the entry in the FAQ
"How do I sort a hash (optionally by value instead of key)?"
<URL:http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq4/
How_do_I_sort_a_hash_optionaly.html>
--
Andrew Langmead
------------------------------
Date: Thu, 11 Dec 1997 08:06:47 -0500
From: TechMaster Pinyan <jefpin@bergen.org>
To: Andrew Wood <andrew.wood@cableol.co.uk>
Subject: Re: using PERL with Personal Web server under 95
Message-Id: <Pine.SGI.3.95.971211080536.4194B-100000@vangogh.bergen.org>
>I have installed Front Page on my Windows 95 machine and have PERL on
>it.
>I have changed the first line of my cgi script to reflect the new
>location of perl from its unix form to its Windows form.
>I am still getting HTTP/1.0 500 Server errors trying to run the code.
>Does anybody have an answer to this problem as the page that Micorsoft
>say too look at doesnt exist, which is nothing unusual for them.
I would suggest switching to OmniHTTPD... it is much nicer, allows for
Perl, and is much easier to handle (IMHO)...
http://www.fas.harvard.edu/~glau/httpd/
----------------
| "I don't contemplate it, I just sit and think about it."
| - Sonia Balsky
----------------
Jeff Pinyan | http://users.bergen.org/~jefpin | jefpin@bergen.org
webXS - the new eZine for WebProgrammers! TechMaster@bergen.org
Visit us @ http://users.bergen.org/~jefpin/webXS
*NEW* techmaster@mindless.com | jpinyan@sdf.lonestar.org *NEW*
** I can be found on #perl on irc.ais.net as jpinyan **
- geek code -
GCS/IT d- s>+: a--- C+>++ UAIS+>$ P+++$>++++ L E--->---- W++$
N++ !o K--? w>+ !O M>- V-- PS PE+ !Y !PGP t+ !5 X+ R tv+ b>+
DI+++ D+>++ G>++ e- h- r y?
------------------------------
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 1454
**************************************