[16783] in Perl-Users-Digest
Perl-Users Digest, Issue: 4195 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 1 00:05:31 2000
Date: Thu, 31 Aug 2000 21:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <967781111-v9-i4195@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 31 Aug 2000 Volume: 9 Number: 4195
Today's topics:
Re: "Premature end of script headers" (Gwyn Judd)
Re: anyone interested in being part of a new website? (Martien Verbruggen)
Re: Array Compare (Keith Calvert Ivey)
Re: Bug in perl 5.005_03 or 5.003_01? ("my" and loops) (Keith Calvert Ivey)
Re: Bug in Perl regular expressions? (Keith Calvert Ivey)
Re: converting text to doc files... <jhelman@wsb.com>
Re: Creating a subroutine library for PerlScript <davidbullock@tech-center.com>
Dealing with uninitialized values? <carter@aodinc.com>
dynamic object instantiation using eval <johnston.p@worldnet.att.net>
Re: dynamic object instantiation using eval (Mike Stok)
Re: Fat comma quoting [was: Re: Bulk add to a hash.. Th (Keith Calvert Ivey)
File slurping [was: Re: replace some word in text file] (Keith Calvert Ivey)
How to source a shell script from perl ? zagni@yahoo.com
Re: interchanging variables <stevea@wrq.com>
LWP::Parallel joekind@my-deja.com
Re: My Perl looks like C! (Keith Calvert Ivey)
Re: open web file <lxzy@yeah.net>
Re: open web file <tony_curtis32@yahoo.com>
Re: open web file (Gwyn Judd)
Re: open web file (Abigail)
Re: output fun (Martien Verbruggen)
Re: output fun (Gwyn Judd)
Re: Parsing text file not working properly (Keith Calvert Ivey)
Re: Parsing text file not working properly (Keith Calvert Ivey)
Re: Perl/ODBC/SQL Wierdness? (Keith Calvert Ivey)
Re: regexp and accentuated letters (Keith Calvert Ivey)
Re: regexp and accentuated letters (Abigail)
why is my perl script using so much memory <elijah@workspot.net>
Re: why is my perl script using so much memory <rick.delaney@home.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 01 Sep 2000 03:04:56 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: "Premature end of script headers"
Message-Id: <slrn8qu76l.ci6.tjla@thislove.dyndns.org>
I was shocked! How could Jon Drukman <jsd@cluttered.com>
say such a terrible thing:
>On Thu, 31 Aug 2000 18:13:03 GMT,
> reschramz@my-deja.com <reschramz@my-deja.com> wrote:
>>What I want to know is how your script manages to work just fine, when
>>usually truncated HTTP headers means that the CGI output won't display
>>at all.
>
>most likely the script works fine some times and outputs errors
>other times, which come out before the Content-type header.
>
>using $|=1 sometimes eliminates this situation. better error
>checking usually fixes it completely.
*sigh*
#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
always eliminates this problem.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
If you put it off long enough, it might go away.
------------------------------
Date: Fri, 01 Sep 2000 03:10:51 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: anyone interested in being part of a new website?
Message-Id: <slrn8qu7h9.2cp.mgjv@verbruggen.comdyn.com.au>
On Thu, 31 Aug 2000 16:34:57 -0400,
paceman97@aol.com <paceman97@aol.com> wrote:
> i'm a web developer/designer and always interested in internet
> idea's. tell me more about this.
^
visit alt.possessive.its.has.no.apostrophe. Unfortunaly there is
no alt.plurals.have.no.apostrophe.
Maybe I'm just way off here.. Maybe I just don't understand this
Internet thingy, or maybe things have changed in the last 10 minutes...
But..
Wouldn't it be much easier for both of you if you just used email?
Martien
--
Martien Verbruggen |
Interactive Media Division | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd. | spot.
NSW, Australia |
------------------------------
Date: Fri, 01 Sep 2000 02:31:30 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Array Compare
Message-Id: <39b814ac.5844446@news.newsguy.com>
marxjkj123@my-deja.com wrote:
>My array looks like:
>Arrayx
>= "weblogic.ejb.deploy=\y:/main/CommerceServer/WORKAREA/WL_Property_WA/W
>ebLogicCommerce/lib/STIGA."
>
>and
>
>Array(y)
>= "weblogic.ejb.deploy=\y:/main/CommerceServer/WORKAREA/WL_Property_WA/W
>ebLogicCommerce/lib/marcus.jary:/main/CommerceServer/WORKAREA/WL_Propert
>y_WA/WebLogicCommerce/lib/dave.jary:/main/CommerceServer/WORKAREA/WL_Pro
>perty_WA/WebLogicCommerce/lib/stiga.jar"
Those aren't arrays. Do you perhaps want to use the split()
function to split the strings on colons?
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 02:23:05 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Bug in perl 5.005_03 or 5.003_01? ("my" and loops)
Message-Id: <39b61253.5243662@news.newsguy.com>
Tim Conrow <tim@ipac.caltech.edu> wrote:
>Or just ...
>
>print join("\n",@test_array),"\n";
>
>... if @test_array isn't too big.
Or
$\ = "\n";
print for @test_array;
or
$, = $\ = "\n";
print @test_array;
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 02:09:23 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Bug in Perl regular expressions?
Message-Id: <39b40f58.4480180@news.newsguy.com>
decklin+usenet@red-bean.com (Decklin Foster) wrote:
>jba_lixx@my-deja.com <jba_lixx@my-deja.com> writes:
>
>> ($scoretext=~ /^(\d+):(\d+)/) && ($score1= $1) && ($score2 = $2)
>
>[OK, I see several responses, but all use a regex to find the numbers]
And make sure that they're numbers, which your solution
doesn't do.
>Overkill.
I don't think so.
> ($score1, $score2) = split(/:/, $scoretext);
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 02:38:44 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: converting text to doc files...
Message-Id: <39AF172F.13A387EF@wsb.com>
closetgeekla@my-deja.com wrote:
>
> i need to convert formatted text documents (made from MAS90 reports) to
> *.doc with landscape formatiing and with a courier 8pt font. Anyone have
> any ideas on how to start?
By .doc do I assume correctly that you want an MS Word document? I'd
recommend a combination of Perl (to parse your files if needed) and Word
macros (to make Word documents).
We can help with the Perl part, but I'd advise investigating a Word
macro group for conversions to MS Word.
JH
------------------------------
Date: Thu, 31 Aug 2000 20:09:52 -0700
From: David Bullock <davidbullock@tech-center.com>
Subject: Re: Creating a subroutine library for PerlScript
Message-Id: <af7uqssmcfhubn8rcbpfoo64elshfejvfs@4ax.com>
On Thu, 31 Aug 2000 20:59:37 -0400, "Milt Ginsburg"
<miltginsburg@email.com> wrote:
>
>David Bullock <davidbullock@tech-center.com> wrote in message
>news:anntqs4hn7s5658hku6j2offde09ocqc23@4ax.com...
>>
>> Here's an article on using Perl in ASP.
>>
>> http://www.asptoday.com/articles/19990716.htm
>
>Thanks.
>
>Did Alan say something?
Of course he did.
Hope the links helped...
Dave
------------------------------
Date: Thu, 31 Aug 2000 21:33:25 -0600
From: "Carter" <carter@aodinc.com>
Subject: Dealing with uninitialized values?
Message-Id: <8on7rk$7bk$1@news.chatlink.com>
How does one deal with uninitialized values?
Since adding the -w to the hashbang call at the beginning of my script, any
time I test using an uninitialized value, I (obviously) get the warning, and
I don't quite know how to deal with this.
Incasing everything within
if ($var) { do this } else { uninitialized }
type structures is just too much.
It's pretty easy to avoid the problem when using standard variables. Just
make sure every variable is initialized at the beginning. The problem is
with hashes.
I store data in a hash in name/value pairs, $form{$name}=$value. When going
through and testing the hash, the name may or may not exist depending on the
data which was fed into it.
--
carter
------------------------------
Date: Fri, 01 Sep 2000 01:07:48 GMT
From: "Paul Johnston" <johnston.p@worldnet.att.net>
Subject: dynamic object instantiation using eval
Message-Id: <EjDr5.13028$Q36.949225@bgtnsc07-news.ops.worldnet.att.net>
# This works:
package Foo;
use MyPackage::MyClass;
my $obj = MyPackage::MyClass->new($myargs);
# This dies with "Can't find method new":
package Foo;
my $class = "MyPackage::MyClass";
my $obj = eval $class . '->new($myargs)';
# this dies with can't find MyPackage::MyClass;
package Foo;
my $class = "MyPackage::MyClass";
require $class;
What am I doing wrong? I must have screwed with this for two hours today!
I've done this type of thing before without problems but it does not seem to
be working this time... Grr.
Paul
------------------------------
Date: Fri, 01 Sep 2000 03:23:49 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: dynamic object instantiation using eval
Message-Id: <9jFr5.27665$K5.455094@typhoon.austin.rr.com>
In article <EjDr5.13028$Q36.949225@bgtnsc07-news.ops.worldnet.att.net>,
Paul Johnston <johnston.p@worldnet.att.net> wrote:
># This works:
>package Foo;
>use MyPackage::MyClass;
>my $obj = MyPackage::MyClass->new($myargs);
>
># This dies with "Can't find method new":
>package Foo;
>my $class = "MyPackage::MyClass";
>my $obj = eval $class . '->new($myargs)';
Has the interpreter had a chance to reaf the MyPackage::MyClass module
anywhere before this? Just invoking a method won't cause perl to go and
load the class. MyPackage::MyClass::new must have been presented to perl
for that call to succeed (unless you're into advanced trickery to fake up
the sub on demand). In the debugger:
DB<1> $class = 'CGI'
DB<2> print "worked" if $o = eval $class . '->new({})';
DB<3> use CGI
DB<4> print "worked" if $o = eval $class . '->new({})';
worked
At step 2 nothing had caused perl to read the CGI module, once read the
statement worked.
You are aware that $myargs will not interpolate inside single quotes,
so you may have a problem there. You can say
my $obj = $class->new($myargs); # maybe @myargs
DB<5> print "worked" if $o = $class->new({});
worked
DB<6> print $o
CGI=HASH(0x832dd54)
># this dies with can't find MyPackage::MyClass;
>package Foo;
>my $class = "MyPackage::MyClass";
>require $class;
>
>What am I doing wrong? I must have screwed with this for two hours today!
>I've done this type of thing before without problems but it does not seem to
>be working this time... Grr.
Did you spend some time reading the manual, which should be installed with
a perl installation? On my system
perldoc -tf require
includes this:
require VERSION
require EXPR
[...]
If EXPR is a bareword, the require assumes a ".pm" extension and
replaces "::" with "/" in the filename for you, to make it easy
to load standard modules. This form of loading of modules does
not risk altering your namespace.
In other words, if you try this:
require Foo::Bar; # a splendid bareword
The require function will actually look for the "Foo/Bar.pm"
file in the directories specified in the `@INC' array.
But if you try this:
$class = 'Foo::Bar';
require $class; # $class is not a bareword
#or
require "Foo::Bar"; # not a bareword because of the ""
The require function will look for the "Foo::Bar" file in the
@INC array and will complain about not finding "Foo::Bar" there.
In this case you can do:
eval "require $class";
For a yet-more-powerful import facility, see the use entry
elsewhere in this document and the perlmod manpage.
It's worth spending some time reading the docs, and getting a feel for
what's happening. Using the debugger and examining things like %INC, and
understanding the difference between perl's compile and run phases will
pay off handsomely.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ |
GPG PGP Key 1024D/059913DA | Fingerprint 0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work) | 75D2 9EC4 C1C0 0599 13DA
------------------------------
Date: Fri, 01 Sep 2000 02:01:08 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Fat comma quoting [was: Re: Bulk add to a hash.. Thanks for the help!]
Message-Id: <39b30cc1.3817087@news.newsguy.com>
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "KCI" == Keith Calvert Ivey <kcivey@cpcug.org> writes:
> KCI> I thought it was the other way around: the common use of -foo in
> KCI> sub calls came from the fact that you could do it. And a
> KCI> bareword is still a bareword if it has an operator in front of
> KCI> it.
>
>my impression is that many modules like tk and cgi used -foo for keys a
>long time before +> was fixed to handle a leading -. i recall complaints
>about why it doesn't work with them, and now it does. i bet a little
>searching of the deltas would clear this up. i have to run so i can't do
>it now.
You're probably right. I just assumed that one reason minus was
chosen as the character to distinguish the names was that it
worked with the => operator. Otherwise, why not use % or = or *
or anything else not likely to occur at the beginning of an
argument?
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 01:36:58 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: File slurping [was: Re: replace some word in text file]
Message-Id: <39b106d9.2305186@news.newsguy.com>
Larry Rosler <lr@hpl.hp.com> wrote:
>The fastest way turned out to be (as posted by Anno Siegel):
>
> read FILE, $File, -s FILE;
I'm sticking with
my $file;
{ local $/; $file = <FILE>; }
because the files I slurp most often are text files on Windows
systems. I know the read() version works anyway, but it bothers
me that -s FILE doesn't match the number of bytes read() thinks
it's read. I know, I should just get over it (actually, Windows
is what I should get over).
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 01:51:49 GMT
From: zagni@yahoo.com
Subject: How to source a shell script from perl ?
Message-Id: <8on23e$32d$1@nnrp1.deja.com>
I need to source a shell script from a perl program and make the
variables visible to the program.
Thanks,
Renzo
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 31 Aug 2000 13:33:28 -0700
From: Steve Allan <stevea@wrq.com>
Subject: Re: interchanging variables
Message-Id: <u66oh5fxj.fsf@wrq.com>
Ankur Banerjee <ankban4@indiainfo.com> writes:
>HI,
>How do i interchange values of three variables $a,$b,$c WITHOUT using
>this expression:-
>($a,$b,$c)=($b,$c,$a);
>
I can't tell if you're looking for serious solutions or interesting
solutions, since you've eliminated the most natural and idiomatic
approach. So, just to be different, how about
@array = ($a, $b, $c) = 3..5;
$array[@array] = shift @array;
# or push(@array, shift @array);
($a, $b, $c) = @array;
This is not how I'd do it, but it may be interesting if only as a
general approach to moving the first element in a list to the end.
--
-- Steve __
------------------------------
Date: Fri, 01 Sep 2000 03:16:40 GMT
From: joekind@my-deja.com
Subject: LWP::Parallel
Message-Id: <8on729$8fe$1@nnrp1.deja.com>
Hello. I am using lwp::parallel::useragent to get the content from
some sites. Here is my code:
require LWP::Parallel::UserAgent;
use HTTP::Request;
my (@reqs) = ();
my $reqs = [HTTP::Request->new('GET', $search[0]),
HTTP::Request->new('GET', $search[1]),
HTTP::Request->new('GET', $search[2]),
HTTP::Request->new('GET', $search[3]),
HTTP::Request->new('GET', $search[4]),
HTTP::Request->new('GET', $search[5]),
HTTP::Request->new('GET', $search[6]),
HTTP::Request->new('GET', $search[7]),
];
my $pua = LWP::Parallel::UserAgent->new();
$pua->in_order (1); # handle requests in order of registration
$pua->duplicates(0); # ignore duplicates
$pua->timeout (5); # in seconds
$pua->redirect (1); # follow redirects
foreach my $req (@$reqs) {
if ( my $res = $pua->register ($req) ) {
print STDERR $res->error_as_HTML;
}
}
my $entries = $pua->wait();
foreach (keys %$entries) {
my $res = $entries->{$_}->response;
$response_body = $res->content();
@$var2 = split(/$split/, $response_body); #content from specified
site
$p++;
}
The problem is that after connecting to a few sites it says
LWP::Parallel cannot handle request (501 error).
Can someone please help me because I want to make this script grab the
content from these sites fast and that is why I am using
LWP::Parallel::UserAgent. I have just used LWP::UserAgent before and
got it to work, but I need it to be faster.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 01 Sep 2000 02:59:25 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: My Perl looks like C!
Message-Id: <39ba1a65.7309842@news.newsguy.com>
"Andrew N. McGuire " <anmcguire@ce.mediaone.net> wrote:
>On Thu, 31 Aug 2000, Tim quoth:
>~~ o Use hashes. A lot.
>
>Based on what premise? A hash is not the end all data structure.
>Use the appropriate data structure for the task you are trying to
>accomplish!
I think these are supposed to be rules of thumb, and as such
shouldn't be pressed too far. Hashes are one of the strengths
of Perl, and those new to Perl often fail to use them when
they're the best solution.
>~~ o Use logical operators. this() or die; is a lot cleaner than
>~~ if (this()) { die; }. Same with $x = $this || $that;
>
>I usually use:
>
>$x ||= $that;
>
>most often to set defaults after a GetOptions(). It is a matter of
>style, I suppose.
It's a matter of what you're trying to do. Tim's statement does
something different from yours. If he'd written
$x = $x || $that;
then your correction would have been right.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 1 Sep 2000 09:04:09 +0800
From: "Xin Li" <lxzy@yeah.net>
Subject: Re: open web file
Message-Id: <8omv54$97f$1@info.bta.net.cn>
Hi,
but i can open *.htm files.
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:877l8xgdev.fsf@limey.hpcc.uh.edu...
> >> On 31 Aug 2000 20:29:39 -0400,
> >> steveo@panix.com (Steven M. O'Neill) said:
>
> > David Wall <darkon@one.net> wrote:
> >> I wrote:
> >>
> >>> open() is for opening files.
> >>> http://www.foo.com/bar.html isn't a file.
>
> > HTML files are not files? -- Steven O'Neill
>
> URLs are not files. There's a big, big difference.
>
> hth
> t
> -
> "I'm not easily impressed. Wow! A blue car!"
> Homer Simpson
------------------------------
Date: 31 Aug 2000 20:12:56 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: open web file
Message-Id: <874s40hq3r.fsf@limey.hpcc.uh.edu>
>> On Fri, 1 Sep 2000 09:04:09 +0800,
>> "Xin Li" <lxzy@yeah.net> said:
> Hi, but i can open *.htm files.
That's nice. What's that got to do with "open"ing URL's
over a network?
hth
t
--
"I'm not easily impressed. Wow! A blue car!"
Homer Simpson
------------------------------
Date: Fri, 01 Sep 2000 03:20:49 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: open web file
Message-Id: <slrn8qu84c.ci6.tjla@thislove.dyndns.org>
I was shocked! How could Abigail <abigail@foad.org>
say such a terrible thing:
>Sean Scannell (sean@access-management.com) wrote on MMDLVII September
>MCMXCIII in <URL:news:ZBAr5.85$WH4.68667@news.pacbell.net>:
>|| Why does the following die:
>||
>|| open (TEMP, 'http://www.foo.com/bar.html') || die
>
>Why do you ask? Perl has a useful mechanism that tells you why
>something failed. Why don't you use it instead of asking here?
>
>|| I guess I can fetch the file via LWP, but just wondering.
>
>open() has lots of magic, but only C-API specific and, unfortunally,
>no HTTP semantics. It would be useful though.
Useful or confusing? What if you happen to have a directory called
"http://www.slashdot.org"? Sometimes it's a good thing to have a
seperation between functions that do two somewhat different things.
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Any three sharp lawyers know at all times which three of them are lying.
------------------------------
Date: 01 Sep 2000 03:54:39 GMT
From: abigail@foad.org (Abigail)
Subject: Re: open web file
Message-Id: <slrn8qua2c.8ac.abigail@alexandra.foad.org>
Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote on MMDLVIII September MCMXCIII
in <URL:news:slrn8qu84c.ci6.tjla@thislove.dyndns.org>:
`' I was shocked! How could Abigail <abigail@foad.org>
`' say such a terrible thing:
`' >
`' >open() has lots of magic, but only C-API specific and, unfortunally,
`' >no HTTP semantics. It would be useful though.
`'
`' Useful or confusing? What if you happen to have a directory called
`' "http://www.slashdot.org"? Sometimes it's a good thing to have a
`' seperation between functions that do two somewhat different things.
So, you'd use "./http://www.slashdot.org".
That's what you do if you have a file called '-', or '> foo', or
'&<4' or '| wc -l'. Why would "http://www.slashdot.org" suddenly
be an obstacle?
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
Date: Fri, 01 Sep 2000 03:05:26 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: output fun
Message-Id: <slrn8qu774.2cp.mgjv@verbruggen.comdyn.com.au>
On Tue, 29 Aug 2000 13:21:47 GMT,
ankban4@my-deja.com <ankban4@my-deja.com> wrote:
> HI
> Without using the formatting features , how do i print an output like
> this . i tried but my code is too huge and ugly.
>
> ABCDEFGFEDCBA
> ABCDEF FEDCBA
> ABCDE EDCBA
> ABCD DCBA
> ABC CBA
> AB BA
> A A
The simplest way would be
print <<EOF;
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
EOF
If you want to waste CPU cycles and memory, look at the methods that
all these other people are posting.
Martien
PS. Insert winky emoticon anywhere you want.
--
Martien Verbruggen |
Interactive Media Division | That's not a lie, it's a
Commercial Dynamics Pty. Ltd. | terminological inexactitude.
NSW, Australia |
------------------------------
Date: Fri, 01 Sep 2000 03:33:59 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: output fun
Message-Id: <slrn8qu8t4.ci6.tjla@thislove.dyndns.org>
I was shocked! How could Logan Shaw <logan@cs.utexas.edu>
say such a terrible thing:
>In article <8ogdcm$56v$1@nnrp1.deja.com>, <ankban4@my-deja.com> wrote:
>Well, my code is a little longer than others' code, but here it is:
> select (undef, undef, undef, rand * rand);
ITYM:
select(undef, undef, undef, rand() * rand());
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Occasionally I think about doing something to change my situation, but
where am I going to get hold of a Stealth bomber? (contributed by Frank
v Waveren)
------------------------------
Date: Fri, 01 Sep 2000 02:45:16 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Parsing text file not working properly
Message-Id: <39b91695.6333523@news.newsguy.com>
Rick Nakroshis <nakroshis@smart.net> wrote:
>$search = "BB";
>open (DATAFILE, "data.dat") or die "Can't open the data file: $!";
>while (<DATAFILE>) {
> if (index (<DATAFILE>, $search) eq 0) {
There are two problems with the line above: First, you're
reading another line out of the file and not saving it (use $_
in place of <DATAFILE>). Second, you're using eq to compare
numbers (change eq to ==), though that's not causing a problem
in this case.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 03:06:11 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Parsing text file not working properly
Message-Id: <39bb1bfd.7717523@news.newsguy.com>
"Kiel Stirling" <taboo@comcen.com.au> wrote:
>while (<FILE>) {
> ($field1, $field2) = split "," $_ if /^$search/;
> # split $_ if the value of $search is at the start
> # of the line
Well, okay, but I don't think you want to do the next line if
there's no match -- and there's a syntax error (and unnecessary
$_) too. I'd replace that line with
next unless /^$search/;
($field1, $field2) = split /,/;
It's a good idea to use slashes for the split() regex. If you
use quotes you're likely to forget that it's a regex and end up
confused when you try something like split "|".
> print $field1,$field2,"\n";
You might want to print something between the variables there.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 02:16:33 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Perl/ODBC/SQL Wierdness?
Message-Id: <39b5107f.4775558@news.newsguy.com>
Stephan Gross <sg@loralskynet.com> wrote:
>"SELECT TABLE1.CUSTOMER, TABLE1.FIELD1, TABLE2.FIELD1
>FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.COMMON = TABLE2.COMMON"
>
>When I run this in Access, I get unique values for TABLE1.FIELD1 and
>TABLE2.FIELD1.
>
>I then cut and paste the exact same SQL statement into my perl ODBC
>program. When I run the program, TABLE1.FIELD1 returns the same value
>as TABLE2.FIELD1.
If you're getting the data out in a hash, the keys of the hash
are the (unqualified) names of the fields, so one FIELD1
overwrites the other. Either get the data out as an array, or
use an alias:
SELECT TABLE1.CUSTOMER, TABLE1.FIELD1,
TABLE2.FIELD1 AS FIELD1_T2
FROM TABLE1 INNER JOIN TABLE2
ON TABLE1.COMMON = TABLE2.COMMON
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 01:27:32 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: regexp and accentuated letters
Message-Id: <39b00534.1884210@news.newsguy.com>
abigail@foad.org (Abigail) wrote:
>But why do this for each pattern if you can just use a module and
>overload your regexes?
[snip]
> $ perl -Maccented -wle '$re = qr /Eleve/; print $re'
> (?-xism:[EÈÉÊË]l[eèéêë]v[eèéêë])
> $
>
>Just don't use character classes yourself.... ;-)
And don't try to interpolate in the regex:
perl -Maccented -wle "$pat = 'Eleve'; $re = qr/$pat de
francais/; print $re"
(?-xism:Eleve d[eèéêë] fr[aáâãäå][nñ][cç][aáâãäå][iìíîï]s)
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: 01 Sep 2000 03:58:43 GMT
From: abigail@foad.org (Abigail)
Subject: Re: regexp and accentuated letters
Message-Id: <slrn8qua9v.8ac.abigail@alexandra.foad.org>
Keith Calvert Ivey (kcivey@cpcug.org) wrote on MMDLVIII September
MCMXCIII in <URL:news:39b00534.1884210@news.newsguy.com>:
\\ abigail@foad.org (Abigail) wrote:
\\
\\ >But why do this for each pattern if you can just use a module and
\\ >overload your regexes?
\\
\\ [snip]
\\
\\ > $ perl -Maccented -wle '$re = qr /Eleve/; print $re'
\\ > (?-xism:[EÈÉÊË]l[eèéêë]v[eèéêë])
\\ > $
\\ >
\\ >Just don't use character classes yourself.... ;-)
\\
\\ And don't try to interpolate in the regex:
\\
\\ perl -Maccented -wle "$pat = 'Eleve'; $re = qr/$pat de
\\ francais/; print $re"
\\ (?-xism:Eleve d[eèéêë] fr[aáâãäå][nñ][cç][aáâãäå][iìíîï]s)
Hah. I knew someone would come with that. But, it works if you do it right.
$ perl -Maccented -wle '$pat = qr /Eleve/; $re = qr/$pat de
francais/; print $re'
(?-xism:(?-xism:[EÈÉÊË]l[eèéêë]v[eèéêë]) d[eèéêë]
fr[aáâãäå][nñ][cç][aáâãäå][iìíîï]s)
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: 1 Sep 2000 01:33:07 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: why is my perl script using so much memory
Message-Id: <eli$0008312106@qz.little-neck.ny.us>
I happened to be watching a perl script I wrote in top,
and I noticed that the memory usage didn't stop growing
when I thought it should.
The general format of the script is roughly:
$i = 0;
for $file (@list) {
open(IN,$file) or die "Can't read $file: $!\n";
while(<IN>){
if (($id, $val) = /^(\d+)\t(\d+)/) {
${$bighash{$id}}[$i] = $val;
}
}
close IN;
$i ++;
}
Followed by some code to print %bighash as a tab-seperated values
file. I understand and expect perl's memory to grow rapidly while
I am reading input, the bit that puzzles me is that it continues
to grow during the output stage as well. %bighash has about
120,000 entries, and the output file is about 13megs. This makes
the roughly 30megs of memory growth during the output stage very
surprising to me.
The exact code of the output portion is below. All variables not
my'ed are declared in 'use vars' at the start of the script.
print "Memory before\nps -p $$ -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd\n"
. `ps -p $$ -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd` . "\n";
while(($id,$cols) = each %bighash) {
if (!defined(${$cols}[0])) {
${$cols}[0] = $emptycol;
}
if (!defined(${$cols}[1])) {
${$cols}[1] = $emptycol;
}
if (!defined(${$cols}[2])) {
${$cols}[2] = $emptycol;
}
if (!defined(${$cols}[3])) {
${$cols}[3] = $emptycol;
}
if (!defined(${$cols}[4])) {
${$cols}[4] = $emptycov; # special val for this col
}
if (!defined(${$cols}[5])) {
${$cols}[5] = $emptyart; # special val for this col
}
if (!defined(${$cols}[6])) {
${$cols}[6] = $emptycol;
}
print OUT "$id\t" . join("\t",@{$cols}) . "\n";
}
close OUT;
print "Memory after\nps -p $$ -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd\n"
. `ps -p $$ -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd` . "\n";
my $rtime = (time() - $^T);
my $min = $rtime / 60;
my $sec = $rtime % 60;
print "Running time $min minutes and $sec seconds.\n";
With perl5.6.0 built for i686-linux-thread, the output diagnostics
are:
Memory before
ps -p 30915 -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd
PID %CPU %MEM DSIZ RSS SZ TIME CMD
30915 96.9 40.8 109365 105252 27526 00:00:50 perl big-daddy
Memory after
ps -p 30915 -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd
PID %CPU %MEM DSIZ RSS SZ TIME CMD
30915 91.9 52.7 140161 136056 35225 00:01:08 perl big-daddy
Running time 1 minutes and 14 seconds.
With perl5.00503 built for i386-linux, the output diagnostics are:
Memory before
ps -p 30912 -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd
PID %CPU %MEM DSIZ RSS SZ TIME CMD
30912 95.5 40.6 109064 104780 27384 00:00:25 perl5.00503 big-daddy
Memory after
ps -p 30912 -o pid,%cpu,%mem,dsiz,rss,sz,time,cmd
PID %CPU %MEM DSIZ RSS SZ TIME CMD
30912 86.0 52.6 139860 135584 35083 00:00:37 perl5.00503 big-daddy
Running time 0 minutes and 43 seconds.
Perl 5.6.0 is consistent in taking about 70% longer than perl5.00503
running this simple script. Price of progress, I guess.
Any ideas why the memory goes up though? Additional CPU time is
not significant to me, but if I double the size of %bighash this
will start swapping, and that slowness will bother me.
Elijah
------
named the script 'big-daddy' since it is replacing five other scripts
------------------------------
Date: Fri, 01 Sep 2000 03:28:24 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: why is my perl script using so much memory
Message-Id: <39AF24C0.D07EFDE2@home.com>
[posted & mailed]
Eli the Bearded wrote:
>
> I understand and expect perl's memory to grow rapidly while
> I am reading input, the bit that puzzles me is that it continues
> to grow during the output stage as well.
[snip]
> while(($id,$cols) = each %bighash) {
> if (!defined(${$cols}[0])) {
> ${$cols}[0] = $emptycol;
> }
Does this happen a lot? If so, you should expect the memory to increase
during the output portion since you are creating new entries. If you
replace your list of files with the same file repeated seven times, does
that make a difference?
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4195
**************************************