[22737] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4958 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 8 11:07:04 2003

Date: Thu, 8 May 2003 08:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 8 May 2003     Volume: 10 Number: 4958

Today's topics:
        beautification: ip number translation <pdongen@azu.nl>
    Re: Help: Need nifty idea for efficiently linking objec <zawrotny@jaguar.sb.fsu.edu>
        how to enforce decimal interpretation of a number <mfranz@users.sourceforge.banana>
    Re: how to enforce decimal interpretation of a number <nospam@nospam.de>
    Re: how to enforce decimal interpretation of a number <garry@ifr.zvolve.net>
    Re: how to enforce decimal interpretation of a number <mfranz@users.sourceforge.banana>
    Re: Ina a binary file is a space padded text file conve <tassilo.parseval@rwth-aachen.de>
    Re: Ina a binary file is a space padded text file conve <wallabyedward@hunterlink.net.au>
        More on flock().... <look@my.signature>
    Re: More on flock().... <tassilo.parseval@rwth-aachen.de>
        need help reading / displaying http with perl <RobS@southernbell.net>
        Net::SMTP debug <bigus AT creationfactor DOT net>
    Re: Net::SMTP debug <nospam@nospam.de>
        Newbie how to split file <fclack50@yahoo.com>
    Re: Perl code to dump palm datebook? <josef.moellers@fujitsu-siemens.com>
        Recursive copying question (Mark Smith)
    Re: Recursive copying question <nospam@nospam.de>
    Re: Recursive copying question (Randal L. Schwartz)
    Re: Removal or HTML tags from pages (Stephen Adam)
        Using Net::Ping in cgi script (Joe B)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 08 May 2003 16:28:46 +0200
From: Costyn van Dongen <pdongen@azu.nl>
Subject: beautification: ip number translation
Message-Id: <b9dprr$d79$1@little.azu.nl>

Hi,

I have some really ugly code that I'm sure someone here can think of 
something more elegant. The input is an IP number, or part of an ip 
number. My code then, based on how many octets are specified, generates 
a slice of SQL code, which will go into a larger SQL code piece later.
INET_ATON converts an IP number from octets to integer.

Some examples:

Input: 143.121.100.27
Output: ip=INET_ATON('143.121.100.27')

Input: 143.121.100
Output: ip BETWEEN INET_ATON('143.121.100.0') AND
                    INET_ATON('143.121.100.255')

Input: 143.121
Output: ip BETWEEN INET_ATON('143.121.0.0') AND
                    INET_ATON('143.121.255.255')

etc

I would really appreciate your help. I don't like my current kludge. :-)

Here's some code:

sub ipSearchTerms
{
     my $searchterm = shift ;
     my $start      = "";
     my $stop       = "" ;
     my $octet      = 0 ;
     my $returnSQL  = "" ;

     if( $searchterm =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ ) {
         $returnSQL  = " ip=INET_ATON('$searchterm') " ;
     } else {
         my @ipaddress = split( $searchterm, "." ) ;

         foreach $octet ( @ipaddress ) {
             if( $octet ne "" ) {
                 $start .= ".$octet" ;
                 $stop  .= ".$octet" ;
             } else {
                 $start .= ".0" ;
                 $stop  .= ".255" ;
             }
         }

         $returnSQL = " ip BETWEEN INET_ATON('$start') and
                                   INET_ATON('$stop') " ;
     }

     return $returnSQL ;
}



------------------------------

Date: 8 May 2003 14:14:33 GMT
From: Michael Zawrotny <zawrotny@jaguar.sb.fsu.edu>
Subject: Re: Help: Need nifty idea for efficiently linking objects together and making comparisons,,,
Message-Id: <slrnbbkpi9.rge.zawrotny@jaguar.sb.fsu.edu>

On 7 May 2003 20:32:41 -0700, entropy123 <email_entropy123@yahoo.com> wrote:
>  For example, starting with the knowledge of the bonds each atom has I
>  need to figure out if there is a ring structure. So, for a six carbon
>  molecule is it something like C-C-C-C-C-C or a ring structure.
>  
>  My idea is to take the bonding information and - starting with an
>  individual atom - create an array. If the array ever has the starting
>  atom as an element then I know I have a ring..

