[7282] in Perl-Users-Digest
Perl-Users Digest, Issue: 907 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 22 19:17:17 1997
Date: Fri, 22 Aug 97 16:00:26 -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 Fri, 22 Aug 1997 Volume: 8 Number: 907
Today's topics:
Re: another regex <dbenhur@egames.com>
Re: beginner's help (Sami Sandqvist)
Constants in Perl (was Re: Help: Perl) (Matthew Cravit)
Re: Forcing print<< to be VERY LITERAL (Kirk L. Israel)
Re: foreach and arrays xewj@odin.sunquest.com
Re: foreach and arrays (Mike Stok)
Re: How can I get rid of carriage return in textarea (brian d foy)
Re: I'm looking for a perl logo... (Brandon S. Allbery KF8NH)
Re: naming arrays <rstarling@btg.com>
Re: Newbie 'exec' question <arv@fcee.urv.es>
Re: OS/2: Locales / I18N problem: What to do? (Brandon S. Allbery KF8NH)
Re: Passing multiple arrays to subroutine ??? (Terry Michael Fletcher - PCD ~)
Re: Pattern repacement with variables question (Brandon S. Allbery KF8NH)
Re: Perl Patterns for CGI (Brandon S. Allbery KF8NH)
Re: Perl5 garbage collection too lazy? (Brandon S. Allbery KF8NH)
Problem with opening file for appending.....ARGH!!!!! <daveck@top.monad.net>
Proprietary Perl ??? (O'Reilly Perl Resource Kit) <selden@NOSPAM.instinet.com>
Re: Question about arrays. (Chris Sherman)
Re: reading a gz file <zenin@best.com>
Removing duplicates from an array (Patrick Randall)
Re: Removing duplicates from an array (Mike Stok)
Re: Removing duplicates from an array <mattrope@mdhost.cse.tek.com>
Re: Search Engine scripts ? <usenet-tag@qz.little-neck.ny.us>
Slides from my perl/database talk available <frank@w3-design.com>
Re: Still not solved (was: Pattern repacement with vari (Brandon S. Allbery KF8NH)
Re: WILL PAY for help and or development work <zenin@best.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 22 Aug 1997 12:33:15 -0700
From: Devin Ben-Hur <dbenhur@egames.com>
To: Greg Land <gland@ccs.neu.edu>
Subject: Re: another regex
Message-Id: <33FDE97B.4CE6@egames.com>
[mail&post]
Greg Land wrote:
> Ok... once again I am faced with a few lines of code and my problem
> is dealing with regexes. I have a section that looks like this:
> <P>Someone@somewhere.com
> What I need is to make it look like this:
> <P><a href="Someone@somewhere.com">Someone@somewhere.com</a>
This should do it:
s/([^\s<>"]+\@[^\s<>"]+)/<a href="$1">$1<\/a>/g;
Though I suspect you really meant:
s/([^\s<>"]+\@[^\s<>"]+)/<a href="mailto:$1">$1<\/a>/g;
The [^\s<>"]+ matchs one or more characters which aren't whitespace
or < > or ". The $1 in the replacement part expands to the string
matched within the grouping parens in the regexp part.
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
Warning: Dates in Calendar are closer than they appear.
------------------------------
Date: 22 Aug 1997 21:22:29 GMT
From: sami@d246a.mtalo.ton.tut.fi (Sami Sandqvist)
Subject: Re: beginner's help
Message-Id: <slrn5vs0qs.2td.sami@d246a.mtalo.ton.tut.fi>
On Fri, 22 Aug 1997 14:12:18 -0600, frankel@cs.concordia.ca wrote:
>I tried to use the hex function to convert hexadecimal to decimal.
>Since hex() doesn't recognize negatif number, I check for it and I just
>delete it.
>Here's the code :
>
>#!/site/bin/perl
>print "Enter hexadecimal number: ";
>$answer=<STDIN>;
> if ($answer= ~/^-/) {
^
Remove the space between '=' and '~'.
> print "-";
> $answer= ~s/^-/""/;
This becomes:
$answer =~ s/^-//;
>}
>print hex($answer),"\n";
Sami
--
#################################################
#Sami Sandqvist #Finger for PGP key #
#samiss@cc.tut.fi # #
#################################################
------------------------------
Date: 22 Aug 1997 14:19:01 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Constants in Perl (was Re: Help: Perl)
Message-Id: <5tkvo5$du6$1@shell3.ba.best.com>
In article <5tkqjf$5f5@news-central.tiac.net>,
Mike Stok <mike@stok.co.uk> wrote:
>In article <5tkp3t$26b$1@nnrp.cs.ubc.ca>,
>Henry Avatar Chan <q8e192@ugrad.cs.ubc.ca> wrote:
>>Question 1)
>>How do you make CONSTANTS in Perl.
> use constant BUFFER_SIZE => 4096;
The other way you can do this is to take advantage of the fact that
subroutines without a return statement return the last thing they
evaluated. So, you could do something like this:
sub PI { 3.14159; }
sub SENDMAIL { "/usr/sbin/sendmail"; }
print "Pi = ", PI, "\n";
print "Sendmail lives in \"", SENDMAIL, "\".\n";
This will print out:
Pi = 3.14159
Sendmail lives in "/usr/sbin/sendmail".
Hope this helps.
/MC
--
Matthew Cravit, N9VWG | Experience is what allows you to
E-mail: mcravit@best.com (home) | recognize a mistake the second
mcravit@taos.com (work) | time you make it.
------------------------------
Date: 22 Aug 1997 21:32:07 GMT
From: kisrael@allegro.cs.tufts.edu (Kirk L. Israel)
Subject: Re: Forcing print<< to be VERY LITERAL
Message-Id: <5tl0gn$h8t$1@d2.tufts.edu>
Kirk L. Israel (kisrael@allegro.cs.tufts.edu) wrote:
: Is there any way to force print<<ENDofQUOTE to behave and do
: no interpretation til the 'ENDofQUOTE'? I'm having a perl script
: that outputs a big block of complicated javascript (javascript that
: writes javascript, in fact) and I need \n and \' to be saved for use
: by the metajavascript-- I'll even sacrifice interpretation of
: $variables if need be.
I got my answer from 'experts exchange' ( http://www.experts-exchange.com
-- i suspect they added the dash to not be confused with expert-sexchange)
Despite their *vaguely* spammy way of getting my attention (looking for
'unanswered questions' on usenet groups, then using e-mail to suggest
their surface as an alternative) it's an excellent service and a good
idea, with a much better S/N ration and quicker turn around than Usenet.
The implementation needs work (especially a search engine!) but the
concept is sound.
Anyway, the answer i got was to put the end of quote name in single
quotes,
like this
print<<'EoQ';
this is literal!\n\'\'!!
EoQ
which indicates single quote mode. very nice.
My work around was to put the javascript in an external file, then
read it in using the usual open;while(<>)print;close; kind of stuff.
That actually has some advantages in this case (keeping the javascript in
an external editable file) but it's nice to have the option.
Now if only I could get blockquoting WITH variable interprolation and
WITHOUT interpreting \n and \'
hey, looks like my perl implementation of unix fortune has some kind
of instinct for picking a timely .sig ;-)
--
Kirk Is | "The road to hell is paved with melting snowballs."
kisrael@ | --Larry Wall
alienbill.com |
------------------------------
Date: 22 Aug 1997 20:23:21 GMT
From: xewj@odin.sunquest.com
Subject: Re: foreach and arrays
Message-Id: <5tksfp$jr5$1@iggy.sunquest.com>
In article <nqo67syz61m.fsf@mitra.phys.uit.no>,
Tom Grydeland <tom@mitra.phys.uit.no> wrote:
>denis@mathi.uni-heidelberg.de writes:
>> how can i find out the offset i need, without
>> changing my foreach in a for to do...?
>When you need the index in the array, it means you change foreach to for.
>That's what for's for.
Or just have an arbitrary variable you increment each time: a for in a foreach
------------------------------
Date: 22 Aug 1997 20:45:51 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: foreach and arrays
Message-Id: <5tktpv$af1@news-central.tiac.net>
In article <5tksfp$jr5$1@iggy.sunquest.com>, <xewj@odin.sunquest.com> wrote:
>In article <nqo67syz61m.fsf@mitra.phys.uit.no>,
>Tom Grydeland <tom@mitra.phys.uit.no> wrote:
>>denis@mathi.uni-heidelberg.de writes:
>>> how can i find out the offset i need, without
>>> changing my foreach in a for to do...?
>>When you need the index in the array, it means you change foreach to for.
>>That's what for's for.
>
>Or just have an arbitrary variable you increment each time: a for in a foreach
One feature I like about recent perls is that you can get "properly"
scoped variables e.g.
#!/usr/local/bin/perl -w
use strict;
use vars qw/@array/;
@array = qw/Thrang Thrang Gozinbulx/;
for (my $index = 0; $index < @array; $index++) {
print "array[$index] is $array[$index]\n";
}
__END__
has the lexical $index usefully confined to the for loop.
Just an observation,
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: Fri, 22 Aug 1997 09:37:23 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: How can I get rid of carriage return in textarea
Message-Id: <comdog-2208970937230001@netnews.worldnet.att.net>
In article <01bcaea2$99eccfe0$677112ce@1>, "Brendan Murphy"
<info@arkson.com> wrote:
> How can I get rid of carriage return in textarea form to avoid messing up
> when the database cgi program build a file (db) where all the input should
> be on one line?
is s/\r|\n/ /g; not working?
--
brian d foy <http://computerdog.com>
------------------------------
Date: 22 Aug 1997 19:58:29 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: I'm looking for a perl logo...
Message-Id: <slrn5vrrn1.dr.bsa@rushlight.kf8nh.apk.net>
On 21 Aug 1997 02:13:39 GMT, Jim Scofield <jimsco@beorc.com> wrote:
+-----
| Don't laugh. From what I hear, Gateway is going after companies that use
| Cows for marketing.
+--->8
Chick-Fil-A? Hershey Foods? This ought be interesting.
------------------------------
Date: Fri, 22 Aug 1997 11:52:20 -0400
From: Rob Starling <rstarling@btg.com>
Subject: Re: naming arrays
Message-Id: <33FDB5B4.677A@btg.com>
Tad McClellan wrote:
>
> MAHANTA girish (mahanta@cs.concordia.ca) wrote:
>
> : Hello!
>
> : Can I know how to go about this:
>
> : I have a large number of arrays named: @bw00, @bw01, .... @bw050
> : Inside the program I want to reference the arrays dynamically, with help of
> : the numbers following the @bw string. Say @bw$n where $n has the subscript
> : of the array I want to reference, without having to wrtie @bw00 explicitely.
>
> : Is there any way I can do this? I appreciate any help.
>
> Whenever you find yourself using variables with increasing integer parts
> in the variable name, you are probably doing something that should be
> in an array instead.
>
> So, since you have arrays with such names, you would likely be better
> off by using an array of arrays. See the perllol man page for info
> on how to do that.
>
> If you insist on doing it as originally stated, then you may find the
> 'Symbolic references' section in the perlref man page to be helpful...
>
> --
> Tad McClellan SGML Consulting
> tadmc@flash.net Perl programming
> Fort Worth, Texas
or
eval "\@bw$n"
--Rob
#include <disclaimer.h>
------------------------------
Date: Sat, 23 Aug 1997 00:36:55 +0200
From: Alexis Roda <arv@fcee.urv.es>
To: Claude Montpetit <claude@macadamian.com>
Subject: Re: Newbie 'exec' question
Message-Id: <33FE1487.6F6164C1@fcee.urv.es>
Claude Montpetit wrote:
>
> Do I need to do something special in the perl script for this output to
> be redirected to a browser? The browser does not receive it. Here is my
> perl code invoking my application:
>
> exec 'c:\java MyApp';
system is better than exec, exec will end the perl script. I don't know
how it works under DOS, under UNIX the http server redirects stdout of
the CGI script so the output it produces can be sent back to the
browser. I think that your perl script ends after the exec and the http
server don't wait for the "execed" program to end. Also you should
consider setting the $| variable if you get mixed output.
Hope this help
Saludos
Alexis Roda
------------------------------
Date: 22 Aug 1997 20:38:12 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: OS/2: Locales / I18N problem: What to do?
Message-Id: <slrn5vru1h.dr.bsa@rushlight.kf8nh.apk.net>
On 28 May 1997 06:25:53 GMT, Koos Pol <koos_pol@nl.compuware.com.NO_JUNK_MAIL> wrote:
+-----
| Thanks Ilya for yet another response! You seem to be the only guy around
| with interest in Perl/2. Well, with me you have at least 1 very happy customer!
+--->8
He's not the only one, just the only one that hangs out here regularly.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
(APK spam kill&log system now in use: change "void" to "kf8nh" to mail me.)
------------------------------
Date: 22 Aug 1997 16:14:35 GMT
From: tfletche@pcocd2.intel.com (Terry Michael Fletcher - PCD ~)
Subject: Re: Passing multiple arrays to subroutine ???
Message-Id: <5tkdtb$r4h$1@news.fm.intel.com>
Simon Fairey (sfairey@adc.metrica.co.uk) so eloquently and verbosely pontificated:
> James H. Blackwell wrote:
> > [stuff]
> > my_routine(\@arr1, \@arr2, \@arr3)
>
> [more stuff]
> sub my_routine {
> my( $ar1_ref, $ar2_ref, $ar3_ref ) = @_;
>
> Then to process one of the array references as an array use '@$ar1_ref'
> and to access individual elements use '$$ar1_ref[0]' or the much nicer
> '$ar1_ref->[0]'.
>
> PS: You might also want to look at prototyping your subroutine so that
> you dont need to de-reference the arrays ( see perlsub manpage ).
right. do a quick 'perl -v' from the command line, and if you have
>=5.003, then you can do the prototypes:
sub my_routine (\@\@\@;) {
my ($ref1, $ref2, $ref3) = @_;
} # now refer to them as @$ref1[x], $$ref1[x], or $ref1->[x]
my_routine (@array1, @array2, @array3);
# now you dont need the backslash when you call the routine, only the
# prototype
hope that helped.
--
print "J" ."u". # -- Terry Fletcher
"s" ."t". " A", "n" # tfletche@pcocd2.intel.com
. "o" ,""."". "the", "r ","P". # Views expressed....not
"e"."rl" ." Ha", "c",'' ."" ."". # INTeL's....yadda yadda
"" , "k". "e" ."r" ;# yadda....
------------------------------
Date: 22 Aug 1997 21:06:13 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: Pattern repacement with variables question
Message-Id: <slrn5vrvm1.dr.bsa@rushlight.kf8nh.apk.net>
On Mon, 18 Aug 1997 14:07:38 -0700, Mark Tripod <mark@pbi.net> wrote:
+-----
| change $replace = '$2 $1';
| to $replace = "$2 $1";
|
| single quotes prevent the variable substitution that you are looking
| for.
+--->8
At the time you do this the operation that sets $1 and $2 hasn't taken place
yet; he'll get the results from the last pattern match, which for the test
case will be empty and $replace will be ' '.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
(APK spam kill&log system now in use: change "void" to "kf8nh" to mail me.)
------------------------------
Date: 22 Aug 1997 21:18:14 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: Perl Patterns for CGI
Message-Id: <slrn5vs0ci.dr.bsa@rushlight.kf8nh.apk.net>
On Sat, 7 Jun 1997 05:09:34 GMT, Abigail <abigail@fnx.com> wrote:
+-----
| Michael Iles (thuja@internauts.ca) wrote on 1375 September 1993 in
| <URL: news:339868B0.4B58@internauts.ca>:
| ++ CGI programming. CGI requires an interesting model as all output must be
| ++ buffered until after any processing that might fail.
| Unless they changed something about the protocol behind my back, it
| doesn't. Do you have a reference to back up your claim?
+--->8
As a practical matter, a CGI error after outputting half of a web page made
the browsers I tried produce even uglier messages than they did when the error
happened before page output. I worked around it by buffering output into
variables and generating the page afterward.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
(APK spam kill&log system now in use: change "void" to "kf8nh" to mail me.)
------------------------------
Date: 22 Aug 1997 21:29:53 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: Perl5 garbage collection too lazy?
Message-Id: <slrn5vs12e.dr.bsa@rushlight.kf8nh.apk.net>
On Fri, 06 Jun 1997 15:48:33 +0200, Douglas Seay <seay@absyss.fr> wrote:
+-----
| Scott Maxwell wrote:
| > Douglas Seay <seay@absyss.fr> writes:
| > > As a side note, I have heard that the linux implementation of free() can
| > > release memory, but I've never looked to see if this was true or just
| > > another rumor.
| > I tried this on my Linux box (kernel 2.0.29, perl 5.003), and in a C
| > program, free() did cause the process's SIZE (as reported by ps) to
| > decrease to its value before the malloc().
| if you even get some space back, you're ahead of the original poster who
| got nothing from HP-UX 10. Funny how free software can often do things
| the big name company software cannot, not that I'm knocking HP in
| particular.
+--->8
I suspect you can in HP/UX; it's just not the default. (Under certain
conditions it can cause sbrk() "thrashing", and some buggy-to-begin-with
programs can core using it.) Try malloc(3x), with particular attention to
mallopt(). (Unless HP zapped it, of course.)
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
(APK spam kill&log system now in use: change "void" to "kf8nh" to mail me.)
------------------------------
Date: Fri, 22 Aug 1997 18:14:05 -0400
From: David Eck <daveck@top.monad.net>
Subject: Problem with opening file for appending.....ARGH!!!!!
Message-Id: <33FE0F2D.97AFDC52@top.monad.net>
Hi,
I am having a problem with the following code. It is driving me crazy.
I am a novice so if its something obvious, go easy on me.
I have confirmed that the value of $filename is what it should be. Yet
it does not open the file. When I replace $filename with the static
text of the actual file name it works fine. This is driving me crazy,
so if anyone could help, I would appreciate it.
open FOLDER, '>>$filename' or
&CgiDie("Could not open file - ($filename)");
Thanks,
David Eck
Please forward to me at daveck@monad.net.
------------------------------
Date: Fri, 22 Aug 1997 16:06:33 -0400
From: Michael Shael O'Neill Selden <selden@NOSPAM.instinet.com>
Subject: Proprietary Perl ??? (O'Reilly Perl Resource Kit)
Message-Id: <33FDF149.211E@NOSPAM.instinet.com>
Greetings All,
I was checking out the O'Reilly site for information regarding
the upcoming Advanced Perl Programming book (totem animal shock!)
when I came across a page detailing an O'Reilly product due out in
10/97 called the Perl Resource Kit (http://perl.oreilly.com/), the
blurb for which indicates that it includes new language features
("commercially-enhanced Perl compiler, written by Larry Wall, creator of
Perl", "enhanced database support tools", "enhanced Perl security
modules", etc.). What I am curious about is (in addition to details
regarding the new features, which I have asked O'Reilly for :-}) what
the impact of this development (no pun intended) will be on the P.D.
Perl world. In other words, is this going to result in a discrepancy
between the Perl used by paid-in-full corporate accounts and your
average download and code type. Curiosity overwhelms me; I seek
enlightenment.
Michael.
--
Michael Shael O'Neill Selden, SA, DBA, JAPH, DAD
selden@instinet.com
Remove "NOSPAM." From Address To Return Mail
PGP Public Key Available Upon Request
------------------------------
Date: Fri, 22 Aug 1997 20:59:02 GMT
From: sherman@unx.sas.com (Chris Sherman)
Subject: Re: Question about arrays.
Message-Id: <EFC2AE.EFD@unx.sas.com>
In <5tib84$6bq$1@news.rsn.hp.com> nigelr@convex.hp.com (Nigel Reed) writes:
>Tomorrow, I'm going to be working on a program to process a file
>It'll be in the format
>char(8),int,int,int,int,int
>Now, what I am going to want to do, is all up all the integer
>values for all occurences of char.
>For example.
>Andy,1,6,5,3,6
>Andy,5,6,3,5,2
>Bill,5,3,1,4,6
>Bill,6,7,3,3,1
>Ted,1,5,9,7,5
>Tom,4,5,6,2,1
>I need to end up with an array like this
>Andy,6,12,8,8,8
>Bill,11,10,4,7,7
>Ted,1,5,9,7,5
>Tom,4,5,6,2,1
Try this:
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#!/usr/local/bin/perl5
while (<>) {
my $i = 0;
chop;
($name,@list) = split ',';
map {
if (defined($sum{$name}[$i])) {
$sum{$name}[$i++] += $_;
}
else {
$sum{$name}[$i++] = $_;
}
} @list;
}
foreach $i (sort keys %sum) {
print "$i," . join(',', @{$sum{$i}}) . "\n";
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It could probably be made smaller, but I left it like this so you could
see what was going on.
Hope this helps...
--
____/ / / __ / _ _/ ____/
/ / / / / / / Chris Sherman
/ ___ / _/ / /
_____/ __/ __/ __/ _\ _____/ _____/ sherman@unx.sas.com
------------------------------
Date: 22 Aug 1997 21:19:33 GMT
From: Zenin <zenin@best.com>
Subject: Re: reading a gz file
Message-Id: <5tkvp5$rug$1@nntp2.ba.best.com>
David Smits <bb@b-b.nl> wrote:
> Is there a possibility to read in a gz file with out unpacking it first.
open SESAME, "gunzip -c filename.gz |"
or die $!;
$file = join '', <SESAME>;
close SESAME
or die $!;
Hope this helps!
--
-Zenin
zenin@best.com
------------------------------
Date: Fri, 22 Aug 1997 19:07:21 GMT
From: randall@grcmc.net (Patrick Randall)
Subject: Removing duplicates from an array
Message-Id: <33fde2e9.507603635@news.grfn.org>
Can anyone show me an easy way to remove duplicate elements from an
array?
I've tried using foreach loops, but it seems terribly inefficient.
thanks,
patrick
------------------------------
Date: 22 Aug 1997 20:16:13 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Removing duplicates from an array
Message-Id: <5tks2d$7hm@news-central.tiac.net>
In article <33fde2e9.507603635@news.grfn.org>,
Patrick Randall <randall@grcmc.net> wrote:
>Can anyone show me an easy way to remove duplicate elements from an
>array?
>
>I've tried using foreach loops, but it seems terribly inefficient.
The perl FAQ (available as manual pages in the latest releases or from
http://www.perl.com/FAQ/ anobngst other places on the web/net) has this
to say in response to the question How can I extract just the unique
elements of an array?
There are several possible ways, depending on whether the array is
ordered and whether you wish to preserve the ordering.
a) If @in is sorted, and you want @out to be sorted:
$prev = 'nonesuch';
@out = grep($_ ne $prev && ($prev = $_), @in);
This is nice in that it doesn't use much extra memory,
simulating uniq's behavior of removing only adjacent
duplicates.
b) If you don't know whether @in is sorted:
undef %saw;
@out = grep(!$saw{$_}++, @in);
c) Like (b), but @in contains only small integers:
@out = grep(!$saw[$_]++, @in);
d) A way to do (b) without any loops or greps:
undef %saw;
@saw{@in} = ();
@out = sort keys %saw; # remove sort if undesired
e) Like (d), but @in contains only small positive integers:
undef @ary;
@ary[@in] = @in;
@out = sort @ary;
Note that a relies on the first element of the array not being'nonesuch'
;-)If you don't care about sorting then
@list = keys %{{map {$_ => 1} @list}};
might work for you (but be aware of the memory consumption when
working with a large data set...)
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: Fri, 22 Aug 1997 13:44:02 -0700
From: Matt Roper <mattrope@mdhost.cse.tek.com>
To: Patrick Randall <randall@grcmc.net>
Subject: Re: Removing duplicates from an array
Message-Id: <Pine.SUN.3.95q.970822134001.12270E-100000@tekgp4.cse.tek.com>
On Fri, 22 Aug 1997, Patrick Randall wrote:
> Can anyone show me an easy way to remove duplicate elements from an
> array?
>
> I've tried using foreach loops, but it seems terribly inefficient.
>
> thanks,
> patrick
>
>
>
>
Hmm. I don't know if this works or not since I haven't tried it, but how
about something like this:
foreach $element(@array) {
$temp{$element} = 1; ##### Use an associative array
}
@array = keys %temp;
This way if a duplicate was found, it wouldn't create a new entry in the
associative array, just change the value. At the end, all of the keys
would be unique and the keys statement could be used to turn it back into
a normal array.
There's probably an even easier way to do it, but this is what I though of
first. Hope this helps!
==============
Matt Roper
mattrope@mdhost.cse.tek.com
------------------------------
Date: 22 Aug 1997 20:38:25 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: Search Engine scripts ?
Message-Id: <eli$9708221632@qz.little-neck.ny.us>
Peter Douglas <rmanocha@rocketmail.com> wrote:
> I am developing a search engine for a company. The search engine is
> probably going to be in a similar format as yahoo or search.com where you
> can search through many categories.
>
> I am looking for a script (preferably free) which does a similar thing.
So let me get this straight,
(1) You are being paid to do some work
(2) You would like to steal someone else's code as a framework
(3) You don't want to pay for the code
(4) You can't be bothered to actually look for it yourself
and so
(5) You are asking comp.lang.perl.misc and comp.lang.perl.tk to help you.
Sod off.
Elijah
------
annoyed with the surfeit of cgi shit
------------------------------
Date: Fri, 22 Aug 1997 14:39:12 -0700
From: Frank San Filippo <frank@w3-design.com>
Subject: Slides from my perl/database talk available
Message-Id: <33FE06FF.F2F@w3-design.com>
For those interested, the slides from my talk, "DBI/DBD and Ease of
Portability -- The Hollywood Reporter: A Case Study," are available at
http://www.w3-design.com/perlconf/
This was part of Tim Bunce's presentation on DBI.
It was really great meeting all you folks in San Jose!
F.
--
<html><head><title>
F r a n k S a n F i l i p p o
</title></head><body><a href="http://www.w3-design.com/">
w 3 - d e s i g n
<p>(310) 815-1177 fax:(310) 815-1133</p>
</a></body></html>
------------------------------
Date: 22 Aug 1997 21:04:27 GMT
From: bsa@void.apk.net (Brandon S. Allbery KF8NH)
Subject: Re: Still not solved (was: Pattern repacement with variables question)
Message-Id: <slrn5vrvio.dr.bsa@rushlight.kf8nh.apk.net>
On 20 Aug 1997 10:53:04 +0200, Ronald Fischer <rovf@earthling.net> wrote:
+-----
| Scalar found where operator expected at (eval 1) line 1, near "$2 $1"
| (Missing operator before $1?)
|
| Using two 'e' don't make sense to be; the Camel book, at least, does
| not mention any effect of doubling the /e modifier, so I tried the
| variant
+--->8
I think you missed the reference, because it doubles, triples, quadruples,
etc. The problem with the substitution is that the Perl expression
$2 $1;
is a syntax error. I can't think of any quick fixes offhand.
--
brandon s. allbery [Team OS/2][Linux] bsa@void.apk.net
cleveland, ohio mr/2 ice's "rfc guru" :-) FORZA CREW!
Warpstock '97: OS/2 for the rest of us! http://www.warpstock.org
(APK spam kill&log system now in use: change "void" to "kf8nh" to mail me.)
------------------------------
Date: 22 Aug 1997 21:56:08 GMT
From: Zenin <zenin@best.com>
Subject: Re: WILL PAY for help and or development work
Message-Id: <5tl1to$rug$2@nntp2.ba.best.com>
Robby <rob@riverweb.co.uk> wrote:
>snip<
> Will there be a problem with TCP/IP?
Yes. Most people don't have a TCP/IP stack installed on
stand alone Windows boxes. This meens your CD will require
they install TCP/IP drivers and reboot there machine before
your CDROM will work.
Netscape (and browsers in general) need a way of faking local
CGI support... :(
> Does the server and interpreter have to be installed in the standalone
> or can it run from CD?
Depends. If neither need to write anything (just junk the web
logs) then it should be fine as you can execute from the CD.
--
-Zenin
zenin@best.com
------------------------------
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 907
*************************************