[23335] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5555 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 24 14:06:03 2003

Date: Wed, 24 Sep 2003 11:05:15 -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           Wed, 24 Sep 2003     Volume: 10 Number: 5555

Today's topics:
    Re: class methods <mpapec@yahoo.com>
    Re: class methods <mpapec@yahoo.com>
    Re: class methods <mpapec@yahoo.com>
    Re: cron/http absolute directories (Anno Siegel)
    Re: cron/http absolute directories <no.name@eidosnet.co.uk>
        Example of tk::HTML??? <ama@PW.CA>
    Re: Fetching ActiveState PPD files without Installing t <Graham.T.Wood@oracle.com>
    Re: new to perl <shondell@cis.ohio-state.edu>
    Re: new to perl <peter@semantico.com>
    Re: new to perl (Jon Bell)
    Re: new to perl <syscjm@gwu.edu>
    Re: new to perl <REMOVEsdnCAPS@comcast.net>
        Newbie: form checkboxes & param <nadine@mail.sdsu.edu>
    Re: PPM problems <x12code-del@del-yahoo.com>
    Re: Q: File contents substitution (Anno Siegel)
    Re: Q: File contents substitution <abuse@microsoft.com>
    Re: Q: File contents substitution (Helgi Briem)
    Re: Q: File contents substitution (Anno Siegel)
    Re: Q: File contents substitution <abuse@microsoft.com>
        Q: RegEx - string substitution <abuse@microsoft.com>
    Re: Q: RegEx - string substitution <xx087@freenet.carleton.ca>
    Re: Q: RegEx - string substitution <syscjm@gwu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 24 Sep 2003 18:55:36 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: class methods
Message-Id: <t8h3nvo7k5desnfdb460u1b1pu23ieg2bf@4ax.com>

X-Ftn-To: Jeff 'japhy' Pinyan 

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
>I assume you mean that you have code like so:
>  package Foo;
>  sub this {
>    ...
>  }
>  sub that {
>    this(...);
>  }
>and
>  package Bar;
>  Foo->this(...);

Yes.

>I would suggest that you NOT call a METHOD as a FUNCTION.  But if you are

So what to do instead, 

  package Foo;
  sub this {
    ...
  }
  sub that {
    $self->this(...);
  }
  package Bar;
  $object->this(...); #is Foo->this() also fine?

?

>"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
> years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
> Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

Sure, and the crowd looked like plain English citizens. ;)


-- 
Matija


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

Date: Wed, 24 Sep 2003 18:55:37 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: class methods
Message-Id: <vih3nv4mci3svq71bvja3rjes5bbmcejp3@4ax.com>

X-Ftn-To: Kevin Michael Vail 

Kevin Michael Vail <kevin@vaildc.net> wrote:
>What do you mean by inside and outside the package?  Are you saying that 
>you want to call it as Foo->bar() from outside the package, and just as 
>bar() from within the package?

Yes.
>  I don't think you actually should do 
>that, because that makes it impossible for anyone to override bar() if 
>they create a subclass of your class.
>
>If you can throw the first argument away, as what you've written above 
>suggests, then I would just always call it as a method.  If you're 
>calling it from inside the package, just use the $self (or $this) 
>pointer you've got from the method you're in.  That way inheritance 
>works properly.

So basicaly it would be safest to call Foo()
$self->Foo(); within the package, and
SomeClass->Foo(); from other packages?



-- 
Matija


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

Date: Wed, 24 Sep 2003 18:55:38 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: class methods
Message-Id: <mvh3nvcihpkfi4u735bbf4105ht8v11b1f@4ax.com>

X-Ftn-To: Tore Aursand 

Tore Aursand <tore@aursand.no> wrote:
>> I have situation where /class method/ can be called inside and outside of
>> package so I have to know when to throw away the first argument.
>
>What do you mean, actually?  Do you want to call the call a method's class
>as a function, as in 'MyClass->Foo()'?

Yes.

>Seems like bad behaviour in my eyes, but then again I've never used
>anything else than this syntax:
>
>  my $MyObject = MyClass->new();
>  $MyObject->foo();

