[19084] in Perl-Users-Digest
Perl-Users Digest, Issue: 1279 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 11 03:47:03 2001
Date: Wed, 11 Jul 2001 00:46:41 -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: <994837601-v10-i1279@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 11 Jul 2001 Volume: 10 Number: 1279
Today's topics:
problems with Apache and DBI (Oracle) <czajko@ocas.on.ca>
Problems with GetHostByName and getting URL addresses <jeremyalansmith@netscapeonline.co.uk>
Re: Problems with GetHostByName and getting URL address (Eric Bohlman)
Re: Problems with GetHostByName and getting URL address (Rafael Garcia-Suarez)
Re: Problems with GetHostByName and getting URL address <jeremyalansmith@netscapeonline.co.uk>
Re: Problems with GetHostByName and getting URL address <pne-news-20010710@newton.digitalspace.net>
Production ready solution for Linux/mod_perl/DBI to M$ <cb@onsitetech.com>
Re: Production ready solution for Linux/mod_perl/DBI to <cpryce@pryce.net>
Reading file backwards <shino_korah@yahoo.com>
Re: Reading file backwards (Brian Pontz)
Re: Reading file backwards (Tony L. Svanstrom)
reading numbers across platforms (Steve Miller)
Re: reading numbers across platforms <dbe@wgn.net>
Re: reading numbers across platforms <gnarinn@hotmail.com>
Re: reading numbers across platforms (Steve Miller)
Re: referencing methods nobull@mail.com
Re: referencing methods <iltzu@sci.invalid>
Re: Regex problem: Multiple matches across Multiple lin <hillr@ugs.com>
Re: Regex problem: Multiple matches across Multiple lin <hillr@ugs.com>
Re: REGEX <goldbb2@earthlink.net>
regular expression ??? <eric138@yahoo.com>
Re: regular expression ??? <pne-news-20010710@newton.digitalspace.net>
Re: regular expression ??? rik@tidi.be
Re: regular expression ??? <pne-news-20010710@newton.digitalspace.net>
Removing tags from an HTML file. <scott@remove.generator.co.za>
Re: Removing tags from an HTML file. <pne-news-20010710@newton.digitalspace.net>
Re: Removing tags from an HTML file. <laszlo.gerencser@portologic.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Jul 2001 19:33:30 GMT
From: "Daniel Czajko" <czajko@ocas.on.ca>
Subject: problems with Apache and DBI (Oracle)
Message-Id: <GG9vuC.15D5@alfalfa.utcs.utoronto.ca>
I'm trying to run some Perl scripts that connect to an Oracle Database and
output the information onto an HTML page running on Apache. I can fetch the
information from the database via DBI and display it at command line, but I
don't seem to be able direct the output onto an HTML page. Does anybody
know of any issues between Apache and DBI (Oracle)? I wish I could provide
some output errors but there are none, the html page just won't appear.
Any help is appreciated
------------------------------
Date: Tue, 10 Jul 2001 10:57:49 +0100
From: "jeremyalansmith" <jeremyalansmith@netscapeonline.co.uk>
Subject: Problems with GetHostByName and getting URL addresses
Message-Id: <4iA27.13413$WS4.2088394@news6-win.server.ntlworld.com>
Hi everyone!
I'm writing a small web browser as an exercise in web programming.
I use gethostbyname() and create an object "host", the address of which is
returned in host.h_addr, which I put in a 32-bit number, and then open with
"GET \ HTTP 1.0".
I have a problem with some websites...
If I connect to http://teenguide.bla-bla.com (a website of mine),
gethostbyname() returns 216.105.165.65. This is a dead page. I noticed I get
the same host address (216.105.165.65) if I Ping the website.
I'm confused! And searching on the web, it's very hard to find information
on this.
So if anyone knows more about HTTP and browsers than me, I'd appreciate
knowing about this. It's a pain having a browser that won't work with most
of the pages I go to with it!
Just to clarify: I want to know which function or protocol (data sent) to
get me the working (ie, as you see the page in Netscape) IP address of
http://teenguide.bla-bla.com - once I know this, I'm sure the other websites
will work with this method too.
I have tried using SocketSpy in Windows to look at what Netscape does, but
it's unregistered, so it doesn't display all the strings...
Cheers,
Jeremy.
------------------------------
Date: 10 Jul 2001 10:42:51 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Problems with GetHostByName and getting URL addresses
Message-Id: <9iem7b$2g0$3@bob.news.rcn.net>
jeremyalansmith <jeremyalansmith@netscapeonline.co.uk> wrote:
> If I connect to http://teenguide.bla-bla.com (a website of mine),
> gethostbyname() returns 216.105.165.65. This is a dead page. I noticed I get
> the same host address (216.105.165.65) if I Ping the website.
My guess is that teenguide.bla-bla.com is a name-based virtual host,
meaning that it shares its IP with any number of second-level domains.
You need to make sure to send a Host: header whenever you make an HTTP
request to it.
------------------------------
Date: 10 Jul 2001 11:05:27 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Problems with GetHostByName and getting URL addresses
Message-Id: <slrn9klocf.7mj.rgarciasuarez@rafael.kazibao.net>
Eric Bohlman wrote in comp.lang.perl.misc:
} jeremyalansmith <jeremyalansmith@netscapeonline.co.uk> wrote:
} > If I connect to http://teenguide.bla-bla.com (a website of mine),
} > gethostbyname() returns 216.105.165.65. This is a dead page. I noticed I get
} > the same host address (216.105.165.65) if I Ping the website.
}
} My guess is that teenguide.bla-bla.com is a name-based virtual host,
} meaning that it shares its IP with any number of second-level domains.
} You need to make sure to send a Host: header whenever you make an HTTP
} request to it.
A header that is automatically sent by the LWP library.
To the OP : even if you want to write your own implementation, it may be
a good idea to look at the code of other software to get clues about how
things are done. Also, look at the RFCs, the definitive references for
the internel protocols, esp. HTTP (http://www.rfc-editor.org/).
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Tue, 10 Jul 2001 20:33:58 +0100
From: "jeremyalansmith" <jeremyalansmith@netscapeonline.co.uk>
Subject: Re: Problems with GetHostByName and getting URL addresses
Message-Id: <fKI27.22350$B56.3974268@news2-win.server.ntlworld.com>
"Rafael Garcia-Suarez" <rgarciasuarez@free.fr> wrote in message
news:slrn9klocf.7mj.rgarciasuarez@rafael.kazibao.net...
> Eric Bohlman wrote in comp.lang.perl.misc:
> } jeremyalansmith <jeremyalansmith@netscapeonline.co.uk> wrote:
> } > If I connect to http://teenguide.bla-bla.com (a website of mine),
> } > gethostbyname() returns 216.105.165.65. This is a dead page. I noticed
I get
> } > the same host address (216.105.165.65) if I Ping the website.
> }
> } My guess is that teenguide.bla-bla.com is a name-based virtual host,
> } meaning that it shares its IP with any number of second-level domains.
> } You need to make sure to send a Host: header whenever you make an HTTP
> } request to it.
>
> A header that is automatically sent by the LWP library.
>
> To the OP : even if you want to write your own implementation, it may be
> a good idea to look at the code of other software to get clues about how
> things are done. Also, look at the RFCs, the definitive references for
> the internel protocols, esp. HTTP (http://www.rfc-editor.org/).
Hi! Many thanks, I dug around on the web about the Host: header.
There was one bug, I didn't put a "/" in HTTP/1.0 (it said 'HTTP 1.0' with a
space, thanks to a poor tutorial I followed). After this, I changed it to
HTTP/1.1, and added the Host: line, so the final string being sent (to
server http://teenguide.bla-bla.com, port 80) looks like this (the single
slash after GET refers to the base page, index.htm or .html)
GET / HTTP/1.1\r\n
Host: teenguide.bla-bla.com:80\r\n\r\n (2 \r\n's are essential to end an
HTTP request, as I found out)
I received:
HTTP/1.1 200 OK
Date: Tue, 10 Jul 2001 19:19:27 GMT
Server: Apache/1.3.12 (Unix) PHP/4.0.2
Content-Type: text/html
Age: 323
Connection: close
Via: HTTP/1.1 hud (Traffic-Server/3.0.3FCS [uScMsSf pSeN:t cCMi p sS])
Followed by the document.
This worked like a dream, the index page scrolling up in all its glory. Now
I just have to parse the incoming header that comes before the document, but
that should be pretty simple.
Thanks again all! Problem solved.
Thanks too for the RFC page, I'll check it out and it should come in handy.
Regards,
Jeremy.
------------------------------
Date: Tue, 10 Jul 2001 21:59:07 +0200
From: Philip Newton <pne-news-20010710@newton.digitalspace.net>
Subject: Re: Problems with GetHostByName and getting URL addresses
Message-Id: <2gnmkt8r39s6cuqusmaqis57iioafqf20c@4ax.com>
On Tue, 10 Jul 2001 20:33:58 +0100, "jeremyalansmith"
<jeremyalansmith@netscapeonline.co.uk> wrote:
> This worked like a dream, the index page scrolling up in all its glory. Now
> I just have to parse the incoming header that comes before the document, but
> that should be pretty simple.
If you use LWP, I think it puts the header in an HTTP::Header object
that allows easy access to each header.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 10 Jul 2001 16:05:40 GMT
From: "Christian Brink" <cb@onsitetech.com>
Subject: Production ready solution for Linux/mod_perl/DBI to M$ SQLServer
Message-Id: <9if94k$376@dispatch.concentric.net>
According to the DBI_DBD FAQ (
tlowery.hypermart.net/perl_dbi_dbd_faq.html) there are 3 solutions to the
Linux/mod_perl/DBI to M$ SQLServer.
The 3 solutions stated are:
1. DBI::Proxy - comments I have seen "terribly slow, and breaks all the
time"
2. OpenLinks - seems somewhat pricey but will do if it is the only solution
that works
3. unixODBC - Have not seen much about it other than the home site.
I have 3 questions if anyone is willing to offer an opinion.
1. Which of these solutions has anyone used, they all seem fairly new?
2. How did it perform?
3. Is DBD::ADO an option?
TIA
Christian Brink
cb@onsitetech.com
------------------------------
Date: Tue, 10 Jul 2001 12:25:45 -0500
From: cp <cpryce@pryce.net>
Subject: Re: Production ready solution for Linux/mod_perl/DBI to M$ SQLServer
Message-Id: <B770A4C9.82FF%cpryce@pryce.net>
in article 9if94k$376@dispatch.concentric.net, Christian Brink at
cb@onsitetech.com wrote on 07/10/2001 11:05 AM:
> 1. DBI::Proxy - comments I have seen "terribly slow, and breaks all the
> time"
> 2. OpenLinks - seems somewhat pricey but will do if it is the only solution
> that works
> 3. unixODBC - Have not seen much about it other than the home site.
>
> I have 3 questions if anyone is willing to offer an opinion.
> 1. Which of these solutions has anyone used, they all seem fairly new?
> 2. How did it perform?
> 3. Is DBD::ADO an option?
>
> TIA
I've tested (but not benchmarked against other, similar solutions) a product
from easysoft, based on the unixODBC software. It is similar in price to the
OpenLinks software, but there is a free one connection license. Since we use
it as a backend to our intranet server, it works. http://www.easysoft.com
cp
------------------------------
Date: Mon, 9 Jul 2001 11:29:41 -0700
From: "terminalsplash" <shino_korah@yahoo.com>
Subject: Reading file backwards
Message-Id: <9ict6m$jut@news.or.intel.com>
Hi
I have a file (huge). I want to find pattern which occurs last. So I guess
if I can read the file from the end it will be fine.
How to do it?
My line lengths are not same
Thanks
------------------------------
Date: Mon, 09 Jul 2001 18:58:20 GMT
From: pontz@NO_SPAMchannel1.com (Brian Pontz)
Subject: Re: Reading file backwards
Message-Id: <3b49fe14.7539595@news.ne.mediaone.net>
>I have a file (huge). I want to find pattern which occurs last. So I guess
>if I can read the file from the end it will be fine.
>How to do it?
Use Uri's
File::ReadBackwards
module. Download it at
http://www.cpan.org/authors/id/U/UR/URI/File-ReadBackwards-0.94.tar.gz
>My line lengths are not same
Doesnt matter
>Thanks
Welcome :-)
Brian
------------------------------
Date: Mon, 09 Jul 2001 22:48:02 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Reading file backwards
Message-Id: <1ewb0ve.vv4bhp1wnta9sN%tony@svanstrom.com>
terminalsplash <shino_korah@yahoo.com> wrote:
> I have a file (huge). I want to find pattern which occurs last. So I guess
> if I can read the file from the end it will be fine.
> How to do it?
> My line lengths are not same
Search this NG for information regarding that, I think googles NG-stuff
is up and running...
/Tony
--
the truth is dead, faith is gone, reality killed... ruled by the plastic
laws of modern life we're pushed towards the hell of personal doubt,
betrayal, hate, lust and murder... the now has become an illusion, a
paradise of a dead tomorrow... (c)2000-2001 tony@svanstrom.com
------------------------------
Date: 9 Jul 2001 14:23:50 -0700
From: steveaux@my-deja.com (Steve Miller)
Subject: reading numbers across platforms
Message-Id: <12db7b5d.0107091323.712e39f0@posting.google.com>
Hi!
I regularly use the following script to read a numeric value from a
binary file and then use that number to strip the header (whose length
I am reading) from the file. It works perfectly in Linux, but I can't
get either method in the script to work under Windoze. Anybody have
anything else I can try? I need to get this working on NT and 98.
Thanks!
Steve Miller
***
#!/usr/local/bin/perl -w
open(INPUT, "$ARGV[0]") || die "cannot open $ARGV[0]: $!";
open(OUTPUT, ">$ARGV[1]") || die "cannot open $ARGV[1]: $!";
binmode INPUT;
read(INPUT, $header_length_bin, 4);
$header_length = unpack("N", $header_length_bin);
# Note: If that doesn't work, try:
# $header_length = unpack("V", $header);
#What 'unpack' is doing is changing the binary info in
$header_length_bin
#to an actual number. N and V are 2 possible formats for that number.
seek (INPUT, $header_length, 1);
while ($size = read(INPUT, $info, 16384)) {
syswrite (OUTPUT, $info, $size);
}
------------------------------
Date: Mon, 09 Jul 2001 14:51:48 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: reading numbers across platforms
Message-Id: <3B4A2774.DD785F6C@wgn.net>
Steve Miller wrote:
>
> Hi!
>
> I regularly use the following script to read a numeric value from a
> binary file and then use that number to strip the header (whose length
> I am reading) from the file. It works perfectly in Linux, but I can't
> get either method in the script to work under Windoze. Anybody have
> anything else I can try? I need to get this working on NT and 98.
>
> Thanks!
>
> Steve Miller
>
> ***
>
> #!/usr/local/bin/perl -w
>
> open(INPUT, "$ARGV[0]") || die "cannot open $ARGV[0]: $!";
> open(OUTPUT, ">$ARGV[1]") || die "cannot open $ARGV[1]: $!";
>
> binmode INPUT;
> read(INPUT, $header_length_bin, 4);
> $header_length = unpack("N", $header_length_bin);
>
> # Note: If that doesn't work, try:
> # $header_length = unpack("V", $header);
>
> #What 'unpack' is doing is changing the binary info in
> $header_length_bin
> #to an actual number. N and V are 2 possible formats for that number.
>
> seek (INPUT, $header_length, 1);
>
> while ($size = read(INPUT, $info, 16384)) {
> syswrite (OUTPUT, $info, $size);
> }
Try dumping the first 4 chars from the file and see what they are.
Also dump the value you are getting after the unpack and see if
they differ. Then you should be able to determine what's wrong
with the byte ordering. Here's a dump routine of mine you can use:
# dump a variable in hex/ASCII (def to STDERR)
sub dumpit { # &dumpit (<var>[, *FH]);
my $buf = shift;
my $fh = *STDERR;
$fh = shift if @_;
for (my $ii = 0; $ii < length ($buf); $ii += 16) {
printf $fh "%04x ", $ii;
my $len = length ($buf) - $ii;
$len = 16 if $len > 16;
my $buffer = substr ($buf, $ii, 16);
print $fh map { sprintf "%02x ", $_; } unpack 'C8', $buffer;
print $fh ' ';
print $fh map { sprintf "%02x ", $_; } unpack 'C*',
substr ($buffer, 8, 8) if length $buffer > 8;
print $fh ' ' . ' ' x (16 - $len);
for (my $jj = 0; $jj < $len; $jj++) {
my $ch = substr $buffer, $jj, 1;
if ((ord $ch) >= 32 && (ord $ch) < 0x7f) {
print $fh $ch;
} else {
print $fh '.';
}
}
print $fh "\n";
}
}
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Tue, 10 Jul 2001 09:18:55 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: reading numbers across platforms
Message-Id: <994756735.805927324108779.gnarinn@hotmail.com>
In article <12db7b5d.0107091323.712e39f0@posting.google.com>,
Steve Miller <steveaux@my-deja.com> wrote:
>
>I regularly use the following script to read a numeric value from a
>binary file and then use that number to strip the header (whose length
>I am reading) from the file. It works perfectly in Linux, but I can't
>get either method in the script to work under Windoze. Anybody have
>anything else I can try? I need to get this working on NT and 98.
>
(snipped script)
in what way dows it 'not work'?
why binmode on input but not output?
gnari
------------------------------
Date: 10 Jul 2001 09:40:12 -0700
From: steveaux@my-deja.com (Steve Miller)
Subject: Re: reading numbers across platforms
Message-Id: <12db7b5d.0107100840.426cb2ca@posting.google.com>
> (snipped script)
>
> in what way dows it 'not work'?
>
> why binmode on input but not output?
>
> gnari
Cool! I just added "binmode OUTPUT;" and that seems to have solved the
problem. My output files were coming out larger than my input files.
Now I get the same results as I had been in Linux.
Thanks to everyone who answered. I just now got to look at the problem
again.
Steve
------------------------------
Date: 09 Jul 2001 18:04:39 +0100
From: nobull@mail.com
Subject: Re: referencing methods
Message-Id: <u9d77a9gpk.fsf@wcl-l.bham.ac.uk>
Skycrawler <thomasalbrightREMOVE@home.com> writes:
> I know that to reference a subroutine use:
>
> $code_ref = \&sub
>
> But how do I reference a method in a class such as:
>
> $class->sub()
See FAQ: "How can I pass/return a {Function, FileHandle, Array, Hash,
Method, Regex}?"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 9 Jul 2001 23:21:58 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: referencing methods
Message-Id: <994719231.7416@itz.pp.sci.fi>
In article <9ib1ke$qvk$1@bob.news.rcn.net>, Eric Bohlman wrote:
>Skycrawler <thomasalbrightREMOVE@home.com> wrote:
>> I know that to reference a subroutine use:
>
>> $code_ref = \&sub
>
>> But how do I reference a method in a class such as:
>
>> $class->sub()
>
>$code_ref = $class->can('sub');
Note that, to call the method, you'll have to pass $class explicitly:
$code_ref->($class, @other_params);
To get a subroutine you can call without explictly passing $class, you'd
have to construct a closure. The simplest way to do that is by writing
a function for it:
sub method_ref {
my ($pkg, $meth) = @_;
return sub { $pkg->$meth(@_) };
}
$closure = method_ref($class, 'sub');
$closure->(@other_params);
The subroutine just happens to provide a suitable scope for $pkg and
$meth, so that the closure will work as expected. As written above, the
actual method lookup won't happen until the closure is called. If you
want it to happen before the closure is created, try this instead:
sub method_ref {
my $pkg = shift;
my $sub = $pkg->can(shift);
return $sub && sub { $sub->($pkg, @_) };
}
In fact, one could get *really* clever and define the above subroutine
in the UNIVERSAL package. Then one could call it like this:
$closure = $class->method_ref('sub');
I don't think I'd do that in production code, though..
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post something,
we discuss its implications. If the discussion happens to answer a question
you've asked, that's incidental." -- nobull in comp.lang.perl.misc
------------------------------
Date: Tue, 10 Jul 2001 06:07:34 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: Regex problem: Multiple matches across Multiple lines
Message-Id: <3B4AFE16.E6864960@ugs.com>
Ren Maddox wrote:
> When I need to parse data such as this, and there is sufficient
> context for each element of the match such that the overall format is
> unimportant, I end up matching the individual pieces separately. Here
> is what I would use for this case:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my %fields = (Product => qr/^PRODUCT:\s*(.*)$/m,
> Subject => qr/^SUBJECT:\s*(.*)$/m,
> Submitter => qr/^SUBMITTED\s+BY:\s*(.*?)\s*SUBMITTED/m,
> Submitted => qr/SUBMITTED\s+DATE:\s*(.*)$/m,
> IR => qr/^IR\s*#:\s*(.*?)\s*DOCUMENT/m,
> DocID => qr/DOCUMENT\s+ID:\s*(.*)$/m,
> Platform => qr/^PLATFORM:\s*(.*?)\s*OPERATING/m,
> OS => qr/OPERATING\s+SYSTEM:\s*(.*)$/m,
> OSVer => qr/^OS\s+VERSION:\s*(.*?)\s*UG\s+VERSION/m,
> UGVer => qr/UG\s+VERSION:\s*(.*)$/m,
> Hardware => qr/^HARDWARE.*\n((?:.*\n)*?)SYMPTOM/m,
> Symptom => qr/^SYMPTOM.*\n((?:.*\n)*?)SOLUTION/m,
> Solution => qr/^SOLUTION.*\n((?:.*\n)*?)REFERENCE/m,
> Reference => qr/^REFERENCE.*\n(.*)/ms);
>
> $_ = do { local $/; <DATA> }; # slurp
>
> my %data;
> for my $field (keys %fields) {
> ($data{$field}) = /$fields{$field}/
> or die "Problem matching $field in $_\n";
> }
>
> # Now %data is populated, use it however desired.
>
> __DATA__
> There was too much data, so I snipped it from this post....
> __END__
>
> That's a first pass at it (tested), but there are some things I would
> probably change. For example, the multi-line fields have separators
> in the data that I would probably skip.
>
> --
thanks for the help
Ron
------------------------------
Date: Tue, 10 Jul 2001 06:08:31 -0700
From: Ron Hill <hillr@ugs.com>
Subject: Re: Regex problem: Multiple matches across Multiple lines
Message-Id: <3B4AFE4F.48A6F16B@ugs.com>
Benjamin Goldberg wrote:
>
>
> What's the point in doing a while, when there's only going to be one
> value? After all, EOF generally only occurs once per stream.
>
> local $_ = do { local $/; <DATA>; };
>
> This causes $/ to be undef for the minimal time necessary, and sets it
> back to the default afterwards (and sticks <DATA> in $_, but that should
> be obvious). Also, remember that it's usually a good idea to make $_
> local, rather than just assigning to it, for various and sundry reasons.
>
> > /
>
> You really ought to use an explicit m for match, and some character
> other than /, except in fairly short regexs. If there's no / characters
> in your pattern, it's ok, I guess, but [] often improve readability.
>
>
>
Thanks for the help!!
Ron
------------------------------
Date: Mon, 09 Jul 2001 12:01:42 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: REGEX
Message-Id: <3B49D566.9492B2F4@earthlink.net>
> According to Philip M. Gollucci <philip@p6m7g8.student.umd.edu>:
> > Suppose I'm doing lexical-like scanning on a Java like file.
> >
> > I want to match
> >
> > STR
> > A string is a sequence of characters beginning and ending with a
> > double-quote mark ("). Any character except newline may appear
> > inside string. A double-quote mark can be represented inside a
> > string by escaping (preceding) it by a backslash (\); for example:
> > "I said, \"Hello!\"\n" is a string containing two double-quote
> > marks. Note that \n is used to represent the newline inside the
> > string, but it is not the newline character itself. Obviously, a
> > double-quote that immediately follows a backslash cannot be used to
> > terminate a string.
What happens with backslashes which don't precede quotes?
Personally, I would do kind of string matching as:
my %escape = ("\n" => "", n => "\n" );
if( m[\G"((?:\\.|[^\\])*)"]gs ) {
(my $str = $1) =~ s
[\\(.)]
[exists $escape{$1} ? $escape{$1} : $1]egs;
print "STR = $str\n";
}
Slghtly more complicated things need to be done if you want to have
multibyte escapes, like \x?? for hex values, etc.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 10 Jul 2001 16:06:15 +0800
From: "Eric Chow" <eric138@yahoo.com>
Subject: regular expression ???
Message-Id: <9iecja$lpi22@ctmsun0.macau.ctm.net>
Hello,
Would you please to teach me how I can compare two string to test if they
are equals or not by using regular expression ?
The two string may not be considered their space or capital letter at every
separated word.
Best regards,
Eric
------------------------------
Date: Tue, 10 Jul 2001 11:07:49 +0200
From: Philip Newton <pne-news-20010710@newton.digitalspace.net>
Subject: Re: regular expression ???
Message-Id: <7chlktc3brsiu77gl2g90o8h078p3s6avs@4ax.com>
On Tue, 10 Jul 2001 16:06:15 +0800, "Eric Chow" <eric138@yahoo.com>
wrote:
> Would you please to teach me how I can compare two string to test if they
> are equals or not by using regular expression ?
You don't need a regular expression to test string equality. Just use
'eq'. Example:
if($sometext eq $othertext) { ... }
> The two string may not be considered their space or capital letter at every
> separated word.
I'm not sure what this means. Can you say it another way, please?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 10 Jul 2001 13:13:29 +0200
From: rik@tidi.be
Subject: Re: regular expression ???
Message-Id: <3B4AE359.54D6CAED@tidi.be>
#!/usr/bin/perl -w
$a = "abc123C"
if ($a =~ /abc/) {
print "<br> \$a contains abc!";
}
if ($a =~ /^abc/) {
print "<br> \$a begins with abc!";
}
if ($a =~ /abc$/) {
print "<br> \$a ends with abc!";
}
if ($a =~ /^ abc$/) {
print "<br> \$a equals abc!";
}
if ($a =~ /^ abc$/i) {
print "<br> \$a equals abc or ABC, etc...!";
}
regards,
rik
Eric Chow wrote:
> Hello,
>
> Would you please to teach me how I can compare two string to test if they
> are equals or not by using regular expression ?
>
> The two string may not be considered their space or capital letter at every
> separated word.
>
> Best regards,
> Eric
------------------------------
Date: Tue, 10 Jul 2001 21:20:00 +0200
From: Philip Newton <pne-news-20010710@newton.digitalspace.net>
Subject: Re: regular expression ???
Message-Id: <6kkmktsvjjrse9n8giurpripu9b57um87h@4ax.com>
On Tue, 10 Jul 2001 13:13:29 +0200, rik@tidi.be wrote:
> #!/usr/bin/perl -w
> $a = "abc123C"
> if ($a =~ /abc/) {
> print "<br> \$a contains abc!";
^^^^
What's that for? (And don't say "it's to make a line break", because
that sounds as if you want to write a CGI script -- but if you wanted to
do that, you'd need to output a content-type header, and then you might
as well say 'text/plain'.)
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 10 Jul 2001 10:59:12 +0200
From: "scotth" <scott@remove.generator.co.za>
Subject: Removing tags from an HTML file.
Message-Id: <3b4ac459$0$227@hades.is.co.za>
Hi All.
Could anyone out there please advise me on how to remove all markup and
scripting from an HTML file
I want to remove all HTML tags, JavaScript, embedded PHP code etc, and only
have the meaningful content left.
My PERL knowledge is very limited, but am I correct in assuming that it
would involve using the s/ operator?
I have had a look around on the web, and I could only find this
$_=~s/<\?([^>])*\?>/ /gs;
which seems to work great for HTML tags, but I am still left with
<script><!-- --></script> and <? ?> and everything in between.
All advice is welcomed!
Thanks in advance.
--
Scott Houseman
Software Developer/Systems Administrator
tel +27 21 425 9710
fax +27 21 425 9713
GENERATOR COMMUNICATIONS | BE AN ISLAND
------------------------------
Date: Tue, 10 Jul 2001 11:17:07 +0200
From: Philip Newton <pne-news-20010710@newton.digitalspace.net>
Subject: Re: Removing tags from an HTML file.
Message-Id: <unhlktk2cg91clb2f77baamfpm71ose5hk@4ax.com>
On Tue, 10 Jul 2001 10:59:12 +0200, "scotth"
<scott@remove.generator.co.za> wrote:
> Could anyone out there please advise me on how to remove all markup and
> scripting from an HTML file
Probably best to use an HTML parser such as HTML::Parser or
HTML::TokeParser and only print out the text.
Note that those modules expect HTML, not text containing HTML and
PHP/ASP/ColdFusion/Vignette/... directives combined. So if you have
<%...%> or <?...?> or [...] or whatever in your code and want those
filtered out, you probably cannot use those modules.
> My PERL knowledge is very limited, but am I correct in assuming that it
> would involve using the s/ operator?
No. Using regular expressions to parse HTML is, in general, not a good
idea. Better to use parser than to have to code lots of little
exceptions.
> I have had a look around on the web, and I could only find this
> $_=~s/<\?([^>])*\?>/ /gs;
> which seems to work great for HTML tags
That only filters out tags like <? blabla ?> and not tags like <p> or
</strong>. And if you leave out the question marks, you'll have trouble
with stuff like <img src="equation.gif" alt="a > b"> since this simple
regular expression will think the '>' in the string 'a > b' terminates
the tag.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 10 Jul 2001 09:24:15 GMT
From: Laszlo Gerencser <laszlo.gerencser@portologic.com>
Subject: Re: Removing tags from an HTML file.
Message-Id: <3B4AC9F9.D2DFD9F9@portologic.com>
scotth wrote:
>
> Hi All.
> Could anyone out there please advise me on how to remove all markup and
> scripting from an HTML file
> I want to remove all HTML tags, JavaScript, embedded PHP code etc, and only
> have the meaningful content left.
I'm sure there is at least one module on CPAN that does this for you.
> My PERL knowledge is very limited, but am I correct in assuming that it
> would involve using the s/ operator?
> I have had a look around on the web, and I could only find this
> $_=~s/<\?([^>])*\?>/ /gs;
> which seems to work great for HTML tags, but I am still left with
Hmm... what about this:
$_ =~ s/<([^>])*>//gs;
Your example is better for PHP code I think...
> but I am still left with
> <script><!-- --></script> and <? ?> and everything in between.
Do it with separate regexps.
Example (untested!):
#Cutting out PHP code
$_ =~ s/<\?.*?\?>//gs;
$_ =~ s/<\&.*?\&>//gs;
#Cutting out SSI code
$_ =~ s/<\-\-\#.*?\-\->//gs;
#Cutting out SCRIPT code
$_ =~ s/<script.*?>.*?<\/script.*?>//gsi;
And so on...
> All advice is welcomed!
Do yourselves. It's fun! :-))
> Thanks in advance.
You are welcome
--
Laszlo Gerencser
PortoLogic Ltd.
------------------------------
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 1279
***************************************