in reply to Regex Strikes again!

You are slurping in the file in one go, due to your setting of $/ to undef. That means <F> is going to return a single string, the content of the entire file. Which means that if the file contains a C or C++ style comment, or a single or double quoted string, that single string is passed to map. The map makes a two element list out of this, the first element the line number of the last "line" of the file - it this case 1, as there is only one line. So, you get a one-key hash, with key 1, and value the entire content of the file.

The problem you are working on is a bit more complicated than what you can do in a simple regexp.

Abigail

Replies are listed 'Best First'.
Re: Re: Regex Strikes again!
by nofernandes (Beadle) on Jul 16, 2003 at 10:07 UTC

    Hmm.. i see.. your rigth!

    But can i put this condition in while cicle!!? I guess not because in that case i could not catch multiline comments!! Because in this case the file would be read line by line! And i must read all the file at once! Donīt i?

    Thank you again

      Put which condition in which while cycle? There's no while in your code fragment.

      Which part of "what you are trying to do is to complex for a simple regexp" do you fail to understand?

      I've said this before, what you need is a parser, nor a regexp. For simple languages like Java, you can get away with a parser that's not a full-language parser. I told you this three weeks ago, but you still are on the regexp road, and have made remarkably little progress.

      Don't match - parse!

      Abigail