[19928] in Perl-Users-Digest
Perl-Users Digest, Issue: 2123 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 13 14:06:06 2001
Date: Tue, 13 Nov 2001 11:05:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005678317-v10-i2123@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Nov 2001 Volume: 10 Number: 2123
Today's topics:
'stdin' instead of 'STDIN' <joachim.ziegler@gmx.de>
Re: 'stdin' instead of 'STDIN' <uri@stemsystems.com>
Re: -M $file on win32 <dump@the-core.net>
Re: -M $file on win32 <bart.lateur@skynet.be>
Re: Accessing NT Network Neighbourhood <s.warhurst@rl.ac.uk>
Re: Accessing NT Network Neighbourhood nobull@mail.com
Array from text file <paul_wasilkoff@ucg.org>
Re: Array from text file <josef.moellers@fujitsu-siemens.com>
Re: Array from text file <bart.lateur@skynet.be>
Re: comp.lang.perl <pne-news-20011113@newton.digitalspace.net>
Is two-dim hash inefficient? (Markus Dehmann)
Re: Is two-dim hash inefficient? <mjcarman@home.com>
keys of a hash of arrays <bspage@unity.ncsu.edu>
Re: keys of a hash of arrays (John J. Trammell)
Re: keys of a hash of arrays <echang@netstorm.net>
Re: Making an array of records (Anno Siegel)
Re: Making an array of records <emarkert@netscape.net>
Need help with strange performance problem processing l (Tim Moose)
Net::LDAP to access Exchange Directory <jay.w.smith@tyson.com>
open /dev/tty in jailed env <Jan.Gruber@primacom.net>
Pattern Matching <hunter@nortelnetworks.ca>
Re: Pattern Matching (Mike Eggleston)
Re: Pattern Matching (John J. Trammell)
Perl - MySQL question <echnathonh@yahoo.com>
Re: Perl Problems <camerond@mail.uca.edu>
Re: Perl Problems nobull@mail.com
Perl.dl v.v. Perl.exe; it's stability and what is the m (Jongkees)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Nov 2001 18:39:17 +0100
From: Joachim Ziegler <joachim.ziegler@gmx.de>
Subject: 'stdin' instead of 'STDIN'
Message-Id: <9srluc$15k3m7$1@ID-107292.news.dfncis.de>
hi,
i'm just wondering why i can say
$x=<stdin>;
instead of
$x=<STDIN>;
but not the following:
$x=<Stdin>;
so, are names of filehandles case-sensitive, or not, or what?
greetings from germany,
joachim
------------------------------
Date: Tue, 13 Nov 2001 18:29:54 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: 'stdin' instead of 'STDIN'
Message-Id: <x78zdajzex.fsf@home.sysarch.com>
>>>>> "JZ" == Joachim Ziegler <joachim.ziegler@gmx.de> writes:
JZ> hi,
JZ> i'm just wondering why i can say
JZ> $x=<stdin>;
JZ> instead of
JZ> $x=<STDIN>;
JZ> but not the following:
JZ> $x=<Stdin>;
JZ> so, are names of filehandles case-sensitive, or not, or what?
stdin is a special case alias for STDIN. from perl.c:
PL_stdingv = gv_fetchpv("STDIN",TRUE, SVt_PVIO);
GvMULTI_on(PL_stdingv);
IoIFP(GvIOp(PL_stdingv)) = PerlIO_stdin();
tmpgv = gv_fetchpv("stdin",TRUE, SVt_PV);
GvMULTI_on(tmpgv);
GvIOp(tmpgv) = (IO*)SvREFCNT_inc(GvIOp(PL_stdingv));
and in perlop.pod we find:
The filehandles STDIN, STDOUT, and STDERR are predefined. (The
filehandles C<stdin>, C<stdout>, and C<stderr> will also work except in
packages, where they would be interpreted as local identifiers rather
than global.)
so i wouldn't use the lower case versions. why they are still supported,
i don't know.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 13 Nov 2001 16:42:53 +0100
From: Lars Oeschey <dump@the-core.net>
Subject: Re: -M $file on win32
Message-Id: <5of2vtse49127t2iof9lf233uc6apkuu6p@4ax.com>
On Tue, 13 Nov 2001 10:18:16 +0100, "Dr. Peter Dintelmann"
<Peter.Dintelmann@dresdner-bank.com> wrote:
> Thus I suspect you wanted to type
> if (-f "$localdir/$datei") { ... }
> Is this of any help to you?
> Peter
hm, this really solved the problem of the multi-dot-files, I see them
all now. But with the same construction, the -M doesn't work, I just
get nothing back...
this is the code:
opendir (SAVE, "$localdir");
while ($datei = readdir (SAVE)) {
if (-f "$localdir/$datei") {
$alter = -M "$localfile/$datei";
print $datei . ": " . $alter . "\n";
}
}
Lars
--
GPZ900R xxMm+2,5Mm http://www.oeschey.de
GS400 xxMm+1,5Mm http://www.the-core.net
------------------------------
Date: Tue, 13 Nov 2001 16:38:47 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: -M $file on win32
Message-Id: <dvi2vtkhqovb5i1f9bb4gouqscosibm67f@4ax.com>
Lars Oeschey wrote:
>1. A file that Windows-Explorer says "last change date 31.10.2001"
>gives me with a -M $file a result of 22.92323342 which is too much (-M
>should give me tha days since last change, no?)
Perhaps use the stat() function call instead, and see what fields 8, 9
and 10 (especially 9) return, when printed as scalar localtime.
--
Bart.
------------------------------
Date: Tue, 13 Nov 2001 14:43:00 -0000
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Accessing NT Network Neighbourhood
Message-Id: <9srbhl$134o@newton.cc.rl.ac.uk>
<nobull@mail.com> wrote in message news:u9lmhbknty.fsf@wcl-l.bham.ac.uk...
> > open(FILE, "\\\\servername\\directory\\file.txt")
>
> That is attempting to open the file for reading. Opening files for
> reading does not create them if they don't already exist. For an
> explaination of how to open files in other modes with the open()
> function see the documentation of the open() function.
Sorry.. my error.. I simply forgot to include the ">" in the example code
above.. in fact I cannot read or write to that remote machine.
Spencer
------------------------------
Date: 13 Nov 2001 17:57:30 +0000
From: nobull@mail.com
Subject: Re: Accessing NT Network Neighbourhood
Message-Id: <u9eln2lfjp.fsf@wcl-l.bham.ac.uk>
"S Warhurst" <s.warhurst@rl.ac.uk> writes:
> <nobull@mail.com> wrote in message news:u9lmhbknty.fsf@wcl-l.bham.ac.uk...
>
> > > open(FILE, "\\\\servername\\directory\\file.txt")
> >
> > That is attempting to open the file for reading. Opening files for
> > reading does not create them if they don't already exist. For an
> > explaination of how to open files in other modes with the open()
> > function see the documentation of the open() function.
>
> Sorry.. my error.. I simply forgot to include the ">" in the example code
> above.. in fact I cannot read or write to that remote machine.
Does open() indicate that it failed? If so what reason is given for
the failure?
Are you running the script in forground by double clicking on it in
exploerer (or equivalent)? Or are you running it by some other
mechanism that would cause it to run with different credentials from
those of the console user? This, of course, has nothing to do with Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 13 Nov 2001 11:06:14 -0500
From: "Paul Wasilkoff" <paul_wasilkoff@ucg.org>
Subject: Array from text file
Message-Id: <tv2h81833cp719@corp.supernews.com>
I am looking for a way to stuff the contents of a text file into an array.
The text file would be in .csv format (for example: HH,RV,GE,BC,GN)
I would like to rand the array so that I can randomly pluck one of the
2-character pairs from the array.
When trying this on my own I get the text file in the array as one entry. I
need the entries to be inserted individually - in other words, I need "HH"
to be @list[1], "RV" to be @list[2], etc. How do I need to modify my set
up?
$File="/usr/local/list.txt";
open(FILE, "<$File") || die $!;
while (<FILE>)
{$PUB=$_;}
close(FILE) || die $!;
@Pub=($PUB);
Many thanks!
------------------------------
Date: Tue, 13 Nov 2001 17:11:07 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Array from text file
Message-Id: <3BF1461B.C1952A90@fujitsu-siemens.com>
Paul Wasilkoff wrote:
> =
> I am looking for a way to stuff the contents of a text file into an arr=
ay.
> The text file would be in .csv format (for example: HH,RV,GE,BC,GN)
> =
> I would like to rand the array so that I can randomly pluck one of the
> 2-character pairs from the array.
> =
> When trying this on my own I get the text file in the array as one entr=
y. I
> need the entries to be inserted individually - in other words, I need "=
HH"
> to be @list[1], "RV" to be @list[2], etc. How do I need to modify my s=
et
> up?
> =
> $File=3D"/usr/local/list.txt";
> open(FILE, "<$File") || die $!;
> while (<FILE>)
> {$PUB=3D$_;}
> close(FILE) || die $!;
> @Pub=3D($PUB);
> =
> Many thanks!
split is your friend:
while (<FILE>) {
@list =3D split /,/;
# $list[0] =3D "HH", ...
HTH,
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Tue, 13 Nov 2001 16:52:15 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Array from text file
Message-Id: <erj2vtsp8t3n2qqagoec38583fburh86oe@4ax.com>
Paul Wasilkoff wrote:
>The text file would be in .csv format (for example: HH,RV,GE,BC,GN)
>
>I would like to rand the array so that I can randomly pluck one of the
>2-character pairs from the array.
>
>When trying this on my own I get the text file in the array as one entry. I
>need the entries to be inserted individually - in other words, I need "HH"
>to be @list[1], "RV" to be @list[2], etc. How do I need to modify my set
>up?
Use split(). Uh... you don't mind if "HH" is $list[0], "RV" is $list[1],
etc. do you?
while(<FILE>) {
chomp;
@list = split /,/;
...
}
--
Bart.
------------------------------
Date: Tue, 13 Nov 2001 18:42:28 +0100
From: Philip Newton <pne-news-20011113@newton.digitalspace.net>
Subject: Re: comp.lang.perl
Message-Id: <q3k2vto4n21aa05iar3veb8176c94epu0v@4ax.com>
On Mon, 12 Nov 2001 01:13:10 GMT, "Daniel Berger" <djberg96@hotmail.com>
wrote:
> I guess what I don't understand is why some people feel *compelled* to
> respond
We've had this topic several times before.
One reason is so that people learn how to do it the right way, and so
that bad advice going into the permanent archive has a warning about the
quality of the advice and some better advice to counterbalance it, also
in the permanent archive.
> in the harsh manner that they do.
That's a different matter, as Martien noted.
> Here's a novel concept - IGNORE THE THREAD! Move on your merry little way
> to the next post and even put the offending newbie in your killfile if it
> annoys you that much (and spare us that *PLONK* bologna).
It's already been said, multiple times, why many regulars choose not to
go this path.
Do you want to be appointed official FAQ answerer for this newsgroup?
I'm sure lots of people wouldn't mind if there were one of those; then
they could really follow your advice and ignore such posts.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 13 Nov 2001 07:24:13 -0800
From: markus.cl@gmx.de (Markus Dehmann)
Subject: Is two-dim hash inefficient?
Message-Id: <c1e48b51.0111130724.ed2b740@posting.google.com>
I stored data in a two-dim hash, like:
$hash{"A1"}{"X Z"} = 11142;
$hash{"B2"}{"Y X"} = 232;
I have to store a lot of data in %hash.
With another data set, I get longer keys like:
$hash{"A1"}{"whole_word another_word"} = 11142;
$hash{"B2"}{"another_word bla_bla"} = 232;
And now, just looping over each hash key is so slow, it's
unbelievable. Does Perl store the two-dimensional hash in an
inefficient way?
Is it better to have a pseudo-one-dim hash?
$hash{"A1-whole_word another_word"} = 11142;
$hash{"B2-another_word bla_bla"} = 232;
Or rather, have an index with these words:
0 for "whole_word", 1 for "another_word", ...
And then store just:
$hash{"A1"}{"1"} = 11142;
$hash{"B2"}{"2"} = 232;
Any ideas, experts? Thankx!!!
------------------------------
Date: Tue, 13 Nov 2001 11:35:42 -0600
From: Michael Carman <mjcarman@home.com>
Subject: Re: Is two-dim hash inefficient?
Message-Id: <3BF159EE.122D807C@home.com>
Markus Dehmann wrote:
>
> I stored data in a two-dim hash, like:
> $hash{"A1"}{"X Z"} = 11142;
> $hash{"B2"}{"Y X"} = 232;
> I have to store a lot of data in %hash.
>
> [...]
>
> And now, just looping over each hash key is so slow, it's
> unbelievable. Does Perl store the two-dimensional hash in an
> inefficient way?
Perl stores it efficiently enough, but it still takes time to do the
lookups. With a multiple level hash it has to do multiple lookups. The
standard idiom looks like this:
foreach my $key1 (%hash) {
foreach my $key2 (%{$hash{$key1}}) {
# do something to $hash{$key1}{$key2}
}
}
The problem is that inside the inner loop, you're asking Perl to lookup
$hash{$key1} each time before it can look for $hash{$key1}{$key2}. You
can prevent this by saving the hashref in a temporary variable:
foreach my $key1 (%hash) {
my $inner_hash = $hash{$key1};
foreach my $key2 (%{$inner_hash}) {
# do something to $inner_hash->{$key2}
}
}
Now the outer lookup only happens once for each of the outer keys. For
large hashes (with lots of inner keys) this could make a substantial
difference.
-mjc
------------------------------
Date: Tue, 13 Nov 2001 11:55:13 -0500
From: Shawn Page <bspage@unity.ncsu.edu>
Subject: keys of a hash of arrays
Message-Id: <3BF15071.4B69C673@unity.ncsu.edu>
Why does keys %ids return 4 instead of 3?
snippet:
#!/local/perl5.6 -w
my %ids={};
my @array = (1, 2, 1, 3, 1, 4, 2, 5, 2, 6, 2, 7, 3, 8, 3, 9, 3, 10);
for (@array) {print "$_ "};
print "\n";
my $idx=0;
while ($idx <=$#array) {
my ($acct_id, $invoice_num) = ($array[$idx], $array[$idx+1]);
print "$idx:acct_id: $acct_id\tinvoice_num: $invoice_num\n";
push @{$ids{$acct_id}}, $invoice_num;
$idx+=2;
}
print "\nidx: $idx, last: $#array\n";
my $num_key = keys %ids;
print "num keys: $num_key\n\n";
foreach my $acct_id (keys %ids) {
print "acct id: $acct_id\n";
print "$acct_id: @{ $ids{$acct_id} } \n";
}
output:
1 2 1 3 1 4 2 5 2 6 2 7 3 8 3 9 3 10
0:acct_id: 1 invoice_num: 2
2:acct_id: 1 invoice_num: 3
4:acct_id: 1 invoice_num: 4
6:acct_id: 2 invoice_num: 5
8:acct_id: 2 invoice_num: 6
10:acct_id: 2 invoice_num: 7
12:acct_id: 3 invoice_num: 8
14:acct_id: 3 invoice_num: 9
16:acct_id: 3 invoice_num: 10
idx: 18, last: 17
num keys: 4
acct id: 1
1: 2 3 4
acct id: 2
2: 5 6 7
acct id: 3
3: 8 9 10
acct id: HASH(0xfb960)
Use of uninitialized value in array dereference at dsc_test.pl line 23.
HASH(0xfb960):
--
-Shawn Page
bspage@unity.ncsu.edu
------------------------------
Date: Tue, 13 Nov 2001 11:34:34 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: keys of a hash of arrays
Message-Id: <slrn9v2mg4.9fi.trammell@haqq.el-swifto.com>
On Tue, 13 Nov 2001 11:55:13 -0500, Shawn Page <bspage@unity.ncsu.edu> wrote:
> Why does keys %ids return 4 instead of 3?
>
> snippet:
> #!/local/perl5.6 -w
use strict;
> my %ids={};
Perhaps you mean
my %ids = ();
Why turn on warnings if you're just going to ignore them?
> my @array = (1, 2, 1, 3, 1, 4, 2, 5, 2, 6, 2, 7, 3, 8, 3, 9, 3, 10);
> for (@array) {print "$_ "};
>
> print "\n";
>
> my $idx=0;
> while ($idx <=$#array) {
> my ($acct_id, $invoice_num) = ($array[$idx], $array[$idx+1]);
> print "$idx:acct_id: $acct_id\tinvoice_num: $invoice_num\n";
> push @{$ids{$acct_id}}, $invoice_num;
> $idx+=2;
> }
>
> print "\nidx: $idx, last: $#array\n";
> my $num_key = keys %ids;
> print "num keys: $num_key\n\n";
>
[snip]
And I can't reproduce your problem. :-P
----- foo.pl -----
#!/usr/bin/perl -w
use strict;
my %ids;
my @array = (1, 2, 1, 3, 1, 4, 2, 5, 2, 6, 2, 7, 3, 8, 3, 9, 3, 10);
my $idx = 0;
while ($idx <= $#array)
{
my ($acct_id, $invoice_num) = ($array[$idx], $array[$idx+1]);
push @{$ids{$acct_id}}, $invoice_num;
$idx += 2;
}
printf "number of keys: %d\n", scalar(keys %ids);
----- ------ -----
[ ~ ] perl foo.pl
number of keys: 3
[ ~ ]
------------------------------
Date: Tue, 13 Nov 2001 18:33:43 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: keys of a hash of arrays
Message-Id: <Xns91588AFDBF710echangnetstormnet@207.106.93.86>
Shawn Page <bspage@unity.ncsu.edu> wrote in
news:3BF15071.4B69C673@unity.ncsu.edu:
> Why does keys %ids return 4 instead of 3?
Because your hash has four keys, why else? :)
There were two clear clues:
First.
> snippet:
>#!/local/perl5.6 -w
>
> my %ids={};
This statement produces the warning:
"Reference found where even-sized list expected at snippet line 4."
telling you that this statement did not do what you thought it did.
Curlies {} do not define a hash, they define a reference to an
anonymous hash. A suitable initial value for a hash is a (possibly
empty) list containing pairs of keys and values in order.
[snip]
> num keys: 4
>
> acct id: 1
> 1: 2 3 4
> acct id: 2
> 2: 5 6 7
> acct id: 3
> 3: 8 9 10
> acct id: HASH(0xfb960)
> Use of uninitialized value in array dereference at dsc_test.pl line
> 23. HASH(0xfb960):
Here's the other clue - and the fourth key. It is the reference that
you tried to assign at the beginning. Of course there's been no value
assigned to it, hence the warning.
So your question would better have been phrased "How did I manage to
add a hash reference as a fourth key on my %ids hash?" That would have
pointed you towards the answer.
--
EBC
------------------------------
Date: 13 Nov 2001 14:08:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Making an array of records
Message-Id: <9sr9gr$5lo$1@mamenchi.zrz.TU-Berlin.DE>
According to Zoltan Kandi <zoltan.kandi@tellabs.com>:
[snippage]
> Aother question.
> Here I'm doing something wrong. But what??? I've read perldoc but still
> ...
>
> my %phon_list = {Peter => "1234",
> Julia => "34567",
> Romeo => "17369"};
You want () instead of {} here. { ...} returns a scalar (which is a
reference to an anonymous hash). That cannot be reasonably assigned
to a hash. Turn on warnings!
> foreach $person (sort keys %phon_list)
> {
> print "Person ".$person." has phone_no ".$phon_list->{$person}."\n";
^^^^^^^^^^
Here you assume a scalar variable $phon_list, which ought to contain a
hashref for the code to make sense. Write "$phon_list{$person}" instead,
that accesses the hash %phon_list. And use strict.
> }
>
> print "Person Romeo has phone_no ".$phon_list->{Romeo}."\n";
> exit;
>
> # Result:
> # Person HASH(0x1b9efcc) has phone_no
> # Person Romeo has phone_no
>
> What am I referencing incorrectly? (Sorry, I'm a newbie...)
You must decide whether you want to work with a hash %phon_list (the
way you declared it) or a scalar hash reference $phon_list (the way
you used it most of the time). In the absence of surrounding code,
there is no advantage in using a reference, so you should use a plain
hash as indicated. "use warnings; use strict;" plus probably "use
diagnostics;" would have explained your errors.
Anno
------------------------------
Date: Tue, 13 Nov 2001 17:00:34 GMT
From: Erich Markert <emarkert@netscape.net>
Subject: Re: Making an array of records
Message-Id: <3BF151FB.1000505@netscape.net>
Sasha wrote:
> Hi
>
> I was wondering if some one could help me to make an array / hash of
> records. I have an input variables that contains a phone number like :
>
> $new_phon_nr =(
> "Peter" =>"46978955",
> )
>
> And i want to have an hash/array that keep this information with an index,
> like:
>
> $phon_list{$index}=$new_phon_nr ;
>
I offcer this without knowing the full reasons behind wanting to do this
or how large your data sets are. But wouldn't it be more efficient,
faster AND flexible to use one of the file based DBM technologies
especially if you're talking about LARGE datasets? I'm not talking
about using MySQL rather something like Berkley DBM, MDBM, etc.
------------------------------
Date: 13 Nov 2001 08:27:08 -0800
From: wtmoose@yahoo.com (Tim Moose)
Subject: Need help with strange performance problem processing large files
Message-Id: <48a86175.0111130827.7ab166ae@posting.google.com>
Hello All! I am seeing a strange performance with a file processing
script. For large files, in this case ~30 MB, the script drags to a
crawl after a while. The script becomes unusably slow with larger
files. I believe the problem to be related to inefficient memory
allocation, although there is plenty of free RAM available. I am
running ActivePerl v5.6.1 Windows 2000 with 384 MB RAM. If anyone has
an explanation---or better yet, a solution, please let me know. Thanks
in advance!
Description of the problem follows.
I've boiled the original problem down to a much smaller size and
included the code at the end of the message. Here is the main loop.
The loop reads in a line, modifies and stores the line an a newly
created object and pushes the object onto an array.
# Read in the file and store some data in some objects.
while (<FILE>) {
if ($ARGV[0] eq 'weird') {
# No performance problem when deleting
# only two characters.
# This is very weird!
s/..//;
} else {
# Delete three characters. Is that so bad?
s/....//;
}
# Create an object.
$object = new Object();
if ($ARGV[0] eq 'odd') {
# No performance problem when dummy object are created.
# This is very odd!
$dummy = new Dummy();
push @dummy, $dummy;
}
# Assign the modified line to a data member.
$object->{V1} = $_;
# Store the object away.
push @objects, $object;
# Every 20000 lines, print out the line number and the time
# elapsed since the previous line.
if ($. % 20000 == 0) {
$now = time();
print "$.\t${\($now - $last)}\t${average}\n";
$last = $now;
}
}
Every 20000 lines, the script prints out the line number and the time
elapsed from the previous print statement. Here is the output I get.
Notice that processing slows down dramatically after 140000 lines (it
gets much worse with larger files).
C:\tmp>perl slow.pl
Reading input file.
Line# Sec
===== ===
20000 2
40000 3
60000 3
80000 3
100000 2
120000 2
140000 15
160000 42
180000 88
Just for fun, I made some random changes and found the performance
problem to mysteriously vanish. This can be seen by running with an
argument of 'weird' or 'odd'. If you look at what 'weird' and 'odd' do
in the code, it doesn't seem like it should matter. Here is the weird
and odd output.
C:\tmp>perl slow.pl weird
Reading input file.
Line# Sec
===== ===
20000 2
40000 3
60000 2
80000 2
100000 2
120000 1
140000 1
160000 1
180000 2
C:\tmp>perl slow.pl odd
Reading input file.
Line# Sec
===== ===
20000 2
40000 3
60000 3
80000 3
100000 2
120000 2
140000 2
160000 1
180000 3
The input file can be found here in slow.zip. If you have problems
retrieving file, I can email it.
http://briefcase.yahoo.com/bc/wtmoose/lst?.dir=/My+Folder+(shared)&.view=l
The source code is below.
-Tim
###########################################
# Just some object with several data members.
package Object;
sub new {
my $class = shift;
my $self = {
'V1' => undef, 'V2' => undef,
'V3' => undef, 'V4' => undef,
'V5' => undef, 'V6' => undef,
'V7' => undef, 'V8' => undef,
'V9' => undef, 'V10' => undef,
'V11' => undef, 'V12' => undef,
};
return bless $self, $class;
}
# Dummy object that makes it work, oddly enough.
package Dummy;
sub new {
my $class = shift;
my $self = {};
$self->{DUMMY} = undef,
return bless $self, $class;
}
package Main;
print "\nReading input file.\n\n";
print "Line# Sec\n";
print "===== ===\n";
open FILE, "<slow.txt";
$last = time();
# Read in the file and store some data in some objects.
while (<FILE>) {
if ($ARGV[0] eq 'weird') {
# No performance problem when deleting
# only two characters.
# This is very weird!
s/..//;
} else {
# Delete three characters. Is that so bad?
s/....//;
}
# Create an object.
$object = new Object();
if ($ARGV[0] eq 'odd') {
# No performance problem when dummy object are created.
# This is very odd!
$dummy = new Dummy();
push @dummy, $dummy;
}
# Assign the modified line to a data member.
$object->{V1} = $_;
# Store the object away.
push @objects, $object;
# Every 20000 lines, print out the line number and the time
# elapsed since the previous line.
if ($. % 20000 == 0) {
$now = time();
print "$.\t${\($now - $last)}\t${average}\n";
$last = $now;
}
}
###########################################
------------------------------
Date: Tue, 13 Nov 2001 17:07:53 GMT
From: "Jay W. Smith" <jay.w.smith@tyson.com>
Subject: Net::LDAP to access Exchange Directory
Message-Id: <JrcI7.1204$GD2.390412429@newssvr12.news.prodigy.com>
I have been trying to work on a way to pull the smtp address of a user from
exchange from UNIX and NT.
So far I have it down in Visual Basic for NT/2000 but haven't been able to
figure it out on UNIX. I am using perl and the Net::LDAP module with the
following code. Any help is appreciated.
#!c://Perl/bin/Perl.exe
use Net::LDAP;
use Net::LDAP::LDIF;
use Net::LDAP::Util qw(ldap_error_text
ldap_error_name);
my $server = 'exgate3';
my $base = 'o=Tyson'; # I don't
think this is right.
my $filter = 'cn=Recipients,cn=USER_NAME'; # I don't think this is
right.
my $scope = 'subtree';
my $entry;
my $ldap = Net::LDAP->new($server) ;
$ldap->bind or die "$@";
my ($search) = $ldap->search (
base => $base,
scope => $scope,
filter => $filter);
die "Bad Search, errorcode #" . ldap_error_name($search->code()) if
$search->code();
print ldap_error_name($search->code());
print $search->entries();
if ($search) {
$ldif = new Net::LDAP::LDIF("-");
$ldif->write($search->entries());
$ldif->done();
}
$ldap->unbind;
exit (0);
------------------------------
Date: Tue, 13 Nov 2001 18:16:12 +0100
From: Jan Gruber <Jan.Gruber@primacom.net>
Subject: open /dev/tty in jailed env
Message-Id: <3BF1555C.4090101@primacom.net>
Hi, all !
I'm trying use Term::ReadLine in a jailed environment (FreeBSD 4.4-release)
The module is unable to open /dev/tty.
The devices have been created with 'sh MAKEDEV jail' from outside the jail.
I checked the jail doc's, there seems to be nothing in it about not
being able to open devices for read.
Any hint is appreciated.
TIA
Jan
--
cat /dev/world | perl -e "(/(^.*? \?) 42 \!/) && (print $1)"
errors->(c)
_
------------------------------
Date: Tue, 13 Nov 2001 12:06:01 -0500
From: "dh" <hunter@nortelnetworks.ca>
Subject: Pattern Matching
Message-Id: <9srjv4$92f$1@news.storm.ca>
Hi group - easy one for you I think.
I'd like to grab everything inside the square brackets and ignore everything
else. My pattern matching is not catching it for some reason:
#!/utils/bin/perl
$ptitle=`grep -i ONE $file`;
if ($ptitle =~ /\[(\w*)\]/) {
$ptitle=$1;
}
And here's some sample of the file:
ONE GEN:19990708 R:19990727 [Text I'd like to grab.] 0
TIA,
d
------------------------------
Date: Tue, 13 Nov 2001 17:18:04 GMT
From: mikee@kensho.eggtech.com (Mike Eggleston)
Subject: Re: Pattern Matching
Message-Id: <slrn9v2lec.c3q.mikee@kensho.eggtech.com>
On Tue, 13 Nov 2001 12:06:01 -0500, dh <hunter@nortelnetworks.ca> wrote:
> Hi group - easy one for you I think.
>
> I'd like to grab everything inside the square brackets and ignore everything
> else. My pattern matching is not catching it for some reason:
>
> #!/utils/bin/perl
> $ptitle=`grep -i ONE $file`;
> if ($ptitle =~ /\[(\w*)\]/) {
> $ptitle=$1;
> }
>
> And here's some sample of the file:
> ONE GEN:19990708 R:19990727 [Text I'd like to grab.] 0
>
> TIA,
>
> d
>
>
if($ptitle =~ /\[([^\]]*)\]/o) {
$ptitle = $1;
}
------------------------------
Date: Tue, 13 Nov 2001 11:39:56 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Pattern Matching
Message-Id: <slrn9v2mq6.9fi.trammell@haqq.el-swifto.com>
On Tue, 13 Nov 2001 12:06:01 -0500, dh <hunter@nortelnetworks.ca> wrote:
> I'd like to grab everything inside the square brackets and ignore
> everything else. My pattern matching is not catching it for some
> reason:
>
> #!/utils/bin/perl
> $ptitle=`grep -i ONE $file`;
> if ($ptitle =~ /\[(\w*)\]/) {
> $ptitle=$1;
> }
>
> And here's some sample of the file:
> ONE GEN:19990708 R:19990727 [Text I'd like to grab.] 0
>
\w matches alphanumerics plus "_" -- not whitespace or ' though.
How about:
if ($ptitle =~ /\[(.*?)\]/) { $ptitle = $1 }
------------------------------
Date: Tue, 13 Nov 2001 19:55:16 +0100
From: "echnathon" <echnathonh@yahoo.com>
Subject: Perl - MySQL question
Message-Id: <9srpv0$tji$1@rivage.news.be.easynet.net>
I need suggestions: I would like subscribers to my mailinglist (written in
Perl) to end up in a MySQL database, for administrative purposes.
What would be a good place to start ? I suppose modifying the
user-subscription script ?
All tips welcomed ! Thanks !
Echnathon
------------------------------
Date: Tue, 13 Nov 2001 11:07:05 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Perl Problems
Message-Id: <3BF15339.427472BD@mail.uca.edu>
Darlene Murphy wrote:
>
> I have written perl scripts on unix and had no problems. I can not
> get my perl script to run on Redhat Linux or Any window systems. If I
> type perl and the .pl
> they work, but when called from the .html file it just sits there.
>
> Any help? Any suggestions?
The answer to this question is found eloquently in perlfaq1. under the
sub-FAQ "My CGI script runs from the command line but not the browser.
(500 Server Error)."
However, the question that comes to mind to me, since you do not say
that you get a "500 Server Error," is "What webserver are you using?".
If the answer is "none," then that's your problem, not Perl.
In any case, the problem is not Perl since you can use it from the
command line without problems. Check out a comp.infosystems.www.* group.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: 13 Nov 2001 17:40:53 +0000
From: nobull@mail.com
To: deemurphy_us@yahoo.com
Subject: Re: Perl Problems
Message-Id: <u9itcelgbe.fsf@wcl-l.bham.ac.uk>
deemurphy_us@yahoo.com (Darlene Murphy) writes:
> Subject: Perl Problems
Please use the 'Subject' of your post to describe the subject of your
post. 99% of all on-topic threads in this newsgroups could be
characterised as "Perl Problems" so that's not exactly a useful
description. Actually I doubt your problem is Perl related anyhow.
> I have written perl scripts on unix and had no problems. I can not
> get my perl script to run on Redhat Linux or Any window systems. If
> I type perl and the .pl they work, but when called from the .html
> file it just sits there.
So you are saying "My CGI script runs from the command line but not
the browser".
See FAQ entry: "My CGI script runs from the command line but not
the browser".
> Any help?
You give us very little to go on but what little you do give us sounds
like a web server problem - unlikely to be related to the fact that
your scripts are written in Perl rather than Java, Python or whatever.
Of course if could also could be a CGI or an SSI issue, like I say you
give us nothing to go on.
> Any suggestions?
I suggest reading the FAQ _before_ you post to Usenet.
I suggest including sufficient information when you post to Usenet so
that people have an outside chance of helping you.
> Please email me also.
Please use a mail-copies-to header rather than asking people to
transcribe your address by hand.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 13 Nov 2001 08:27:28 -0800
From: robert@context.nl (Jongkees)
Subject: Perl.dl v.v. Perl.exe; it's stability and what is the most recent version?
Message-Id: <38b8bfdb.0111130827.14ba5bfd@posting.google.com>
Hello,
I'm not yet so formiliar whith Perl, but I have some questions
conserning the use of perl on a web-server. Who can help me?
1) I Like to implement a version of Perl on our web-server, but can
anyone inform me about the differences between perl.dll and perl.exe.
If I want an perl-script running whith use of an web-page-call how can
I call this.
2) What is the most recent version of Perl, and what are the
differences between that version and Perl 5.005. Is the script written
for version 5.005 backwards complatible for the newest version.
3) Does somebody know about the stability of this new version versus
the previous one.
4) What is the best way to make use of perl on a web-server. I saw
about ActivePerl on www.activestate.com, but than I also have to make
use PerlEx to use this on a web-server. Is this corret?
Already thanx for any help...
Greetingz,
Robert Jongkees
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 2123
***************************************