[19089] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1284 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 11 09:10:53 2001

Date: Wed, 11 Jul 2001 06:10:33 -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: <994857032-v10-i1284@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Jul 2001     Volume: 10 Number: 1284

Today's topics:
        URL String Problem (Blstone77)
    Re: URL String Problem <gnarinn@hotmail.com>
    Re: URL String Problem (Rafael Garcia-Suarez)
    Re: URL String Problem <laszlo.gerencser@portologic.com>
    Re: variable require (Joe Smith)
    Re: variable require <jimbo@soundimages.co.uk>
    Re: Very good regex question? <wyzelli@yahoo.com>
    Re: Very good regex question? <nospam-abuse@ilyaz.org>
    Re: Very good regex question? <scott@remove.generator.co.za>
    Re: Very good regex question? <wyzelli@yahoo.com>
    Re: Very good regex question? <pne-news-20010711@newton.digitalspace.net>
    Re: Very good regex question? <pne-news-20010711@newton.digitalspace.net>
    Re: Very good regex question? (Tad McClellan)
    Re: why is Vars an undefined subroutine? <bart.lateur@skynet.be>
    Re: why is Vars an undefined subroutine? (TuNNe|ing)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 11 Jul 2001 10:23:20 GMT
From: blstone77@aol.com (Blstone77)
Subject: URL String Problem
Message-Id: <20010711062320.08400.00003709@ng-fw1.aol.com>

$string ="this is my url and it should be deleted as <a
href=http://members.aol.com/davidroom/index.html>this old house</a> is falling
and
it is the house jack built";

$string =~ s/<.*>//g;

I am trying to delete the url in a string. The problem I am having is that it
not only deletes the URL, but also the text between the  <a
href=http://members.aol.com/davidroom/index.html> and the </a> can anyone tell
me how I can delete only urls, anything between < and > but not the text
between the </a>. What am I doing wrong? Thanks much for your help.




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

Date: Wed, 11 Jul 2001 10:10:44 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: URL String Problem
Message-Id: <994846244.623645521700382.gnarinn@hotmail.com>

In article <20010711062320.08400.00003709@ng-fw1.aol.com>,
Blstone77 <blstone77@aol.com> wrote:
>$string ="this is my url and it should be deleted as <a
>href=http://members.aol.com/davidroom/index.html>this old house</a> is falling
>and
>it is the house jack built";
>
>$string =~ s/<.*>//g;
>
>I am trying to delete the url in a string. The problem I am having is that it
>not only deletes the URL, but also the text between the  <a
>href=http://members.aol.com/davidroom/index.html> and the </a> can anyone tell
>me how I can delete only urls, anything between < and > but not the text
>between the </a>. What am I doing wrong? Thanks much for your help.
>


$string =~ s/<.*?>//g;

perldoc perlre
look for 'greedy'

gnari





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

Date: 11 Jul 2001 10:36:03 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: URL String Problem
Message-Id: <slrn9kob1b.aqv.rgarciasuarez@rafael.kazibao.net>

Blstone77 wrote in comp.lang.perl.misc:
} $string ="this is my url and it should be deleted as <a
} href=http://members.aol.com/davidroom/index.html>this old house</a> is falling
} and
} it is the house jack built";
} 
} $string =~ s/<.*>//g;
} 
} I am trying to delete the url in a string. The problem I am having is that it
} not only deletes the URL, but also the text between the  <a
} href=http://members.aol.com/davidroom/index.html> and the </a> can anyone tell
} me how I can delete only urls, anything between < and > but not the text
} between the </a>. What am I doing wrong? Thanks much for your help.

Learn what is a "greedy" regular expression pattern in the perlre
manual. You tried to do :

  $string =~ s/<.*?>//g;

Note also that for more sophisticated HTML tag handling, you'll have to
use a specialized module, such as HTML::Parser (available from CPAN).

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 11 Jul 2001 10:53:39 GMT
From: Laszlo Gerencser <laszlo.gerencser@portologic.com>
Subject: Re: URL String Problem
Message-Id: <3B4C306E.CC6D4ED9@portologic.com>