Not necessarily.

  C
  |
  C-C-C-C
  |
  C


Mike

-- 
Michael Zawrotny
Institute of Molecular Biophysics
Florida State University                | email:  zawrotny@sb.fsu.edu
Tallahassee, FL 32306-4380              | phone:  (850) 644-0069


------------------------------

Date: Thu, 08 May 2003 15:31:03 +0200
From: Melchior FRANZ <mfranz@users.sourceforge.banana>
Subject: how to enforce decimal interpretation of a number
Message-Id: <3eba5c17$0$48606$91cee783@newsreader02.highway.telekom.at>

I've got a table with decimal numbers, some of which are badly
formatted, such as -002.345. Because of the leading zeros,
Perl interprets the integer part as octal and appends the
fractional part verbatim:

  $ perl -e '$x = -0010.345; print "$x\n"'
  -8345

The zeros can, of course, simply be stripped off by applying
a text substitution rule

  $ perl -e '$x = "-0010.345"; $x =~ s/^([+-]?)0*/$1/; print "$x\n"'
  -10.345

but that doesn't really look elegant. There must be a simple
trick -- some equivalent of the (non existing) "dec" function,
analogous to "hex" and "oct". Is there?

m.   :-)


------------------------------

Date: Thu, 8 May 2003 16:20:41 +0200
From: "Thomas Kratz" <nospam@nospam.de>
Subject: Re: how to enforce decimal interpretation of a number
Message-Id: <3eba6faf.0@juno.wiesbaden.netsurf.de>

DQoiTWVsY2hpb3IgRlJBTloiIDxtZnJhbnpAdXNlcnMuc291cmNlZm9yZ2UuYmFuYW5hPiB3cm90
ZQ0KDQo+IEkndmUgZ290IGEgdGFibGUgd2l0aCBkZWNpbWFsIG51bWJlcnMsIHNvbWUgb2Ygd2hp
Y2ggYXJlIGJhZGx5DQo+IGZvcm1hdHRlZCwgc3VjaCBhcyAtMDAyLjM0NS4gQmVjYXVzZSBvZiB0
aGUgbGVhZGluZyB6ZXJvcywNCj4gUGVybCBpbnRlcnByZXRzIHRoZSBpbnRlZ2VyIHBhcnQgYXMg
b2N0YWwgYW5kIGFwcGVuZHMgdGhlDQo+IGZyYWN0aW9uYWwgcGFydCB2ZXJiYXRpbToNCj4gDQo+
ICAgJCBwZXJsIC1lICckeCA9IC0wMDEwLjM0NTsgcHJpbnQgIiR4XG4iJw0KPiAgIC04MzQ1DQoN
CldoYXQgZG8geW91IG1lYW4gd2l0aCB0YWJsZT8NCkRvIHlvdSBoYXZlIHRoZSBzdHJpbmcgJy0w
MDEwLjM0NScgb3IgYSBsaXRlcmFsPw0KIA0KPiBUaGUgemVyb3MgY2FuLCBvZiBjb3Vyc2UsIHNp
bXBseSBiZSBzdHJpcHBlZCBvZmYgYnkgYXBwbHlpbmcNCj4gYSB0ZXh0IHN1YnN0aXR1dGlvbiBy
dWxlDQo+IA0KPiAgICQgcGVybCAtZSAnJHggPSAiLTAwMTAuMzQ1IjsgJHggPX4gcy9eKFsrLV0/
KTAqLyQxLzsgcHJpbnQgIiR4XG4iJw0KPiAgIC0xMC4zNDUNCg0KTm93IGl0IGlzIGEgc3RyaW5n
LiBXaGF0IG5vdywgc3RyaW5nIG9yIGxpdGVyYWw/DQoNCklmIGl0J3MgYSBzdHJpbmcgdGhlbjoN
Cg0KJHggPSAnLTAwMTAuMzQ1JzsNCnByaW50ICR4KzAsICJcbiI7ICMgZm9yY2UgbnVtZXJpYyBj
b252ZXJzaW9uIA0KDQpwcmludHM6DQoNCj4gLTEwLjM0NQ0KDQpUaG9tYXMNCg==



------------------------------

Date: Thu, 08 May 2003 14:26:54 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: how to enforce decimal interpretation of a number
Message-Id: <slrnbbkq9e.b4f.garry@zfw.zvolve.net>