Even in cases when method isn't directly manipulating $MyObject but
impacting a whole class?

>Inside MyClass there's magic hand waving (well, not reall);
>
>  sub foo {
>      my $self = shift;
>      $self->bar();
>  }
>
>  sub bar {
>      my $self = shift;
>      # dada
>  }
>
>Am I out of scope here? :-)

I think you're fine. :)


-- 
Matija


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

Date: 24 Sep 2003 16:17:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: cron/http absolute directories
Message-Id: <bksg3g$qrd$1@mamenchi.zrz.TU-Berlin.DE>

D Borland <no.name@eidosnet.co.uk> wrote in comp.lang.perl.misc:
> Well i cannot see anything wrong with my posting, it's never been moaned
> about before in the 14 years i've been on the internet - So frankly i don't

Usenet != Internet

> care anymore, put me in your killfile if you want, as i think that anyone
> who is childish enough to react like that over something so trivial is
> pathetic so i don't think your replies would be of any use to me anyhow.

Your choice.  I have explained these things to you with quite some patience
because I thought you were a promising poster.  I was wrong.

Personally, I don't use killfiles.  I'll remember this exchange without
one.

> That and the fact i can't see anything wrong with the way i post, it's the
> same as everyone else, everywhere else.  But then again you alsways do have
> the 'spoilt kid or the lick' trying to spoil anything anyone ever does.

It seems to be you who is applying for the part of "spoiled brat".

> Some people should have never been givin the right to life.

Heavens!  Who, did you say, was over-reacting?

Oh, and your spelling suffers when you are upset.  Try a checker.

Anno

[more TOFU snipped]


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

Date: Wed, 24 Sep 2003 16:34:44 +0000 (UTC)
From: "D Borland" <no.name@eidosnet.co.uk>
Subject: Re: cron/http absolute directories
Message-Id: <bksh34$hep$1@titan.btinternet.com>

well if people had actualy just said that it was my quoting style that they
were upset with, rather than "top posting" which to me sounds totaly
un-related and didn't have a clue what you were talking about then i could
have sorted the problem and everyone would have been ok.  Ok so i spell
wrong when i typing fast sometimes, but using "top posting" instead of
"quoting style" is the real problem here.  And having read through the
posting guidelines, i notice the following :-

<extract>

 A note to newsgroup "regulars":

       Do not use these guidelines as a "license to flame" or other
       meanness. It is possible that a poster is unaware of things
       discussed here.  Give them the benefit of the doubt, and just
       help them learn how to post, rather than assume

</extract>

Oh, now there's something.  So all these people who drop first-timers in
their kill file because of this (this and the fact they can't just say
"quoting style" rather than "top posting" which sounds nothing like what the
actualy problem is) are actualy not following the rules according to this
extract.  So they inforce the bit they want and ignore everything else, so
who is the real problem here.  It's obvious.  It's those afore mentioned
regulares who dump first-timers who don't get the quoting style right into
their killfiles, as they have read the rules and choose to ignore what they
want and enfore what the dont.

Dagmar




---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/03




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

Date: Wed, 24 Sep 2003 13:39:02 -0400
From: "A. Ma" <ama@PW.CA>
Subject: Example of tk::HTML???
Message-Id: <bksks4$b0k3@shark.pwgsc.gc.ca>

I am trying to display an HTML file using Tk. I downloaded the module
tk::HTML 3.0002 but there is no documentation. Does anyone have a simple
example of how to create a widget to display HTML using this module? Thanks
in advance.

A.Ma





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

Date: Wed, 24 Sep 2003 16:47:43 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Fetching ActiveState PPD files without Installing them
Message-Id: <3F71BC9F.6FAFF483@oracle.com>

John Ramsden wrote:
<snipped>
> Is there a way to retrieve the ppd file from whichever repository a normal
> 'install' would have obtained it

ActiveState's website has a repository of zipped ppd archives that you
can download and install using ppm from a local folder.

http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/Zips

Just look for the zipfile that corresponds to the modules you're looking
for.

Hope this helps

Graham


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

Date: 24 Sep 2003 11:15:11 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: new to perl
Message-Id: <xcwd6dq2p6o.fsf@psi.cis.ohio-state.edu>

