[24152] in Perl-Users-Digest
Perl-Users Digest, Issue: 6346 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 31 14:10:48 2004
Date: Wed, 31 Mar 2004 11:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 31 Mar 2004 Volume: 10 Number: 6346
Today's topics:
Modify elements of an array <olusola.o.olaode@intel.com>
Re: Modify elements of an array <noreply@gunnar.cc>
Re: Modify elements of an array <tadmc@augustmail.com>
Re: multiple lines / success or failure?! <dwall@fastmail.fm>
Re: multiple lines / success or failure?! <tassilo.parseval@rwth-aachen.de>
Re: multiple lines / success or failure?! <geoffacox@dontspamblueyonder.co.uk>
Re: multiple lines / success or failure?! <nobull@mail.com>
Re: multiple lines / success or failure?! <tassilo.parseval@rwth-aachen.de>
Re: multiple lines / success or failure?! <geoffacox@dontspamblueyonder.co.uk>
Re: multiple lines / success or failure?! <tadmc@augustmail.com>
Problems with installing MIME <helmut_blass@tweb.de>
Re: Spawn child processes - VMS perl 5.6.1 <pkent77tea@yahoo.com.tea>
TCP Connection redirector with password? <ignoramus26612@NOSPAM.26612.invalid>
trapping errors <simalt@totalise.co.uk>
Re: trapping errors <1usa@llenroc.ude>
Re: trapping errors <ittyspam@yahoo.com>
Re: trapping errors <tore@aursand.no>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Mar 2004 10:39:18 -0500
From: "fenisol3" <olusola.o.olaode@intel.com>
Subject: Modify elements of an array
Message-Id: <c4eon6$22n$1@news01.intel.com>
All,
I am a perl beginner and am trying to remove all the commas before the first
word and after the last word in an array. Any hints? Thanks a lot.
-Fenisol3
------------------------------
Date: Wed, 31 Mar 2004 18:09:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Modify elements of an array
Message-Id: <c4eql1$2ibdjt$1@ID-184292.news.uni-berlin.de>
fenisol3 wrote:
> I am a perl beginner and am trying to remove all the commas before
> the first word and after the last word in an array.
In an array??
> Any hints?
- Give it a second thought what you are actually doing.
- Try resolving the problem by help of the docs.
perldoc perlre
perldoc perlop
(the s/// operator)
- Post here if that doesn't help.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 31 Mar 2004 12:41:22 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Modify elements of an array
Message-Id: <slrnc6m46i.1fg.tadmc@magna.augustmail.com>
fenisol3 <olusola.o.olaode@intel.com> wrote:
> I am a perl beginner and am trying to remove all the commas before the first
> word and after the last word in an array. Any hints?
What array?
Show us your data and we will help you figure out how to process your data.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 31 Mar 2004 14:33:22 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: multiple lines / success or failure?!
Message-Id: <Xns94BD6135B6910dkwwashere@216.168.3.30>
Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
[snip]
> package MyParser;
> use base qw(HTML::Parser);
>
> # This parser only looks at opening tags
> sub start {
> my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
> if ($tagname eq 'a') {
> print "URL found: ", $attr{ href }, "\n";
Typo, I guess. Should be $attr->{ href }.
> }
> }
>
> package main;
>
> my $html = <<EOHTML;
> <html>
> <body>
> <a href="http://www.first.com" target="bla">One link</a>
> <a href="http://www.second.com">Second link</a>
> </body>
> </html>
> EOHTML
>
> my $parser = MyParser->new;
> $parser->parse( $html );
> __END__
> URL found: http://www.first.com
> URL found: http://www.second.com
[snip]
> I don't know whether HTML::Parser is covered in any books. But
> maybe the above is already all you need to write your program. It
> takes a little time to get used to these event-based approaches so
> you might want to experiment a bit with it. Once you have grokked
> it, you'll realize how convenient and powerful HTML::Parser is.
Thanks, Tassilo! I've avoided HTML::Parser and used HTML::TokeParser
instead, but the next time I need to parse some HTML I'll pull out my
saved copy of your intro and try again.
--
David Wall
------------------------------
Date: 31 Mar 2004 16:01:36 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: multiple lines / success or failure?!
Message-Id: <c4eq10$qqj$1@nets3.rz.RWTH-Aachen.DE>
Also sprach David K. Wall:
> Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>
> [snip]
>> package MyParser;
>> use base qw(HTML::Parser);
>>
>> # This parser only looks at opening tags
>> sub start {
>> my ($self, $tagname, $attr, $attrseq, $origtext) = @_;
>> if ($tagname eq 'a') {
>> print "URL found: ", $attr{ href }, "\n";
>
> Typo, I guess. Should be $attr->{ href }.
Oups, you're right. I tested most of the examples but apparently I
made a few careless tweaks afterwards without checking those.
>> I don't know whether HTML::Parser is covered in any books. But
>> maybe the above is already all you need to write your program. It
>> takes a little time to get used to these event-based approaches so
>> you might want to experiment a bit with it. Once you have grokked
>> it, you'll realize how convenient and powerful HTML::Parser is.
>
> Thanks, Tassilo! I've avoided HTML::Parser and used HTML::TokeParser
> instead, but the next time I need to parse some HTML I'll pull out my
> saved copy of your intro and try again.
Oddly enough, in the beginning I did prefer HTML::TokeParser as well.
Not having to create a separate class seemed to be less work, but it
turned out that it is easier to adapt to more complex needs the other
way.
I find the same is true for XML (for which in fact even more interface
choices exist). Of all the various approaches that exist, I find the
stream-based XML::Parser the most convenient one.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 31 Mar 2004 16:40:24 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: multiple lines / success or failure?!
Message-Id: <mvsl605pc2lg3eog9kvrco0cpthbi73caa@4ax.com>
> package MyParser;
> use base qw(HTML::Parser);
>
> # we use these three variables to count something
> our ($text_elements, $start_tags, $end_tags);
>
> # here HTML::text/start/end are overridden
> sub text { $text_elements++ }
> sub start { $start_tags++ }
> sub end { $end_tags++ }
>
> package main;
>
> # Test the parser
>
> my $html = <<EOHTML;
> <html>
> <head>
> <title>Bla</title>
> </head>
> <body>
> Here's the body.
> </body>
> </html>
> EOHTML
Tassilo
I am getting a "can't find EOHTML string terminator anywhere before
EOF" message using above. Is there a typo?
Cheers
Geoff
------------------------------
Date: 31 Mar 2004 17:50:30 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: multiple lines / success or failure?!
Message-Id: <u91xn96jvt.fsf@wcl-l.bham.ac.uk>
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
>
> I am getting a "can't find EOHTML string terminator anywhere before
> EOF" message using above. Is there a typo?
Have you eleminiated the most likely cause that is explained when you
look that message up in the reference manual (perldiag)?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 31 Mar 2004 17:37:15 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: multiple lines / success or failure?!
Message-Id: <c4evkb$4n9$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Geoff Cox:
>> package MyParser;
>> use base qw(HTML::Parser);
>>
>> # we use these three variables to count something
>> our ($text_elements, $start_tags, $end_tags);
>>
>> # here HTML::text/start/end are overridden
>> sub text { $text_elements++ }
>> sub start { $start_tags++ }
>> sub end { $end_tags++ }
>>
>> package main;
>>
>> # Test the parser
>>
>> my $html = <<EOHTML;
>> <html>
>> <head>
>> <title>Bla</title>
>> </head>
>> <body>
>> Here's the body.
>> </body>
>> </html>
>> EOHTML
>
>
> Tassilo
>
> I am getting a "can't find EOHTML string terminator anywhere before
> EOF" message using above. Is there a typo?
You have to take care that the end marker EOHTML has no preceeding
spaces (that is, you cannot indent it) and ends with a newline.
Furthermore, there must not be spaces before the newline.
Of course, if that is against your coding style, you can also use a
different quoting mechanism:
my $html = q#
<html>
...
#;
There are many to choose from.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Wed, 31 Mar 2004 17:45:01 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: multiple lines / success or failure?!
Message-Id: <bq0m601ikbhv2b7m6d3l6s20n9ih7crfbq@4ax.com>
On 31 Mar 2004 17:50:30 +0100, Brian McCauley <nobull@mail.com> wrote:
>Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
>>
>> I am getting a "can't find EOHTML string terminator anywhere before
>> EOF" message using above. Is there a typo?
>
>Have you eleminiated the most likely cause that is explained when you
>look that message up in the reference manual (perldiag)?
Making me work for the answer!!
Problem solved - the white spaces in front of the EOHTML ..
Cheers
Geoff
------------------------------
Date: Wed, 31 Mar 2004 12:34:10 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: multiple lines / success or failure?!
Message-Id: <slrnc6m3p2.1fg.tadmc@magna.augustmail.com>
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
> On 31 Mar 2004 17:50:30 +0100, Brian McCauley <nobull@mail.com> wrote:
>>Geoff Cox <geoffacox@dontspamblueyonder.co.uk> writes:
>>>
>>> I am getting a "can't find EOHTML string terminator anywhere before
>>> EOF" message using above. Is there a typo?
>>
>>Have you eleminiated the most likely cause that is explained when you
>>look that message up in the reference manual (perldiag)?
>
> Making me work for the answer!!
Making you do your own work.
We are not a read-the-docs-to-me service.
We hope that posters would be respectful enough of other's time
to try the obvious things themselves before involving thousands
of other people around the world.
Knowing about perldiag.pod can help your troubleshooting
forevermore, well beyond the problem that happened to
bring you here today.
> Problem solved -
It is amazing how often reading the docs applicable to your
problem will do that for you!
Work smart. Try to find help in the best resource available first,
look elsewhere only after that does not help.
The best resource available for Perl is the standard documentation
that comes with perl.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 31 Mar 2004 20:09:54 +0200
From: Helmut Blass <helmut_blass@tweb.de>
Subject: Problems with installing MIME
Message-Id: <c4f1go$hn1$04$1@news.t-online.com>
hi folks,
I'm working with os win98 and I want to install via PPM
the MIME-bundle from ActiveState because I need MIME::Parser.
Unfortunately I am to dump to do this this job :-(. When entering
ppm> Install MIME or
ppm> Install MIME::Parser
I get error messages. However I managed easyly to install MIME::Lite.
any suggestions?
thanx for your help, Helmut
------------------------------
Date: Wed, 31 Mar 2004 18:49:45 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: Spawn child processes - VMS perl 5.6.1
Message-Id: <pkent77tea-2BDB91.18494431032004@pth-usenet-02.plus.net>
In article <c4dmmu01i81@drn.newsguy.com>,
Patrick Flaherty <Patrick_member@newsguy.com> wrote:
> VMSNODE>perl test2.pl
> The Unsupported function fork function is unimplemented at test2.pl line 2.
> %SYSTEM-F-ABORT, abort
> VMSNODE>
>
> Is there any way, under these conditions, to get from here to there?
The perlvms page that should have come with perl (the perlport page is
handy too) says that fork() is not implemented - here's one on-line:
http://search.cpan.org/~jhi/perl-5.8.0/vms/perlvms.pod
The relevant part is:
>>>>>>>>
fork
While in principle the fork operator could be implemented via (and with
the same rather severe limitations as) the CRTL vfork() routine, and
while some internal support to do just that is in place, the
implementation has never been completed, making fork currently
unavailable. A true kernel fork() is expected in a future version of
VMS, and the pseudo-fork based on interpreter threads may be available
in a future version of Perl on VMS (see perlfork). In the meantime, use
system, backticks, or piped filehandles to create subprocesses.
<<<<<<<<<<<
A copy of the perlfork page is:
http://search.cpan.org/~jhi/perl-5.8.0/pod/perlfork.pod
That said, there are references to lib$spawn... but I don't know if
there's a VMS-specific module for creating processes, in the same way
that there is Win32::Process (VMS::Process only seems to do stuff with
existing processes)
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: 31 Mar 2004 18:48:54 GMT
From: Ignoramus26612 <ignoramus26612@NOSPAM.26612.invalid>
Subject: TCP Connection redirector with password?
Message-Id: <c4f3qm$hh1$0@pita.alt.net>
I have access to a particular NNTP service. I would like to write a
script that would listen on a port. Upon connection, it would connect
to the NNTPservice and supply my credentials (authinfo user/pass), and
then simply forewrd whatever data from one socket to another.
Any idea how to do it?
i
------------------------------
Date: Wed, 31 Mar 2004 15:21:42 +0100
From: "Simon" <simalt@totalise.co.uk>
Subject: trapping errors
Message-Id: <406ad3f7$1@primark.com>
How can I trap an error and let the program continue without aborting e.g
I know the die can abort on errors but not sure how to trap the error it
generates and let the program continue.
e.g the following program opens four dirs and read the contents and returns
dir count.
#!/perl/bin/perl -w
use strict;
my($dir1, $dir2, $dir3, $dir4, @file_count, $count, @hold_paths, $num,
@hold_all, $directory_numbers,
$value, $len);
# These are the directory tree paths,
$dir1 = '/tools';
$dir2 = '/test';
$dir3 = '/develop';
$dir4 = '/utils';
@hold_paths = ($dir1,$dir2,$dir3,$dir4);
$num = 0;
for(@hold_paths) { # iterate over each path, open the dir read num of files,
put into array @hold_all
opendir(DIR, $hold_paths[$num]) || die "can't opendir
$hold_paths[$num]: $!";
@file_count = readdir(DIR);
$hold_all[$num] = $hold_paths[$num] ." ". scalar(@file_count) ."\n";
closedir DIR || die "can't opendir $hold_paths[$num]: $!";
$num++;
}
$directory_numbers = 'dir.txt'; # will write to current directory, unless
#you put a 'path'
# this is the file your
writing you data #to
# This is where you actually write to the file
# Will 'overwrite' file each time
open(FILE, ">$directory_numbers") || die "can't open $hold_paths[$num]:
$!";
print FILE @hold_all;
close FILE || die "can't close $hold_paths[$num]: $!";
==============================================
Now what if one of the directory was not available or removed it simply
generates this message:
can't opendir /test: No such file or directory at countdirx.pl line 17.
Is there a way I can allow the program to continue even though the "test"
dir is not available but the program can report on "test" being unavailable
and show what is available.
Thanks for your help.
Simon
------------------------------
Date: 31 Mar 2004 14:43:26 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude>
Subject: Re: trapping errors
Message-Id: <Xns94BD62EB4F763asu1cornelledu@132.236.56.8>
"Simon" <simalt@totalise.co.uk> wrote in news:406ad3f7$1@primark.com:
> can't opendir /test: No such file or directory at countdirx.pl line
> 17.
>
> Is there a way I can allow the program to continue even though the
> "test" dir is not available but the program can report on "test" being
> unavailable and show what is available.
perldoc -f eval
--
A. Sinan Unur
1usa@llenroc.ude (reverse each component for email address)
------------------------------
Date: Wed, 31 Mar 2004 09:53:06 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: trapping errors
Message-Id: <20040331094629.M19862@dishwasher.cs.rpi.edu>
On Wed, 31 Mar 2004, Simon wrote:
> How can I trap an error and let the program continue without aborting e.g
>
> I know the die can abort on errors but not sure how to trap the error it
> generates and let the program continue.
>
> e.g the following program opens four dirs and read the contents and returns
> dir count.
>
> #!/perl/bin/perl -w
>
> use strict;
<snip a bunch of code>
> for(@hold_paths) {
> opendir(DIR, $hold_paths[$num]) || die "can't opendir
> $hold_paths[$num]: $!";
> @file_count = readdir(DIR);
> $hold_all[$num] = $hold_paths[$num] ." ". scalar(@file_count) ."\n";
> closedir DIR || die "can't opendir $hold_paths[$num]: $!";
> $num++;
> }
<snip a bunch more>
>
> Now what if one of the directory was not available or removed it simply
> generates this message:
>
> can't opendir /test: No such file or directory at countdirx.pl line 17.
>
> Is there a way I can allow the program to continue even though the "test"
> dir is not available but the program can report on "test" being unavailable
> and show what is available.
>
The program is only exiting because you told it to. If you don't want it
to die on a failed directory opening, don't tell it to die:
for (@hold_paths){
if (!opendir(DIR, $hold_paths[$num]){
warn "Could not open $holdpaths[$num] ($!), continuing\n";
next;
}
@file_count = readdir(DIR);
$hold_all[$num] = "$hold_paths[$num] " . @file_count . "\n";
closedir DIR || die "can't opendir $hold_paths[$num]: $!";
$num++;
}
Now, if what you actually want to do is trap program-generated fatal
errors (like accidentally dividing by zero), then you want to look at eval
perldoc -f eval
In this case, however, Perl was just doing exactly what you told it to do.
Paul Lalli
------------------------------
Date: Wed, 31 Mar 2004 20:59:32 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: trapping errors
Message-Id: <pan.2004.03.31.18.36.56.596391@aursand.no>
On Wed, 31 Mar 2004 15:21:42 +0100, Simon wrote:
> How can I trap an error and let the program continue without aborting
> [...]
You could use 'eval' to evaluate a piece of your code, or you could try
the Error module. I haven't used much myself, but it looks like a neat
piece of code.
--
Tore Aursand <tore@aursand.no>
"Life is pleasant. Death is peaceful. It's the transition that's
troublesome." -- Isaac Asimov
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V10 Issue 6346
***************************************