[13823] in Perl-Users-Digest
Perl-Users Digest, Issue: 1233 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 30 15:10:32 1999
Date: Sat, 30 Oct 1999 12:10:15 -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: <941310615-v9-i1233@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 30 Oct 1999 Volume: 9 Number: 1233
Today's topics:
Re: perl script for file uploading <gellyfish@gellyfish.com>
Re: Perl script to compile C program. <gellyfish@gellyfish.com>
Re: perlguts question (Ilya Zakharevich)
Re: Q: Hashes of Hashes of Hashes (Clinton Pierce)
Re: Q: Hashes of Hashes of Hashes <gellyfish@gellyfish.com>
qxurl in sub <sun_tong@geocities.com>
Re: Reading a file backwards? <gellyfish@gellyfish.com>
Re: regex match with empty string <xah@best.com>
Re: Searching within web pages for text <gellyfish@gellyfish.com>
Simple socket question <seanc@jps.net>
Re: simplifying a script <uri@sysarch.com>
Re: simplifying a script <vandenbNOSPAM@cistron.nl>
Re: simplifying a script <vandenbNOSPAM@cistron.nl>
Re: simplifying a script <gellyfish@gellyfish.com>
Re: simplifying a script <uri@sysarch.com>
Re: simplifying a script <uri@sysarch.com>
Re: simplifying a script <vandenbNOSPAM@cistron.nl>
Re: simplifying a script <lr@hpl.hp.com>
Re: Stripping live HTML into text (Jason Costomiris)
Re: Whoa. This shouldn't work... <qumsieh@sympatico.ca>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 30 Oct 1999 14:43:19 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: perl script for file uploading
Message-Id: <7vf067$5aq$1@gellyfish.btinternet.com>
On Thu, 28 Oct 1999 17:27:28 -0700 David Cassell wrote:
> Lee Sharp wrote:
>>
>> n.thiyagarajan wrote in message <38189F3D.177A881@yahoo.com>...
>> |i'm new to perl so go easy on me...
>> |
>> |i have an html form that will be used for uploading a file. i want to
>> |write a perl script to upload the file and place the file in a specific
>> |directory. i'm having troble with enctype= multipart-formdata.
>>
>> Try http://www.perlarchive.com/guide/File_Uploading/ for lots of good
>> stuff. Pre canned, and ready to go. cpan is also very good, but daunting
>> to a beginner.
>
> Yes, perlarchive is definitely aimed at the non-Perlite and the
> rank beginner. They consider the use of *any* module to be 'advanced'.
> That strikes me as less-than-sterling advice, but YMMV.
>
I cant be arsed to look right now (Australia and South Africa are kicking
the shit out of each other between fiddling with a ball :) but is this
place in need of examination ? I mean are we talking about something
that definitely *shouldnt* be recommended or something that might be worth
suggesting but probably not of the best ?
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 30 Oct 1999 14:51:06 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl script to compile C program.
Message-Id: <7vf0kq$5at$1@gellyfish.btinternet.com>
On Thu, 28 Oct 1999 22:49:14 -0400 (EDT) KernelKlink@webtv.net wrote:
>
> ==============================
> Have MySQL questions but can't find a
> newsgroup to post them to? Post to the newsgroup comp.databases
> ==============================
>
I think that it might be more appropriate to read the RFD that was posted
in that newsgroup and then act appropriately - I for one would like to
see a group to which we could point MySQL users. I would suggest that
encouraging people to post into a probably *inappropriate* group is either
trolling or an attempt to manipulate the newsgroup creation process.
Of course there are also mailing lists that deal with MySQL.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 30 Oct 1999 17:29:17 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: perlguts question
Message-Id: <7vf9td$lu6$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Alex Rhomberg
<rhomberg@ife.ee.ethz.ch>],
who wrote in article <381B02A8.BE4DDD93@ife.ee.ethz.ch>:
> > > 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.
>
> rather a bug in perlguts than a misprint. Or an 'erratum'? An 'issue' ?
> ;-)
It might have been that there was a suspiction that a future update to
Perl might have made supporting SV* return hard. Apparently, starting
from 5.005_61 the calling sequence of Perl API became as ugly as one
could imagine, but SvREFCNT_inc() still works...
> > 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.
>
> But I shouldn't store the same SV* more than once in a perl struct,
> right?
> I use Data::Dumper, which prints errors if I store the same SV* more
> than once in a hash.
Please report bugs in Data::Dumper to Data::Dumper support channels.
> It seems that the best way to copy a reference is
> newRV_inc(SvRV(orig_ref))
Yes, if you need a *copy* (and a shallow one), this is probably the
quickiest way.
Ilya
------------------------------
Date: Sat, 30 Oct 1999 17:19:29 GMT
From: clintp@geeksalad.org (Clinton Pierce)
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <381b280b.671384098@news.roalok1.mi.home.com>
On Fri, 29 Oct 1999 09:14:25 +0200, Ralf Beckers <bexxx@hasiland.com>
wrote:
>> Have you no imagination?
>I tried doubeling they =>, but maybe I typed s.th. wrong in, cause this
>didn't work.
>So, after that, I asked the list.
>
>This is okay for you?
You have imagination. Just not enough of it.
(Had you read through "perldsc" there were examples of structures like
this with arbitrary complexity.)
--
"If you rush a Miracle Man, you get rotten miracles"
--Miracle Max, The Princess Bride
http://www.geeksalad.org
------------------------------
Date: 30 Oct 1999 18:06:17 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Q: Hashes of Hashes of Hashes
Message-Id: <7vfc2p$5bt$1@gellyfish.btinternet.com>
On Thu, 28 Oct 1999 19:55:21 +0200 Ralf Beckers wrote:
> Hi,
>
> dummy question:
> how can I access (read/write) hashes of hashes of hashes?
>
> In the docs I only found "hashes of hashes" ...
>
Its really just the same but more so ;-:
I think that others have covered it but if you have a *complicated*
Hash of Hash whose stucture you dont know when you run the program then
you might want to use some recursive thing :
#!/usr/bin/perl -w
use strict;
my %hohoh = (
blah => 'woof',
hash1 => {
bark => 'meow',
foo => 'bar',
hash2 => {
cat => 'dog',
duck => 'fish',
hash3 => {
zoo => 'car',
rat => 'mouse'
},
barbie => 'ken'
}
},
trumpet => 'ear'
);
printHoH(\%hohoh,'');
sub printHoH
{
my ($hash,$parent) = @_;
foreach my $key ( keys %{$hash} )
{
if (ref $hash->{$key} eq "HASH" )
{
printHoH($hash->{$key},"$parent $key =>");
}
else
{
print "$parent $key => $hash->{$key}\n";
}
}
}
HTH
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 30 Oct 1999 13:50:19 -0400
From: * Tong * <sun_tong@geocities.com>
Subject: qxurl in sub
Message-Id: <381B2FDB.C68C1F43@geocities.com>
Hi,
I tested and proved the following code is working:
- - >8 - -
#!/usr/bin/perl -n00
# qxurl - tchrist@perl.com
print "$2\n" while m{
< \s*
A \s+ HREF \s* = \s* (["']) (.*?) \1
\s* >
}gsix;
- - >8 - -
But why it stops working after I put it into sub?
(The command is the same: "perl -n00 qxurl.pl <urlh.htm")
- - >8 - -
#!/usr/bin/perl -n00
BEGIN { $/ = '' }
sub sub_url_qx{
print "$2\n" while m{
< \s*
A \s+ HREF \s* = \s* (["']) (.*?) \1
\s* >
}gsix;
}
&sub_url_qx;
exit;
- - >8 - -
And how should I fix it? thanks
-- Tong
Anti-spam: remove underscore to reply.
Welcome to my homepage http://maxpages.com/suntong
- All free contribution & collection
- freeware & music from the heavens
------------------------------
Date: 30 Oct 1999 10:27:42 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Reading a file backwards?
Message-Id: <7veh6u$47r$1@gellyfish.btinternet.com>
On Fri, 29 Oct 1999 10:27:45 -0700 Jacob Rosenschein wrote:
> 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?
>
Just to cover all of the possibilities :
open(REV,"tac $file |" ) || die "Couldnt fork for tac - $!\n";
while(<REV>)
{
print;
}
close(REV) || die "Problem with tac - $?\n";
But of course that is silly ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 30 Oct 1999 10:24:51 -0700
From: Xah <xah@best.com>
Subject: Re: regex match with empty string
Message-Id: <B44077F2.41A4%xah@best.com>
lt lindley <ltl@rgsun40.viasystems.com> wrote:
> There are kernels of truth in what you write. But you have been
> boorish in this thread. Please try to be more entertaining.
wow! somebody loved me! I can now die in peace.
--
Ok everyone. I just don't feel like writing an erotic flame to educate perl
morons here this time. If any guru care, answer:
What is Perl's behavior in
$str = m//;
I will appreciate the answer. (though I may not broadcast it and fucking
waste everyone's bandwidth as unix morons wont to do. And, please read the
whole thread before any replies. For each ignorant jerk reaction, I will cut
off one of your finger. That would certainly move clpm towards a beautiful,
well-written, erudite, informative, cultivated resource. (but that's
probably not what perl mongers want anyway: once perl encroached, always
stupid.))
(PS everyone, allow me to introduce Chris Nandor. Like TomC, he is also an
author: "MacPerl: Power and Ease". What ChrisN is to MacPerl is what TomC to
unix perl. I cannot figure out which is moroner. (btw, Chris, I think last
year or so you killfiled me on MacPerl list. I think it's time you escort me
to /dev/null on clpm too. If you try to screw my chicks on the way, be sure
that my larger and harder dick will squash yours for a warm & bloody lube.
For all to see. For all to see. I didn't want to be wanton in the more or
less focused and civilized MacPerl list back then, but here I'll make your
ignorance and ugliness seen, if time permits. Just try not to act stupid.))
Xah
xah@best.com
http://www.best.com/~xah/PageTwo_dir/more.html
Perl: all unix's stupidities in one.
------------------------------
Date: 30 Oct 1999 12:00:38 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Searching within web pages for text
Message-Id: <7veml6$4e1$1@gellyfish.btinternet.com>
On Fri, 29 Oct 1999 15:30:33 GMT rob watson 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.
>
On HTML::Parser examples duty this week - you could use this module which
is sub-classed from HTML::Parser :
use strict;
package HTMLSearch;
use vars qw(@ISA);
@ISA = qw(HTML::Parser);
require HTML::Parser;
sub new
{
my $this = shift;
my $class = ref($this) || $this;
my $self = $this->SUPER::new();
$self->{FOUND} = undef;
$self->{SEARCH} = undef;
return bless($self,$class);
}
sub search
{
my ($self,$file,$search) = @_;
$self->{SEARCH} = $search;
$self->parse_file($file);
return $self->{FOUND};
}
sub text
{
my ($self, $text) = @_;
$self->{FOUND} += $text =~ /$self->{SEARCH}/s;
}
1;
You would use this like :
#!/usr/bin/perl -w
use strict;
use HTMLSearch;
my $searcher = new HTMLSearch;
my $string = 'configure';
my $hits = $searcher->search('map.html',$string);
print "String '$string' was found $hits times\n";
You will need to save the module in the file HTMLSearch.pm in either the
current directory or somewhere in @INC;
HTH
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 30 Oct 1999 00:44:37 -0700
From: Sean Conley <seanc@jps.net>
Subject: Simple socket question
Message-Id: <381AA1E4.D5CBC795@lightspeed.net>
Okay, here's an easy one. I am writing a telnet client, actually a MUD
client, in perl. How do I tell if the remote side has closed the
socket? I THINK my select loop is set up correctly, I will include it
just in case though. There are still many things I have to take into
consideration, like if you can't write to the socket immediately, etc.
But, this problem is what I want to deal with right now.
while(1){
($nfound, $timeleft) = select($rout=$rin, $wout=$win,
$eout=$ein, $timeout);
if(vec($rout, fileno($sock), 1)){
#read from the socket
$except = $sock->recv($data, 80, 0);
#seperate telnet commands from the regular data
($data, $neg) = split /$telopt{"IAC"}/, $data;
#Process any telnet commands/options if found.
if (length $neg){ telnet_neg($neg); }
#Print any data that was received
print $stdout $data;
}
if(vec($rout, fileno($stdin), 1)){
$data = $stdin->getline();
$except = $sock->send($data);
}
}
------------------------------
Date: 30 Oct 1999 12:25:05 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: simplifying a script
Message-Id: <x7aep0ddem.fsf@home.sysarch.com>
>>>>> "WvdB" == Walter van den Berg <vandenbNOSPAM@cistron.nl> writes:
WvdB> Thanks for the advice, but I really need something like a
WvdB> dummie-book just for introduction, to get through the tough
WvdB> stuff later on, just so I know a little of what the "good" books
WvdB> are talking about. Really makes it easier for me. What can i say
WvdB> - I'm a dummie.
are you also a bug? or full of mistakes? or misleading? or missing large
internal organs? the perl dummies book has all of those diseases. check
out this amusing and scathing review by a respected perl hacker.
http://www.plover.com/~mjd/perl/reviews/p54d.html
if you use that as your main education source, you will have to unlearn
bad habits, fix bugs that should be there and actually learn important
stuff like references elsewhere. and references and objects are probably
the biggest changes from perl4 to perl5 and they are covered in only a
couple of pages.
WvdB> (tutorial bookmarked and saved, thanks!)
read it instead. there are some decent tutorials on the net and more are
being developed. at least some of them have peer review and they respond
to public feedback. the dummies author has been told of its shortcomings
and he defends its lousy attitude.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 30 Oct 1999 19:25:00 +0200
From: "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
Subject: Re: simplifying a script
Message-Id: <7vf9cn$lul$1@voyager.cistron.net>
Abigail wrote
> Are you a dummy?
>
> Abigail
>
Yes, it seems so by reading this book... I will now retreat and lurk for
some months and then come back and ask more stupid questions.
Walter.
------------------------------
Date: Sat, 30 Oct 1999 19:41:00 +0200
From: "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
Subject: Re: simplifying a script
Message-Id: <7vfaam$pb8$1@voyager.cistron.net>
Uri Guttman writes:
> WvdB> (tutorial bookmarked and saved, thanks!)
>
> read it instead
That was the next thing I was going to do... Please be lenient with me, for
I am still ignorant, but thy wisdom has shown me the way...
No, but really, I want to thank you for the good advice. Tomorow I will go
to town and buy a decent book. Is Learning Perl (2nd Edition); By Randal L.
Schwartz a good one?
------------------------------
Date: 30 Oct 1999 14:12:11 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: simplifying a script
Message-Id: <7veubr$59n$1@gellyfish.btinternet.com>
In comp.lang.perl.misc Walter van den Berg <vandenbNOSPAM@cistron.nl> wrote:
>>
>> And please, don't go by "Perl for Dummies", unless someone
>> is holding your family hostage or something. It doesn't
>> explain as well as an intro book should, and it seems to
>> want to make you afraid to program. Try this web tutorial
>> instead:
>> http://www.netcat.co.uk/rob/perl/win32perltut.html
>>
> Thanks for the advice, but I really need something like a dummie-book just
> for introduction, to get through the tough stuff later on, just so I know a
> little of what the "good" books are talking about. Really makes it easier
> for me. What can i say - I'm a dummie.
>
I think that what David is trying to say is that the Dummies book is *bad*,
its *evil*, its worse than useless, this is not to say that the
enterprise of creating a book for extreme beginners to programming and to
Perl is necessarily a bad thing, but this particular book is likely to
result in putting you off both (at this point I must admit that the first
book I ever read about programming had cute cartoons in it too - but no
dummies then).
It is not for nothing that Mark-Jason Dominus ( a well regarded contributor
to the Perl world ) wrote in his Perl Journal review of this book that he
was 'appalled' by it.
If you want to find out about the merits of various books you could do
worse than look at Uri's reviews which can be got at via :
<http://www.sysarch.com>
None of this is a pop at you, you are not a dummy as IDG Books would have
you be - you could probably learn more of use from reading this group
regularly than from reading that book.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 30 Oct 1999 13:55:26 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: simplifying a script
Message-Id: <x766zod981.fsf@home.sysarch.com>
>>>>> "WvdB" == Walter van den Berg <vandenbNOSPAM@cistron.nl> writes:
WvdB> No, but really, I want to thank you for the good advice. Tomorow
WvdB> I will go to town and buy a decent book. Is Learning Perl (2nd
WvdB> Edition); By Randal L. Schwartz a good one?
it is highly recommended by the perl community.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 30 Oct 1999 13:58:35 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: simplifying a script
Message-Id: <x73dusd92s.fsf@home.sysarch.com>
>>>>> "WvdB" == Walter van den Berg <vandenbNOSPAM@cistron.nl> writes:
WvdB> Abigail wrote
>> Are you a dummy?
>>
>> Abigail
>>
WvdB> Yes, it seems so by reading this book... I will now retreat and
WvdB> lurk for some months and then come back and ask more stupid
WvdB> questions.
thatis one of the best features of the dummies books. they make their
readers into dummies who don't know how to learn stuff on their own. if
you like being condescended to and have many insulting assumptions made
about your intelligence, then read dummies books. you are showing more
than that by asking stuff here and wanting to learn more. so get
learning perl, read on-line tutorials, read the perl docs (in small
doses but on a regular basis like when you learn a new function or
operator) and you will do fine.
there are no stupid questions, only stupid questioners!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Sat, 30 Oct 1999 20:08:50 +0200
From: "Walter van den Berg" <vandenbNOSPAM@cistron.nl>
Subject: Re: simplifying a script
Message-Id: <7vfbut$vbk$1@voyager.cistron.net>
Jonathan Stowe wrote:
>
> I think that what David is trying to say is that the Dummies book is
*bad*,
> its *evil*, its worse than useless, this is not to say that the
> enterprise of creating a book for extreme beginners to programming and to
> Perl is necessarily a bad thing, but this particular book is likely to
> result in putting you off
All of you are saying something likewise, but I am not yet put off by the
book. I like Perl, everything I want to do can be done with Perl, and the
book showed me that. I trust you all when you say I'm not learning good
code, but I do not yet dislike Perl because of the book.
>
> None of this is a pop at you, you are not a dummy as IDG Books would have
> you be - you could probably learn more of use from reading this group
> regularly than from reading that book.
>
I've learned a lot about various things just by reading newsgroups, you're
absolutely right, but man, a few hundred postings a day...
Ah well.
Thanks!
Walter.
------------------------------
Date: Sat, 30 Oct 1999 11:48:12 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: simplifying a script
Message-Id: <MPG.1284dd4ad0b0c63698a16a@nntp.hpl.hp.com>
In article <x766zod981.fsf@home.sysarch.com> on 30 Oct 1999 13:55:26 -
0400, Uri Guttman <uri@sysarch.com> says...
> >>>>> "WvdB" == Walter van den Berg <vandenbNOSPAM@cistron.nl> writes:
>
> WvdB> No, but really, I want to thank you for the good advice. Tomorow
> WvdB> I will go to town and buy a decent book. Is Learning Perl (2nd
> WvdB> Edition); By Randal L. Schwartz a good one?
>
> it is highly recommended by the perl community.
And it has two authors, one of whom isn't around to defend himself.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 30 Oct 1999 17:53:29 GMT
From: jcostom@madcow.jasons.org (Jason Costomiris)
Subject: Re: Stripping live HTML into text
Message-Id: <slrn81mc4p.jc0.jcostom@madcow.jasons.org>
On 29 Oct 1999 19:55:04 -0400, Scott Lanning <slanning@bu.edu> wrote:
: sub get_html {
: my $file = shift;
: my $html;
: open(FILE, $file) or die "open: $!";
: $html .= $_ while <FILE>;
: close(FILE) or die "close: $!";
: return $html;
: }
Yikes, this is going to be slow....
How about:
sub get_html {
my $file = shift;
open(FH, $file) or die "open: $!";
my $html = do { local $/; <FILE> };
close(FH);
return $html;
}
That's going to be TONS faster, especially on large files. The first time
I implemented it, I found that my code (which initially looked like yours)
got about 300% faster.
Better still, rather than involving actual disk IO, why not:
use LWP::Simple;
my $html = get("http://www.foo.com/");
I find it confusing that you chose to write out a file, then suck it back
in, especially since you made mention of LWP::Simple::get() in a comment..
Did you have a particular reason for doing that?
--
Jason Costomiris <><
Technologist, cryptogeek, human.
jcostom {at} jasons {dot} org | http://www.jasons.org/
------------------------------
Date: Sat, 30 Oct 1999 16:59:31 GMT
From: Ala Qumsieh <qumsieh@sympatico.ca>
Subject: Re: Whoa. This shouldn't work...
Message-Id: <381B2454.5BBD2EE3@sympatico.ca>
"Brett W. McCoy" wrote:
>
> Also Sprach Douglas Garstang <rainbow@zipworld.com.au>:
>
> >#!/usr/bin/perl
> >use strict;
> >print $a;
> >
> >Thats a little weird. Here I was thinking I was going crazy. It also works with "$b". I can't
> >find any reference in the perldocs to $a or $b being special variables (but I'm sure its there
> >somewhere)...
>
> It didn't work for me. Here's the output I got (I also used the -w switch
> on the shebang line):
>
> Name "main::a" used only once: possible typo at tryme line 5.
> Use of uninitialized value at tryme line 5.
>
> Which is what I expected to get.
No, you're wrong. Douglas meant that the 'use strict;' pragma should
have died at
*compile-time* since the code has a variable ($a) that hasn't been
declared via my().
Even with the -w, your program still runs, and prints the undefined
value of $a, but
it still compiles and runs. This only happens if your variable is $a or
$b, and with
nothing else. The reason is that $a and $b are the special variables
used for the
sort() functions, and since they are not allowed to be declared local or
lexical to
the sort() routines, they are treated differently by the Perl compiler.
In conclusion, try to avoid using $a and $b except for sort()ing.
HTH,
--Ala
------------------------------
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 1233
**************************************