in reply to Substr warning

Could you explain what is the code supposed to do? It seems to me it could be written in one or two lines but I just can't get it straight. Maybe showing and explaining a bigger chunk would help. All in all it looks to me like you are making things much more complex than they have to be.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Replies are listed 'Best First'.
Re^2: Substr warning
by Anonymous Monk on Sep 27, 2004 at 11:05 UTC
    Hi,

    I am extracting information from a html-site, which I have stripped of tags, etc. beforehand. In this instance, I am interested in the two words following the string "Rapporteur: ".

    There is probably a better way of doing it, but at the moment I am using $' to get the text after the string I searched for and then read in every single character once at a time, add it to my variable until there have been two character that equal " " (thus, I have two words).

    I am confused about the substr warning as I am sure, that there are plenty of characters left in the substring.

    Hope this makes my dilemma clearer.

      Yes it does. You can (and should) do this by a single regex. Like this:

      if ($html =~ /Rapporteur: (\S+ \S+)/) { $reporters_name = $1; }

      The regexp searches for "Rapporteur:" followed by a single space, then some non-space characters, a single space and again some nonspace chars. And it captures those two groups of nonspace characters.

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne