[13812] in Perl-Users-Digest
Perl-Users Digest, Issue: 1222 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 29 15:10:57 1999
Date: Fri, 29 Oct 1999 12:10:38 -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: <941224237-v9-i1222@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 29 Oct 1999 Volume: 9 Number: 1222
Today's topics:
Re: perl/cgi calling a window-based program (Scott McMahan)
Re: perlguts question <dan@tuatha.sidhe.org>
Re: perlguts question (Ilya Zakharevich)
Reading a file backwards? <koby@netscape.com>
Re: remove the html tag in the file <flavell@mail.cern.ch>
Re: Searching within web pages for text (Michael Budash)
Re: simplifying a script <wvandenbergNOSPAM@ttpdiskad.nl>
Re: simplifying a script <jeffp@crusoe.net>
Re: simplifying a script <jeffp@crusoe.net>
Re: Slice in scalar context (Kragen Sitaker)
Re: slow txt processing problem (Kragen Sitaker)
Re: slow txt processing problem (M.J.T. Guy)
Strange bug in Perl? <aqumsieh@matrox.com>
Re: Strange bug in Perl? (M.J.T. Guy)
Re: Using an SQL query across OS's via Web browser. (Scott McMahan)
Re: Why can't I get this uniq/perl thing right? (Kragen Sitaker)
Re: Why can't I get this uniq/perl thing right? <shon@mad.scientist.com>
Re: Why can't I get this uniq/perl thing right? <dchristensen@california.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Oct 1999 16:39:59 GMT
From: scott@aravis.softbase.com (Scott McMahan)
Subject: Re: perl/cgi calling a window-based program
Message-Id: <z5kS3.6283$hK6.316007@monger.newsread.com>
Liu, Chunyen (Chunyen.Liu@garmin.com) wrote:
> I am trying to use perl/cgi to invoke a window-based program
> through the web browser because DC (device context) is needed
> to get the final graphics. Looks like the window never gets
> opened. Similar calls work for command-line applications.
> Can anyone give me pointers? Thanks.
Create a virtual printer like Adobe Distiller, and then use Automation
to tell your app to print its document to that printer, and read the
output as a metafile, and do whatever you want with it. After all,
a printer is just a device context with some fancy escapes.
Sounds silly, but any solution to this design will be egregiously slow
and error prone and hard to write.
Scot
------------------------------
Date: Fri, 29 Oct 1999 16:41:31 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: perlguts question
Message-Id: <%6kS3.256$c06.2082@news.rdc1.ct.home.com>
Alex Rhomberg <rhomberg@ife.ee.ethz.ch> wrote:
> Can you explain a bit more? All perlguts says about that function is:
> SV* SvREFCNT_inc(SV* sv);
> SvREFCNT_inc
> Increments the reference count of the given SV.
> void SvREFCNT_inc (SV* sv)
> So it is not very verbose about what is returned.
Well, the void there is pretty explicit.
SvREFCNT_inc officially returns nothing. Unofficially it returns the same
SV pointer that you hand to it, but I wouldn't count on that.
Dan
------------------------------
Date: 29 Oct 1999 18:42:35 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perlguts question
Message-Id: <7vcpqr$e9f$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Dan Sugalski
<dan@tuatha.sidhe.org>],
who wrote in article <%6kS3.256$c06.2082@news.rdc1.ct.home.com>:
> > SvREFCNT_inc
> > Increments the reference count of the given SV.
>
> > void SvREFCNT_inc (SV* sv)
>
> > So it is not very verbose about what is returned.
>
> Well, the void there is pretty explicit.
>
> SvREFCNT_inc officially returns nothing. Unofficially it returns the same
> SV pointer that you hand to it, but I wouldn't count on that.
Well, this 'void' is clearly a misprint. A lot of work went into
making this macro to return sv. Zillions of XSes are peppered with
this usage.
About difference between sv_setsv() and SvREFCNT_inc: the latter
returns *the same* sv. So applying a mutator to the result will
change both to source and the target. If one is not going to apply
mutators, then SvREFCNT_inc is what is needed.
Ilya
------------------------------
Date: Fri, 29 Oct 1999 10:27:45 -0700
From: Jacob Rosenschein <koby@netscape.com>
Subject: Reading a file backwards?
Message-Id: <3819D911.7671A5BB@netscape.com>
Can I read a file, line by line, beginning with the last line and moving
upward towards the beginning of the file? If so, how would I do this in
Perl?
Thanks,
Koby Rosenschein (a newbie)
------------------------------
Date: Fri, 29 Oct 1999 19:33:41 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: remove the html tag in the file
Message-Id: <Pine.HPP.3.95a.991029192947.5569D-100000@hpplus01.cern.ch>
On Fri, 29 Oct 1999, Kragen Sitaker wrote:
> HTML is theoretically SGML. But there are lots of HTML documents out
> there that don't parse well, or at all, with SGML parsers but are,
> nevertheless, rendered correctly by browsers.
This can't be right. Since the error fixup behaviour is undefined, it
cannot be denoted "correct".
> (Here "correctly" means "as the author intended.")
Oh dear. Since many authors' intentions are incompabtible with the
published interworking standards, as a generic statement this _must_ be
wrong.
> I think more than 90% of the HTML on the
> Web is invalid.
Wouldn't surprise me. Describing the browsers' representation of it as
"correct" was not helpful though.
But this is the wrong group to discuss the issue, so I'll curb the
temptation to say more.
------------------------------
Date: Fri, 29 Oct 1999 11:36:32 -0700
From: mbudash@wcws.com (Michael Budash)
Subject: Re: Searching within web pages for text
Message-Id: <mbudash-2910991136320001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <=bwZOA0bZvm7YX8b7c3mCYD63g+N@4ax.com>, rob watson
<sloon@mindless.com> wrote:
> Hi,
>
> I am curious as to how I could search within "only" the content of web
> pages for text. Ignoring the HTML tags, etc. and only searching for
> the given phrase within the text that would normally be rendered on
> the screen when the page is viewed in a browser.
>
> Thank's so much
> rob
never actually used it, but HTML::Summary looks like it could help...
cpan.org...
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@wcws.com
------------------------------
Date: Fri, 29 Oct 1999 18:01:29 +0200
From: "Walter van den Berg" <wvandenbergNOSPAM@ttpdiskad.nl>
Subject: Re: simplifying a script
Message-Id: <7vcgk9$aa7$1@news1.xs4all.nl>
Greg Bacon writes:
> :
> : > my @table;
> : >
> : > foreach my $file (@table_data) {
> : > local $/;
> : > open TD, $file or die "$0: open $file: $!";
> : > push @table, { file => $file, data => <TD> };
> : > close TD;
> : > }
> :
> : Hm, Greg? It doesn't work with me...
>
> Oh, crud. Change the push line to
>
> push @table, { file => $file, data => [ <TD> ] };
Er... Greg? It's better now, but it's not complete. It only puts one table
in my file, but it should put in four. Sorry...
>
> Exercise for the reader: if possible, process the table files one at
> a time instead of slurping each of them; otherwise, prove that it's
> impossible.
>
In a month or so I'll be ready for that. I begun two days ago...
> Greg
> --
> Cop: I can put you in Queens on the night of the hijacking.
> Hockney: Really? I live in Queens. Did you put that together yourself?
Walter
--
No sigs yet.
------------------------------
Date: Fri, 29 Oct 1999 14:57:12 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: simplifying a script
Message-Id: <Pine.GSO.4.10.9910291455150.2694-100000@crusoe.crusoe.net>
[posted & mailed]
On Oct 29, Greg Bacon blah blah blah:
> : > foreach my $file (@table_data) {
> : > local $/;
> : > open TD, $file or die "$0: open $file: $!";
> : > push @table, { file => $file, data => <TD> };
> : > close TD;
> : > }
> Oh, crud. Change the push line to
>
> push @table, { file => $file, data => [ <TD> ] };
That shouldn't be necessary, since you took care of <TD> by setting $/ to
undef, didn't you?
open FILE, ".cshrc";
{
local $/;
$a = { contents => <FILE> };
}
close FILE;
print $a->{contents}; # works fine for me
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: Fri, 29 Oct 1999 14:57:42 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: simplifying a script
Message-Id: <Pine.GSO.4.10.9910291457220.2694-100000@crusoe.crusoe.net>
> I will use arrays! Just have to read further in my Perl for Dummies-book...
NO!!!!!! NOT THAT BOOK!
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: Fri, 29 Oct 1999 16:18:12 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Slice in scalar context
Message-Id: <8NjS3.6315$23.381819@typ11.nn.bcandid.com>
In article <7st0qb$9ns$1@lublin.zrz.tu-berlin.de>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Uri Guttman <uri@sysarch.com> wrote in comp.lang.perl.misc:
>
>>but what about the items themselves? if all you want is the number, just
>>hardwire that value. why count a list you throw away?
>
>The list may be easier to maintain if it changes occasionally. I
>admit it isn't easy to come up with a realistic example, but I may
>want to add to or delete from the list and leave th counting to Perl.
The point is, if you don't store the list anywhere, and it has no side
effects, you don't care how big it is.
This code:
my $x = () = (234, 352, 352, 10);
print $x, "\n";
is exactly equivalent to this code:
my $x = 4;
print $x, "\n";
and the second one is easier to read.
Now, if you were going to store the list's elements in an array or
something so you could use them later, you might have a point. But
then you can just evaluate the array name in scalar context and get the
length of the array. If you're doing the () = CONSTANT-LIST trick
above, you can't store the list elements in an array anyway.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 29 Oct 1999 16:43:19 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: slow txt processing problem
Message-Id: <H8kS3.6344$23.385704@typ11.nn.bcandid.com>
In article <38190ffe.25958616@news.hardlink.com>,
Mike Collins <mike@w3z.com> wrote:
>The script shown below checks about 50 fields against 2800 lines in
>another table to change cryptic codes into user friendly definitions.
>A couple of other subs check additional tables making substitutions.
>Processing 60 records (delim txt) allows enough time to brew a pot of
>coffee before it finishes.
Ah, I see. This routine:
># decode() is 2800 lines long
(I assume you mean it decodes using a 2800-line-long file)
> open (CARPART, "./dat_in/carparts.txt") || die $!;
> while (<CARPART>){
> chomp;
> s/\\/XXA/g; # \
> s/\[/XXB/g; # [
>
># <snip> several additional fields like the above
>
> @parts = "ewords(',', 0, $_);
> if ($parts[0] =~ /$code/){
> $parttxt = $parts[2];
> $parttxt =~ s/(\w+)/\u\L$1/g;
> print CODES "$parttxt", '|';
> last;
> }
> else{next;}
> }
> close CARPART;
>}
for each of the 50 input records, I guess you run this routine, which
reads the 2800-line file. So it processes a line of carparts.txt 50 *
2800 = 140000 times. Maybe that's why your program takes five minutes
-- it can only process about 450 lines a second?
Maybe you should read carparts.txt once, when your program starts, do
all your ugly nasty processing on it then, and store it in a hash.
$parts[0] would become the key and $parttxt would become the value.
If you really mean =~ instead of eq in the above if, you may be out of
luck.
Depending on parts of your code either you or I deleted, using eq or a
hash might also avoid all the XXA crap.
>Get high!! with WEBPOSITION
>http://w3z.com ***** ZD Net
>FREE Download. Do it now!!!
Wow, what kind of a loser are you?
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: 29 Oct 1999 18:24:46 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: slow txt processing problem
Message-Id: <7vcope$qsa$1@pegasus.csx.cam.ac.uk>
Kragen Sitaker <kragen@dnaco.net> wrote:
>
>If you really mean =~ instead of eq in the above if, you may be out of
>luck.
>
>Depending on parts of your code either you or I deleted, using eq or a
>hash might also avoid all the XXA crap.
And even if =~ is *really* what you want (I also have doubts), you can
still avoid the antics by suitably quoting your regex, for example
using \Q or quotemeta.
Mike Guy
------------------------------
Date: Fri, 29 Oct 1999 11:53:23 -0400
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Strange bug in Perl?
Message-Id: <x3yg0yu88p9.fsf@tigre.matrox.com>
First, I apologize for the subject line. I couldn't come up with
anything better!
Now, I think I stumbled upon a bug in Perl. The following is a minimal
program that exhibits the behaviour:
*********************
#!/usr/local/bin/perl -w
use strict;
package X;
sub new {
my $class = shift;
my $obj = {
X => 1,
Y => 2,
EQN => '$x * $y * $t',
};
return bless $obj, $class;
}
{
my ($x, $y);
sub calculate {
my $obj = shift;
unless (defined $x) {
$x = $obj->{X};
$y = $obj->{Y};
}
my $t = shift;
# print "$x $y\n";
my $z = eval $obj->{EQN};
return $z;
}
}
package main;
my $x = new X;
my $z = $x->calculate(3);
print "Z is $z.\n";
***********************
The calculate() method has two static variables $x, and $y which get
set the first time it is called.
Now, running the above program generates the following:
Use of uninitialized value at (eval 1) line 1.
Use of uninitialized value at (eval 1) line 1.
Z is 0.
I didn't expect this error, and couldn't see why I was getting it, so
I added the print() statement to see the values of $x and
$y. Uncommenting the print() statement above, and rerunning the
program generates this output:
1 2
Z is 6.
Which is what I would expect.
But why does the print() make a difference?
I also noticed something even stranger. If the print() statement is
moved *AFTER* the return() statement, and re-running:
Z is 6.
it still works!!!
Anybody has a good explanation for that?
Regards,
--Ala
------------------------------
Date: 29 Oct 1999 18:06:41 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Strange bug in Perl?
Message-Id: <7vcnnh$q1f$1@pegasus.csx.cam.ac.uk>
Ala Qumsieh <aqumsieh@matrox.com> wrote:
>
>Now, I think I stumbled upon a bug in Perl. The following is a minimal
>program that exhibits the behaviour:
>
<mostly snipped>
> unless (defined $x) { # <------- AAA
> $x = $obj->{X}; # <------- BBB
> $y = $obj->{Y};
> }
I can confirm the behaviour you report. Clearly a bug. Still
shows under perl5.005_62 .
Single stepping through the program with the debugger, at points AAA
and BBB we see that $x and $y are referring to different variables.
X::calculate(-:21): unless (defined $x) {
DB<1> x \$x, \$y
0 SCALAR(0x1aba98)
-> undef
1 SCALAR(0x1cbc50)
-> undef
DB<2> s
X::calculate(-:22): $x = $obj->{X};
DB<2> x \$x, \$y
0 SCALAR(0xdd678)
-> undef
1 SCALAR(0xdd690)
-> undef
DB<3>
So the binding of lexicals has got confused in some way.
I'll pass it to perlbug.
Mike Guy
------------------------------
Date: Fri, 29 Oct 1999 16:47:25 GMT
From: scott@aravis.softbase.com (Scott McMahan)
Subject: Re: Using an SQL query across OS's via Web browser.
Message-Id: <xckS3.6286$hK6.316007@monger.newsread.com>
wharmon@prodigy.net wrote:
> Our Web server is an Apache server with Red Hat Linux as the OS. My
> workplace has a NT server running IIS where they intend to locate
> Access db's that are intended for Web access.
Stop right here. Access and the web should not be mentioned in
the same sentence. Access is NOT a web-calibre database and should
not be used in this situation. If you can't afford SQL Server,
put everything into Postgres on the Linux box. Whoever designed
this "system" needs to take a reality check.
> I am wondering if it
> is asking too much if I try and access the MSAccess db from our Apache
> Web server using SQL ? I have noted posts that the DBI module is the
> tool of choice, but I am wondering if cross-platform SQL queries are a
> sane approach or not.
DBI has nothing to do with this -- Access is NOT A CLIENT/SERVER DATABASE,
no matter how much people want it to be, and has NO NETWORK CAPABILITIES
AT ALL. I've ranted and raved about this enough to have my own disk
volume at dejanews to contain all my raves. Access has no networking
or multiuser capabilities at all. A real database like DB2 would do
this no problem. DB2 Connect would be running on the Linux box, DBI
would connect to it, and DB2 Connect would do the networking for you.
But Access is not a real database, it's a single-user desktop thing.
Scott
PS: If you're running IIS on the NT box, why not use ASP and the Access
databases as an ODBC data source? This would redefine "dog slow",
but would work, to an extent. You do not have to use the ASP-generated
pages as direct user output; Perl can scrape these using LWP and you
can rearrange it as you like for the user.
------------------------------
Date: Fri, 29 Oct 1999 16:30:28 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <EYjS3.6332$23.381353@typ11.nn.bcandid.com>
In article <n4cav7.fdh.ln@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
> Any time the problem statement says "unique" (or duplicate,
> or look-up) I expect to see a percent sign somewhere in
> the code. (use a hash).
That's usually the easiest way, but not the only way and not always
the best way.
>: I know TMTOWTDI.
>
> Do you know F-A-Q ?
Do you know manners?
> I'm not surprised that you are wasting a lot of time.
> That's what people who won't check the FAQ get. And they deserve it.
Generally they don't; they're just ignorant. Ignorance is different
from evil.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Thu Oct 28 1999
12 days until the Internet stock bubble bursts on Monday, 1999-11-08.
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 29 Oct 1999 16:35:59 GMT
From: mr_geek <shon@mad.scientist.com>
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <7vcidf$vis$1@nnrp1.deja.com>
In article <n9dav7.eih.ln@magna.metronet.com>,
tadmc@metronet.com (Tad McClellan) wrote:
> Tad McClellan (tadmc@metronet.com) wrote:
> : mr_geek (shon@mad.scientist.com) wrote:
> : And why are you doing it similar to what is shown in the
> ^^^
>
> Uhhh, that, of course, was supposed to be "aren't".
>
I don't want to pick bones with those that are trying to help me. But
if you look at the code regarding the uniq part, it is a near copy of
what is in the FAQ. I am not a programmer by nature, I know a "little"
perl and for the most part have been able to get it to do what I've
needed. I have read the FAQ (not top to bottom) It doesn't answer every
question out there, or apply to every situation.
As to turning on warnings, I did. It only beefed about using $fields[0],
instead of @fields[0] and about using an unitialized value.
Programatically these things are not the issue with my particular
problem.
Thank you for taking the time to remind me of the FAQ.
Shon
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 29 Oct 1999 11:51:15 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: Re: Why can't I get this uniq/perl thing right?
Message-Id: <3819e907$1_4@news5.newsfeeds.com>
comp.lang.perl.misc & Larry:
Larry Rosler wrote in message ...
>In article <3818cafb$1_3@news5.newsfeeds.com> on Thu, 28 Oct 1999
>You haven't dealt with the 'uniq' part of the problem. Your data
>extraction is OK, but it should go into a hash, not an array.
>
> my %bases;
>
> /<td>\s*(.+?)\s*\|.*<\/td>/ and $bases{$1} = 1 while <>;
>
> print map "$_\n" => sort keys %bases;
Oops... Thanks for the correction :-)
--
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
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 1222
**************************************