[11379] in Perl-Users-Digest
Perl-Users Digest, Issue: 4980 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 11:37:41 1999
Date: Fri, 26 Feb 99 08:35:02 -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: 4980
Today's topics:
HTML file & links <botta@workmail.com>
Re: HTML file & links <vamp71@freemail.gr>
Re: HTML file & links <gellyfish@btinternet.com>
HTML links from perl <PRobinson@microdot99.demon.co.uk>
HTML parse problem lufan@hotmail.com
Re: HTML parse problem ikarydis@my-dejanews.com
Re: HTML parse problem (Jonathan Stowe)
Re: HTML parse problem <wfunk@dev.tivoli.com>
Re: HTML parse problem (Greg Ward)
Re: HTML parse problem <correia@barebones.com>
Re: HTML parse problem (I R A Aggie)
Re: HTML parse problem lufan@hotmail.com
Re: HTML parse problem <ebohlman@netcom.com>
Re: HTML parse problem (Ronald J Kimball)
Re: HTML parse problem (Tad McClellan)
Re: HTML parse problem (Jonathan Stowe)
Re: HTML parse problem <correia@barebones.com>
html table columns into arrays <brandeda@se.bel.alcatel.be>
Re: html table columns into arrays <ebohlman@netcom.com>
Re: html table columns into arrays <rick.delaney@home.com>
Re: html table columns into arrays ran@netgate.net
Re: html table columns into arrays ran@netgate.net
Re: html table columns into arrays (Larry Rosler)
Re: html table columns into arrays <jdf@pobox.com>
Re: html table columns into arrays ran@netgate.net
HTML::TreeBuilder - How do I alter & replace text <jerryp.usenet@connected.demon.co.uk>
I am a biginer i need to find a good tutorial in cfg s.l.e@iname.com
I need a tutoriel on CFG s.l.e@iname.com
Re: I need a tutoriel on CFG <tchrist@mox.perl.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Feb 1999 22:26:42 +0200
From: Susan Botta <botta@workmail.com>
Subject: HTML file & links
Message-Id: <36D1BD81.BE748CB0@workmail.com>
Hi!
How could I repleace all URL:s in a HTML file with absolute URL:s (with
hostame and path)? Is it easy to do somehow with URI::URL class? Or do
anybody know any helpful subs?
Thanks a lot in advance for your reply :-)
- Susan -
------------------------------
Date: Mon, 22 Feb 1999 23:09:21 +0200
From: "John Chronakis" <vamp71@freemail.gr>
Subject: Re: HTML file & links
Message-Id: <7asgo1$f64$1@ns1.otenet.gr>
>How could I repleace all URL:s in a HTML file with absolute URL:s (with
>hostame and path)? Is it easy to do somehow with URI::URL class? Or do
>anybody know any helpful subs?
The easiest way to do is to put a <BASE HREF="http://domain/path/"> tag in
the head of the html document.
Then ALL relative urls will be translated according to the base href.
<head>
................
<BASE HREF="http://somewhere.com/mysite/">
................
</head>
<body>
...............
<img src="images/null.gif">
..............
</body>
Will be translated for the browser as <img
src="http://somewhere.com/mysite/images/null.gif">
Consider downloading the exclent html tag list from
http://utopia.knoware.nl/users/schluter/doc/tags/index.html
I love it!
John
------------------------------
Date: 23 Feb 1999 23:21:37 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: HTML file & links
Message-Id: <7avd61$m2$1@gellyfish.btinternet.com>
On Mon, 22 Feb 1999 22:26:42 +0200 Susan Botta wrote:
> Hi!
>
> How could I repleace all URL:s in a HTML file with absolute URL:s (with
> hostame and path)? Is it easy to do somehow with URI::URL class? Or do
> anybody know any helpful subs?
>
Yes you can do this with URI::URL using the abs() method. You will most
probably want to use HTML::Parser to obtain the URLs from the HTML text.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Thu, 25 Feb 1999 20:11:43 -0000
From: "Pete Robinson" <PRobinson@microdot99.demon.co.uk>
Subject: HTML links from perl
Message-Id: <919973343.27062.0.nnrp-03.c1edd369@news.demon.co.uk>
I have a lot of pages to serve which are all based on the same format.
I would like to use a perl script to get input from a text file detailing
body text and locations of image files to be inserted.
This should be pretty easy to implement - but how can I put hyperlinks in to
pages which the script hasn't yet generated?
To clarify, the pages refer to different properties. The parent page has one
external photo and three internals.
The idea is that when one of the small images is clicked it links to a page
with a larger version of the image - any ideas?
------------------------------
Date: Wed, 24 Feb 1999 13:17:21 -0800
From: lufan@hotmail.com
Subject: HTML parse problem
Message-Id: <36D46C61.AE6@hotmail.com>
Does anyone know how to parse and get
2 elements from URL below.
<a href=element1>element2</a>
Can anyonw show me some codes?
I used parse_html, but only got element1 ;(
------------------------------
Date: Wed, 24 Feb 1999 13:23:30 GMT
From: ikarydis@my-dejanews.com
Subject: Re: HTML parse problem
Message-Id: <7b0ugb$hv5$1@nnrp1.dejanews.com>
In article <36D46C61.AE6@hotmail.com>,
lufan@hotmail.com wrote:
> Does anyone know how to parse and get
> 2 elements from URL below.
>
> <a href=element1>element2</a>
>
> Can anyonw show me some codes?
>
> I used parse_html, but only got element1 ;(
>
Try something such as this:
$a = "<a href=\"http://Hello/world\">George</a>"; ($element1, $element2)= $a
=~ /<a[ ]+href=["|']?([^>|^'|^"]+)["|']?>(.*)<\/a>/i; print "Element1:
$element1\nElement2: $element2\n";
It will work in most of the cases...hopefully,
Ioannis Karydis
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 24 Feb 1999 16:49:15 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: HTML parse problem
Message-Id: <36d42d42.28438849@news.dircon.co.uk>
On Wed, 24 Feb 1999 13:23:30 GMT, ikarydis@my-dejanews.com wrote:
>In article <36D46C61.AE6@hotmail.com>,
> lufan@hotmail.com wrote:
>> Does anyone know how to parse and get
>> 2 elements from URL below.
>>
>> <a href=element1>element2</a>
>>
>> Can anyonw show me some codes?
>>
>> I used parse_html, but only got element1 ;(
>>
>
>Try something such as this:
>
>$a = "<a href=\"http://Hello/world\">George</a>"; ($element1, $element2)= $a
>=~ /<a[ ]+href=["|']?([^>|^'|^"]+)["|']?>(.*)<\/a>/i; print "Element1:
>$element1\nElement2: $element2\n";
>
>It will work in most of the cases...hopefully,
>
Hmm "hopefully", I would recommend the use of HTML::Parser and remove
any doubt
/J\
------------------------------
Date: Wed, 24 Feb 1999 11:40:54 -0600
From: "Wade T. Funk" <wfunk@dev.tivoli.com>
Subject: Re: HTML parse problem
Message-Id: <36D439A6.20DD40C0@dev.tivoli.com>
have you tried 'cgi-lib.pl'? It works for me. You can grab
that package from anywhere.
--
Wade T. Funk
Systems Administrator
Tivoli Systems, Inc.
(512) 436-8302
------------------------------
Date: 24 Feb 1999 19:01:16 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: HTML parse problem
Message-Id: <7b1i9s$4k7$5@news0-alterdial.uu.net>
lufan@hotmail.com <lufan@hotmail.com> wrote:
> Does anyone know how to parse and get
> 2 elements from URL below.
>
> <a href=element1>element2</a>
>
> Can anyonw show me some codes?
Keep in mind that this is bogus HTML -- it should be
<a href="element1">element2</a>
Also, your use of the word "element" is suspect. An element is anything
between a start tag and a matching end tag. In your example, "element1"
is an attribute value (the attribute "href" of the tag "a"), and
"element2" is just a chunk of text.
I find the HTML::TokeParser module works quite well for quick, ad-hoc
HTML parsing hacks. It's available as part of the HTML-Parser
distribution from CPAN.
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: Wed, 24 Feb 1999 14:42:49 -0500
From: Jim Correia <correia@barebones.com>
Subject: Re: HTML parse problem
Message-Id: <correia-2402991442490001@204.107.232.123>
In article <7b1i9s$4k7$5@news0-alterdial.uu.net>, gward@cnri.reston.va.us
(Greg Ward) wrote:
> lufan@hotmail.com <lufan@hotmail.com> wrote:
> > Does anyone know how to parse and get
> > 2 elements from URL below.
> >
> > <a href=element1>element2</a>
> >
> > Can anyonw show me some codes?
>
> Keep in mind that this is bogus HTML -- it should be
>
> <a href="element1">element2</a>
What makes you say that? The first is just as valid as the second.
--
Jim Correia Bare Bones Software, Inc.
correia@barebones.com <http://www.barebones.com>
------------------------------
Date: 24 Feb 1999 22:21:03 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: HTML parse problem
Message-Id: <slrn7d8uva.eqg.fl_aggie@enso.coaps.fsu.edu>
On Wed, 24 Feb 1999 14:42:49 -0500, Jim Correia <correia@barebones.com> wrote:
+ In article <7b1i9s$4k7$5@news0-alterdial.uu.net>, gward@cnri.reston.va.us
+ (Greg Ward) wrote:
+
+ > lufan@hotmail.com <lufan@hotmail.com> wrote:
+ > > Does anyone know how to parse and get
+ > > 2 elements from URL below.
+ > >
+ > > <a href=element1>element2</a>
+ > >
+ > > Can anyonw show me some codes?
+ >
+ > Keep in mind that this is bogus HTML -- it should be
+ >
+ > <a href="element1">element2</a>
+
+ What makes you say that? The first is just as valid as the second.
Ummm...you mean "the first is usually parsed by the major browsers just the
same". The standards in question call for the use of "'s. The browsers
don't _care_, for the most part. Unless you do something like:
<a href="a simple example">Simple</a>
<a href=a simple example>Simple</a>
HTH.
James
------------------------------
Date: Thu, 25 Feb 1999 11:20:45 -0800
From: lufan@hotmail.com
Subject: Re: HTML parse problem
Message-Id: <36D5A28D.425D@hotmail.com>
ikarydis@my-dejanews.com wrote:
>
> In article <36D46C61.AE6@hotmail.com>,
> lufan@hotmail.com wrote:
> > Does anyone know how to parse and get
> > 2 elements from URL below.
> >
> > <a href=element1>element2</a>
> >
> > Can anyonw show me some codes?
> >
> > I used parse_html, but only got element1 ;(
> >
>
> Try something such as this:
>
> $a = "<a href=\"http://Hello/world\">George</a>"; ($element1, $element2)= $a
> =~ /<a[ ]+href=["|']?([^>|^'|^"]+)["|']?>(.*)<\/a>/i; print "Element1:
> $element1\nElement2: $element2\n";
>
> It will work in most of the cases...hopefully,
>
> Ioannis Karydis
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Another problem I encountered is how to convert @_ to file handle
<file>?
I have a html buffer to grep and hope I can read it like
while ($_=<file>){
}
but it is in @_, what should I do ???
lufan
------------------------------
Date: Thu, 25 Feb 1999 04:03:39 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: HTML parse problem
Message-Id: <ebohlmanF7ozA3.CAJ@netcom.com>
Greg Ward <gward@cnri.reston.va.us> wrote:
: lufan@hotmail.com <lufan@hotmail.com> wrote:
: > Does anyone know how to parse and get
: > 2 elements from URL below.
: >
: > <a href=element1>element2</a>
: >
: > Can anyonw show me some codes?
: Keep in mind that this is bogus HTML -- it should be
: <a href="element1">element2</a>
No, that's legal in all existing HTML DTDs -- attribute values can be left
unquoted as long as they contain only characters that are acceptable in
name tokens, which this one does (name tokens consist of only letters,
digits, periods and dashes). Of course, there's no harm in quoting all
attribute values, and it will be mandatory in any XML-based DTDs for
HTML, but in this case leaving off the quotes is legal.
------------------------------
Date: Thu, 25 Feb 1999 00:23:19 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: HTML parse problem
Message-Id: <1dnr8f6.6vzammkpzr54N@bay1-206.quincy.ziplink.net>
I R A Aggie <fl_aggie@thepentagon.com> wrote:
> + > <a href="element1">element2</a>
> +
> + What makes you say that? The first is just as valid as the second.
>
> Ummm...you mean "the first is usually parsed by the major browsers just the
> same". The standards in question call for the use of "'s. The browsers
> don't _care_, for the most part.
I believe the standards in question say that the quotes are optional if
the attribute value consists entirely of letters, numbers, or periods.
Thus, <a href=element1> is perfectly valid.
> Unless you do something like:
>
> <a href="a simple example">Simple</a>
> <a href=a simple example>Simple</a>
This attribute value contains spaces. The quotes are not optional here.
--
_ / ' _ / - aka - rjk@linguist.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 24 Feb 1999 18:27:47 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: HTML parse problem
Message-Id: <jt12b7.nmc.ln@magna.metronet.com>
I R A Aggie (fl_aggie@thepentagon.com) wrote:
: On Wed, 24 Feb 1999 14:42:49 -0500, Jim Correia <correia@barebones.com> wrote:
: + In article <7b1i9s$4k7$5@news0-alterdial.uu.net>, gward@cnri.reston.va.us
: + (Greg Ward) wrote:
: +
: + > lufan@hotmail.com <lufan@hotmail.com> wrote:
: + > > Does anyone know how to parse and get
: + > > 2 elements from URL below.
: + > >
: + > > <a href=element1>element2</a>
: + > >
: + > > Can anyonw show me some codes?
: + >
: + > Keep in mind that this is bogus HTML -- it should be
: + >
: + > <a href="element1">element2</a>
: +
: + What makes you say that? The first is just as valid as the second.
: Ummm...you mean "the first is usually parsed by the major browsers just the
: same". The standards in question call for the use of "'s.
^^^^^^^^^^^^^
Which standard are you referring to there?
Can't be the ISO-8879 SGML standard.
I think HTML is an SGML application?
In SGML, the first is just as valid as the second.
:-)
: The browsers
: don't _care_, for the most part. Unless you do something like:
: <a href="a simple example">Simple</a>
: <a href=a simple example>Simple</a>
In SGML you can omit the quotes in some cases, including the
first case quoted up there at the top.
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 25 Feb 1999 12:11:12 GMT
From: gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: HTML parse problem
Message-Id: <36d53db2.11872745@news.dircon.co.uk>
On Wed, 24 Feb 1999 11:40:54 -0600, "Wade T. Funk"
<wfunk@dev.tivoli.com> wrote:
>have you tried 'cgi-lib.pl'? It works for me. You can grab
>that package from anywhere.
Sorry I appear to have missed something here - how is cgi-lib.pl going
to help someone parse HTML ?
/J\
------------------------------
Date: Thu, 25 Feb 1999 09:40:27 -0500
From: Jim Correia <correia@barebones.com>
Subject: Re: HTML parse problem
Message-Id: <correia-2502990940270001@209.244.225.157>
In article <1dnr8f6.6vzammkpzr54N@bay1-206.quincy.ziplink.net>,
rjk@linguist.dartmouth.edu (Ronald J Kimball) wrote:
> I R A Aggie <fl_aggie@thepentagon.com> wrote:
>
> > + > <a href="element1">element2</a>
> > +
> > + What makes you say that? The first is just as valid as the second.
> >
> > Ummm...you mean "the first is usually parsed by the major browsers just
> > the
> > same". The standards in question call for the use of "'s. The browsers
> > don't _care_, for the most part.
>
> I believe the standards in question say that the quotes are optional if
> the attribute value consists entirely of letters, numbers, or periods.
Hyphens too :-)
> Thus, <a href=element1> is perfectly valid.
Yes indeed. I'd like to see the standards in question that require the
quotes (XML doesn't count, since we aren't talking about XML).
--
Jim Correia Bare Bones Software, Inc.
correia@barebones.com <http://www.barebones.com>
------------------------------
Date: Wed, 24 Feb 1999 21:05:27 +0100
From: David Van den Brande <brandeda@se.bel.alcatel.be>
Subject: html table columns into arrays
Message-Id: <36D45B87.47A75CEB@se.bel.alcatel.be>
Hi,
I'm programming perl for my thesis and I have this little problem:
I would like to read an html table into arrays. So that the contents of
every column is put into a separated array (column 1 in @collum1, column
2 in @collum2, ...)
The problem is also that the amount and type of tags in the table (font,
size, alignment, ...) are not the same for every table.
For example:
<Table border>
<TR>
<TD>WG</TD>
<TD>TRS title</TD>
<TD>Main-TRS-number</TD>
<TD>Edition</TD>
</TR>
<TR VALIGN="bottom">
<TD ALIGN="center"><FONT SIZE=2>1</FONT></TD>
<TD ALIGN="left"><FONT SIZE=2>TRS - Coinbox</FONT></TD>
<TD ALIGN="left"><A HREF="wr-trs/21432775TCAADT_03.pl"><FONT
SIZE=2>214-32775-TCAA-DT</FONT></A></TD>
<TD ALIGN="center"><FONT SIZE=2>RL03</FONT></TD>
</TR>
<TR>
<TD>1</TD>
<TD>TRS - Explicit Call Transfer (ECT)</TD>
<TD ALIGN="left"><A HREF="wr-trs/21433164WRAADT_02.pl"><FONT
SIZE=2>214-33164-WRAA-DT</FONT></A></TD>
<TD ALIGN="center"><FONT SIZE=2>RL02</FONT></TD>
</TR>
</table>
The result of the perl script should be:
@collum1 : WG, 1, 1
@collum2 : TRS title, TRS - Coinbox, TRS - Explicit Call Transfer (ECT)
@collum3 : Main-TRS-number, 214-32775-TCAA-DT, 214-32775-TCAA-DT
@collum4 : Edition, RL03, RL02
Can anyone help me with this one?
Thanks in advance!
David
--
V David Van den Brande, Trainee at
----------------- Alcatel Switching VE27
| A L C A T E L | Fr. Wellesplein 1 - 2018 Antwerp - Belgium
----------------- mailto:brandeda@se.bel.alcatel.be
------------------------------
Date: Thu, 25 Feb 1999 03:41:55 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: html table columns into arrays
Message-Id: <ebohlmanF7oy9v.B0q@netcom.com>
David Van den Brande <brandeda@se.bel.alcatel.be> wrote:
: I would like to read an html table into arrays. So that the contents of
: every column is put into a separated array (column 1 in @collum1, column
: 2 in @collum2, ...)
I think you really want to put them into a multidimensional array
instead; that's what the code below does.
: The problem is also that the amount and type of tags in the table (font,
: size, alignment, ...) are not the same for every table.
No problem when you use HTML::Parser.
: For example:
[snip table replicated in code below]
: The result of the perl script should be:
: @collum1 : WG, 1, 1
: @collum2 : TRS title, TRS - Coinbox, TRS - Explicit Call Transfer (ECT)
: @collum3 : Main-TRS-number, 214-32775-TCAA-DT, 214-32775-TCAA-DT
: @collum4 : Edition, RL03, RL02
This code assumes that table cells are closed explicitly (every <TD> has
a </TD>).
package Treader;
require HTML::Parser;
@ISA='HTML::Parser';
my ($in_table,$in_td,$txtbuf,$colcnt,@columns);
# called for each start tag
sub start {
my ($p,$tag,$attr,$attrseq,$orig)=@_;
if ($tag eq 'table') {
$in_table=1;
} elsif ($tag eq 'tr') {
$colcnt=0;
} elsif ($tag eq 'td') {
$in_td=1;
$txtbuf='';
}
}
# called when text seen
# text may be split up into multiple calls
sub text {
my ($p,$t)=@_;
$txtbuf.=$t if ($in_table && $in_td);
}
#called when closing tag seen
sub end {
my ($p,$tag,$orig)=@_;
if ($tag eq 'td') {
push @{$columns[$colcnt++]}, $txtbuf;
$in_td=0;
} elsif ($tag eq 'table') {
$in_table=0;
}
}
my $table=<<EOT;
<Table border>
<TR>
<TD>WG</TD>
<TD>TRS title</TD>
<TD>Main-TRS-number</TD>
<TD>Edition</TD>
</TR>
<TR VALIGN="bottom">
<TD ALIGN="center"><FONT SIZE=2>1</FONT></TD>
<TD ALIGN="left"><FONT SIZE=2>TRS - Coinbox</FONT></TD>
<TD ALIGN="left"><A HREF="wr-trs/21432775TCAADT_03.pl"><FONT
SIZE=2>214-32775-TCAA-DT</FONT></A></TD>
<TD ALIGN="center"><FONT SIZE=2>RL03</FONT></TD>
</TR>
<TR>
<TD>1</TD>
<TD>TRS - Explicit Call Transfer (ECT)</TD>
<TD ALIGN="left"><A HREF="wr-trs/21433164WRAADT_02.pl"><FONT
SIZE=2>214-33164-WRAA-DT</FONT></A></TD>
<TD ALIGN="center"><FONT SIZE=2>RL02</FONT></TD>
</TR>
</table>
EOT
my $p=new Treader;
$p->parse($table);
$p->eof();
# yes, I know this prints unnecessary trailing commas
foreach my $col (@columns) {
foreach my $row (@$col) {
print "$row,";
}
print "\n";
}
------------------------------
Date: Thu, 25 Feb 1999 04:00:38 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: html table columns into arrays
Message-Id: <36D4CCC6.B70B3FBF@home.com>
[posted & mailed]
David Van den Brande wrote:
>
> Hi,
>
> I'm programming perl for my thesis and I have this little problem:
I didn't know they gave degrees in text munging. Where can I get one?
:-)
[HTML table parser problem snipped]
> Can anyone help me with this one?
Sure. Post the part of your code you're having trouble with. Be sure
to describe what you want it to do and what it actually does.
--
Rick Delaney
rick.delaney@home.com
------------------------------
Date: 25 Feb 1999 10:46:14 GMT
From: ran@netgate.net
Subject: Re: html table columns into arrays
Message-Id: <7b39lm$cpf$2@remarQ.com>
In <36D4CCC6.B70B3FBF@home.com>, Rick Delaney <rick.delaney@home.com> writes:
>I didn't know they gave degrees in text munging. Where can I get one?
>:-)
After listening to much wailing and gnashing of teeth about thesis
preparation, I've come to the conclusion that *all* doctorates in the
"liberal arts" are "degrees in text munging"...
Ran
------------------------------
Date: 25 Feb 1999 11:09:19 GMT
From: ran@netgate.net
Subject: Re: html table columns into arrays
Message-Id: <7b3b0v$cpf$3@remarQ.com>
In <ebohlmanF7oy9v.B0q@netcom.com>, Eric Bohlman <ebohlman@netcom.com> writes:
># yes, I know this prints unnecessary trailing commas
I'm still a perl newbie, but there are a couple of tricks I know from
working in C that ought to fix that:
foreach my $col (@columns) {
my $first = 1;
foreach my $row (@$col) {
print $first ? "$row" : ",$row";
$first = 0;
}
print "\n";
}
Or, something that seems a bit more perl-ish:
foreach my $col (@columns) {
my $comma = "";
foreach my $row (@$col) {
print "$comma$row";
$comma = ",";
}
print "\n";
}
Ran
------------------------------
Date: Thu, 25 Feb 1999 06:09:50 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: html table columns into arrays
Message-Id: <MPG.113ef98994c76e67989688@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <7b3b0v$cpf$3@remarQ.com>, on 25 Feb 1999 11:09:19 GMT
ran@netgate.net says...
+ In <ebohlmanF7oy9v.B0q@netcom.com>, Eric Bohlman <ebohlman@netcom.com>
writes:
+
+ ># yes, I know this prints unnecessary trailing commas
+
+ I'm still a perl newbie, but there are a couple of tricks I know from
+ working in C that ought to fix that:
+
+ foreach my $col (@columns) {
+ my $first = 1;
+ foreach my $row (@$col) {
+ print $first ? "$row" : ",$row";
+ $first = 0;
+ }
+ print "\n";
+ }
+
+ Or, something that seems a bit more perl-ish:
+
+ foreach my $col (@columns) {
+ my $comma = "";
+ foreach my $row (@$col) {
+ print "$comma$row";
+ $comma = ",";
+ }
+ print "\n";
+ }
Here is something that seems a *lot* more Perl-ish:
foreach my $col (@columns) {
print join(',', @$col), "\n"
}
Or, to hide both loops, let's go all the way:
print map { join(',', @$_), "\n" } @columns;
This (UNTESTED, but trust me!) one-liner works for reasonable amounts of
data, but might choke on huge arrays (but that wouldn't be likely for
the HTML tables in the submitter's problem).
When you grok the functional approach of these snippets, you'll be a
big step further away from Perl newbie-hood (and from programming in C,
no matter what language you use to express it :-).
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 25 Feb 1999 12:28:18 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: ran@netgate.net
Subject: Re: html table columns into arrays
Message-Id: <m3iucql7f1.fsf@joshua.panix.com>
ran@netgate.net writes:
> I'm still a perl newbie, but there are a couple of tricks I know
> from working in C that ought to fix that:
To mis-apply the Firesign Theater, "Everything You Know is Wrong!"
> my $first = 1;
> foreach my $row (@$col) {
> print $first ? "$row" : ",$row";
> $first = 0;
> }
> print "\n";
Oy vey.
print join(',' , @$col), "\n";
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 26 Feb 1999 02:43:44 GMT
From: ran@netgate.net
Subject: Re: html table columns into arrays
Message-Id: <7b51p0$a55$3@remarQ.com>
In <MPG.113ef98994c76e67989688@nntp.hpl.hp.com>, lr@hpl.hp.com (Larry Rosler) writes:
>When you grok the functional approach of these snippets, you'll be a
>big step further away from Perl newbie-hood (and from programming in C,
>no matter what language you use to express it :-).
Hmmm, yes. Time to see if I still remember how to shift into "APL
mode" after all those years...
Thanks,
Ran
------------------------------
Date: Mon, 22 Feb 1999 20:22:38 +0000
From: Jerry Pank <jerryp.usenet@connected.demon.co.uk>
Subject: HTML::TreeBuilder - How do I alter & replace text
Message-Id: <CiuXfLAOyb02Ewzw@connected.demon.co.uk>
I'm attempting to use HTML::TreeBuilder to find all text =~/SIZE=4/
remove, manipulate and replace it.
It's taken a while but I've managed to get my &munge_text callback
working for me though I'm having problems with the last part.
How do I remove the text enclosed in the specified font tags, alter it
(e.g.: run it through a subroutine that change its content) and then
rebuild the original document.
I'm pretty sure someone can find a better way to detect the font size as
well.
#!/bin/perl5 -w
use strict;
use HTML::TreeBuilder;
my $h = HTML::TreeBuilder->new;
$h->parse_file("F:/cgi-files/wsa/DW_docs/Environment.htm");
$h->traverse(\&munge_text, 1);
print $h->as_HTML;
print "\nDone";
$h->delete;
sub munge_text {
my($e, $start) = @_;
return 1 unless $start;
my $tag = $e->tag;
return 1 unless $tag eq 'font';
if ($e->starttag =~ /SIZE=4/) {
$e->push_content("\nXx. ITS HERE .xX\n");
}
}
-- Jerry Pank http://www.netconnected.com/
jerryp.usenet@netconnected.com
------------------------------
Date: Thu, 25 Feb 1999 00:42:37 GMT
From: s.l.e@iname.com
Subject: I am a biginer i need to find a good tutorial in cfg
Message-Id: <7b269s$kc2$1@nnrp1.dejanews.com>
Hi i am a bigginer and i am looking for a good tutorial were i could find
very good information on configuration file cfg. PLease help me this is
urgent email me to info@amazing-books.com to tell me were to find it. I am
also looking for a very good book and simple to understand for biginners on
cfg. Tell me the cost and how i can obtain it. Thanks
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 24 Feb 1999 04:43:30 GMT
From: s.l.e@iname.com
Subject: I need a tutoriel on CFG
Message-Id: <7b001h$p5m$1@nnrp1.dejanews.com>
Hi every body i am kinda new at with perl but i need to get a realy good
tutorial on configuration file. I have looked every were and i can't find any
good ones. I even wentto the comperter bookstore and they have nothing on cfg.
Please help , i need to do a pragram asap.
Yann
Please email me at webmaster@amazingbooks.zzn.com to send me the response to
the this message
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 23 Feb 1999 22:06:04 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: I need a tutoriel on CFG
Message-Id: <36d388bc@csnews>
In comp.lang.perl.misc, s.l.e@iname.com writes:
:Hi every body i am kinda new at with perl but i need to get a realy good
:tutorial on configuration file. I have looked every were and i can't find any
:good ones. I even wentto the comperter bookstore and they have nothing on cfg.
:Please help , i need to do a pragram asap.
This is covered in the Perl Cookbook. Here's a sample:
$APPDFLT = "/usr/local/share/myprog";
do "$APPDFLT/sysconfig.pl";
do "$ENV{HOME}/.myprogrc";
If you want to ignore the system config file if the user has
their own, test the return of the C<do>.
do "$APPDFLT/sysconfig.pl"
or
do "$ENV{HOME}/.myprogrc";
You can get the code for the book at
ftp://ftp.oreilly.com/published/oreilly/perl/cookbook/pcookexamples.tar.gz
You'll find this one in Chapter 8, which can be fetched
from http://www.ora.com/catalog/cookbook/chapter/index.html
if you would like.
--tom
--
"Make is like Pascal: everybody likes it, so they go in and change it. "
--Dennis Ritchie
------------------------------
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 4980
**************************************