On Thu, 08 May 2003 15:31:03 +0200, Melchior FRANZ
<mfranz@users.sourceforge.banana> wrote:

> I've got a table with decimal numbers, some of which are badly
> formatted, such as -002.345. Because of the leading zeros, Perl
> interprets the integer part as octal and appends the fractional part
> verbatim:
> 
>   $ perl -e '$x = -0010.345; print "$x\n"' -8345
> 
> The zeros can, of course, simply be stripped off by applying a text
> substitution rule
> 
>   $ perl -e '$x = "-0010.345"; $x =~ s/^([+-]?)0*/$1/; print "$x\n"'
>   -10.345
> 
> but that doesn't really look elegant. There must be a simple trick
> -- some equivalent of the (non existing) "dec" function, analogous
> to "hex" and "oct". Is there?

You seem to be confusing data and program: 

    $ perl -wl
    while (<DATA>) {
      print $_ + 0;
    }
    __DATA__
    -0010.345
    -10.345
    ^D
    $ 

If your table is read as data, it will be interpreted as you seem to
want.  If you mean it's a program, then change your program.  

-- 
Garry Williams


------------------------------

Date: Thu, 08 May 2003 16:31:56 +0200
From: Melchior FRANZ <mfranz@users.sourceforge.banana>
Subject: Re: how to enforce decimal interpretation of a number
Message-Id: <3eba6a5c$0$28676$91cee783@newsreader01.highway.telekom.at>

* Thomas Kratz -- Thursday 08 May 2003 16:20:
> $x = '-0010.345';
> print $x+0, "\n"; # force numeric conversion
>
> prints:
> > -10.345

Oh yes, that's simple enough. :-]  Silly me. Thanks! (Yes, it
was a string.)

m.


------------------------------

Date: 8 May 2003 13:13:28 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Ina a binary file is a space padded text file converted to nulls ?
Message-Id: <b9dl5o$3uq$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Anthony:

> just say I had a twelve character hostname field and I'm converting it and
> other data to a binary file, if the text filed hostname is padded witrh
> spaces is this converted to nulls when converting it to binary. If not how
> do you do it ??

How should we tell? You are using your own converting routine so you
should probably know. Show us your code and we can probably tell you
what it does (heh).

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: Thu, 8 May 2003 11:41:38 +1000
From: "Anthony" <wallabyedward@hunterlink.net.au>
Subject: Re: Ina a binary file is a space padded text file converted to nulls ?
Message-Id: <b9dmof$hrfgp$1@ID-82947.news.dfncis.de>


Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote in message
news:b9dl5o$3uq$1@nets3.rz.RWTH-Aachen.DE...
: Also sprach Anthony:
:
: > just say I had a twelve character hostname field and I'm converting it
and
: > other data to a binary file, if the text filed hostname is padded witrh
: > spaces is this converted to nulls when converting it to binary. If not
how
: > do you do it ??
:
: How should we tell? You are using your own converting routine so you
: should probably know. Show us your code and we can probably tell you
: what it does (heh).

well basically it was
    binmode NEW;
    print NEW <<EODATA;
 but if you use
print . . . . pack

is this any different ?

Anthony




------------------------------

Date: 08 May 2003 13:09:41 GMT
From: David Scarlett <look@my.signature>
Subject: More on flock()....
Message-Id: <Xns9375EBA6F4385dscarlett@210.49.20.254>

Let's say I want to write to a file, clobbering whatever was in it, but 
only if I can get an exclusive lock on the file.

Would the way to do this be to open it with mode "+<", ask for a non-
binding exclusive lock, and then go ahead if I get the lock, or close 
the filehandle and forget about it if I don't?


-- 
David Scarlett

dscarlett@_ _ _ _ _ _ _ _
_ _ _ _ _ optusnet.com.au


------------------------------

Date: 8 May 2003 13:16:43 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: More on flock()....
Message-Id: <b9dlbr$45p$1@nets3.rz.RWTH-Aachen.DE>

Also sprach David Scarlett:

> Let's say I want to write to a file, clobbering whatever was in it, but 
> only if I can get an exclusive lock on the file.
> 
> Would the way to do this be to open it with mode "+<", ask for a non-
> binding exclusive lock, and then go ahead if I get the lock, or close 
> the filehandle and forget about it if I don't?

Probably, yes. If your system has nonblocking locks, you can do it
thusly:

    use Fcntl qw/:flock/;

    open F, "+<", "file" or die $!;
    if (flock F, LOCK_EX|LOCK_NB) {
        # got the lock so write into file
        ...
    }

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: Thu, 08 May 2003 07:49:40 GMT
From: Robert Sabine <RobS@southernbell.net>
Subject: need help reading / displaying http with perl
Message-Id: <3EBA0C14.9010408@southernbell.net>

Hi, I was wondering if anyone can show me how to read and display http 
via perl.   I know how to send http to a client using print commands, 
but what I want to do is display what the client sends back.

Specifically, what I want to do is have a program that proves that the 
http command 'last-modified:' causes my client programs to send 'if 
modified since' the next time the script is run.  I also want to do this 
for Etags but it should pretty much be the same.

Thanks for any suggestions.



------------------------------

Date: Thu, 8 May 2003 15:10:35 +0100
From: "Bigus" <bigus AT creationfactor DOT net>
Subject: Net::SMTP debug
Message-Id: <b9doh1$r9e@newton.cc.rl.ac.uk>

Hi

