[24111] in Perl-Users-Digest
Perl-Users Digest, Issue: 6305 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 26 11:06:03 2004
Date: Fri, 26 Mar 2004 08:05:08 -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 Fri, 26 Mar 2004 Volume: 10 Number: 6305
Today's topics:
Re: Database style hash? (dmb000006)
Re: Database style hash? ctcgag@hotmail.com
get multiple html files and convert to pdf <Me@myco.com>
Re: get multiple html files and convert to pdf <tadmc@augustmail.com>
Re: get multiple html files and convert to pdf <Me@myco.com>
Re: get multiple html files and convert to pdf <tore@aursand.no>
Re: get multiple html files and convert to pdf <Me@myco.com>
Re: get multiple html files and convert to pdf <jwillmore@remove.adelphia.net>
Re: get multiple html files and convert to pdf <Me@myco.com>
how get next 5 lines? <geoffacox@dontspamblueyonder.co.uk>
Re: how get next 5 lines? (Walter Roberson)
Re: how get next 5 lines? <postmaster@castleamber.com>
Re: How to interpolate string containing a variable <nobull@mail.com>
Re: How to interpolate string containing a variable <mark.gaber@obs.unige.ch>
Re: How to interpolate string containing a variable <matthew.garrish@sympatico.ca>
Re: I want to scanf, dammit! <tassilo.parseval@rwth-aachen.de>
Re: I want to scanf, dammit! <ittyspam@yahoo.com>
Re: I want to scanf, dammit! (Anno Siegel)
Re: I want to scanf, dammit! <uri@stemsystems.com>
listen socket during 3 seconds and then, give up <luc2@nospam.invalid>
Re: Parsing <td> tags with HTML::Parser after a certain (Myron Turner)
Re: problem with index not matching string exactly (G)
scripts which report on application crashes <terry@terryland.co.uk>
Re: scripts which report on application crashes <jwillmore@remove.adelphia.net>
Re: Signal handling in objects. Good idea? Best pract (Carlton Brown)
Re: Signal handling in objects. Good idea? Best pract (Carlton Brown)
Re: Signal handling in objects. Good idea? Best pract <remorse@partners.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Mar 2004 03:53:39 -0800
From: dmb000006@hotmail.com (dmb000006)
Subject: Re: Database style hash?
Message-Id: <934a5d96.0403260353.9d53f2@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c3vkas$f9f$1@mamenchi.zrz.TU-Berlin.DE>...
> dmb000006 <dmb000006@hotmail.com> wrote in comp.lang.perl.misc:
> > Hello,
> >
> > I have a database style data structure, each record has several
> > fields.
> >
> > I would like to create a nested data structure that would let me
> > 'query' the data on the value of certain fields.
> >
> > I did this by making the following type of data...
>
> [snip most code]
>
> > # Parse PDB file (see $pdbTemplate above)
> > my @atom = unpack( $pdbTemplate, $_ );
> >
> > # Trim each value.
> > foreach ( @atom ){ s/^\s+// };
> >
> > # Must be a better way? (to make a HASH).
> > my %atom = map { $pdbDescriptive[$_], $atom[$_] } ( 0..$#atom );
>
> This can indeed be streamlined. You don't really need the @atom array.
>
> my %atom;
> @atom{ @pdbDescriptive} = unpack( $pdbTemplate, $_ );
> s/^\s+// for values %atom;
>
> That's it.
Cool! Thanks!
> [...]
>
> > But I would like to go one step further and for each chain return each
> > residue, or for each residue return each chain etc... (i.e. recursive
> > data structure).
>
> Sorry, I don't follow you. Too much shop talk of chains and residues
> for someone not acquainted with the problem area.
>
> Anno
Yup, sorry about that, simplefied version...
ID X Y
1 A ONE
2 A ONE
3 B ONE
4 B TWO
5 C TWO
6 C TWO
7 D ONE
my data structure allows me to say...
foreach my $X (sort keys %{ $data->{'X'} }){ print $X }; # "ABCD"
foreach my $Y (sort keys %{ $data->{'Y'} }){ print $Y }; # "ONETWO"
But what I would like to do is first select say Y = 'ONE', then do the
for each $X type thing from above...
$chunk_o_data = $data->{'Y'}->{'ONE'};
foreach my $X (sort keys %{ $chunk_o_data->{'X'} }){ print $X }; #
"ABD"
i.e. each sub part of the data structure contains the relevant section
of the whole, to any particular depth I care to decend..
Getting the above to work is what I can't work out.
Thanks for the previous code!
Dan.
i.e. atom CA of residue PRO of chain A
NB a chain is a collection of residues, a residue is a collection of
atoms. same residues may exist in different chains, same atoms may
exist in different residues.
------------------------------
Date: 26 Mar 2004 15:57:57 GMT
From: ctcgag@hotmail.com
Subject: Re: Database style hash?
Message-Id: <20040326105757.987$4E@newsreader.com>
dmb000006@hotmail.com (dmb000006) wrote:
> Hello,
>
> I have a database style data structure, each record has several
> fields.
>
> I would like to create a nested data structure that would let me
> 'query' the data on the value of certain fields.
>
> I did this by making the following type of data...
>
> Sample PDB data...
>
> ATOM 72 C ARG L 9 41.592 23.248 98.505 1.00 34.28
> C
> ATOM 73 O ARG L 9 42.467 23.303 97.634 1.00 33.66
> O
> ATOM 74 CB ARG L 9 40.542 25.445 99.063 1.00 32.51
> C
> ATOM 75 CG ARG L 9 40.415 26.641 99.989 1.00 30.92
> C
> ATOM 76 CD ARG L 9 39.771 27.823 99.291 0.00 47.64
> C
> ATOM 77 NE ARG L 9 38.331 27.672 99.123 0.00 67.84
> N
>
> package PDB;
>
> our $pdbTemplate
> = 'x6 A5 x1 A4 A1 A3 x1 A1 A4 A1 x3 A8 A8 A8 A6 A6 x6';
>
> our @pdbDescriptive
> = qw( serial name altLoc resName chainID resSeq iCode x y z
> occupancy tempFactor segID element charge );
>
> our @pdbDataIndex
> = qw( serial name altLoc resName chainID resSeq iCode );
>
> sub readPDB {
> my $pdb = shift;
>
> unless (ref($pdb) eq "GLOB"){
> $pdb = openPDB($pdb);
> }
>
> # Data to return
> my %pdbData;
>
> while ( <$pdb> ){
> next unless /^ATOM|^HETATM/o;
>
> # Parse PDB file (see $pdbTemplate above)
> my @atom = unpack( $pdbTemplate, $_ );
>
> # Trim each value.
> foreach ( @atom ){ s/^\s+// };
>
> # Must be a better way? (to make a HASH).
> my %atom = map { $pdbDescriptive[$_], $atom[$_] } ( 0..$#atom );
>
> # Build up quite a complex data structure.
> foreach (@pdbDataIndex){
> push @{$pdbData{$_}{$atom{$_}}}, \%atom;
> }
> push @{$pdbData{'data'}}, \%atom;
> }
> return \%pdbData;
> }
>
> __END__
>
> This lets me say...
>
> use PDB;
>
> my $data # Special data structure!
> = readPDB( $pdb ); # Would be good to use Fields;
>
> my @chainIDs # Lookup 'chain' entries
> = sort keys %{ $data->{'chainID'} };
>
> foreach my $chainID ( @chainIDs ){
>
> my @atoms # Use 'chain' entry to get at underlying
> atoms.
> = @{ $data->{'chainID'}->{$chainID} };
>
> print "$chain\t". scalar(@atoms). "\n";
> }
>
> __END__
>
> But I would like to go one step further and for each chain return each
> residue,
For just this one, all you would have to do is push the hash level one
deeper.
> or for each residue return each chain etc... (i.e. recursive
> data structure).
Does this make sense? A residue is identified by the chain it is in, so
if you know which residue, you know which chain. Or do want to do this
by residue type rather than redisue identity, e.g. all chains with at least
one histidine?
> How can I do this?
If you want just two index levels deep, then something like this:
foreach my $k1 (@pdbDataIndex){
foreach my $k2 (@pdbDataIndex) {
next if $k1 eq $k2;
push @{$pdbData{'twofers'}{$atom{$k1}}{$atom{$k2}}}, \%atom;
}
}
But really, I don't think you want to do this at all. What are you trying
to accomplish?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 26 Mar 2004 18:53:57 +0530
From: AB <Me@myco.com>
Subject: get multiple html files and convert to pdf
Message-Id: <2gW8c.22$sP4.158@news.oracle.com>
Hi All,
This may seem a bit trivial, but here goes ..
I need to grab a set of html files from a given directory on a web
server, and convert it into one pdf ..
any pointers on how to go about it would be great !
searching cpan provided info about the pdf module , but nothing else ..
Pointers on modules (if any) to use for the following would be great :
1. Download all files in a given web server directory
2. *shrink* to a single html
3. convert html into pdf
TIA
AB
------------------------------
Date: Fri, 26 Mar 2004 07:34:29 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <slrnc68cb5.npq.tadmc@magna.augustmail.com>
AB <Me@myco.com> wrote:
> 1. Download all files in a given web server directory
The primary question here is whether or not the server is
configured so that you can find the names of all of the files
in some directory.
Once you have the file's names and can incorporate them into a URL,
fetching them is pretty easy.
perldoc -q HTML
or
perldoc -q fetch
How do I fetch an HTML file?
> 2. *shrink* to a single html
Or, convert to PDF and shrink to a single PDF.
> 3. convert html into pdf
http://www.google.com/search?q=html2pdf
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 26 Mar 2004 19:39:54 +0530
From: AB <Me@myco.com>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <8XW8c.23$sP4.228@news.oracle.com>
Tad McClellan wrote:
> AB <Me@myco.com> wrote:
>
>
>>1. Download all files in a given web server directory
>
>
>
> The primary question here is whether or not the server is
> configured so that you can find the names of all of the files
> in some directory.
>
If I go to the directory by pointing my web browser to it, I do get the
directory listing instead of an "index.html" page
Foe eg, If I want to get all files under http://www.example.org/thisdir,
when I give the above link to the browser, I am able to get the
directory listing.
> Once you have the file's names and can incorporate them into a URL,
> fetching them is pretty easy.
>
> perldoc -q HTML
> or
> perldoc -q fetch
>
> How do I fetch an HTML file?
>
Thanks ! but how do I get to know what all files I need to get ,
considering my comment above ?
>
>
>>2. *shrink* to a single html
>
> Or, convert to PDF and shrink to a single PDF.
>
>
>
>>3. convert html into pdf
> http://www.google.com/search?q=html2pdf
TIA
AB
------------------------------
Date: Fri, 26 Mar 2004 16:03:00 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <pan.2004.03.26.15.02.02.327726@aursand.no>
On Fri, 26 Mar 2004 19:39:54 +0530, AB wrote:
> Foe eg, If I want to get all files under http://www.example.org/thisdir,
> when I give the above link to the browser, I am able to get the
> directory listing.
>
> [...]
>
> Thanks ! but how do I get to know what all files I need to get ,
> considering my comment above ?
You want us to whipe your ass, too? :) What have you tried so far? What
approaches did you consider? What's not working?
--
Tore Aursand <tore@aursand.no>
"Scientists are complaining that the new "Dinosaur" movie shows
dinosaurs with lemurs, who didn't evolve for another million years.
They're afraid the movie will give kids a mistaken impression. What
about the fact that the dinosaurs are singing and dancing?" -- Jay
Leno
------------------------------
Date: Fri, 26 Mar 2004 20:49:14 +0530
From: AB <Me@myco.com>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <8YX8c.32$sP4.413@news.oracle.com>
Tore Aursand wrote:
>
> You want us to whipe your ass, too? :) What have you tried so far? What
That comment was uncalled for and downright vulgar.
> approaches did you consider? What's not working?
Looking at the demented language you use, dont think explaining that to
*you* would be of any help.
Try to learn some netiquette before you comment on someone - even if you
are a vet and myself a newbie.
Regards
AB
------------------------------
Date: Fri, 26 Mar 2004 10:50:38 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <pan.2004.03.26.15.50.36.918538@remove.adelphia.net>
On Fri, 26 Mar 2004 19:39:54 +0530, AB wrote:
> Tad McClellan wrote:
>> AB <Me@myco.com> wrote:
> If I go to the directory by pointing my web browser to it, I do get the
> directory listing instead of an "index.html" page
>
> Foe eg, If I want to get all files under http://www.example.org/thisdir,
> when I give the above link to the browser, I am able to get the
> directory listing.
>
>> Once you have the file's names and can incorporate them into a URL,
>> fetching them is pretty easy.
>>
>> perldoc -q HTML
>> or
>> perldoc -q fetch
>>
>> How do I fetch an HTML file?
>>
> Thanks ! but how do I get to know what all files I need to get ,
> considering my comment above ?
You could use HTMLDOC (http://www.easysw.com/htmldoc/). There's a
command line interface and its also got a GUI and you could point an click
your way to PDF's :-)
In fact, there is a Perl module to interface with the application
(http://search.cpan.org/~mfrankl/HTML-HTMLDoc-0.07/lib/HTML/HTMLDoc.pm).
As far as *which* files you want to fetch, *you* need to at least try to
do this on your own first :-)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"About the time we think we can make ends meet, somebody moves the ends."
-- Herbert Hoover
------------------------------
Date: Fri, 26 Mar 2004 21:32:37 +0530
From: AB <Me@myco.com>
Subject: Re: get multiple html files and convert to pdf
Message-Id: <OAY8c.33$sP4.445@news.oracle.com>
James Willmore wrote:
>
> You could use HTMLDOC (http://www.easysw.com/htmldoc/). There's a
> command line interface and its also got a GUI and you could point an click
> your way to PDF's :-)
>
> In fact, there is a Perl module to interface with the application
> (http://search.cpan.org/~mfrankl/HTML-HTMLDoc-0.07/lib/HTML/HTMLDoc.pm).
>
> As far as *which* files you want to fetch, *you* need to at least try to
> do this on your own first :-)
Thanks a ton for your inputs
> HTH
Sure does :)
Regards
AB
------------------------------
Date: Fri, 26 Mar 2004 13:49:14 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: how get next 5 lines?
Message-Id: <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>
Hello
I am opening a file to look for a piece of data and having found that
data I want to read the next 5 lines...as there is another bit of data
on one of those lines...
appreciate a little help here!
Thanks
Geoff
------------------------------
Date: 26 Mar 2004 14:32:03 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: how get next 5 lines?
Message-Id: <c41et3$as3$1@canopus.cc.umanitoba.ca>
In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>,
Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
:I am opening a file to look for a piece of data and having found that
:data I want to read the next 5 lines...as there is another bit of data
:on one of those lines...
my (undef, undef, undef, undef, $interestingline) =
map { <FILEHANDLE> } (1..5);
--
vi -- think of it as practice for the ROGUE Olympics!
------------------------------
Date: Fri, 26 Mar 2004 08:35:47 -0600
From: John Bokma <postmaster@castleamber.com>
Subject: Re: how get next 5 lines?
Message-Id: <4064408d$0$24358$58c7af7e@news.kabelfoon.nl>
Walter Roberson wrote:
> In article <8vc860l0c6ifrepujr8pm89upcgua6pp59@4ax.com>,
> Geoff Cox <geoffacox@dontspamblueyonder.co.uk> wrote:
> :I am opening a file to look for a piece of data and having found that
> :data I want to read the next 5 lines...as there is another bit of data
> :on one of those lines...
>
> my (undef, undef, undef, undef, $interestingline) =
> map { <FILEHANDLE> } (1..5);
uhm, on "one of those lines" :D
my @oneofthoselines = map { <FILEHANDLE> } (1..5);
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
------------------------------
Date: 26 Mar 2004 12:29:38 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to interpolate string containing a variable
Message-Id: <u9ekrfeqq5.fsf@wcl-l.bham.ac.uk>
Mark Gaber <mark.gaber@obs.unige.ch> writes:
> I am almost sure that there is a way in Perl to make it evaluate the
> string so that the logging is more informative.
I'm not sure what you are asking but I think it may be FAQ: "How can I
expand variables in text strings?"
Note: many people, including myself consider the answer in the FAQ to
be seriously flawed. For more info see numerous previous theads that
contain the literal phrase "How can I expand variables in text
strings?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 26 Mar 2004 15:02:15 +0100
From: Mark Gaber <mark.gaber@obs.unige.ch>
Subject: Re: How to interpolate string containing a variable
Message-Id: <406437E7.151E67E3@obs.unige.ch>
Brian McCauley wrote:
> I'm not sure what you are asking but I think it may be FAQ: "How can I
> expand variables in text strings?"
Thanks. I did find the answer there. The answer involves using regular
expressions to replace occurences of variables in a string. To their
example I added a line to handle $ENV{} environment variables. The
solution is:
#!/usr/bin/perl
$foo = "XXXX";
$bar = "YYYY";
$text = 'this has a $foo a $bar and a $ENV{TERM}';
print "text is $text\n";
$text =~ s/\$ENV\{(\w+)}/$ENV{$1}/g;
$text =~ s/\$(\w+)/${$1}/g;
print "text is $text\n";
exit;
The output is:
text is this has a $foo a $bar and a $ENV{TERM}
text is this has a XXXX a YYYY and a dtterm
Thanks very much for the help.
Mark
------------------------------
Date: Fri, 26 Mar 2004 09:15:50 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: How to interpolate string containing a variable
Message-Id: <mWW8c.42831$re.2438418@news20.bellglobal.com>
"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:c40s6o$8c8$1@mamenchi.zrz.TU-Berlin.DE...
> Matt Garrish <matthew.garrish@sympatico.ca> wrote in comp.lang.perl.misc:
> >
> >
> > eval "$strCmd";
>
> Why the quotes?
>
Ugh! A case of just not paying attention to what I was typing. Especially
bad since I know I've chastised others for the useless use of quotes... : (
Matt
------------------------------
Date: 26 Mar 2004 12:24:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: I want to scanf, dammit!
Message-Id: <c417e9$igj$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Anno Siegel:
> Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote in comp.lang.perl.misc:
>> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
>> news:c3vj6k$5c$1@nets3.rz.RWTH-Aachen.DE:
>> >>> If it doesnt, just use Inline::C.
>> >>
>> >> Er.. what's that?
>> >
>> > Inline::C allows you to embed C code into your Perl script.
>> > Here's a super-simplistic scanner on top of fscanf() available
>> > from Perl:
>> >
>> > #! /usr/bin/perl -w
>> >
>> > use strict;
>> > use Inline Config => BUILD_NOISY => 1;
>> > use Inline 'C';
>> [snip]
>>
>> I am sorry, I can't find any mention of Inline in my Perl docs...
>
> It's a standard module, "perldoc Inline" should show it. If not,
> http://cpan.uwinnipeg.ca/htdocs/Inline/, but you should check your
> installation.
Not quite yet. It's one of the reasons why I prefer plain XS over
Inline::C.
There are rumors that Inline is going to be standard in perl5.10,
though.
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: Fri, 26 Mar 2004 07:40:35 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: I want to scanf, dammit!
Message-Id: <20040326073810.H21521@dishwasher.cs.rpi.edu>
On Thu, 25 Mar 2004, Uri Guttman wrote:
> >>>>> "PL" == Paul Lalli <ittyspam@yahoo.com> writes:
>
> PL> my ($i, $word);
> PL> while ($word = <$fs>){
> PL> last if ++$i == 500;
> PL> }
>
> couldn't that be just
>
> <$fs> for 1 .. 500 ;
>
> for provides void context so it will read one record at a time as
> defined by $/.
>
> it could be off by 1 so that might be 1 .. 499.
>
Well, that would certainly read the first 500, but it wouldn't be storing
them anywhere. < > doesn't automatically assign the 'line' read into $_
unless it's used as the conditional for a while(). When used in the body
of the for loop, it reads a line and throws it away. So it would still
have to be something like:
<$fs> for 1 .. 499;
$line = <$fs>;
print $line;
Paul Lalli
------------------------------
Date: 26 Mar 2004 12:52:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: I want to scanf, dammit!
Message-Id: <c41936$hdm$1@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.parseval@post.rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach Anno Siegel:
>
> > Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote in
> comp.lang.perl.misc:
> >> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
> >> news:c3vj6k$5c$1@nets3.rz.RWTH-Aachen.DE:
> >> >>> If it doesnt, just use Inline::C.
> >> >>
> >> >> Er.. what's that?
> >> >
> >> > Inline::C allows you to embed C code into your Perl script.
> >> > Here's a super-simplistic scanner on top of fscanf() available
> >> > from Perl:
> >> >
> >> > #! /usr/bin/perl -w
> >> >
> >> > use strict;
> >> > use Inline Config => BUILD_NOISY => 1;
> >> > use Inline 'C';
> >> [snip]
> >>
> >> I am sorry, I can't find any mention of Inline in my Perl docs...
> >
> > It's a standard module, "perldoc Inline" should show it. If not,
> > http://cpan.uwinnipeg.ca/htdocs/Inline/, but you should check your
> > installation.
>
> Not quite yet. It's one of the reasons why I prefer plain XS over
> Inline::C.
>
> There are rumors that Inline is going to be standard in perl5.10,
> though.
Sorry. I could have sworn...
Anno
------------------------------
Date: Fri, 26 Mar 2004 14:58:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: I want to scanf, dammit!
Message-Id: <x7smfvy7s7.fsf@mail.sysarch.com>
>>>>> "PL" == Paul Lalli <ittyspam@yahoo.com> writes:
PL> On Thu, 25 Mar 2004, Uri Guttman wrote:
>> couldn't that be just
>>
>> <$fs> for 1 .. 500 ;
PL> Well, that would certainly read the first 500, but it wouldn't be storing
PL> them anywhere. < > doesn't automatically assign the 'line' read into $_
PL> unless it's used as the conditional for a while(). When used in the body
PL> of the for loop, it reads a line and throws it away. So it would still
PL> have to be something like:
PL> <$fs> for 1 .. 499;
PL> $line = <$fs>;
PL> print $line;
the OP said this so i was answering the 'better yet' part. :)
> > the logic of the problem. Suppose the file contains 2500 numbers
> > and I need to read the first 500, or better yet, read just the
> > number #500. This number can be in the middle of a line, for all I
> > know.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 26 Mar 2004 15:31:50 GMT
From: luc2 <luc2@nospam.invalid>
Subject: listen socket during 3 seconds and then, give up
Message-Id: <40644ce6$1$5618$636a15ce@news.free.fr>
i'd like to write a PORTABLE perl script which listens to a socket during 3
seconds, and gives up after theses 3 seconds. given that i want a
portable code, i can't use fork, pipe, or system V signals.
problem 1 : if i listen the socket using $line = <$socket>, it will
listen to it till a response is received. it won't be possible to make
it give up after 3 seconds.
solution 1 : i execute $line = <$socket> in a child process, and the
father will wait with "sleep 3". i use "threads-new" for the
portability, and no fork...
problem 2 : if the child receives a udp response, it must warn the
father. indeed, the father must stop waiting, as a response is received.
however, the only way to wake a "sleep" up is to send it a system V
signal, which i'm not allowed to.
solution 2 : to make the father sleep, i don't therefore use "sleep",
but a semaphore. to wake it up, ANOTHER child process will wait 3
seconds, and then, it will wake the father up by opening the semaphore.
the child process which listen to the socket will also open the
semaphore if a UDP response is received.
conclusion : my code works, but it looks ugly. i'd like to know if you'd
have a better solution...
my code :
use threads;
use Thread::Semaphore;
use IO::Socket;
wait_udp_for( 3 ); # 3 seconds
sub wait_udp_for
{
my( $seconds ) = @_;
$s = new Thread::Semaphore(0);
my $listening_thread = threads->new( \&listening_thread );
my $wake_me_thread = threads->new( \&wake_me_thread, $seconds );
print "The father waits...\n";
$s->down;
print "The father wakes up.\n";
}
sub listening_thread
{
$socket = IO::Socket::INET->new
(
Proto => "udp",
LocalPort => 6112
)
or die "Cannot create socket";
$line = <$socket>;
print $line;
$s->up;
}
sub wake_me_thread
{
my( $seconds ) = @_;
print "The child waits for $seconds seconds.\n";
sleep $seconds;
print "The child tries to wake the father up.\n";
$s->up;
}
------------------------------
Date: Fri, 26 Mar 2004 11:46:43 GMT
From: mturner@ms.umanitoba.ca (Myron Turner)
Subject: Re: Parsing <td> tags with HTML::Parser after a certain event
Message-Id: <4064163d.1931088889@news.wp.shawcable.net>
I had left out that <a> handler from my original post.
On Wed, 10 Mar 2004 11:38:00 -0700, Ravi Parimi
<parimi@nowhere.none.com> wrote:
use HTML::Parser;
use strict;
my @data = ();
my $count = 0;
my $item = 0;
my $p = HTML::Parser->new(
api_version => 3,
start_h => [\&start, "tagname, attr, attrseq, text"],
);
$p->report_tags('a', 'td');
open(F, "test.html") || die;
$p->parse_file(*F);
$p->eof;
foreach my $d(@data) {
foreach my $k(keys %$d) {
print "$k = $d->{$k}\n";
}
print "\n";
}
sub start {
my ($tag, $attr, $attrseq, $origtext) = @_;
return unless $tag =~/^a$/ || $tag =~/^td$/;
$data[$count] = {};
$data[$count]->{tag} = $tag;
foreach my $at (@$attrseq) {
$data[$count]->{href} = $attr->{$at} if $at =~/^href$/;
}
if($tag =~/^a$/) {
$p->handler(text=>\&a_handler,"text");
}
else{
$p->handler(text=>\&td_handler,"text");
}
}
sub td_handler {
my ($origtext) = @_;
return unless $data[$count]->{tag} =~/^td$/;
# strip way leading and trailing whitespace
# this lets you see if there's anything
# in $origtext
$origtext =~ s/^\s+//;
$origtext =~ s/\s+$//;
# blank TD's occur (I believe) where you've
#nested <TD><A>. . . . </A></TD>
return if !$origtext;
# you need something to flag that this field
# is a user name, so you can write sometuing like:
# <TD>Username John</TD>
return if $origtext !~ /name/i;
$data[$count -1]->{username} =
$origtext if $count && exists $data[$count -1]->{href};
}
sub a_handler {
my ($origtext) = @_;
$origtext =~ s/^\s+//;
$origtext =~ s/\s+$//;
return if !$origtext;
$data[$count]->{key} = $origtext;
$count++;
}
Myron Turner
Myron Turner
www.room535.org
------------------------------
Date: 26 Mar 2004 05:13:08 -0800
From: bay_dar@yahoo.com (G)
Subject: Re: problem with index not matching string exactly
Message-Id: <cad04083.0403260513.6a83bc31@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c3vcn5$a0d$2@mamenchi.zrz.TU-Berlin.DE>...
> G <bay_dar@yahoo.com> wrote in comp.lang.perl.misc:
> > I'm looping through a sales_file looking for matches to $code. Note
> > the file contains no spaces after the "|". Duplicates are allowed on
> > different lines, but not the same line. The file has a number of
> > entries such as the following (sample $sales_file):
> >
> > sales item aaa|543,m423a
> > sales item bbb|m423,543 #Note how code 543 is on the 1st 2ndline.
> > sales item ccc|m423b
> > sales item ddd|423,423b,m523,652
> >
> > - Also note we have entires of m423, m423a and m423b. The problem with
>
> So, are these equivalent or not? You're not saying.
They are not equivilent.
>
> > my code, is that it matches the $entered_code of m423 to m423, m423a,
> > and m423b but I want it to only match up to m423. Of course 423 should
> > only match up to 423 and so on. Anyone have a suggestion to fix this?
> >
> > Here is the code segment:
> >
> > open FILE, "<$sales_file" or die "could not open '$sales_file' $!";
> > while (<FILE>) {
> > chomp;
> > my ($sales_item, $code) = split /\|/;
> > my @code = split /,/, $exits;
> >
> > if (index($code, $entered_code) != -1) {
> > $list .="<ul>" if !($list);
> > $list .= "<li><p>$sales_item</li>";
> > }
> >
> > }
>
> Your code and your verbal description don't agree. Don't you want
> to split $code in the second split? If not, what's in $exit?
>
> In any case, what's in $entered_code?
$entered_code would be an entry such as m423 or 423.
The program should work as follows:
I want to add the text($sales_item) to the left of "|" in the sales
file to my $list if I find a match.
For instance an $entered_code of 423 would add "sales item ddd" to the
list. An $entered_code of m423b would add "sales item ddd" and "sales
item ddd" to the list.
>
> Your description leaves open too many possibilities. What, exactly, are
> the "codes" you speak of, and what are the strings you want to compare
> them too?
my ($sales_item, $code) is the array that reads in the $sales file and
associated codes.
e.g.
sales item aaa,543
sales item aaa,m423a
sales item bbb,m423
sales item bbb,543
...
I hope I made myself a little clearer.
Thanks
>
> Anno
------------------------------
Date: Fri, 26 Mar 2004 15:00:17 +0000
From: Tezza <terry@terryland.co.uk>
Subject: scripts which report on application crashes
Message-Id: <c2h8605et9l4mc1bqmmeo8ghvogsi10q57@4ax.com>
Hi
Does anyone know where would I find pre-written scripts which collect
information about the state of a server - I am particularly trying to
find scripts which will report on application errors/crashs ande the
state of the server before and after the application crash?
Thanks for any help
Richard
------------------------------
Date: Fri, 26 Mar 2004 10:37:25 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: scripts which report on application crashes
Message-Id: <pan.2004.03.26.15.37.24.47784@remove.adelphia.net>
On Fri, 26 Mar 2004 15:00:17 +0000, Tezza wrote:
> Does anyone know where would I find pre-written scripts which collect
> information about the state of a server - I am particularly trying to
> find scripts which will report on application errors/crashs ande the
> state of the server before and after the application crash?
Try http://freshmeat.net/ or http://sourceforge.net/
One script (application) that is written in Perl to look at is Webmin
(http:/webmin.com/).
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"There was a boy called Eustace Clarence Scrubb, and he almost
deserved it." -- C. S. Lewis, The Chronicles of Narnia
------------------------------
Date: 26 Mar 2004 06:53:03 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Signal handling in objects. Good idea? Best practices?
Message-Id: <aa611a32.0403260653.765ee787@posting.google.com>
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnc67cuq.mh9.tadmc@magna.augustmail.com>...
> Carlton Brown <carltonbrown@hotmail.com> wrote:
>
> > #!/usr/local/bin/perl
>
>
> You should ask for all the help you can get:
The minor pecadillos are duly noted, but neither they nor the
stricture messages shed any light on the larger question of if, why,
whether, or how one would design signal handlers into objects. The
toy program was not a debugging request, it was to illustrate how I
attempted to approach the problem (Also to anticipate the question
"What did you try?").
------------------------------
Date: 26 Mar 2004 06:58:49 -0800
From: carltonbrown@hotmail.com (Carlton Brown)
Subject: Re: Signal handling in objects. Good idea? Best practices?
Message-Id: <aa611a32.0403260658.348c75e7@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c410do$ad1$1@mamenchi.zrz.TU-Berlin.DE>...
> my $coderef = $self->can( 'gripe');
>
> However, the automatic calls to $SIG{INT} aren't method calls, so putting
> that in $SIG{INT} won't work right with "real" methods (as opposed to
> ones that ignore their first argument). It also freezes method resolution
> to the moment when $SIG{INT} is set, so dynamic changes in inheritance
> wouldn't be honored.
>
> The new() method could do this:
>
> $SIG{'INT'} = sub { $self->gripe };
>
> That would call ->gripe correctly and do method dispatch each time.
Thank you for the clarification. I will try this and see how it works
out.
I am sure it will work programmatically, but what do you think about
this practice in general? Is it a "good idea" to have per-object
signal handlers? From the example you have given, it seems that it
could only be done by an instance method and not a class method, would
you agree with that statement?
------------------------------
Date: Fri, 26 Mar 2004 10:36:41 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Signal handling in objects. Good idea? Best practices?
Message-Id: <remorse-6E5706.10364026032004@plato.harvard.edu>
In article <aa611a32.0403260658.348c75e7@posting.google.com>,
carltonbrown@hotmail.com (Carlton Brown) wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<c410do$ad1$1@mamenchi.zrz.TU-Berlin.DE>...
> > my $coderef = $self->can( 'gripe');
> >
> > The new() method could do this:
> >
> > $SIG{'INT'} = sub { $self->gripe };
> >
> > That would call ->gripe correctly and do method dispatch each time.
>
> I am sure it will work programmatically, but what do you think about
> this practice in general? Is it a "good idea" to have per-object
> signal handlers? From the example you have given, it seems that it
> could only be done by an instance method and not a class method, would
> you agree with that statement?
Speaking completely without any idea of anything, I'm guessing that if
you wanted to use a class method, you would do something like:
$SIG{'INT'} = sub { MyClass->gripe };
I can't speak to the advisability of this though, as signal handlers are
completely out of my experience.
HTH,
Ricky
------------------------------
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 6305
***************************************