$text !~ s/<%.*%>//s;
what the above regex is supposed to do, is strip all asp tags and code out
of a block of html code.. but it does not do the job.
any ideas ?
regards,
Michael
Yup, use an HTML parser to parse HTML. I suggest HTML::Parser available
at http://www.cpan.org/
Cheers,
Bernard
Try:
$text =~ s/<%.*?%>//sg;
One of us is confused on the function of !~.
sh
$text =~ s/<%(.*?)%>//sg;
Tyler Cruz
"Sean Hamilton" <s...@planetquake.com> wrote in message
news:BELI7.5108$c4.9...@news0.telusplanet.net...
Greediness. It will eat anything from the first opening marker till the
last closing marker. Try this instead:
$text =~ s/<%.*?%>//sg;
I'm assuming that the whole document is one string.
--
Bart.
The parentheses are only necessary if you want to use what ".*?"
captures. It will be stored in the special $1 variable if the
()s are present. Read more in perlre.
But again, I have to warn you that you can't parse HTML with a regex.
Unless you're really sure of your input HTML you should be using
a parser. Don't say you weren't warned when you get burned.
Cheers,
Bernard
Only if you want to store them for some reason.
Otherwise $text =~ s/<%.*?%>//sg; will work just fine (with all the
usual limitations/pitfalls on trying to use simple regexes to deal with
HTML style tags...).
Paul
>But again, I have to warn you that you can't parse HTML with a regex.
>Unless you're really sure of your input HTML you should be using
>a parser. Don't say you weren't warned when you get burned.
You'll get burned if you'll try parsing "<%...%>"-like tags with
HTML::Parser. It doesn't like it. Actually, it treats it like text
(splitting for calls between the "<" and the "%").
--
Bart.
: The parentheses are only necessary if you want to use what ".*?"
: captures. It will be stored in the special $1 variable if the
: ()s are present. Read more in perlre.
Not entirely true, the ()'s are also important for logical grouping.
e.g. ([A-Z][a-z]*[0-9]+)?
the final ? is for everything in the parentheses - the match within the
()'s must happen exactly zero or one times.
Add "?:" to prevent the ()'s from setting $1 $2 etc.
e.g. (?:[A-Z][a-z]*[0-9]+)?
Entirely true in the example above. The OP asked about a specific
regex and I gave a specific response. I then pointed the OP at
the documentation using the words "read more" to suggest there's
more to read. When a beginner asks a specific question you shouldn't
complicate matters. Just give a specific answer and a pointer to more
information.
Cheers,
Bernard
I am facing strange problem while using Perl Objects (aka modules). I am
not able to have any instace variable. If I make two objects of a class
and add some elements in one object, it automatically gets added in
second class also (as if it is singleton, but I do not want that). Any
ideas how to reslove that (Looks like i have not understood perl objects
clearly)
Any help will be welcome.
Here goes a simple program which can show my question
-- file check.pm
package check;
sub new {
my $ref = {};
bless $ref;
return $ref;
}
sub add {
my $ref = shift;
$ref{symbols} = {
"one" => "1",
"two" => "2"
};
}
sub print {
my $ref = shift;
foreach $name (sort keys %{$ref{symbols}}) {
print $ref{symbols}->{$name}."\n";
}
}
1;
-- file 1.pl
#!/usr/bin/perl -w
use check;
$oref = check->new();
$oref->add();
$oref->print();
print "Second Object\n";
$newref = check->new();
$newref->print();
---
Now if I run 1.pl
$ 1.pl
1
2
Second Object
1
2
So "one" and "two" is added automatically for both objects, even when I
have called "add" for only one object.
sachin
> I am facing strange problem while using Perl Objects (aka modules). I am
> not able to have any instace variable. If I make two objects of a class
> and add some elements in one object, it automatically gets added in
> second class also (as if it is singleton, but I do not want that). Any
> ideas how to reslove that (Looks like i have not understood perl objects
> clearly)
Actually, it looks like understanding the correct syntax to access
via references is your problem.
> package check;
>
> sub new {
> my $ref = {};
> bless $ref;
> return $ref;
> }
So far, so good.
> sub add {
> my $ref = shift;
> $ref{symbols} = {
Here's the problem. That should be:
$ref->{symbols} = {
(You want the 'symbols' entry of the hash referred to by $ref,
*not* the 'symbols' entry of the hash %ref. Putting a 'use strict;'
at the start of your package would have pointed out this problem.)
> "one" => "1",
> "two" => "2"
> };
> }
>
> sub print {
> my $ref = shift;
>
> foreach $name (sort keys %{$ref{symbols}}) {
> print $ref{symbols}->{$name}."\n";
Same problem here. You want:
foreach $name (sort keys %{$ref->{symbols}}) {
print $ref->{symbols}->{$name}."\n";
Damian
> Actually, it looks like understanding the correct syntax to access
> via references is your problem.
>
> > package check;
> >
> > sub new {
> > my $ref = {};
> > bless $ref;
> > return $ref;
> > }
>
> So far, so good.
Both syntactically and semantically the constructor is of course correct.
For futureness-'proofness' he might perhaps want to use the two-argument
form of bless in case he later wants to extend his classes and even add
a lot bit of inheritence to it. In the current form one couldn't
subclass 'check'.
sub new {
my $class = shift;
my $ref = bless {}, $class;
return $ref;
}
Regards,
Tassilo
--
Help fight continental drift.
"Sachin Goyal" <sgo...@cs.utah.edu> wrote in message
news:3C0A9B98...@cs.utah.edu...
> Hello,
>
> I am facing strange problem while using Perl Objects (aka modules). I am
> not able to have any instace variable. If I make two objects of a class
> and add some elements in one object, it automatically gets added in
> second class also (as if it is singleton, but I do not want that). Any
> ideas how to reslove that (Looks like i have not understood perl objects
> clearly)
>
> Any help will be welcome.
Inside check.pm, when you receive $ref, you're treating it as a hash.
It's not a hash, it's a reference (AKA pointer) to a hash.
So to access the key "symbols", you can't do $ref{"symbols"} since that
overrides the original pointer with a new hash with the same name.
What you want is the dereferrence operator ->
It's used like so: $ref->{'symbols'}
Use that in your assignment and in your looping and you'll be fine :-)
-----BEGIN PGP SIGNATURE-----
Version: 6.5.8ckt http://www.ipgpp.com/
Comment: Think of PGP as a tamper-proof envelope for your email !
Comment: KeyID: 0x63227FAC
Comment: Fingerprint: A3C1 D7CF 4383 D614 74DA 54C9 792F 7DA4 6322 7FAC
iQA/AwUBPAqv/3kvfaRjIn+sEQKQSwCg2DkhmsuxIS3Z9IEj2nocdaVklK0AoJsj
HFxvb5SJUh0F+zfsawfRaJDy
=8KEo
-----END PGP SIGNATURE-----
: I am facing strange problem while using Perl Objects (aka modules). I am
(snip)
: Any help will be welcome.
Add "use strict" near the top.
: Here goes a simple program which can show my question
: -- file check.pm
: package check;
use strict; # ADDED
: sub new {
: my $ref = {};
: bless $ref;
: return $ref;
: }
: sub add {
: my $ref = shift;
: $ref{symbols} = {
The above error should be detected by the use strict.
: "one" => "1",
: "two" => "2"
: };
: }
: sub print {
: my $ref = shift;
:
: foreach $name (sort keys %{$ref{symbols}}) {
: print $ref{symbols}->{$name}."\n";
: }
: }
: 1;
(Please don't post your message so many times.)