[11378] in Perl-Users-Digest
Perl-Users Digest, Issue: 4978 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 11:37:39 1999
Date: Fri, 26 Feb 99 08:32:50 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 26 Feb 1999 Volume: 8 Number: 4978
Today's topics:
How do I handle command-line variables/options in Perl? <s6606555@np.edu.sg>
Re: How do I handle command-line variables/options in P (Abigail)
Re: How do I handle command-line variables/options in P <hove@ido.phys.ntnu.no>
How do I keep the program running, but sleep one portio <baillie@my-dejanews.com>
Re: How do I keep the program running, but sleep one po wyndo@cxo.com
Re: How do I keep the program running, but sleep one po <cederstrom@removethis.kolumbus.fi>
How do I make an interactive session ? <vacevedo@tyr.mty.itesm.mx>
Re: How do I make an interactive session ? <barmar@bbnplanet.com>
Re: How do I make an interactive session ? <ron.dilley@ada.com>
Re: How do I make an interactive session ? <pierre.bachelart@skynet.be>
Re: How do I make an interactive session ? <ywwong_hk@hotmail.com>
Re: How do ignore delimiters within quoted strings? <ebohlman@netcom.com>
Re: how do you find if a string contains something?? <Philip.Newton@datenrevision.de>
Re: how do you find if a string contains something?? <tchrist@mox.perl.com>
Re: how do you find if a string contains something?? (Sam Holden)
How do you make an array of hashes? <craig@skybound.demon.nl>
Re: How do you make an array of hashes? (Alastair)
Re: How do you make an array of hashes? <tchrist@mox.perl.com>
Re: How do you make an array of hashes? (Tad McClellan)
How does one get the filename from select() filehandle (Mark)
Re: How does one get the filename from select() filehan (Sam Holden)
How to do very big hashes? <geoff@gdreyer.com>
Re: How to do very big hashes? <morrowc@his.com>
How to force variable interpolation? kejones@my-dejanews.com
Re: How to force variable interpolation? (Tad McClellan)
Re: How to force variable interpolation? <tchrist@mox.perl.com>
How to get HTML::TokeParser to parse a scalar, not a fi (Garry D. Qualls)
Re: How to get HTML::TokeParser to parse a scalar, not <cw@dwc.ch>
Re: How to get HTML::TokeParser to parse a scalar, not (Greg Ward)
Re: How to get HTML::TokeParser to parse a scalar, not (Garry D. Qualls)
Re: How to get HTML::TokeParser to parse a scalar, not <jdf@pobox.com>
how to get parent's name ? <ilyao@tx.technion.ac.il>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Feb 1999 13:57:04 +0800
From: "Y.K. Goh" <s6606555@np.edu.sg>
Subject: How do I handle command-line variables/options in Perl?
Message-Id: <36d4e630.0@nsuxnews>
In C, we can use the argv and argc to get the command-line
variables. But how do we do it in Perl?
------------------------------
Yong-Kwang Goh
Ngee Ann Polytechnic
The Centre for Computer Studies
Email: s6606555@np.edu.sg
------------------------------
------------------------------
Date: 25 Feb 1999 08:17:53 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: How do I handle command-line variables/options in Perl?
Message-Id: <7b30vh$qm7$2@client2.news.psi.net>
Y.K. Goh (s6606555@np.edu.sg) wrote on MMIV September MCMXCIII in
<URL:news:36d4e630.0@nsuxnews>:
{}
{} In C, we can use the argv and argc to get the command-line
{} variables. But how do we do it in Perl?
man perlvar. Grep for @ARGV.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
------------------------------
Date: 25 Feb 1999 10:23:38 +0100
From: Joakim Hove <hove@ido.phys.ntnu.no>
Subject: Re: How do I handle command-line variables/options in Perl?
Message-Id: <k0n7lt6hm5h.fsf@ido.phys.ntnu.no>
> In C, we can use the argv and argc to get the command-line
> variables. But how do we do it in Perl?
The command-line options you supply will be in the array @ARGV, which
in scalar context evaluates to the number of arguments.
#/usr/bin/perl -w
$number_of_arguments = @ARGV;
print("This program was started with $number_of_arguments arguments\n");
if ($numer_of_arguments > 0) {
print("The arguments were @ARGV \n");
}
HTH - Joakim
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / 352 GF | Skoyensgate 10D #
# N - 7034 Trondheim hove@phys.ntnu.no | N - 7030 Trondheim #
=====================================================================
------------------------------
Date: Mon, 22 Feb 1999 19:30:22 GMT
From: wil <baillie@my-dejanews.com>
Subject: How do I keep the program running, but sleep one portion?
Message-Id: <7asb8f$j9l$1@nnrp1.dejanews.com>
I currently have a small daemon-esque process that basically checks for new
users logging in. I want to be able to sleep for (let's say) 5 minutes when
a user logs on, but I want the program to continue with about a 5 second
sleep. How do I do this? Basically all I'm doing with the user that's logged
in is to continue to check if he's there every 5 minutes or so.
thanks
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Feb 1999 20:36:12 GMT
From: wyndo@cxo.com
Subject: Re: How do I keep the program running, but sleep one portion?
Message-Id: <7av3fr$o$1@nnrp1.dejanews.com>
In article <7asb8f$j9l$1@nnrp1.dejanews.com>,
wil <baillie@my-dejanews.com> wrote:
> I currently have a small daemon-esque process that basically checks for new
> users logging in. I want to be able to sleep for (let's say) 5 minutes when
> a user logs on, but I want the program to continue with about a 5 second
> sleep. How do I do this? Basically all I'm doing with the user that's logged
> in is to continue to check if he's there every 5 minutes or so.
Is this a web-based program? If so, I did this without having Perl keep
running -- I instead wrote a tiny "heartbeat" program which is called
periodically from a JavaScript timer in the user's browser.
Mike Snyder
http://www.lunatix-online.com/
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 26 Feb 1999 08:39:27 +0200
From: "Juho Cederstrvm" <cederstrom@removethis.kolumbus.fi>
Subject: Re: How do I keep the program running, but sleep one portion?
Message-Id: <7b6a2h$d3s$2@news.kolumbus.fi>
>running -- I instead wrote a tiny "heartbeat" program which is called
>periodically from a JavaScript timer in the user's browser.
Why not to use
<meta http-equiv="Refresh" content="60; URL=go_here.htm">
It works with IE and Netscape even if JavaScript isn't enabled.
This doesn't work with Lynx, but JavaScript does neither.
--
# this is a perl script which will display my email address
$_="acbecddeerfsgthriojmkaltmknoolpuqmrbsutsudvowtxfyi";
s/(.)(.)/$2/eg;s/at/@/;s/dot/./;print $_;
------------------------------
Date: Tue, 23 Feb 1999 12:09:21 -0600
From: Victor Acevedo <vacevedo@tyr.mty.itesm.mx>
Subject: How do I make an interactive session ?
Message-Id: <36D2EED0.8CF853DD@tyr.mty.itesm.mx>
I'm trying to make an interactive session with perl.
What I'm doing is : I'm starting a modem connection to a dial-up server,
then I want
to automatically send my user and password, and after a while log-out
and finish the
connection.
My problem begins when I try to automatically interact, how can I do
this in perl, exists any command which can do this?
Thanks in advance ...
------------------------------
Date: Tue, 23 Feb 1999 18:54:13 GMT
From: Barry Margolin <barmar@bbnplanet.com>
Subject: Re: How do I make an interactive session ?
Message-Id: <pPCA2.41$Uu.1058@burlma1-snr2>
In article <36D2EED0.8CF853DD@tyr.mty.itesm.mx>,
Victor Acevedo <vacevedo@tyr.mty.itesm.mx> wrote:
>I'm trying to make an interactive session with perl.
See Expect.pm.
--
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
------------------------------
Date: Tue, 23 Feb 1999 11:03:30 -0800
From: Ron Dilley <ron.dilley@ada.com>
Subject: Re: How do I make an interactive session ?
Message-Id: <36D2FB82.A95B1CC4@ada.com>
Victor,
look at open2
Ron
Victor Acevedo wrote:
>
> I'm trying to make an interactive session with perl.
>
> What I'm doing is : I'm starting a modem connection to a dial-up server,
> then I want
> to automatically send my user and password, and after a while log-out
> and finish the
> connection.
>
> My problem begins when I try to automatically interact, how can I do
> this in perl, exists any command which can do this?
>
> Thanks in advance ...
--
+--------------------------------------------------------+
| Ron Dilley Sr. UNIX Network Administrator |
| ron.dilley@ada.com Applied Digital Access |
+--------------------------------------------------------+
------------------------------
Date: Wed, 24 Feb 1999 06:47:06 +0100
From: sky34169 <pierre.bachelart@skynet.be>
Subject: Re: How do I make an interactive session ?
Message-Id: <36D3925A.A6E1E4B0@skynet.be>
Victor Acevedo wrote:
>
> I'm trying to make an interactive session with perl.
>
> What I'm doing is : I'm starting a modem connection to a dial-up server,
> then I want
> to automatically send my user and password, and after a while log-out
> and finish the
> connection.
>
> My problem begins when I try to automatically interact, how can I do
> this in perl, exists any command which can do this?
>
> Thanks in advance ...
I would have a look at "Expect" from Don Libbes.
------------------------------
Date: Fri, 26 Feb 1999 13:18:55 +0800
From: Y W Wong <ywwong_hk@hotmail.com>
Subject: Re: How do I make an interactive session ?
Message-Id: <36D62EBF.67A91AED@hotmail.com>
Have a look at Expect homepage
http://expect.nist.gov/
Victor Acevedo wrote:
> I'm trying to make an interactive session with perl.
>
> What I'm doing is : I'm starting a modem connection to a dial-up server,
> then I want
> to automatically send my user and password, and after a while log-out
> and finish the
> connection.
>
> My problem begins when I try to automatically interact, how can I do
> this in perl, exists any command which can do this?
>
> Thanks in advance ...
------------------------------
Date: Tue, 23 Feb 1999 08:47:50 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: How do ignore delimiters within quoted strings?
Message-Id: <ebohlmanF7Ln3q.C2t@netcom.com>
Jeremy Page <jpage@cwcom.net> wrote:
: BTW, what is the difference between Text::CSV and Text::CSV_XS (if you
: know)? If that is another FAQ then I've boobed again.
Text::CSV_XS has the inner-loop part of the code written in C to make it
faster. Their functionality is the same.
------------------------------
Date: Tue, 23 Feb 1999 10:02:41 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: how do you find if a string contains something??
Message-Id: <36D26EB1.2BE6EE05@datenrevision.de>
Tom Christiansen wrote:
>
> In comp.lang.perl.misc, sads (screwed up addess) writes:
> :im new to perl and i wanna know how i could figure out if a host
> :address (bou-058.dorm.uml.edu) contains "uml.edu" ??
>
> The index() function is used to search for one string within
> another. This is in the fine perlfunc manpage on your system.
> Please consult it.
One problem specifically with the perlfunc manpage is that it is in the
top three biggest manpages by bytes (maybe even the biggest, don't
remember), and so takes a while to search through if you don't know what
you're looking for. It would be better if everyone read it though, true.
Cheers,
Philip
------------------------------
Date: 23 Feb 1999 06:51:52 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how do you find if a string contains something??
Message-Id: <36d2b278@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Philip Newton <Philip.Newton@datenrevision.de> writes:
:One problem specifically with the perlfunc manpage is that it is in the
:top three biggest manpages by bytes (maybe even the biggest, don't
:remember), and so takes a while to search through if you don't know what
:you're looking for. It would be better if everyone read it though, true.
For this Ken invented grep.
--tom
--
"Most of what I've learned over the years has come from signatures."
--Larry Wall
------------------------------
Date: 24 Feb 1999 02:15:24 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: how do you find if a string contains something??
Message-Id: <slrn7d6o5s.i64.sholden@pgrad.cs.usyd.edu.au>
On 23 Feb 1999 06:51:52 -0700, Tom Christiansen <tchrist@mox.perl.com> wrote:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, Philip Newton <Philip.Newton@datenrevision.de> writes:
>:One problem specifically with the perlfunc manpage is that it is in the
>:top three biggest manpages by bytes (maybe even the biggest, don't
>:remember), and so takes a while to search through if you don't know what
>:you're looking for. It would be better if everyone read it though, true.
>
>For this Ken invented grep.
There's also a introduction that lists the functions by group, and since they
are reasonably named (in most cases, some are very unix oriented in their
names, but they are mostly used on a 'unixy' system... ).
--
Sam
Perl was designed to be a mess (though in the nicest of possible ways).
--Larry Wall
------------------------------
Date: Sun, 21 Feb 1999 23:06:10 +0100
From: Craig <craig@skybound.demon.nl>
Subject: How do you make an array of hashes?
Message-Id: <36D08352.7F0A@skybound.demon.nl>
Hi,
I'm using ODBC to retrieve rows from a dataset using Perl. Because I
want to count the rows retrieved before printing them I'ld like to store
them in an array. These rows however are associative arrays of
fieldname=value associations.
I used push(@allrows, %thisrow) to store each hash, but I can't retrieve
the the hashes from the containing array @allrows later on.
Is there a way to do this?
------------------------------
Date: Sun, 21 Feb 1999 22:43:19 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: How do you make an array of hashes?
Message-Id: <slrn7d132t.5a.alastair@calliope.demon.co.uk>
Craig <craig@skybound.demon.nl> wrote:
>Hi,
>I'm using ODBC to retrieve rows from a dataset using Perl. Because I
>want to count the rows retrieved before printing them I'ld like to store
>them in an array. These rows however are associative arrays of
>fieldname=value associations.
>I used push(@allrows, %thisrow) to store each hash, but I can't retrieve
>the the hashes from the containing array @allrows later on.
>Is there a way to do this?
There's documentation on this with your perl distribution called the 'perldsc'
(Perl Data Structures Cookbook). Check out ;
perldoc perldsc
It explains hwo to access a list of hashes.
HTH.
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: 21 Feb 1999 16:12:28 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How do you make an array of hashes?
Message-Id: <36d092dc@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, Craig <craig@skybound.demon.nl> writes:
:I used push(@allrows, %thisrow) to store each hash, but I can't retrieve
:the the hashes from the containing array @allrows later on.
:Is there a way to do this?
Somehow you appear to have missed the proper answer when you studiously
searched the standard Perl documentation on your very own system.
It was there waiting for you.
% man -f perlref
perlref (1) - Perl references and nested data structures
% man -f perllol
perlLoL (1) - Manipulating Lists of Lists in Perl
% man -f perldsc
perldsc (1) - Perl Data Structures Cookbook
--tom
--
Chip Salzenberg sent me a complete patch to add System V IPC (msg, sem and
shm calls), so I added them. If that bothers you, you can always undefine
them in config.sh. :-) --Larry Wall in <9384@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Mon, 22 Feb 1999 02:45:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do you make an array of hashes?
Message-Id: <0u1ra7.km1.ln@magna.metronet.com>
Craig (craig@skybound.demon.nl) wrote:
: I'm using ODBC to retrieve rows from a dataset using Perl. Because I
: want to count the rows retrieved before printing them I'ld like to store
: them in an array. These rows however are associative arrays of
: fieldname=value associations.
: Is there a way to do this?
If all you want is to count them, then you don't need to put
them into an array first.
Perl FAQ, part 4:
"How can I know how many entries are in a hash?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 22 Feb 1999 00:49:39 GMT
From: mark@sunsite.unc.edu (Mark)
Subject: How does one get the filename from select() filehandle
Message-Id: <7aq9j3$oc6$1@fddinewz.oit.unc.edu>
Keywords: filehandle select filename
Hi,
Consider this code:
use IO::File;
use IO::Select;
$FH{$file1} = IO::File->new($file1, O_RDONLY|O_NONBLOCK);
$FH{$file2} = IO::File->new($file2, O_RDONLY|O_NONBLOCK);
$FH{$file3} = IO::File->new($file3, O_RDONLY|O_NONBLOCK);
$select = IO::Select->new();
foreach $fh (values %FH) {
$select->add(*$fh);
}
if (@filehandles = $select->can_read(0)) {
foreach $fh (@filehandles) {
chomp($line = <$fh>);
&print_a_line("$file $line");
}
}
This code happily works and satisfies my requirements except it isn't
immediately apparent how one translates a filehandle obtained from
the select->can_read(0) call into a filename, thus the &print_a_line()
subroutine doesn't get a valid filename. I need to know the filename
in order to process the line properly... efficiency is useful as well.
Comparing filehandles is slightly pointless, select returns fh's
that look like "*Symbol::GEN6", IO::File->new gives "IO::File=GLOB(0x2b5128)"
so I can't correlate easily.
I've hunted around in Programming Perl, Perl Cookbook and Perl in a Nutshell
but can't ferret the answer out of them. Any assistance is much appreciated.
Please reply to me by email if you could, it's been a while since I usenetted.
Cheers,
Mark
mark@zang.com
mark@metalab.unc.edu
------------------------------
Date: 22 Feb 1999 01:37:46 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: How does one get the filename from select() filehandle
Message-Id: <slrn7d1d7a.35l.sholden@pgrad.cs.usyd.edu.au>
On 22 Feb 1999 00:49:39 GMT, Mark <mark@sunsite.unc.edu> wrote:
>Hi,
>
>This code happily works and satisfies my requirements except it isn't
>immediately apparent how one translates a filehandle obtained from
>the select->can_read(0) call into a filename, thus the &print_a_line()
>subroutine doesn't get a valid filename. I need to know the filename
>in order to process the line properly... efficiency is useful as well.
You could store the file names in an array indexed by fileno, and just
call use $file_names[fileno($fh)] to access them.
--
Sam
Just don't create a file called -rf. :-)
--Larry Wall
------------------------------
Date: Tue, 23 Feb 1999 07:55:06 -0800
From: Geoff Dreyer <geoff@gdreyer.com>
Subject: How to do very big hashes?
Message-Id: <36D2CF5A.E1597920@gdreyer.com>
I'm making a server for a large flatfile database. In my first attempt,
I make a large array of the database records (@pool), then make an
in-memory hash of various keys who's values are arrays of references to
elements of @pool. This works fine on a test flatfile. (Yes, an sql
database would make better sense, but...)
The real case must use a flatfile of >120 mb, and my SGI can't handle
that size for @pool. I tried to use a dbm, but the database records are
>1024 bytes so this won't work. (Also, it seems a dbm gets very large
on disk?).
What is a good scheme for disk hashing, a module, or other tricks (such
as data compression?), that I could use for this (probably quite
standard) problem?
Very appreciatively,
Geoff
------------------------------
Date: Tue, 23 Feb 1999 22:38:41 -0500
From: Chris Morrow <morrowc@his.com>
To: Geoff Dreyer <geoff@gdreyer.com>
Subject: Re: How to do very big hashes?
Message-Id: <36D37441.4E2C008F@his.com>
I have a script in development right now that creates 6-9 hashes which
total over 450MB of ram... it seems to work great on a Sun Ultra3000
with dual processors :)
Perhaps it's what you are DOING with the hashes that is causing you
problems?
-Chris
Geoff Dreyer wrote:
>
> I'm making a server for a large flatfile database. In my first attempt,
> I make a large array of the database records (@pool), then make an
> in-memory hash of various keys who's values are arrays of references to
> elements of @pool. This works fine on a test flatfile. (Yes, an sql
> database would make better sense, but...)
>
> The real case must use a flatfile of >120 mb, and my SGI can't handle
> that size for @pool. I tried to use a dbm, but the database records are
> >1024 bytes so this won't work. (Also, it seems a dbm gets very large
> on disk?).
>
> What is a good scheme for disk hashing, a module, or other tricks (such
> as data compression?), that I could use for this (probably quite
> standard) problem?
>
> Very appreciatively,
> Geoff
------------------------------
Date: Tue, 23 Feb 1999 01:44:27 GMT
From: kejones@my-dejanews.com
Subject: How to force variable interpolation?
Message-Id: <7at15p$6bc$1@nnrp1.dejanews.com>
I have a line in a file which reads something like
"My name is $name"
(No quotes in the file.)
Now, I want to do something like
$sentence = <FILE>; #Read the line in from the file
$name = "Joe"; #Assign a name
$interpolation1 = "$sentence"; #This should interpolate to "My name is $name"
$interpolation2 = "$interpolation1"; #This should interpolate to "My name is
Joe"
But when I print $interpolation2, it always comes out "My name is $name".
Given that I've assigned $sentence as shown, how do I force perl to
interpolate the $name within the string, and print out "My name is Joe"?
Thanks for any advice or pointers,
Kelly
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Feb 1999 02:20:58 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to force variable interpolation?
Message-Id: <qskta7.au2.ln@magna.metronet.com>
kejones@my-dejanews.com wrote:
: I have a line in a file which reads something like
: "My name is $name"
: Now, I want to do something like
: $sentence = <FILE>; #Read the line in from the file
: $name = "Joe"; #Assign a name
: $interpolation1 = "$sentence"; #This should interpolate to "My name is $name"
: $interpolation2 = "$interpolation1"; #This should interpolate to "My name is
: Joe"
: Thanks for any advice or pointers,
The answer is likely already sitting on your hard disk.
It would be Much Better if you could have gotten the answer
from there.
Faster too.
Perl FAQ, part 4:
"How can I expand variables in text strings?"
Use the resources that are provided with every perl.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 22 Feb 1999 18:55:09 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to force variable interpolation?
Message-Id: <36d20a7d@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, kejones@my-dejanews.com writes:
:I have a line in a file which reads something like
:"My name is $name"
I'm afraid my good humor is spent. I've probably answered this five times
or more in two weeks on this group. PLUS it's in the FAQ. Look it up.
--tom
--
"There is no idea so sacred that it cannot be questioned, analyzed...
and ridiculed." --Cal Keegan
------------------------------
Date: Thu, 25 Feb 1999 07:05:28 GMT
From: NO-SPAMgqualls@exis.net (Garry D. Qualls)
Subject: How to get HTML::TokeParser to parse a scalar, not a file
Message-Id: <NO-SPAMgqualls-2502990204140001@cx45214-a.nwptn1.va.home.com>
Hey!
I'm trying to use HTML::TokeParser to help me parse some HTML which
works amazingly well as long as I point it to a file (like the examples in
the docs). What I would rather do is process a scalar that is the result
of a LWP get:
$doc = get 'http://someURL';
Right now, I'm having to print $doc to a file and then process the file.
I would like to just give it $doc and be done with it.
The documentation says:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$p = HTML::TokeParser->new( $file_or_doc );
The object constructor argument is either a file name, a file
handle object, or the complete document to be parsed.
If the argument is a plain scalar, then it is taken as the name of
a file to be opened and parsed. If the file can't be opened for reading,
then the constructor
will return an undefined value and $! will tell you why it failed.
If the argument is a reference to a plain scalar, then this scalar
is taken to be the document to parse.
Otherwise the argument is taken to be some object that the
HTML::TokeParser can read() from when it need more data. The stream will
be read() until EOF, but not closed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I'm guessing that the answer is stated very plainly but my FORTRAN
background has left me woefully unprepared for constructors and the like.
I've spent a while with the camel book and the cookbook and I've picked up
some new concepts, but I still can't put things together properly.
Any help/code snippets would be greatly appreciated!
GQ
P.S. I'm not building a web spider. I'm automating some things on a web
site that I've built and I'm snagging the <INPUT> tags from my forms
and stuff like that.
------------------------------
Date: Thu, 25 Feb 1999 09:28:09 +0100
From: Werns <cw@dwc.ch>
Subject: Re: How to get HTML::TokeParser to parse a scalar, not a file
Message-Id: <36D50999.30D32227@dwc.ch>
"Garry D. Qualls" wrote:
>
> I'm trying to use HTML::TokeParser to help me parse some HTML which
> works amazingly well as long as I point it to a file (like the examples in
> the docs). What I would rather do is process a scalar that is the result
> of a LWP get:
>
> $doc = get 'http://someURL';
>
> Right now, I'm having to print $doc to a file and then process the file.
> I would like to just give it $doc and be done with it.
I've banged my head against that wall already; it's impossible with the
current release of HTML::TokeParser. You can either patch
HTML::TokeParser or subclass it and override the method in question.
-w
------------------------------
Date: 25 Feb 1999 19:36:34 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: How to get HTML::TokeParser to parse a scalar, not a file
Message-Id: <7b48o2$r3j$1@news0-alterdial.uu.net>
Garry D. Qualls <NO-SPAMgqualls@exis.net> wrote:
> I'm trying to use HTML::TokeParser to help me parse some HTML which
> works amazingly well as long as I point it to a file (like the examples in
> the docs). What I would rather do is process a scalar that is the result
> of a LWP get:
>
> $doc = get 'http://someURL';
Looks like you missed a small but important paragraph in the
HTML::TokeParser man page:
$p = HTML::TokeParser->new( $file_or_doc );
[...]
If the argument is a reference to a plain scalar, then
this scalar is taken to be the document to parse.
So this should work (disclaimer: untested and off-the-top-of-my-head!):
$string = "<p>This is some <a href="http://www.w3c.org/">HTML</a>."
$parser = new HTML::TokeParser (\$string);
Hope this helps --
Greg
--
Greg Ward - software developer gward@cnri.reston.va.us
Corporation for National Research Initiatives
1895 Preston White Drive voice: +1-703-620-8990 x287
Reston, Virginia, USA 20191-5434 fax: +1-703-620-0913
------------------------------
Date: Fri, 26 Feb 1999 04:52:48 GMT
From: NO-SPAMgqualls@exis.net (Garry D. Qualls)
Subject: Re: How to get HTML::TokeParser to parse a scalar, not a file
Message-Id: <NO-SPAMgqualls-2502992351330001@cx45214-a.nwptn1.va.home.com>
In article <7b48o2$r3j$1@news0-alterdial.uu.net>, gward@cnri.reston.va.us
(Greg Ward) wrote:
> Garry D. Qualls <NO-SPAMgqualls@exis.net> wrote:
> > I'm trying to use HTML::TokeParser to help me parse some HTML which
> > works amazingly well as long as I point it to a file (like the examples in
> > the docs). What I would rather do is process a scalar that is the result
> > of a LWP get:
> >
> > $doc = get 'http://someURL';
>
> Looks like you missed a small but important paragraph in the
> HTML::TokeParser man page:
>
> $p = HTML::TokeParser->new( $file_or_doc );
> [...]
> If the argument is a reference to a plain scalar, then
> this scalar is taken to be the document to parse.
>
> So this should work (disclaimer: untested and off-the-top-of-my-head!):
>
> $string = "<p>This is some <a href="http://www.w3c.org/">HTML</a>."
> $parser = new HTML::TokeParser (\$string);
>
> Hope this helps --
>
> Greg
I read that but I didn't (and still don't) understand why the "\" is
required in front of $string. I tried to do the reference thing as
$$string. Sad but true.
Thanks for the tip! It works great!
GQ
------------------------------
Date: 26 Feb 1999 09:54:46 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: gqualls@exis.net (Garry D. Qualls)
Subject: Re: How to get HTML::TokeParser to parse a scalar, not a file
Message-Id: <m3sobtrz9l.fsf@joshua.panix.com>
gqualls@exis.net (Garry D. Qualls) writes:
> I read that but I didn't (and still don't) understand why the "\" is
> required in front of $string. I tried to do the reference thing as
> $$string. Sad but true.
You use the backwhack to *construct* a reference. The $$ construct
*dereferences* a reference to a scalar. You need to read the perlref
document.
$ref_to_scalar = \$scalar;
$scalar = $$ref_to_scalar;
$ref_to_array = \@array;
@array = @$ref_to_array;
etc.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Sun, 21 Feb 1999 21:48:26 +0200
From: "Eli" <ilyao@tx.technion.ac.il>
Subject: how to get parent's name ?
Message-Id: <7apntr$f7i$1@techftp.technion.ac.il>
Hi.
How can I get the name of parent proccess that called my script (in unix)?
I've tried somethig like this :
in foo.pl:
#!/usr/bin/per
system "bar.pl";
in bar.pl :
#!/usr/bin/perl
$ppid = getpid();
@out = `ps -p $ppid`;
@name = split /\s+/,$out[1] # the first line is header
$pname = pop @name; # process name is the last field
On differnt systems (IBM/HP) I got different results :
IBM : $pname was equil "perl"
HP : $pname was equil "sh"
But I wanted "foo.pl"
So what's the problem ?
Any ideas how to to that ?
--
{***************************************************************}
(*IN_GOD_WE_TRUST_AND_HE_TRUSTS_IN_US*}
{***************************************************************}
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 4978
**************************************