Try this:
$string =~ s/<.*?>//sg;

The ? after the * makes * not greedy (so > will match the first > not
the last one).
The s before the g will speed up your regexp telling perl that $string
is considered as a single-line one. This enables matching tags broken to
multiple lines also.

Anyway, you should read perldoc perlre.
Not an easy reading, but if you have basic regexp knowledge, it will be
extremely useful.

Hope, this helps

--
Laszlo Gerencser
PortoLogic Ltd.


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

Date: Wed, 11 Jul 2001 07:17:14 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: variable require
Message-Id: <9iguhq$jq6$1@nntp1.ba.best.com>

In article <Qij27.3858$PE5.70380@NewsReader>,
jimbo <jimbo@soundimages.co.uk> wrote:
>> > require "c:/Inetpub/wwwroot/news/preedit.cgi";
>> >
>> > However I want it to be partially variable something like this
>> >
>> > require "c:/Inetpub/wwwroot/$page";
>>
>> That should work if $page is defined.  You may need to import it also.
>
>require is compile time and $page is run time.  It is very unlikely that
>$page will be defined before it is required.

No, 'use' is compile time; 'require' is run time.  It is quite likely
that $page will be defined before it is required.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Wed, 11 Jul 2001 09:12:26 +0100
From: "jimbo" <jimbo@soundimages.co.uk>
Subject: Re: variable require
Message-Id: <vST27.5104$PE5.96158@NewsReader>

> No, 'use' is compile time; 'require' is run time.  It is quite likely

Your quite right, I lost my grip. :(

> that $page will be defined before it is required.

I'll leave that an an exercise to the programmer.

jimbo
;-)




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

Date: Wed, 11 Jul 2001 16:52:55 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Very good regex question?
Message-Id: <O3T27.30$BZ3.1948@vic.nntp.telstra.net>

"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:7rS27.26$BZ3.1611@vic.nntp.telstra.net...
> "scotth" <scott@remove.generator.co.za> wrote in message
> news:3b4be806$0$227@hades.is.co.za...
> > Hi All.
>
> I think this should work.  At least it does with the case you describe
> above.
> s/'([\w']+?[^s])'(s')?/$1/g;
>
>
> Could have a problem with 'Foobars's' though.
>
> Sometimes it is easier to deal with the steps one at a time, and there
> really is no harm with using a couple of regexen in sequence to solve the
> problem.
>
> s/(^|\W)'(\w)/$1$2/g;
> s/(\w)'(\W|$)/$1$2/g;
> s/'s\b//g;
>
> That sequence should cover all eventualities.

Course that all was assuming more than one word in a string.  If there is
only one word in the string, the following may be better.

s/'((\w')?[\w]+)('s)?'/$1/;

Wyzelli
--
@x='074117115116032097110111116104101114032080101114108032104097099107101114
'=~/(...)/g;
print chr for @x;





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

Date: Wed, 11 Jul 2001 07:42:21 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Very good regex question?
Message-Id: <9ih00t$195g$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Wyzelli
<wyzelli@yahoo.com>], who wrote in article <PuS27.27$BZ3.1652@vic.nntp.telstra.net>:
> > $string =~ s/^\'//g;     # REMOVE ' AT BEGINNING.
> 
> Single quote does not need to be escaped in the first half of a regex.  

Why "in the first half of a regex"?  And there is no such thing as
"the first half of a regex".

Unless //e, the second half *of the substitution* is in the same
context wrt quoting of '.

> > $string =~ s/\'$//g;     # REMOVE ' AT END.
> 
> Ditto, only one end of string.

Strictly speaking, this is wrong.  A lot of strings have "two ends of
string" in the sense that $ can match in two places.  [Not applicable
to \'$\, of course.]

Ilya


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

Date: Wed, 11 Jul 2001 09:46:41 +0200
From: "scotth" <scott@remove.generator.co.za>
Subject: Re: Very good regex question?
Message-Id: <3b4c04e0$0$232@hades.is.co.za>

