in reply to Automatically hyperlinking text fails with newlines

try...
while(<FILE>) { chomp; $output .= $_; }
which will remove newlines from $_

                - Ant
                - Some of my best work - Fish Dinner

Replies are listed 'Best First'.
Re: Re: Automatically hyperlinking text fails with newlines
by Anonymous Monk on Sep 20, 2001 at 21:14 UTC
    Hi, thanks for this.

    However I only want to remove the \n from inside the hyperlink whilst still preserving the newlines elsewhere. In other words the output should be:

    The quick brown fox at <a href="http://fish.org" target="_blank">http: +//fish.org</a> would like to go home and <a href="http://seethrough.c +om" target="_blank">http://see through.com</a> what there is to eat
    (http://www.seethrough.com is preserved within the href tag, but still has the newline for the display)
      well then... you could pass $1 as a function, since you are matching the hyperlink with the \n, similar to...
      s/regex/make_link($1)/eg; sub make_link { my $url = $_[0]; $url =~ s/\s+//g; qq`<A HREF="$url">$url</A>`; }

                      - Ant
                      - Some of my best work - Fish Dinner

      Greetings.

      This being the case, I would (still) slurp the entire file, not replace \n, and put \n among the acceptable characters in the regexp (and I *think* you may have to use the /s modifier). I would then replace the \n still embedded in the href.

      Not perfect, because this:

      Ehi, check this out on http://cnn.com\n
      dude!
      
      would yield: http://cnn.comdude. In other words, if you want ignorable newlines within URIs, then URIS must always be separated by real whitespace from the surrounding text.

      Cheers,
      alf