[16774] in Perl-Users-Digest
Perl-Users Digest, Issue: 4186 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 31 06:10:29 2000
Date: Thu, 31 Aug 2000 03:10:13 -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: <967716613-v9-i4186@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 31 Aug 2000 Volume: 9 Number: 4186
Today's topics:
No subject was specified. <jwolpert@slip.net>
Re: No subject was specified. (Martien Verbruggen)
Re: output fun <anmcguire@ce.mediaone.net>
Re: output fun (Logan Shaw)
Parsing HTML <lubbers@jps.net>
Re: Parsing HTML (Abigail)
Re: Parsing HTML <nickco3@yahoo.co.uk>
perl newbie seeks assistance billgreenwood@my-deja.com
Re: perlcc - Compiler errors kerims@my-deja.com
Re: Problem with perl generated images in MSIE4 pages toni_cornelissen@my-deja.com
Removing an entry from a text file <dave.labbett@intelliware-systems.com>
Re: Removing an entry from a text file (Rafael Garcia-Suarez)
Re: replace some word in text file <elephant@squirrelgroup.com>
Re: Tricking STDIN (Mark-Jason Dominus)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 Aug 2000 07:36:44 GMT
From: Jake <jwolpert@slip.net>
Subject: No subject was specified.
Message-Id: <39AE0A7C.236C5685@slip.net>
perl, version 5.004_04 built for i386-freebsd(2.2.8)
------------------------------
perl5 in realloc(): warning: modified (chunk-) pointer.
perl5 in free(): warning: modified (chunk-) pointer.
perl5 in free(): warning: modified (chunk-) pointer.
perl5 in realloc(): warning: modified (page-) pointer.
------------------------------
If anyone recognizes these "chunk-" and "page-" ,
"are these messages generated by a BAD program or a BAD build
or BAD OS?"
------------------------------
Date: Thu, 31 Aug 2000 08:23:54 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: No subject was specified.
Message-Id: <slrn8qs5g7.2cp.mgjv@verbruggen.comdyn.com.au>
[Please, for future reference: Put a subject in your subject header.
Many people won't even bother reading your post, if you don't.]
On Thu, 31 Aug 2000 07:36:44 GMT,
Jake <jwolpert@slip.net> wrote:
>
> perl, version 5.004_04 built for i386-freebsd(2.2.8)
>
> ------------------------------
> perl5 in realloc(): warning: modified (chunk-) pointer.
> perl5 in free(): warning: modified (chunk-) pointer.
> perl5 in free(): warning: modified (chunk-) pointer.
> perl5 in realloc(): warning: modified (page-) pointer.
> ------------------------------
>
> If anyone recognizes these "chunk-" and "page-" ,
>
> "are these messages generated by a BAD program or a BAD build
> or BAD OS?"
These are not Perl messages (i.e. they don't appear in the perldiag
documentation). The malloc(3) man page of FreeBSD _does_ mention this
error. It looks like you have a sick perl binary, either wrongly
compiled, or compiled for a slightly different platform than the one
you're on.
You should probably consider building a newer perl yourself.
Martien
--
Martien Verbruggen |
Interactive Media Division | This matter is best disposed of from
Commercial Dynamics Pty. Ltd. | a great height, over water.
NSW, Australia |
------------------------------
Date: Thu, 31 Aug 2000 02:52:48 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: output fun
Message-Id: <Pine.LNX.4.21.0008310242460.27691-100000@hawk.ce.mediaone.net>
On Tue, 29 Aug 2000, Uri Guttman quoth:
~~ Date: Tue, 29 Aug 2000 23:25:06 GMT
~~ From: Uri Guttman <uri@sysarch.com>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: output fun
~~
~~ >>>>> "RG" == Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
~~
~~ RG> ankban4@my-deja.com wrote in comp.lang.perl.misc:
~~ >> HI
~~ >> Without using the formatting features , how do i print an output like
~~ >> this . i tried but my code is too huge and ugly.
~~ >>
~~ >> ABCDEFGFEDCBA
~~ >> ABCDEF FEDCBA
~~ >> ABCDE EDCBA
~~ >> ABCD DCBA
~~ >> ABC CBA
~~ >> AB BA
~~ >> A A
~~ >>
~~ >> Thanks for your time.
~~
~~ RG> $_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/(\w)( *)\1/'
~~ RG> 'x(2+length$2)/eg;
~~
~~ simplified:
~~
~~ $_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/.( +)\S/ $1 /g;
Lopping off the "\n" and repacing it with '-l' and removing the
superfluous g modifier:
perl -le '$_="ABCDEFGFEDCBA";print;print while y~G~ ~||s~.( +)\S~ $1 ~'
I assumed you were running it as:
perl -e '$_="ABCDEFGFEDCBA\n";print;print \
while y/G/ /||s/.( +)\S/ $1 /g;'
anm
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Andrew N. McGuire ~
~ anmcguire@ce.mediaone.net ~
~ "Plan to throw one away; you will, anyhow." - Frederick P. Brooks, Jr. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: 31 Aug 2000 03:10:37 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: output fun
Message-Id: <8ol3tt$bim$1@provolone.cs.utexas.edu>
In article <8ogdcm$56v$1@nnrp1.deja.com>, <ankban4@my-deja.com> wrote:
>HI
>Without using the formatting features , how do i print an output like
>this . i tried but my code is too huge and ugly.
>
> ABCDEFGFEDCBA
> ABCDEF FEDCBA
> ABCDE EDCBA
> ABCD DCBA
> ABC CBA
> AB BA
> A A
>
>Thanks for your time.
Well, my code is a little longer than others' code, but here it is:
#! /usr/local/bin/perl
require Term::Cap;
@string = ('A' .. 'G');
$terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600 };
print $terminal->Tputs ('cl');
for ($col = 0; $col < @string; $col++)
{
for ($row = 0; $row + $col < @string; $row++)
{
push (@codes,
$terminal->Tgoto ('cm',
$col, $row)
. $string[$col],
$terminal->Tgoto ('cm',
2 * @string - $col - 2, $row)
. $string[$col]
);
}
}
$final = $terminal->Tgoto ('cm', 0, $col);
for ($i = 0; $i < @codes; $i++)
{
$j = int rand ($i+1);
@codes[$i,$j] = @codes[$j,$i];
}
$| = 1;
foreach (@codes)
{
print;
select (undef, undef, undef, rand * rand);
}
print $final;
I realize I could do a better order than random, but that's just life,
I guess.
- Logan
------------------------------
Date: Wed, 30 Aug 2000 21:59:18 -0700
From: "Peter Lubbers" <lubbers@jps.net>
Subject: Parsing HTML
Message-Id: <yClr5.172$3U2.13029@nntp3.onemain.com>
Hi
Does anyone have some sample code for parsing the text out of an HTML or JSP
file.
What I need to do is loop through a whole bunch of HTML files and get a
wordcount of each file. With the raw HTML that would not be a correct number
as there are all the tags included.
Thanks in advance.
Pete
------------------------------
Date: 31 Aug 2000 06:37:53 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Parsing HTML
Message-Id: <slrn8qrv8g.8ac.abigail@alexandra.foad.org>
Peter Lubbers (lubbers@jps.net) wrote on MMDLVII September MCMXCIII in
<URL:news:yClr5.172$3U2.13029@nntp3.onemain.com>:
^^ Hi
^^ Does anyone have some sample code for parsing the text out of an HTML or JSP
^^ file.
^^ What I need to do is loop through a whole bunch of HTML files and get a
^^ wordcount of each file. With the raw HTML that would not be a correct number
^^ as there are all the tags included.
What do you have so far? I assume you've visited CPAN.
Abigail
--
split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Thu, 31 Aug 2000 09:13:49 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: Parsing HTML
Message-Id: <39AE13BC.BEBBB108@yahoo.co.uk>
Peter Lubbers wrote:
> Hi
> Does anyone have some sample code for parsing the text out of an HTML or JSP
> file.
> What I need to do is loop through a whole bunch of HTML files and get a
> wordcount of each file. With the raw HTML that would not be a correct number
> as there are all the tags included.
>
> Thanks in advance.
> Pete
From the FAQ (which you're supposed to look at before posting here)
How do I remove HTML from a string?
The most correct way (albeit not the fastest) is to use HTML::Parse
from CPAN (part of the HTML-Tree package on CPAN).
Many folks attempt a simple-minded regular expression approach, like
C<s/E<lt>.*?E<gt>//g>, but that fails in many cases because the tags
may continue over line breaks, they may contain quoted angle-brackets,
or HTML comment may be present. Plus folks forget to convert
entities, like C<<> for example.
Here's one "simple-minded" approach, that works for most files:
#!/usr/bin/perl -p0777
s/<(?:[^>'"]*|(['"]).*?\1)*>//gs
If you want a more complete solution, see the 3-stage striphtml
program in
http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/striphtml.gz
.
Here are some tricky cases that you should think about when picking
a solution:
<IMG SRC = "foo.gif" ALT = "A > B">
<IMG SRC = "foo.gif"
ALT = "A > B">
<!-- <A comment> -->
<script>if (a<b && a>c)</script>
<# Just data #>
<![INCLUDE CDATA [ >>>>>>>>>>>> ]]>
If HTML comments include other tags, those solutions would also break
on text like this:
<!-- This section commented out.
<B>You can't see me!</B>
-->
------------------------------
Date: Thu, 31 Aug 2000 08:41:37 GMT
From: billgreenwood@my-deja.com
Subject: perl newbie seeks assistance
Message-Id: <8ol5nu$qb8$1@nnrp1.deja.com>
Hello group
My name is bill greenwood and i am a prepress guy
at a uk repro house, we have SGI system and i would
like to use the power of perl and unix to make our
lives a little easier.
I need assistance with my first [of many i hope]
perl script.
My aim is to have a script that takes the name of a
postscript file and copies that to memory, then
finds a text string within specified parameters
"/Title(**********)def" with stars being a
variable wildcard text string, then and inserts/
pastes the previously copied filename before the
wildcard text string wherever it is found in the
document.
Finaly saving the document to another directory and
deleting the first or maybe even passing the file
to another application.
I will then attempt to make this script watch a
drirectory for postsctipt/text files to action
upon.
i can be contacted direct at
bill.greenwood@colourpath.co.uk
many thnaks to all who take the time to reply
thanks for listening
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 09:29:26 GMT
From: kerims@my-deja.com
Subject: Re: perlcc - Compiler errors
Message-Id: <8ol8h8$ta8$1@nnrp1.deja.com>
perlcc has a bug!
insert 'use DynaLoader;' at line 393 in perlcc
print $fd <<"EOF";
use DynaLoader;
use FileHandle;
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 07:37:02 GMT
From: toni_cornelissen@my-deja.com
Subject: Re: Problem with perl generated images in MSIE4 pages
Message-Id: <8ol1us$mdo$1@nnrp1.deja.com>
In article <8od976$il4$1@nnrp1.deja.com>,
toni_cornelissen@my-deja.com wrote:
I had a problem
> When I use that script to include images in my web pages, the
> images won't show if I use MS Internet Explorer 4. (I got the
> red cross and the text in my alt tag) When I use Netscape or MSIE3
> the images show without a problem, and if I use MSIE4 to load just
(...)
> if (($filename) && ("image/" . $filname =~ /$ENV{'HTTP_ACCEPT'}/)) {
The problem wat in the HTTP_ACCEPT that IE5 generated only "*/*" instead
of "image/gif image/jpeg" etc.
Thanks to everybody that helped me.
Toni
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 30 Aug 2000 15:26:00 +0100
From: "Dave Labbett" <dave.labbett@intelliware-systems.com>
Subject: Removing an entry from a text file
Message-Id: <39ad19b2_1@nnrp1.news.uk.psi.net>
I'm a PERL beginner so please bear with me if this is a simple question.
I've set up a PERL program which lets me log 2 pieces of data (Name and ID)
to a tab separated text file.
Example of how the text file looks :
Dave Labbett 12345
John Smith 23456
Tom Jones 24680
It works fine and I can read and display the data in this text file straight
to a web page no problem.
However, from an ADMIN script, I want to be able to delete an entry from
this text file based on the ID number. I type in this ID and the script
reads through the text file, line by line until it gets a match. It should
then delete this line from the file - leaving all the rest intact.
Trouble is - I just cannot get it to work at all - the relevant piece of
code is:
$this_id = ($input{'userid'});
open (ADDD, "$info_dir/peoplelist.txt") or &error("Unable open mirror
file");
@openfile = <ADDD>;
close (ADDD);
open (NDL, ">$info_dir/peoplelist.txt");
$check='NO';
foreach $line (@openfile) {
$theline = $line;
($person, $id) = split(/\t/, $theline);
if (($this_id ne $id) or ($check eq 'YES')){
print NDL "$line";
}
else{
$check = "YES";
}
}
Any advice anyone can give would be greatly appreciated!
Cheers
Dave Labbett
------------------------------
Date: Thu, 31 Aug 2000 06:35:34 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Removing an entry from a text file
Message-Id: <slrn8qrvam.a86.rgarciasuarez@rafael.kazibao.net>
Dave Labbett wrote in comp.lang.perl.misc:
>I'm a PERL beginner so please bear with me if this is a simple question.
>
>I've set up a PERL program which lets me log 2 pieces of data (Name and ID)
>to a tab separated text file.
>
>Example of how the text file looks :
>
>Dave Labbett 12345
>John Smith 23456
>Tom Jones 24680
>
>It works fine and I can read and display the data in this text file straight
>to a web page no problem.
>
>However, from an ADMIN script, I want to be able to delete an entry from
>this text file based on the ID number. I type in this ID and the script
>reads through the text file, line by line until it gets a match. It should
>then delete this line from the file - leaving all the rest intact.
>
>Trouble is - I just cannot get it to work at all - the relevant piece of
>code is:
>
>$this_id = ($input{'userid'});
> open (ADDD, "$info_dir/peoplelist.txt") or &error("Unable open mirror
>file");
> @openfile = <ADDD>;
> close (ADDD);
>
> open (NDL, ">$info_dir/peoplelist.txt");
You should check the return value of this open too. opens do fail. This
happens.
> $check='NO';
> foreach $line (@openfile) {
> $theline = $line;
> ($person, $id) = split(/\t/, $theline);
Here is the error. $id contains a trailing "\n".
Include the line
chomp $line;
before the split.
The variable $theline is unneccessary: split does not modify its
argument.
> if (($this_id ne $id) or ($check eq 'YES')){
> print NDL "$line";
Unneccessary quotes around $line. But if you chomp'd $line, you'll have to
print NDL "$line\n";
> }
> else{
> $check = "YES";
> }
>}
>
>Any advice anyone can give would be greatly appreciated!
Other advices:
If peoplelist.txt is a large file, don't read it in memory; open a file
peoplelist.new where you put the new contents, then unlink
peoplelist.txt and rename peoplelist.new to peoplelist.txt.
It is perhaps better style to use 0 and 1 instead of YES and NO for
$check.
--
Rafael Garcia-Suarez
------------------------------
Date: Thu, 31 Aug 2000 09:24:01 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: replace some word in text file
Message-Id: <MPG.1418c1a8ed309c2a989739@localhost>
Keith Calvert Ivey <kcivey@cpcug.org> wrote ..
>Albert Dewey <timewarp@shentel.net> wrote:
>
>> open(FILE,"<file.txt") or print "ERROR: 404<br>Cannot open file because
>>$!<br>";
>
>Why 404? This isn't a CGI program, and even if it were script
>errors aren't 404 errors.
>
>> while(<FILE>)
>> {
>> $File .= $_ if $. >= 0
>> }
>> close (FILE);
>
>That's a new way to do it. Usually Perl newbies do something
>like
>
> @lines = <FILE>;
> $File = join '', @lines;
>
>But the normal Perl idiom for slurping a whole file would be
>
> { local $/; $File = <FILE>; }
someone showed me a neater WTDI that - for some reason - I'd never
thought of before .. I like it because it saves the separate 'my'
declaration which always looks clumsy
my $file = do { local $/; <FILE> };
syntactic sugar .. yummy
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 31 Aug 2000 04:11:16 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Tricking STDIN
Message-Id: <39addae4.3199$36f@news.op.net>
In article <8ok0kp$5rs4@news1.lmtas.lmco.com>, mike <mike@hulenbend.net> wrote:
>I am trying to create a text string and then when I call <stdin>, i want to
>read that string.
There is an IO::Stringy module you can get from CPAN that does exactly that.
------------------------------
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 4186
**************************************