I've been following a tutorial
(http://perl.about.com/library/weekly/aa022000d.htm) on sending an email
using Net::SMTP.

Nice and simple and everything works fine, but... I want to change the debug
part of it.

At present, the following lines from the script on that article feed all the
transaction conversation with the mail server to my browser:

my $DEBUG = 1;
if($DEBUG)
{
   $| = 1;
   open(STDERR, ">&STDOUT");
}

Now, I don't actually want to feed the debug info to the browser, however, I
*do* want to know that the transaction went OK.

So, given that one of the last lines in the transaction reads like this:

<<< 250 2.0.0 h48Dkw013626 Message accepted for delivery
Net::SMTP=GLOB(0x18857a8)

I thought that if, instead of using STDERR (which I don't know how to use),
I fed all the transaction lines into a scalar or array, then I could test
for the presence of the string "Message accepted for delivery" and if it
can't find it then print out the whole transaction conversation to a log
file and display a simple error message in the browser.

The question is, how do I feed the debug transaction info into a variable? I
tried:

$| = 1;
$stdout = ">&STDOUT";

but that didn't work (as you can probably see, I've never used this STDOUT
thing before ;).

Thanks

Bigus




------------------------------

Date: Thu, 8 May 2003 16:53:36 +0200
From: "Thomas Kratz" <nospam@nospam.de>
Subject: Re: Net::SMTP debug
Message-Id: <3eba7765.0@juno.wiesbaden.netsurf.de>

DQoiQmlndXMiIDxiaWd1cyBBVCBjcmVhdGlvbmZhY3RvciBET1QgbmV0PiB3cm90ZS4uLg0KPiBI
aQ0KPiANCj4gSSd2ZSBiZWVuIGZvbGxvd2luZyBhIHR1dG9yaWFsDQo+IChodHRwOi8vcGVybC5h
Ym91dC5jb20vbGlicmFyeS93Z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thu, 8 May 2003 12:36:11 +1000
From: "Freidrich" <fclack50@yahoo.com>
Subject: Newbie how to split file
Message-Id: <b9dpun$hupgo$1@ID-82947.news.dfncis.de>

Hello,

Pardon my English. new to Perl have not used it

I have file is 28 bytes
and I need to  have text name = 12 bytes char and textnumber = 16bytes
numerics.

Can please tell how to split,
    ($textname, $textnumber) = split(/    /$line)


Freid.




------------------------------

Date: Thu, 08 May 2003 15:10:22 +0200
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Perl code to dump palm datebook?
Message-Id: <3EBA573E.CE904489@fujitsu-siemens.com>

Helgi Briem wrote:
> =

> On Wed, 7 May 2003 20:32:10 +0000 (UTC), joe@jolomo.net
> wrote:
> =

> >Does anyone have some perl code that will take the datebook.dat
> >file from the palm hot-sync and output the entries in a log format
> >something like:
> >
> >  2002 Dec 29 Sun 10:15 DFW -> ATL delta 1119
> >  2003 Jan  9 Thu 14:00 Doctor appt
> >  2003 Jan  9 Thu 16:00 Drinks @ Trader Vics
> >  2003 Jan 12 Sun 13:00 Movie: It Happened One Night
> >
> >ie only print lines for times when there is data. If not from
> >the datebook.dat maybe some other version of palm data (which?)
> >
> >I've looked at pilot-link & the PDB module, but they don't
> >seem to do it.
> =

> What does the databook.dat file look like?
> =

> What have you tried?
> =

> I suggest the concerted use of the Perl
> functions open, die, while*, split, print and close.

Having played around with Palm files myself, it's not that easy. Your
answer also applies to M$ Office files, yet reading Office files still
is a pain in the neck.
For one, you need to know where a record starts and how long it is, how
dates are coded and whether text is compressed.

IIRC Ted T'so has written some software to work on Palm's prc files, so
that might be a start.
Also, there is a module which converts plain text to compressed prc file
format. It's on cpan: Palm::PalmDoc.

Josef
-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


------------------------------

Date: 8 May 2003 07:16:06 -0700
From: Mark.Smith@sonyericsson.com (Mark Smith)
Subject: Recursive copying question
Message-Id: <cf24885e.0305080616.1f8911a1@posting.google.com>

I need to write a Perl program under Windows 2000 that will go through
all the directories from a specified drive or path and copy all files
that meet a preset file extension to a pre-defined path on the same
drive.

Say I have lots of directories on drive D: each several directories
deep and I want to copy all files ending with .txt to the directory
"textfiles" also on drive D:.  Now if a file has already been
encountered and copied to "textfiles" and is encountered again I need
it to only overwrite the file in "textfiles" if the newly discovered
file has a more recent time and date stamp.

Can anyone provide pointers or sample code as I am at a bit of a loss
where to start.  I currently have over 6000 files that meet my file
extension criteria of which about 130 are uniquely named, with the
others being alternate versions from different times and dates.  I
need all the latest versions of the 130+ unique files to end up
residing in my specified directory.

Any help would be appreciated.

Regards,

    Mark


------------------------------

Date: Thu, 8 May 2003 16:31:32 +0200
From: "Thomas Kratz" <nospam@nospam.de>
Subject: Re: Recursive copying question
Message-Id: <3eba7239.0@juno.wiesbaden.netsurf.de>

DQoiTWFyayBTbWl0aCIgPE1hcmsuU21pdGhAc29ueWVyaWNzc29uLmNvbT4gd3JvdGUuLi4NCj4g
SSBuZWVkIHRvIHdyaXRlIGEgUGVybCBwcm9ncmFtIHVuZGVyIFdpbmRvd3MgMjAwMCB0aGF0IHdp
bGwgZ28gdGhyb3VnaA0KPiBhbGwgdGhlIGRpcmVjdG9yaWVzIGZyb20gYSBzcGVjaWZpZWQgZHJp
dmUgb3IgcGF0aCBhbmQgY29weSBhbGwgZmlsZXMNCj4gdGhhdCBtZWV0IGEgcHJlc2V0IGZpbGUg
ZXh0ZW5zaW9uIHRvIGEgcHJlLWRlZmluZWQgcGF0aCBvbiB0aGUgc2FtZQ0KPiBkcml2ZS4NCj4g
DQo+IFNheSBJIGhhdmUgbG90cyBvZiBkaXJlY3RvcmllcyBvbiBkcml2ZSBEOiBlYWNoIHNldmVy
YWwgZGlyZWN0b3JpZXMNCj4gZGVlcCBhbmQgSSB3YW50IHRvIGNvcHkgYWxsIGZpbGVzIGVuZGlu
ZyB3aXRoIC50eHQgdG8gdGhlIGRpcmVjdG9yeQ0KPiAidGV4dG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------------

Date: Thu, 08 May 2003 14:43:17 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Mark.Smith@sonyericsson.com (Mark Smith)
Subject: Re: Recursive copying question
Message-Id: <fc942dbf91a78b091e4631e672573f37@TeraNews>

>>>>> "Mark" == Mark Smith <Mark.Smith@sonyericsson.com> writes:

Mark> I need to write a Perl program under Windows 2000 that will go through
Mark> all the directories from a specified drive or path and copy all files
Mark> that meet a preset file extension to a pre-defined path on the same
Mark> drive.

Mark> Say I have lots of directories on drive D: each several directories
Mark> deep and I want to copy all files ending with .txt to the directory
Mark> "textfiles" also on drive D:.  Now if a file has already been
Mark> encountered and copied to "textfiles" and is encountered again I need
Mark> it to only overwrite the file in "textfiles" if the newly discovered
Mark> file has a more recent time and date stamp.

Mark> Can anyone provide pointers or sample code as I am at a bit of a loss
Mark> where to start.  I currently have over 6000 files that meet my file
Mark> extension criteria of which about 130 are uniquely named, with the
Mark> others being alternate versions from different times and dates.  I
Mark> need all the latest versions of the 130+ unique files to end up
Mark> residing in my specified directory.

I'm writing this using Unix syntax, so hopefully you can adapt to taste:

    use File::Find;
    use File::Copy;

    my $top_src = "drive_d/src";
    my $dest = "drive_d/dest";
    find sub {
      ## ignore non txt files
      return unless -f and /\.txt$/;
      ## don't copy if we already have a later file
      if (-e "$dest/$_" and -M "$dest/$_" <= -M $_) {
        ## tracing: turn off when you're happy
        warn "ignoring older $File::Find::name\n";
        return;
      }
      ## tracing: turn off when you're happy
      warn "copying $File::Find::name to $dest/$_\n";
      copy $_, "$dest/$_";
    }, $top_src;

Untested, but I usually do pretty good on this on the first try. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: 8 May 2003 07:56:12 -0700
From: 00056312@brookes.ac.uk (Stephen Adam)
Subject: Re: Removal or HTML tags from pages
Message-Id: <945bf980.0305080656.497c7228@posting.google.com>

Cheers for the suggestions, 

I will have a look at HTML::Stripper. And I will have a look at using
your suggestion too Abigail.

Thanks again 

Steve  



00056312@brookes.ac.uk (Stephen Adam) wrote in message news:<945bf980.0305070940.5431d0b2@posting.google.com>...
> Hi guys and girls, 
> 
> Just a quickie. I want to remove all tags, scripts etc from WWW pages
> leaving just the text a user would see and maybe parsing some of the
> meta content tags, I know the perl cook book has some thing on it (I
> may have to buy the book) though I am thinking the "HTML::Parser"
> module would be my best bet.
> 
> Does anyone know were I can find a good tutorial on the "HTML::Parser"
> module?
> 
> Thanks for your help in advance, any comments and advice would be
> great, cheers.
> 
> Steve


------------------------------

Date: 8 May 2003 06:22:04 -0700
From: Joe_Blakistone@performanceretail.com (Joe B)
Subject: Using Net::Ping in cgi script
Message-Id: <b7cae375.0305080522.3ca4f96b@posting.google.com>

I am getting the following error when trying to run my cgi script. 
Any constructive help would be appreciated.

172.30.19.100
Can't udp protocol by name at
D:\OracleDS\j2ee\home\default-web-app\ping.pl line 32

Here is a copy of my script (the lookup file server.txt just has a
list of IPs on my network).  I have verified that the script will
compile from the command line using the perl -c command.-

#Name - ping.pl
use strict;
use Net::Ping;

my $time = localtime();
my $lookupFile = 'server.txt';
my $host;
my $p;
my $proto;
my $timeout ="1";
my $i;
my $down;

print "content-type: text/html\n\n";

open (LOOKUPFILE,"<$lookupFile") or die "Fatal Error: Unable to open
lookup file $lookupFile";
while (<LOOKUPFILE>) {
	chomp;
	if (/^#/) {do nothing}
	else {
		($host) =  $_;
		$p = Net::Ping->new($proto,$timeout);
		$down = 1;
		for($i=0; $i<3; $i++){
		  if($p->ping($host)){
			$down = 0;
			last;
		  }
             }
		$p->close();
		
	      if ($down) {
              print "<h1>$host cannot be pinged</h1>";
		}	
	
	}
}
close (LOOKUPFILE);


------------------------------

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.  

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 4958
***************************************


home help back first fref pref prev next nref lref last post