Hi There.
Thanks for the prompt help.
Much appreciated:-)

"Wyzelli" <wyzelli@yahoo.com> wrote in message
news:O3T27.30$BZ3.1948@vic.nntp.telstra.net...
> "Wyzelli" <wyzelli@yahoo.com> wrote in message
> news:7rS27.26$BZ3.1611@vic.nntp.telstra.net...
> > "scotth" <scott@remove.generator.co.za> wrote in message
> > news:3b4be806$0$227@hades.is.co.za...
> > > Hi All.
> >
> > I think this should work.  At least it does with the case you describe
> > above.
> > s/'([\w']+?[^s])'(s')?/$1/g;
> >
> >
> > Could have a problem with 'Foobars's' though.
> >
> > Sometimes it is easier to deal with the steps one at a time, and there
> > really is no harm with using a couple of regexen in sequence to solve
the
> > problem.
> >
> > s/(^|\W)'(\w)/$1$2/g;
> > s/(\w)'(\W|$)/$1$2/g;
> > s/'s\b//g;
> >
> > That sequence should cover all eventualities.
>
> Course that all was assuming more than one word in a string.  If there is
> only one word in the string, the following may be better.
>
> s/'((\w')?[\w]+)('s)?'/$1/;
>
> Wyzelli
> --
>
@x='074117115116032097110111116104101114032080101114108032104097099107101114
> '=~/(...)/g;
> print chr for @x;
>
>
>




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

Date: Wed, 11 Jul 2001 17:27:48 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Very good regex question?
Message-Id: <wAT27.31$BZ3.1915@vic.nntp.telstra.net>

"Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message
news:9ih00t$195g$1@agate.berkeley.edu...
> [A complimentary Cc of this posting was sent to
> Wyzelli
> <wyzelli@yahoo.com>], who wrote in article
<PuS27.27$BZ3.1652@vic.nntp.telstra.net>:
> > > $string =~ s/^\'//g;     # REMOVE ' AT BEGINNING.
> >
> > Single quote does not need to be escaped in the first half of a regex.
>
> Why "in the first half of a regex"?  And there is no such thing as
> "the first half of a regex".
>

s/regex/substitution/ - oops

>
> > > $string =~ s/\'$//g;     # REMOVE ' AT END.
> >
> > Ditto, only one end of string.
>
> Strictly speaking, this is wrong.  A lot of strings have "two ends of
> string" in the sense that $ can match in two places.  [Not applicable
> to \'$\, of course.]

That could lead to semantics, but I know what you are saying, although I
doubt it would apply here, (embedded line endings in a multiline string for
example) but those type of assumtions are the ones which tend to bite us...

Thanks for the pointers.

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';





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

Date: Wed, 11 Jul 2001 10:31:54 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: Very good regex question?
Message-Id: <km3oktsrs1li7h0g1e9ncvrklusfm9rrpc@4ax.com>

On Wed, 11 Jul 2001 07:42:21 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:

> Unless //e, the second half *of the substitution* is in the same
> context wrt quoting of '.

Not like "? The right-hand side of a substitution interpolates
variables, and ' doesn't.

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: Wed, 11 Jul 2001 10:35:20 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: Very good regex question?
Message-Id: <rn3oktsh7nhmj5uvmkofi4u7p66tfbk11q@4ax.com>

On Wed, 11 Jul 2001 17:27:48 +0930, "Wyzelli" <wyzelli@yahoo.com> wrote:

> "Ilya Zakharevich" <nospam-abuse@ilyaz.org> wrote in message
> news:9ih00t$195g$1@agate.berkeley.edu...
> > Strictly speaking, this is wrong.  A lot of strings have "two ends of
> > string" in the sense that $ can match in two places.  [Not applicable
> > to \'$\, of course.]
> 
> That could lead to semantics, but I know what you are saying, although I
> doubt it would apply here, (embedded line endings in a multiline string for
> example) but those type of assumtions are the ones which tend to bite us...

I don't think multiline strings are what he meant; rather, that /$/ can
match either at the end of string (like /\z/) or at a newline just
before the end (like /(?=\n\z)/). So /o[^f]$/ could match "foo\n" either
as at "oo"-before-\n or at "o\n"-before-end-of-string.

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: Wed, 11 Jul 2001 06:58:13 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Very good regex question?
Message-Id: <slrn9koca5.dpn.tadmc@tadmc26.august.net>

Wyzelli <wyzelli@yahoo.com> wrote:
>"scotth" <scott@remove.generator.co.za> wrote in message
>news:3b4bf1ab$0$231@hades.is.co.za...

>> $string =~ s/^\'//g;     # REMOVE ' AT BEGINNING.
>
>Single quote does not need to be escaped in the first half of a regex.


What is a "half of a regex"?

   Single quote does not need to be escaped in a regex.

and

   Single quote does not need to be escaped in a string, such
   as the replacement string in a s/// operation.
   
(errr, except when it might be taken as a package separator...)


s/// is not a regex, it is an operator.

The first part of the s/// operator is a regex.

The second part of s/// is NOT a regex :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 11 Jul 2001 08:59:56 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: why is Vars an undefined subroutine?
Message-Id: <g75oktsnhprjn9ojirofndq5cfi4mi112v@4ax.com>

Philip Newton wrote:

>> my %params = $q->Vars;
>
>Where did you get the method 'Vars' from? It's not in my copy of the
>CGI.pm documentation. (Hint, hint[1].)

???

Either you didn't look well, or you need an upgrade.

>[1] Bigger hint: try the section labelled "FETCHING THE NAMES OF ALL THE
>PARAMETERS PASSED TO YOUR SCRIPT".

No, let's look at "FETCHING THE PARAMETER LIST AS A HASH":

  FETCHING THE PARAMETER LIST AS A HASH:

        $params = $q->Vars;
        print $params->{'address'};
        @foo = split("\0",$params->{'foo'});
        %params = $q->Vars;

        use CGI ':cgi-lib';
        $params = Vars;

  Many people want to fetch the entire parameter list as a hash in which
  the keys are the names of the CGI parameters, and the values are the
  parameters' values. The Vars() method does this. Called in a scalar
  context, it returns the parameter list as a tied hash reference.
  Changing a key changes the value of the parameter in the underlying
  CGI parameter list. Called in a list context, it returns the parameter
  list as an ordinary hash. This allows you to read the contents of the
  parameter list, but not to change it.

I don't know when Vars was added, but your posts suggests it can't have
been too long.

-- 
	Bart.


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

Date: Wed, 11 Jul 2001 10:53:49 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: Re: why is Vars an undefined subroutine?
Message-Id: <3b4c4d5b.25653388@news>

On Wed, 11 Jul 2001 08:59:56 GMT, Bart Lateur <bart.lateur@skynet.be>
wrote:

[snip]
>No, let's look at "FETCHING THE PARAMETER LIST AS A HASH":
>
>  FETCHING THE PARAMETER LIST AS A HASH:
>
>        $params = $q->Vars;
>        print $params->{'address'};
>        @foo = split("\0",$params->{'foo'});
>        %params = $q->Vars;
>
>        use CGI ':cgi-lib';
>        $params = Vars;
>
>  Many people want to fetch the entire parameter list as a hash in which
>  the keys are the names of the CGI parameters, and the values are the
>  parameters' values. The Vars() method does this. Called in a scalar
>  context, it returns the parameter list as a tied hash reference.
>  Changing a key changes the value of the parameter in the underlying
>  CGI parameter list. Called in a list context, it returns the parameter
>  list as an ordinary hash. This allows you to read the contents of the
>  parameter list, but not to change it.
[/snip]

Thanks for copy and pasting the CGI.pm document. I've read this and
tried just about all combinations provided, previous to posting.

Does this mean I need to get a newer version of CGI.pm?
perl -v tells me "This is perl, version 5.005_03 build for i386 linux"

TuNNe|ing


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

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


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