"Matthew Browning" <usenet@NOSPAM.matthewb.org> writes:

> On Wed, 24 Sep 2003 07:08:51 +0000, mani wrote:
> > I understand this code because i have been reading Learning Perl
> > written by Randal Schwartz & Tom C. I am assuming this Sendmail is a
> > subroutine
> > but arent su routines called as is like SendMail instead of the & in
> > the front... Or am i missing something here.... I have been reading
> > Perl 5.0
> > 
> > Please help me out
> 
> No need to ask twice.
> 
> You need the ampersand if the subroutine in question has not been
> previously defined (either in the program itself or imported from a
> module).

Err, not exactly. You need the '&' if you want to circumvent
prototypes, or if you want to "pass" the current value of @_ to the
subroutine by making it visible.

> Since you can always legally use it, you're probably best off doing so
> if in doubt.

Ugh, no! You're best NOT using it unless you understand what it
does. It is almost always better to just say foo().

Read perldoc perlsub

-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


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

Date: Wed, 24 Sep 2003 16:39:28 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: new to perl
Message-Id: <3f71bab0$0$24117$afc38c87@news.easynet.co.uk>

mani wrote:
> Hi,
> 
>   I read this sample code somewhere on the web and it is as follows:
> 
> $db="/www/emailadd.txt";
> open (DB,"$db") || die "Can't Open mailadd: $!\n";
> while (<DB>) {
>    chop;
>   &SendMail;
> }
> close DB;
> 
> 
> 
> I understand this code because i have been reading Learning Perl
> written by Randal Schwartz & Tom C. I am assuming this Sendmail is a
> subroutine
> but arent su routines called as is like SendMail instead of the & in
> the front... Or am i missing something here.... I have been reading
> Perl 5.0
> 
> Please help me out
> 
> regards
> Mani

For some of us the use of & before a subroutine says version 4 (of perl)



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

Date: Wed, 24 Sep 2003 15:16:26 +0000 (UTC)
From: jtbellq2f@presby.edu (Jon Bell)
Subject: Re: new to perl
Message-Id: <bkscga$fdk$1@jtbell.presby.edu>

In article <1c84265c.0309240608.69db10b@posting.google.com>,
mani <indian_spindoctor@yahoo.com> wrote:
>
>$db="/www/emailadd.txt";
>open (DB,"$db") || die "Can't Open mailadd: $!\n";
>while (<DB>) {
>   chop;
>  &SendMail;
>}
>close DB;
[snip]
>but arent su routines called as is like SendMail instead of the & in
>the front... Or am i missing something here.... I have been reading
>Perl 5.0

It's probably very old Perl code, or code written by someone who learned
Perl about ten years ago and hasn't bothered to keep up with developments
since then.  Back in the Dark Ages of Perl 4.x, when I first learned Perl,
that was the usual way to call a subroutine.

-- 
Jon Bell <jtbellap8@presby.edu>                     Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: Wed, 24 Sep 2003 12:06:33 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: new to perl
Message-Id: <3F71C109.30504@gwu.edu>

Jon Bell wrote:
> In article <1c84265c.0309240608.69db10b@posting.google.com>,
> mani <indian_spindoctor@yahoo.com> wrote:
> 
>>$db="/www/emailadd.txt";
>>open (DB,"$db") || die "Can't Open mailadd: $!\n";
>>while (<DB>) {
>>  chop;
>> &SendMail;
>>}
>>close DB;
> 
> [snip]
> 
>>but arent su routines called as is like SendMail instead of the & in
>>the front... Or am i missing something here.... I have been reading
>>Perl 5.0
> 
> 
> It's probably very old Perl code, or code written by someone who learned
> Perl about ten years ago and hasn't bothered to keep up with developments
> since then.  Back in the Dark Ages of Perl 4.x, when I first learned Perl,
> that was the usual way to call a subroutine.
> 
Another good indication that it's obsolete code is the use of chop
instead of chomp.

                      Chris Mattern



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

