in reply to Strange values in hash reference

My bet is that you are running on a *nix platform and the data in the database includes \r\n sequences. Therefore when you display a line it displays the line, does a carriage return, and then (since you don't do the newline advance) displays the next line on top of the old.

Try stripping out \r and see if that makes a difference.

  • Comment on Re (tilly) 1: Strange values in hash reference

Replies are listed 'Best First'.
Re: Re (tilly) 1: Strange values in hash reference
by filmo (Scribe) on Aug 15, 2001 at 11:05 UTC
    Thanks, this totally fixed the problem. New code =

     $$job_hash{'subjects'} =~ s/\r\n/<br>/g;
    --
    Filmo the Klown

      Be careful. The line endings in your database could be inconsistent. Try:
      s/\r\n?|\n\r?/<br>/g;
      which should work no matter which line ending is in the database whether you are on Windows, Unix, or a Mac.

      If you are (as it looks) trying to define a set of conversions for turning text into somewhat equivalent HTML, you might also want to look at Parse::RecDescent for a much better way to do parsing than just throwing a few regular expressions at it. Or you can go for the hand-rolled version at Why I like functional programming (see the bottom of the thread for a cleaner rewrite through). The rule here could be done by adding the handler

      sub {'<br>'}
      for each of "\r\n", "\n\n", "\r", and "\n". Why would you do that you ask? Well because with that code you can readily implement markup rules based on user defined choices without getting into a mess of custom logic.