in reply to Counting the start and end elements in a line

it is not working

Please give more information. "It is not working" isn't very helpful. What happens? Do you get the wrong answer? Does the program not compile? Does the program crash? Give an error message? Or does your computer burst into flames?

If you're really calling your function like this:

counttags(I); counttags(B);

then I expect you'd get a warning about barewords under use strict. If you go on to use:

counttags(+); counttags(-);

Then I strongly suspect that it won't even compile (I haven't tried it). You probably want to rewrite these lines as:

counttags('I'); counttags('B'); counttags('+'); counttags('-');

And if that fixes it (which it won't for the reasons that rminner points out), then you should probably get into the habit of using use strict and use warnings in your programs.

Of course, this is all guesswork as I don't really have enough information to go on.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Counting the start and end elements in a line
by rsriram (Hermit) on Jun 27, 2006 at 11:43 UTC

    When I call the function

    counttags(+);

    When the script is compiled, I get a error,

    Syntax error at vtag.pl at line 275, near "+)"
    Execution of vtag.pl aborted due to compilation errors.

    On the otherhand, if I have the code as counttags("+");, the $stag and $etag values remain 0.

    For you to understand better, the content in the file goes like:
    Die Errichtung <I>einer</I> Zweigniederlassung ist durch die Geschäftsführer anzumelden. Der Anmeldung ist eine öffentlich beglaubigte Abschrift des Gesellschaftsvertrages und der Liste der Gesellschafter beizufügen.<+>2</+>

    In my function, I am trying to find the number of <I> and </I>, <+> and </+> and check whether the opening and the closing tag count matches.

      When I call the function

      counttags(+);

      When the script is compiled, I get a error,

      Syntax error at vtag.pl at line 275, near "+)"
      Execution of vtag.pl aborted due to compilation errors.

      Yes. That's what I expected. You can't just drop an operator in the middle of some source code at random and expect the compiler to know what to do.

      On the otherhand, if I have the code as counttags("+");, the $stag and $etag values remain 0.

      This is probably because of one of the other errors that have been pointed out to you in this thread. Developing with use strict and use warnings will almost certainly help you track down problems like this.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg