From: Canol Gökel <[EMAIL PROTECTED]>
> On Sat, 29 Nov 2008 21:19:01 -0500
> [EMAIL PROTECTED] ("Chas. Owens") wrote:
>
> > And yes, asking about what variables are on a different languages list
> > is foolish.  For instance, Perl's variables are dynamic and loosely
> > typed, whereas Pascals are static and strongly typed.  If you asked
> > here about variables and then tried to use what you were told in
> > Pascal you would wonder why none of your code even compiled.
>
> You see? You just complicate things. I just want to learn what a
> variable is. "It is that simple". But you try to teach me what dynamic
> or loosely variables are (You even use the word itself inside the your
> definition). And this is the exact problem we are having here, with my
> question.

What a variable is depends on the language. Variable is NOT the same
thing in Perl and Pascal. Sure the most basic idea is the same, a
name for some data. But the details are different, the behaviours are
different. Very few things we could tell you about variables in Perl
would be true in Pascal and vice versa. The answer "it's a name for
some data" is true in both, but useless.

> > Sadly, this is what many people think.  It isn't that easy.  What if
> > the code looks like this
> >
> > <p><img src="end_p_tag.jpg" alt="</p>"></p>
> >
> > Now you have to understand image tags and paragraph tags, there are
> > countless other examples.  The cavalier "I'll just through some regex
> > at it" attitude is why we have things like XSS and injection attacks.
> >
>
> 1) How can I make you understand, there won't be any attributes or img
> tags or javascript etc. Please stop giving examples of HTML
> structures,

For example by never taling about HTML in the first place.

> 2) It won't look like that because _I_ will enter the input,
> 3) Since I won't use this as a serious application it doesn't matter whether 
> it is secure or not.

You never know where might the code end up later.

> If it will help, I change my example. How can I match structures like this:
>
> [block]
>       this is a block
>       [block]
>               this is another block
>       [/block]
>       first block ends
> [/block]
>
> You see? No HTML. This is a language I invented it has just [block]
> and [/block] keywords, nothing else. Sure parsing is a good thing but
> it is not necessary for this problem and I want to do it in regexp
> way, wait a minute, wasn't that Perl's idiom: "There is more than one
> way to do it".
>
> Please don't continue the "you are doing it wrong way" thing, the
> discussion is already out of its way! If you don't know how to do this
> then please don't speak, if you do, please tell...

What do you mean by "match"? Do you want to find the innermost block,
do something with it, find the other one, ...

Or do you want to check whether it's properly nested? In neither case
will a sole regexp suffice. I sent you a possible solution for the
first case already, here's one for the other:


$text = <<'*END*';
starting
[block]
        this is a block
        [block]
                this is another block
        [/bclock]
        first block ends
[/block]
blah
*END*

print "TEXT: $text\n\n";
$text =~ s{.*?(?:\[(\/?)block\]|$)}{
  if (defined $1) {
    $1 ? '>' : '<'
  }
}gse;
print "TEXT: $text\n\n";

1 while ($text =~ s/<>//g);

if ($text) {
 print "Not nested properly.\n"
} else {
 print "Nested properly.\n"
}


As you see the solutions are different. And if you wanted to "match
the tag" for a different reason it would be again different. Possibly
very different. How do you expect us to know what do you want if you
do not tell us?

"Match a tag" is about as descriptive as "parse an XML". It does tell
us you want to do something with some text in some more or less
specific format. What is it you want to do ... noone can tell.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to