Date: Wed, 24 Sep 2003 11:59:20 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: new to perl
Message-Id: <Xns9400841B13F43sdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Matthew Browning" <usenet@NOSPAM.matthewb.org> wrote in 
news:pan.2003.09.24.14.56.11.543524@NOSPAM.matthewb.org:

> You need the ampersand if the subroutine in question has not been
> previously defined (either in the program itself or imported from a
> module).
> 
> Since you can always legally use it, you're probably best off doing so
> if in doubt.

No; using & has some side effects that can cause hard-to-find bugs.  You're 
much better off using "foo()" than "&foo".

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP3HNWmPeouIeTNHoEQJG+QCeIpsg4E+vr5VIqmXYgR6lqtRsFfQAoOBt
f4ubkWyLlnuIr/mc3Ili90an
=Iszq
-----END PGP SIGNATURE-----


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

Date: Wed, 24 Sep 2003 10:33:02 -0700
From: Nadine <nadine@mail.sdsu.edu>
Subject: Newbie: form checkboxes & param
Message-Id: <bksk5j$to3$1@gondor.sdsu.edu>

I have a script to print out the values of a form's fields to a file. 
That works fine.  However I wanted to print out the values of all the 
checkboxes, not just the ones checked, to make analysis easier.  I 
shortened my script to deal with just the checkboxes until I got this 
matter settled.  I found  several ideas on the web about using param 
with checkboxes.  I tried two but, being a newbie, I do not know how to 
fix the script.  Debug says I have compilation errors near line 24 and 
"0".  I tried a couple things but got nowhere.

My checkboxes are called "c1", "c2", "c3", "c4".

#!/usr/bin/perl -w
use CGI qw(:standard);

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

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
     ($name, $value) = split(/=/, $pair);
     $value =~ tr/+/ /;
     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
     $FORM{$name} = $value;
}

print "<html><head><title>Results</title></head>\n";
print "<body>\n";
print "<h2>Results</h2>\n";

@boxes = ("c1", "c2", "c3", "c4");
my $key;
my $box;
foreach $key(@boxes) {
  $box=param($FORM{$key})||'0';    # print value or zero
  	print "$box|\n";
  }

print "</body></html>\n";

Thanks in advance for your help.



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

Date: Wed, 24 Sep 2003 11:06:48 -0500
From: David McDivitt <x12code-del@del-yahoo.com>
Subject: Re: PPM problems
Message-Id: <q4g3nv4rg3ukp973avjhaqvokhruccpp59@4ax.com>

My problem was I did not place HTTP:// in front of the string assigned to
the HTTP_PROXY environment variable.


>From: David McDivitt <x12code-del@del-yahoo.com>
>Subject: PPM problems
>Date: Mon, 22 Sep 2003 13:17:16 -0500
>
>I read what I could find about package importing prior to posting. When I
>typed:
>
>   ppm install DBI
>
>I received an error and what I read indicated it was because of our
>firewall. I displayed connection properties in internet explorer and found
>the following:
>
>   a03.zzzz.zzzz.zz.us:8080
>
>The following environment variable was added to Win2000:
>
>   set HTTP_PROXY=a03.zzzz.zzzz.zz.us:8080
>
>Now I the following error with PPM:
>
>   Error: No valid repositories: Error: 501 Protocol scheme
>   'a03.zzzz.zzzz.zz.us' is not supported Error: 501 Protocol
>   scheme 'a03.zzzz.zzzz.zz.us' is not supported
>
>DBI.zip was downloaded from ActivePerl and unzipped into a folder honoring
>folder names in the zip file. When I type the following:
>
>   ppm install DBI.ppd
>
>I still get the internet error above. I would like to know two things.
>First, how do I get rid of the internet error so I don't have to download
>stuff. Second, why is it trying to use the internet if I invoked PPM from
>within the directory I unzipped the files. Thanks



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

Date: 24 Sep 2003 15:43:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Q: File contents substitution
Message-Id: <bkse2v$p8q$1@mamenchi.zrz.TU-Berlin.DE>

