[10374] in Perl-Users-Digest
Perl-Users Digest, Issue: 3966 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 13 19:07:22 1998
Date: Tue, 13 Oct 98 16:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 13 Oct 1998 Volume: 8 Number: 3966
Today's topics:
Re: ?? Builtin function gets (R. Ransbottom)
Re: Are there any "perl.newbie" group or forum? (John Stanley)
ARRAYS!!!!!!!!!! <jmcmilla@gettysburg.edu>
Better ways to do this? <stacy.doss@amd.com>
Compiling perl 5.005_02 on Dynix/ptx 4.2.3 (Mark Doyle)
Re: Continuing s/// from the last position. <antti.boman**SP@MPROTECTION***helsinki.fi>
Re: Continuing s/// from the last position. <uri@camel.fastserv.com>
Re: Creating an unreadable perl executable (brian d foy)
Re: encryption (John Stanley)
Re: encryption (Michael J Gebis)
Re: Help Debugging Formatted Writes (Perl 5.005) <whitepr@scp1.bellcore.com>
How to Adduser/mail for NT ??? dragnovich@my-dejanews.com
Re: How to Adduser/mail for NT ??? <rootbeer@teleport.com>
Re: London.pm - Changed URL (brian d foy)
Re: Max lines in an Array? <sales@madm.com>
Need msqlperl tar file for version 1.15 of msqlperl <sirron@mail.mcoe.k12.ca.us>
Off-topic - Wayward shopping trolleys <gellyfish@btinternet.com>
Re: Perl Cookbook - is this the best perl book? (Ilya Zakharevich)
Re: Perl Cookbook - is this the best perl book? (Larry Rosler)
Re: Perl Cookbook - is this the best perl book? (Brand Hilton)
Re: Perl Cookbook - is this the best perl book? <tchrist@mox.perl.com>
Re: Perl Cookbook - is this the best perl book? (Brand Hilton)
Re: Perl Cookbook - is this the best perl book? (Brand Hilton)
Perl object - why does this fail? <dlhawley@user1.teleport.com>
Re: Perl object - why does this fail? <rootbeer@teleport.com>
Re: Perl object - why does this fail? (Mark-Jason Dominus)
Re: perl scripts won't work: (RH5.1 Linux) "command not <eashton@bbnplanet.com>
Re: perl scripts won't work: (RH5.1 Linux) "command not <jdf@pobox.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Oct 1998 14:53:51 -0400
From: rir@phavl.ultranet.com (R. Ransbottom)
Subject: Re: ?? Builtin function gets
Message-Id: <7007jv$118$1@phavl.ethernet>
In article <6vuabr$laf$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>In article <6vtlic$53q$1@phavl.ethernet>,
>R. Ransbottom <rir@phavl.ultranet.com> wrote:
>>Is there any doc's for gets.
>
>Perl doesn't have `gets'. Instead, you do this:
>
> $line = <FILE>;
>
>where FILE is a filehandle. This reads one line of input form the
>filehandle and stores it in $line.
>
>You really need to get a book about Perl, and then you need to read
>it. Reading lines from a file will be covered in the first pages of
>any reasonable introductory book.
Thanks for trying to help.
I hate it when I take a condescending stance in a large
group and am wrong.
perldoc FileHandle says to see perlfunc for the docs on builtin gets.
perlfunc and _Programming_Perl_ (2nd ed) don't tell you what it is,
though the Camel book mentions it.
I am trying to translate stuff like this to use FileHandle,
I thought gets might be worth knowing about:
#!/usr/bin/perl -w
use strict;
open FH, "<afile";
my $r = new Reader;
print $r->read( *FH), "\n";
package Reader;
sub new { bless {}, shift;}
sub read {
$p = shift;
$p =~ /^Reader.+/ ? local *FH = $p : local *FH = shift;
my $b = "";
read *FH, $b, 2;
return $b;
}
--
rob
rir@phavl.ultranet.com
------------------------------
Date: 13 Oct 1998 21:10:30 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <700fk6$no8$1@news.NERO.NET>
In article <1dgqya1.151mx2bp5l112N@slip166-72-108-149.ny.us.ibm.net>,
Kevin Reid <kpreid@ibm.net> wrote:
>about where to find help for Perl). Would it be possible to do something
>similar with clp.misc (not moderated, but people have to register before
>posting)?
Register with whom?
------------------------------
Date: Tue, 13 Oct 1998 16:39:46 -0400
From: Graham McMillan <jmcmilla@gettysburg.edu>
Subject: ARRAYS!!!!!!!!!!
Message-Id: <3623BA92.E5040FBC@gettysburg.edu>
I'm trying to create a program that will read from a text file and print
in a text field in a form. I have all the arrays declared like this:
open(textfile, "file.txt");
chomp(@lines = <textfile>);
close(textfile);
($foo1,$foo2,$foo3,$foo4,$foo5,$foo6)=split(/:/,$lines[1]);
now I will have all I want is to have 1 variable by it's self (the one
above has 6). I want to print one that will just print one variable
from the @lines array.
If anyone can help please e-mail me at gmcmilla@nettaxi.com or post the
answer.
------------------------------
Date: Mon, 12 Oct 1998 23:53:48 -0500
From: Stacy Doss <stacy.doss@amd.com>
Subject: Better ways to do this?
Message-Id: <3622DCDC.85AD7E7A@amd.com>
I was recently asked how to convert a range (a splice) of an array of
binary data into hex format.
The data looks something like this
@data = (0, 1, 0, 1, 1, 1, 0, 1);
# 10111010 in msb format
# So the array in natural representation is ordered least significant
bit to most significant bit, but we want msb to lsb.
# We also only want (for arguments sake) bits 2 - 5 (It will always be a
range)
# 10[1110]10 or 1110
The result should be a scalar hex value.
i.e. For the above example
'e' or '0xe'
The following are my solutions. The first 5 address the problem of
lsb->msb to msb->lsb. The final three are concerned with getting the hex
value. Anybody got a cheaper/better way of doing this? BTW I think my
best is Solution #8. As all ways there is more than one way to do it.
# Through out I'll be using the variables $msb and $lsb, "Most
Significant
# Bit and Least Significant Bit" respectively, and @array which is an
# arbitrary length array of 1's or 0's i.e. the data for a *full* bus.
# Consider these are defined elsewhere in the proper scope, etc., etc.
# Then we maybe have something as simple and straight forward as ...
# Solution #1
my $bus = "";
for (my $i = $msb; $i >= $lsb; $i--) {
$bus .= $array[$i];
}
__END__
# Or .. (being a little cute) gives
# Soulution #2
foreach $i (reverse $lsb .. $msb) {
$bus .= $array[$i];
}
__END__
# Or yet another way
# Solution #3
@range = reverse @array[$lsb..$msb];
$bus = join '', @range;
__END__
# Even simpler (The way I'd probably do it)
# Solution #4
$bus = join '', reverse @array[$lsb..$msb];
__END__
# but a way, way much more complex, not suggested way
# Solution #5
my $bus = {
array => \@array,
m2l => sub {join '', reverse (@{$bus->{array}}[@_[1]..@_[0]])}
};
print &{$bus->{m2l}}($msb,$lsb);
__END__
# Solution #6
# For hex numbers
# Get binary representation
my $hexnum = ""
my @q = reverse @array[$lsb..$msb];
# Get decimal representation
foreach (@q) {
$hexnum = $hexnum * 2 + $_;
}
# Get hex representation
$hexnum = sprintf "%lx", $hexnum *= 2 ** $lsb;
__END__
# Compact that a little and you get
# Solution #7
# Get binary representation
my $hexnum = ""
# Get decimal representation
foreach (reverse @array[$lsb..$msb]) {
$hexnum = $hexnum * 2 + $_;
}
# Get hex representation
$hexnum = sprintf "%lx", $hexnum *= 2 ** $lsb;
__END__
# Solution #8
# But my personal favorite ...
# Lots of hand waving ... ... ...
my $hexnum = unpack('H32', pack ("b$msb", join '', @array[$lsb ..
$msb]));
__END__
------------------------------
Date: 13 Oct 1998 21:38:54 GMT
From: doyle@aps.org (Mark Doyle)
Subject: Compiling perl 5.005_02 on Dynix/ptx 4.2.3
Message-Id: <700h9e$f82$1@sun20.ccd.bnl.gov>
Hi,
We are trying to compile perl 5.005_02 on a Sequent machine running Dynix/ptx
4.2.3 and everything seems to go fine except for the lib/io_sel.t test which
indicates a problem with the 4-argument select.
Specifically, it begins to fail at test number 11. Has anybody run into this
or otherwise successfully compiled 5.005_02 on this platform? Suggestions
welcome... Our configuration is just what ./Configure -des supplies.
Thanks
Mark
------------------------------
Date: Wed, 14 Oct 1998 00:08:29 +0200
From: "Antti Boman" <antti.boman**SP@MPROTECTION***helsinki.fi>
Subject: Re: Continuing s/// from the last position.
Message-Id: <700ffh$37t$1@hiisi.inet.fi>
>A code snippet would have helped, but here are a couple of attempts:
>
>First, you could use the /g option, as in s/pattern/replacement/g
Aw, sorry but I didn't mean anything this basic :) The point was to replace
one string, and, to save time/processor resources, continue the next,
_different_ replacement, from the same position.
Any ideas now?
Thanks,
Antti
------------------------------
Date: 13 Oct 1998 17:51:09 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Continuing s/// from the last position.
Message-Id: <sarogrgqgfl.fsf@camel.fastserv.com>
>>>>> "AB" == Antti Boman <antti.boman**SP@MPROTECTION***helsinki.fi> writes:
>> A code snippet would have helped, but here are a couple of
>> attempts:
>>
>> First, you could use the /g option, as in s/pattern/replacement/g
AB> Aw, sorry but I didn't mean anything this basic :) The point was
AB> to replace one string, and, to save time/processor resources,
AB> continue the next, _different_ replacement, from the same
AB> position.
AB> Any ideas now?
well, you are right that /g and \G only work with m// and you want to
use s///.
how about using substr on the string. use pos, $& and m//g to locate the
matches, assign the new text into the spot with substr, and continue on
after setting the new pos. in effect this is all s/// does (but more
efficiently). use \G to anchor the search to the position of tha last match.
there may be other possibilities including using index if the strings
are not regexes.
hth,
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Tue, 13 Oct 1998 19:00:04 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Creating an unreadable perl executable
Message-Id: <comdog-ya02408000R1310981900040001@news.panix.com>
Keywords: from just another new york perl hacker
In article <36239041.C003F101@hal.ddntl.didata.co.za>, Mark Fergusson <mferg@hal.ddntl.didata.co.za> posted:
>How do I make an unreadable perl executable, (even with root
>permissions) ? Is there some perl conversion program ?
chmod 111 file.pl
however, you should consider that it's quite simple to retreive the
source if one can execute it.
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers needs volunteers! <URL:http://www.pm.org/to-do.html>
------------------------------
Date: 13 Oct 1998 21:18:21 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: encryption
Message-Id: <700g2t$nuo$1@news.NERO.NET>
In article <MPG.108d59559cb3626989808@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <1dguxph.19aj5d81jj881qN@host036-210.seicom.net> on Tue, 13
>Oct 1998 21:53:43 +0100, Joergen W. Lang <jwl@_munged_worldmusic.de>
>says...
>> Orlando Frooninckx <Frook@mail.dma.be> wrote:
>> > does anyone have a nice encryption function example so I can crypt
>> > sentences before writing them to a file?
>>
>> look for "crypt" in the "perlfunc" manpage;
>>
>> hth, Joergen
>
>That won't help. The 'crypt' function is useful only for encrypting
>passwords. It is effective only for the first eight characters of the
>input string.
But it is damn effective on those first 8.
You could always operate on the sentences 8 characters at a time.
------------------------------
Date: 13 Oct 1998 21:27:22 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: encryption
Message-Id: <700gjq$ist@mozo.cc.purdue.edu>
stanley@skyking.OCE.ORST.EDU (John Stanley) writes:
}In article <MPG.108d59559cb3626989808@nntp.hpl.hp.com>,
}Larry Rosler <lr@hpl.hp.com> wrote:
}>In article <1dguxph.19aj5d81jj881qN@host036-210.seicom.net> on Tue, 13
}>Oct 1998 21:53:43 +0100, Joergen W. Lang <jwl@_munged_worldmusic.de>
}>says...
}>> Orlando Frooninckx <Frook@mail.dma.be> wrote:
}>> > does anyone have a nice encryption function example so I can crypt
}>> > sentences before writing them to a file?
}>> look for "crypt" in the "perlfunc" manpage;
}>> hth, Joergen
}>That won't help. The 'crypt' function is useful only for encrypting
}>passwords. It is effective only for the first eight characters of the
}>input string.
}But it is damn effective on those first 8.
}You could always operate on the sentences 8 characters at a time.
If you're going to do this, you should probably just save yourself time
and unlink the file.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Tue, 13 Oct 1998 17:05:56 -0400
From: Paul White <whitepr@scp1.bellcore.com>
Subject: Re: Help Debugging Formatted Writes (Perl 5.005)
Message-Id: <3623C0B4.6068@scp1.bellcore.com>
Paul White wrote:
>
> I would appreciate any help I can get with
> this problem ... (scratching my head for awhile).
>
> I am running Perl 5.005 for WinNT in debug
> mode to decipher the following error:
>
> Use of uninitialized value at "filename" line "number", <IN> chunk
> "number".
>
> The location of the error is a formatted write
> to an output datafile.
>
> The program flow goes:
>
> #!/usr/bin/perl -w
> format FILENAME =
> @<<<<<< @<<<<<< @<<<<
> $a,$b,$c
> .
> open (FILENAME,">filename.dat");
>
> #... define parameters in this part
>
REMOVED THIS STUPID COMMAND and it works ....
> ($a,$b,$c) = split(/,/); # want comma field delimiter
>
> write FILENAME;
>
> close (FILENAME);
------------------------------
Date: Tue, 13 Oct 1998 21:57:04 GMT
From: dragnovich@my-dejanews.com
Subject: How to Adduser/mail for NT ???
Message-Id: <700ibh$q1k$1@nnrp1.dejanews.com>
Hello folks!
I develp software in perl for UNIX, but now we are trying to port our
programs to Windows. Now we need some function that can do a Adduser (just
like unix) or a program that can be configured for that! or some documentatio
to see HOW THE WINDOWS CREATES A USER! but we are bloqued in this point in
the proyect ...
And we need too, a mail program that can be used similar to the sendmail
command in UNIX...
I.e :
mail -s"hello this is a test" dragnovich@my-dejanews.com < filename.txt
Note : that we need Perl-Windows help!
See ya!
------------------------
Juan Carlos Lopez
QDesigns President & CEO
http://www.qdesigns.com
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 13 Oct 1998 22:29:10 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: How to Adduser/mail for NT ???
Message-Id: <Pine.GSO.4.02A.9810131527010.1979-100000@user2.teleport.com>
On Tue, 13 Oct 1998 dragnovich@my-dejanews.com wrote:
> I develp software in perl for UNIX, but now we are trying to port our
> programs to Windows. Now we need some function that can do a Adduser
> (just like unix) or a program that can be configured for that! or some
> documentatio to see HOW THE WINDOWS CREATES A USER!
Actually, this is not a Perl question. You'd need the same information if
your programs were written in C, for example. You're needing to know how
to interface to NT, so the docs, FAQs, and newsgroups about NT should be
of help to you. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 13 Oct 1998 18:48:52 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: London.pm - Changed URL
Message-Id: <comdog-ya02408000R1310981848520001@news.panix.com>
Keywords: from just another new york perl hacker
In article <36237659.DD3E86B1@bbnplanet.com>, Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> posted:
>> and it's free as in "freedom" and as is in "free beer". :)
>
>Even the box was free...it just doesn't get any cheaper does it?
i was under the impression that you got the "free beer" at any Perl
Monger event for the donation ;)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers needs volunteers! <URL:http://www.pm.org/to-do.html>
------------------------------
Date: Tue, 13 Oct 1998 14:34:49 -0700
From: "Doyle Johnson" <sales@madm.com>
Subject: Re: Max lines in an Array?
Message-Id: <700hvr$37i$1@nnrp03.primenet.com>
Thanks everyone... I was e-mailed some code that actually got me over the
20,000 line limit I was looking for... it is much slower than using Arrays
but it did get the job done... It is obviously a limitation that our system
has on each proccess that was running out of mem. So I was finally able to
work around it.
Thanks for all your help
D.Johnson
Doyle Johnson wrote in message <6vu4o4$egq$1@nnrp03.primenet.com>...
>Hi again,
>
> Im beginning to think the out of mem errors are more to do with a
>possible maximum amount of lines allowed in an @Array instead of physical
>mem.
>
> Is there a limit to the number of lines you can stuff into an array? or
is
>there a buffer size that can be adjusted?
>
>Thanks
>
>Dolye johnson
>
>
------------------------------
Date: Tue, 13 Oct 1998 15:31:21 -0700
From: Joseph Norris <sirron@mail.mcoe.k12.ca.us>
Subject: Need msqlperl tar file for version 1.15 of msqlperl
Message-Id: <3623D4B8.A9901DB7@mail.mcoe.k12.ca.us>
Hello group,
Does anyone have the msqlperl tar file for version 1.15 of msqlperl.
Older site running Msql 1.16. Newer versions of msqlperl do not work.
Or if someone has an idea of how I can make the newer version of
msqlperl work that would be great!
thanks.
--
#Joseph Norris (Perl - what else is there?/Linux/CGI/Mysql)
print @c=map chr
$_+100,(6,17,15,16,-68,-3,10,11,16,4,1,14,-68,12,1,14,8,
-68,4,-3,-1,7,1,14,-68,6,11,15,1,12,4,-68,-22,11,14,14,5,15,-90);
------------------------------
Date: 13 Oct 1998 18:02:12 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Off-topic - Wayward shopping trolleys
Message-Id: <70012k$bg$1@gellyfish.btinternet.com>
On 12 Oct 1998 18:33:58 +0100 Jonathan Stowe <gellyfish@btinternet.com> wrote:
> On 12 Oct 1998 09:28:58 +0100 Jim Brewer <jimbo@soundimages.co.uk> wrote:
>> Have you checked your local supermarket. Chances are you will find
>> quite a few shopping carts.
>
> Around here you only have to wait until saturday night and one always
> seems to mysteriously appear in the back yard.
>
Thats spooky,
I post that last night and now our Mayor is on the TV presenting an
initiative to curb the wayward shopping trolleys.
Quite amusing really - they are planning on taking them all to a trolley
pound and getting the Supermarkets to pay the council to get them back.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: 13 Oct 1998 21:07:12 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <700fe0$a92$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<lqyrms@nottingham.ac.uk>],
who wrote in article <6vv8h6$799$1@nnrp1.dejanews.com>:
> Could anybody who has read the Perl Cookbook please tell me if this is the
> best perl book to get. There are a couple of reviews of this book at amazon (
> http://www.amazon.com/exec/obidos/ASIN/1565922433/bibs/ ) , but I would
> appreciate the views of the experts in this newsgroup too.
It is not a perl book at all. This book is about solutions to real
problems, and real problems often require more knowledge of what
happens "under the hood" of your system. They also require knowledge
of Perl, and this book teaches you both.
Perl tries to isolate you as much of possible from these gory details,
but sometimes Perl is not up to the task. Say, the book is filled
with descriptions of how Unix file system works etc. Most the time
you do not care, since the Perl API isolates you from these details,
but sometimes you *need* these details.
The book is really invaluable, both the Perl part and Unix part.
However, one of my objections would be the usage of non-portable
constructs when a portable one will do as well (or maybe better).
Ilya
------------------------------
Date: Tue, 13 Oct 1998 15:09:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <MPG.108d6f7099de16f2989809@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <7002br$jng@news-central.tiac.net> on 13 Oct 1998 17:24:11
GMT, Mike Stok <mike@mike.stok.co.uk> says...
...
> for ($index = $#array; $index >= $[; $index--) {
> if ($item should be deleted) {
> splice @array, $index, 1;
> }
> }
>
> is one way to do it.
>
> Maybe not the best, but it does avoid cutting the ground out from beneath
> yourself. Whether it's OK depends on the side of your data set, how many
> elements get removed and where they are in the array...
My guess is that you eschewed 'grep' because it requires ~< two copies of
the array at the same time. Other than that, it would seem to be more
efficient than repeated splices.
Yes/no?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 13 Oct 1998 22:36:48 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <700km0$7p214@mercury.adc.com>
In article <7009hp$8oq$2@client3.news.psi.net>,
Abigail <abigail@fnx.com> wrote:
>Mike Stok (mike@mike.stok.co.uk) wrote on MDCCCLXIX September MCMXCIII in
><URL:news:7002br$jng@news-central.tiac.net>:
>++ In article <36235D50.1E46F15C@adv.sonybpe.com>,
>++ Anthony Clark <anthony.clark@adv.sonybpe.com> wrote:
>++
>++ >foreach $item ( @array )
>++ >{
>++ > # delete the current $item from the @array if it matches a pattern
>++ >}
>++ >
>++ >How the hell do I do this?
>++
>++ for ($index = $#array; $index >= $[; $index--) {
>++ if ($item should be deleted) {
>++ splice @array, $index, 1;
>++ }
>++ }
>++
>++ is one way to do it.
>++
>++ Maybe not the best, but it does avoid cutting the ground out from beneath
>++ yourself. Whether it's OK depends on the side of your data set, how many
>++ elements get removed and where they are in the array...
>
>
>It's not very likely to be the best.
>
>
>@array = grep {! (expression matching item to be removed)} @array;
use Benchmark;
timethese(1000, {
'splice' => sub {
@array = (1..10000);
for ($index = $#array; $index >= $[; $index--) {
if ($array[$index] =~ /22/) {
splice @array, $index, 1;
}
}
},
'grep' => sub {@array = (1..10000); @array = grep {!/22/} @array;}
})
Benchmark: timing 1000 iterations of grep, splice...
grep: 605 secs (569.51 usr 0.14 sys = 569.65 cpu)
splice: 426 secs (413.87 usr 0.02 sys = 413.89 cpu)
But not so good on memory, either:
$ ps -eo 'vsz args' | grep perl
4452 perl trygrep
3272 perl tryslice
As you would expect, the difference in memory usage becomes greater as
the array becomes larger. Also, the "splice" method's CPU numbers get
much worse as more items are deleted. No surprises in either of
these.
FWIW, the grep uses slightly less CPU if you don't put brackets around
the regex.
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: 13 Oct 1998 22:49:08 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <700ld4$o7r$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Anthony Clark <anthony.clark@adv.sonybpe.com> writes:
:foreach $item ( @array )
:{
: # delete the current $item from the @array if it matches a pattern
:}
:How the hell do I do this?
I believe that you will find that Chapter 4 on arrays does cover this.
Look for the recipe on selecting elements matching a particular criterion.
@stuff = grep { !/pat/ } @stuff;
--tom
--
"SPARC" is "CRAPS" backwards --Rob Pike
------------------------------
Date: 13 Oct 1998 22:53:45 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <700llp$7p215@mercury.adc.com>
In article <700lgi$7p120@mercury.adc.com>,
Brand Hilton <bhilton@tsg.adc.com> wrote:
>In article <MPG.108d6f7099de16f2989809@nntp.hpl.hp.com>,
>Larry Rosler <lr@hpl.hp.com> wrote:
>>[Posted to comp.lang.perl.misc and a copy mailed.]
>>
>>In article <7002br$jng@news-central.tiac.net> on 13 Oct 1998 17:24:11
>>GMT, Mike Stok <mike@mike.stok.co.uk> says...
>>...
>>> for ($index = $#array; $index >= $[; $index--) {
>>> if ($item should be deleted) {
>>> splice @array, $index, 1;
>>> }
>>> }
>>>
>>> is one way to do it.
>>>
>>> Maybe not the best, but it does avoid cutting the ground out from beneath
>>> yourself. Whether it's OK depends on the side of your data set, how many
>>> elements get removed and where they are in the array...
>>
>>My guess is that you eschewed 'grep' because it requires ~< two copies of
>>the array at the same time. Other than that, it would seem to be more
>>efficient than repeated splices.
>>
>>Yes/no?
>
>Surprisingly not, according to recent my recent benchmarking
Forgot to add the caveat, "As long as you aren't deleting too many things."
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: 13 Oct 1998 22:50:58 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Perl Cookbook - is this the best perl book?
Message-Id: <700lgi$7p120@mercury.adc.com>
In article <MPG.108d6f7099de16f2989809@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>[Posted to comp.lang.perl.misc and a copy mailed.]
>
>In article <7002br$jng@news-central.tiac.net> on 13 Oct 1998 17:24:11
>GMT, Mike Stok <mike@mike.stok.co.uk> says...
>...
>> for ($index = $#array; $index >= $[; $index--) {
>> if ($item should be deleted) {
>> splice @array, $index, 1;
>> }
>> }
>>
>> is one way to do it.
>>
>> Maybe not the best, but it does avoid cutting the ground out from beneath
>> yourself. Whether it's OK depends on the side of your data set, how many
>> elements get removed and where they are in the array...
>
>My guess is that you eschewed 'grep' because it requires ~< two copies of
>the array at the same time. Other than that, it would seem to be more
>efficient than repeated splices.
>
>Yes/no?
Surprisingly not, according to recent my recent benchmarking
(available in my reply to Abigail in this thread.) It intrigued me so
much that I decided to run a few more. These probably won't be as
accurate. I cut down on the iterations so I wouldn't have to leave
them 'til morning.
#!/usr/local/bin/perl
use Benchmark;
timethese(100, {
'splice 1000 22' => sub {
@array = (1..1000);
for ($index = $#array; $index >= $[; $index--) {
if ($array[$index] =~ /22/) {
splice @array, $index, 1;
}
}
},
'grep1 1000 22' => sub {@array = (1..1000); @array = grep {!/22/} @array},
'grep2 1000 22' => sub {@array = (1..1000); @array = grep !/22/, @array},
'splice 1000 2' => sub {
@array = (1..1000);
for ($index = $#array; $index >= $[; $index--) {
if ($array[$index] =~ /2/) {
splice @array, $index, 1;
}
}
},
'grep1 1000 2' => sub {@array = (1..1000); @array = grep {!/2/} @array},
'grep2 1000 2' => sub {@array = (1..1000); @array = grep !/2/, @array},
'splice 10000 22' => sub {
@array = (1..10000);
for ($index = $#array; $index >= $[; $index--) {
if ($array[$index] =~ /22/) {
splice @array, $index, 1;
}
}
},
'grep1 10000 22' => sub {@array = (1..10000); @array = grep {!/22/} @array},
'grep2 10000 22' => sub {@array = (1..10000); @array = grep !/22/, @array},
'splice 10000 2' => sub {
@array = (1..10000);
for ($index = $#array; $index >= $[; $index--) {
if ($array[$index] =~ /2/) {
splice @array, $index, 1;
}
}
},
'grep1 10000 2' => sub {@array = (1..10000); @array = grep {!/2/} @array},
'grep2 10000 2' => sub {@array = (1..10000); @array = grep !/2/, @array}
})
(output nicely indented for readability)
Benchmark: timing 100 iterations of grep1 1000 2, grep1 1000 22, grep1
10000 2, grep1 10000 22, grep2 1000 2, grep2 1000 22, grep2 10000 2,
grep2 10000 22, splice 1000 2, splice 1000 22, splice 10000 2, splice
10000 22...
grep1 1000 2: 9 secs ( 4.27 usr 0.01 sys = 4.28 cpu)
grep1 1000 22: 8 secs ( 4.31 usr 0.00 sys = 4.31 cpu)
grep1 10000 2: 111 secs (55.12 usr 0.10 sys = 55.22 cpu)
grep1 10000 22: 115 secs (56.99 usr 0.00 sys = 56.99 cpu)
grep2 1000 2: 7 secs ( 3.74 usr 0.00 sys = 3.74 cpu)
grep2 1000 22: 8 secs ( 3.81 usr 0.00 sys = 3.81 cpu)
grep2 10000 2: 83 secs (40.84 usr 0.00 sys = 40.84 cpu)
grep2 10000 22: 87 secs (42.89 usr 0.01 sys = 42.90 cpu)
splice 1000 2: 8 secs ( 3.93 usr 0.00 sys = 3.93 cpu)
splice 1000 22: 7 secs ( 3.39 usr 0.00 sys = 3.39 cpu)
splice 10000 2: 143 secs (71.61 usr 0.00 sys = 71.61 cpu)
splice 10000 22: 84 secs (42.34 usr 0.00 sys = 42.34 cpu)
--
_____
|/// | Brand Hilton bhilton@adc.com
| ADC| ADC Telecommunications, ATM Transport Division
|_____| Richardson, Texas
------------------------------
Date: Tue, 13 Oct 1998 21:39:36 GMT
From: "David L. Hawley" <dlhawley@user1.teleport.com>
Subject: Perl object - why does this fail?
Message-Id: <sMPU1.1281$lU3.787165@news.teleport.com>
#! /usr/local/bin/perl
#What is going on here? As written, I get the "strict" error:
# Global symbol "ISA" requires explicit package name at t1 line 32.
#If I remove the 'use strict;', I get:
# bb -> f
# Can't locate object method "new" via package "dd" at t1 line 15.
# if I dup bb:new in dd, it can't find f()
# ---------------------------------------------------------------------
$|++;
$bb = new bb; $bb->f; # create a bb, call bb:f()
$dd = new dd; $dd->f; #line 15
package bb; # simple object
#use strict;
sub new { return bless {}, shift; } # note 2 arg bless
sub f { # dumb sub routine
my $self = shift;
my $class = ref($self);
print "$class -> f\n";
}
package dd; # should inherit from bb
@ISA = qw( bb ); #line 32
# /Sno/src/io> perl -v
# This is perl, version 5.004
# Copyright 1987-1997, Larry Wall
--
David L. Hawley D.L. Hawley and Associates 1(503)274-2242
Software Engineer dlhawley@teleport.com
------------------------------
Date: Tue, 13 Oct 1998 22:03:02 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Perl object - why does this fail?
Message-Id: <Pine.GSO.4.02A.9810131501510.1979-100000@user2.teleport.com>
On Tue, 13 Oct 1998, David L. Hawley wrote:
> #What is going on here? As written, I get the "strict" error:
> # Global symbol "ISA" requires explicit package name at t1 line 32.
> @ISA = qw( bb ); #line 32
That's because you're using a global variable named "ISA" without
declaring it. Try using 'use vars' just before that line:
use vars qw/ @ISA /; # Declare @ISA
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 13 Oct 1998 18:45:06 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Perl object - why does this fail?
Message-Id: <700l5i$3j4$1@monet.op.net>
In article <sMPU1.1281$lU3.787165@news.teleport.com>,
David L. Hawley <dlhawley@user1.teleport.com> wrote:
>#! /usr/local/bin/perl
>
>#What is going on here? As written, I get the "strict" error:
># Global symbol "ISA" requires explicit package name at t1 line 32.
1. I guess you don't know what `strict' is for. You must read the
manual, or else you must stop using `strict' until you do read the
manual. Either one will do. To get the manual, use the command
`perldoc strict'.
2. When you say `use strict', you are saying to the Perl compiler ``If
I write any global variables, I will say explictly what package
they are in.'' You didn't do that with @ISA. That is what it
means when it says
># Global symbol "ISA" requires explicit package name at t1 line 32.
You must replace this:
@ISA = qw(bb);
with this:
@dd::ISA = qw(bb);
to avoid a strict failure. That `dd::' says that you want to
modify the @ISA from package dd. Then strict knows that you meant
the global dd::ISA variable on purpose, and not some other variable
by accident.
3. Lines in your program are executed in order. The call `new dd' is
in line 15. Later, on line 35, at the very end of the program, you
initialize @ISA. Until you do that, it is empty. When you call
`new dd', Perl doesn't know that you want dd to inherit from bb,
because @dd::ISA is empty. There is no dd::new, and you have not
defined any inheritance for it. Perl says:
># Can't locate object method "new" via package "dd" at t1 line 15.
One way to solve this: Move
@dd::ISA = qw(bb);
up to the top of the program so that it happens first. Another
way: Leave it where it is, and change it to this:
BEGIN { @dd::ISA = qw(bb) }
The most normal way: Put the `dd' package into its own file,
`dd.pm', and, in the main file, say
use dd;
which executes all of dd.pm at once.
4.
># if I dup bb:new in dd, it can't find f()
Same problem as #3. Now there is a dd::new, but when you ask it
for $dd->f, it looks for a function named `f' in package dd.
There isn't one. You want it to find the one in bb, but you have
not told it yet that dd should inherit from bb.
5. Until you understand better how this works, why don't you consider
naming your packages `Parent' and `Child'? It can't be helpful to
try to think about bb and dd.
------------------------------
Date: Tue, 13 Oct 1998 21:23:48 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: perl scripts won't work: (RH5.1 Linux) "command not found" plz help
Message-Id: <3623C264.9EC89BC5@bbnplanet.com>
Mark den hartog wrote:
> problem: Perl-scripts won't work. The bash returns : "command not
> found".
Make sure that /usr/bin/perl or wherever Perl resides is in your $PATH.
e.
------------------------------
Date: 14 Oct 1998 00:52:50 +0200
From: Jonathan Feinberg <jdf@pobox.com>
To: mdh@cyberjunkie.com (Mark den hartog)
Subject: Re: perl scripts won't work: (RH5.1 Linux) "command not found" plz help
Message-Id: <m3yaqkm5vh.fsf@joshua.panix.com>
mdh@cyberjunkie.com (Mark den hartog) writes:
> problem: Perl-scripts won't work. The bash returns : "command not
> found".
Look at the first line of a Perl script that won't work. See if the
path given in the #! line is sensible. For example, you say that you
have a perl installed as /usr/bin/perl, but the script might specify
/usr/share/opt/foozitz/perl. Either edit the script to point to a
perl, or put in a symlink where the script expects it.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3966
**************************************