Troll <abuse@microsoft.com> wrote in comp.lang.perl.misc:
> 
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:bks7p9$fqs$2@mamenchi.zrz.TU-Berlin.DE...
> > Troll <abuse@microsoft.com> wrote in comp.lang.perl.misc:
> > > Hi,
> > >
> > > I posted this in one of the other grps but have had no real luck yet.
> Sorry.
> > >
> > > I need 2b able to change the contents of a file, ie. to substitute
> > > occurences of 'one' to 'two'.
> > > I have something like:
> > > **************************
> > > sub replace {
> > >     s/one/two/g;
> > > }
> > >
> > > open (INFILE, "+<test.txt") || etc...
> > > while (<>) {
> > >     replace ();
> > > }
> > > **************************
> > >
> > > Contents of test.txt are:
> > > hello one
> > > one ten one ten
> > >
> > > What am I missing to make this work? I'd love to read the manual [like
> > > someone has suggested] but by the time I get there it'll be next year...
> >
> > Then read the FAQ instead, it's short and sweet.  perldoc -q 'line in a
> file'.
> >
> > Anno
> 
> Anno,
> Do I put
> line in a file
> in the search field on perldoc? Have never been there b4. What's the -q for?

-q lets perldoc search the faq for keywords.  See "perldoc perldoc" for the
whole story.

Anno


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

Date: Wed, 24 Sep 2003 15:47:32 GMT
From: "Troll" <abuse@microsoft.com>
Subject: Re: Q: File contents substitution
Message-Id: <o0jcb.121398$bo1.8972@news-server.bigpond.net.au>

*snip*

> > > Anno
> >
> > Anno,
> > Do I put
> > line in a file
> > in the search field on perldoc? Have never been there b4. What's the -q
for?
>
> -q lets perldoc search the faq for keywords.  See "perldoc perldoc" for
the
> whole story.
>
> Anno

OK, I got it. The script works now. Thanks very much :)




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

Date: Wed, 24 Sep 2003 16:07:27 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: Q: File contents substitution
Message-Id: <3f71c042.777552761@News.CIS.DFN.DE>

On Wed, 24 Sep 2003 14:35:06 GMT, "Troll" <abuse@microsoft.com> wrote:

>> > What am I missing to make this work? I'd love to read the manual [like
>> > someone has suggested] but by the time I get there it'll be next year...
>>
>> Then read the FAQ instead, it's short and sweet.  
>> perldoc -q 'line in a file'.
>>
>Do I put line in a file in the search field on perldoc? 
>Have never been there b4. What's the -q for?

perldoc is a program that comes bundled with every 
distribution of Perl.  

You run it from a command line.  If you used Unix
all of this would be obvious, so I'll assume you use
Windows.  Go to the Start ->Programs->Accessories
menu and start "Command Prompt" to get a
command line window (Or Start -> Run -> cmd.exe)

-q is a command line switch and stands for "query"

Read 
perldoc perldoc 
for further info on how to use perldoc.

--
Helgi Briem  hbriem AT simnet DOT is

Excuse the munged address.  My last
e-mail address was killed by spammers.


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

Date: 24 Sep 2003 16:21:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Q: File contents substitution
Message-Id: <bksga1$qrd$2@mamenchi.zrz.TU-Berlin.DE>

Helgi Briem <f_baggins80@hotmail.com> wrote in comp.lang.perl.misc:

[perldoc]

> -q is a command line switch and stands for "query"

I alsways thought it stood for faQ (because -f was taken by something
more important).

Anno


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

Date: Wed, 24 Sep 2003 17:12:19 GMT
From: "Troll" <abuse@microsoft.com>
Subject: Re: Q: File contents substitution
Message-Id: <Tfkcb.121426$bo1.45420@news-server.bigpond.net.au>


"Helgi Briem" <f_baggins80@hotmail.com> wrote in message
news:3f71c042.777552761@News.CIS.DFN.DE...
> On Wed, 24 Sep 2003 14:35:06 GMT, "Troll" <abuse@microsoft.com> wrote:
>
> >> > What am I missing to make this work? I'd love to read the manual
[like
> >> > someone has suggested] but by the time I get there it'll be next
year...
> >>
> >> Then read the FAQ instead, it's short and sweet.
> >> perldoc -q 'line in a file'.
> >>
> >Do I put line in a file in the search field on perldoc?
> >Have never been there b4. What's the -q for?
>
> perldoc is a program that comes bundled with every
> distribution of Perl.
>
> You run it from a command line.  If you used Unix
> all of this would be obvious, so I'll assume you use
> Windows.  Go to the Start ->Programs->Accessories
> menu and start "Command Prompt" to get a
> command line window (Or Start -> Run -> cmd.exe)
>
> -q is a command line switch and stands for "query"
>
> Read
> perldoc perldoc
> for further info on how to use perldoc.
>
> --
> Helgi Briem  hbriem AT simnet DOT is
>
> Excuse the munged address.  My last
> e-mail address was killed by spammers.

You guessed right. Thanks Helgi.




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

Date: Wed, 24 Sep 2003 17:10:38 GMT
From: "Troll" <abuse@microsoft.com>
Subject: Q: RegEx - string substitution
Message-Id: <iekcb.121425$bo1.71693@news-server.bigpond.net.au>

Hi,

I'd like to change 'Jones & Bros.' to 'Jones and Company' when it appears as
part of a h1 heading in a HTML doc. I have tried the following with no luck:

s/<h1>.*Jones & Bros..*</h1>/<h1>.*Jones and Company.*</h1>/
s/<h1>[\\s|S]*Jones & Bros.[\\s|S]*</h1>/<h1>[\\s|S]*Jones and
Company[\\s|S]*</h1>/

Where am I going wrong? We cannot assume that Jones & Bros. is alone in the
heading. There may be other characters/words including spaces around it.




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

Date: 24 Sep 2003 17:27:45 GMT
From: Glenn Jackman <xx087@freenet.carleton.ca>
Subject: Re: Q: RegEx - string substitution
Message-Id: <slrnbn3l1e.mt5.xx087@smeagol.ncf.ca>

Troll <abuse@microsoft.com> wrote:
>  Hi,
>  
>  I'd like to change 'Jones & Bros.' to 'Jones and Company' when it appears as
>  part of a h1 heading in a HTML doc. I have tried the following with no luck:
>  
>  s/<h1>.*Jones & Bros..*</h1>/<h1>.*Jones and Company.*</h1>/
>  s/<h1>[\\s|S]*Jones & Bros.[\\s|S]*</h1>/<h1>[\\s|S]*Jones and
>  Company[\\s|S]*</h1>/
>  
>  Where am I going wrong? We cannot assume that Jones & Bros. is alone in the
>  heading. There may be other characters/words including spaces around it.

Your error is leaving regex metacharacters in the substitution.
    s{(<h1>.*Jones) & Bros\.}{$1 and Company}

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


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

Date: Wed, 24 Sep 2003 13:41:56 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Q: RegEx - string substitution
Message-Id: <3F71D764.3000608@gwu.edu>

Glenn Jackman wrote:
> Troll <abuse@microsoft.com> wrote:
> 
>> Hi,
>> 
>> I'd like to change 'Jones & Bros.' to 'Jones and Company' when it appears as
>> part of a h1 heading in a HTML doc. I have tried the following with no luck:
>> 
>> s/<h1>.*Jones & Bros..*</h1>/<h1>.*Jones and Company.*</h1>/
>> s/<h1>[\\s|S]*Jones & Bros.[\\s|S]*</h1>/<h1>[\\s|S]*Jones and
>> Company[\\s|S]*</h1>/
>> 
>> Where am I going wrong? We cannot assume that Jones & Bros. is alone in the
>> heading. There may be other characters/words including spaces around it.
> 
> 
> Your error is leaving regex metacharacters in the substitution.
>     s{(<h1>.*Jones) & Bros\.}{$1 and Company}
> 
This will, of course, break in the first h1 heading that doesn't have
"Jones & Bros." on the same line as the h1 tag.  It will also break
if "Jones & Bros." appears on the same line as the h1 tag but after
the heading has been closed.  Finally, it will break if "Jones & Bros."
appears more than once in a heading.

Don't use regexs to parse HTML.  Parsing HTML is *not* trivial and
beyond the capabilities of regexs.  Use a perl package for parsing
HTML, of which several are available on CPAN.

                          Chris Mattern



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

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


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