Hi Monks, I'm new to coding and I'm probably missing something obvious. I'm writing a script to place Markdown footer links under their respective paragraphs. So a file that looks like this:
This is a an example of [Markdown][1] footer links. I'm trying to use +[Perl][2] to organize them more coherently. But I'm getting too many newlines and I'm hoping the [PerlMonks][3] ca +n help. [1]: https://daringfireball.net/projects/markdown/ [2]: http://www.perl.org/ [3]: http://www.perlmonks.org/
Should look like this:
This is a an example of [Markdown][1] footer links. I'm trying to use +[Perl][2] to organize them more coherently. [1]: https://daringfireball.net/projects/markdown/ [2]: http://www.perl.org/ But I'm getting too many newlines and I'm hoping the [PerlMonks][3] ca +n help. [3]: http://www.perlmonks.org/
I want blank lines before and after each block of footer links, but instead, it's placing newlines between each array element, like this:
This is a an example of [Markdown][1] footer links. I'm trying to use +[Perl][2] to organize them more coherently. [1]: https://daringfireball.net/projects/markdown/ [2]: http://www.perl.org/ But I'm getting too many newlines and I'm hoping the [PerlMonks][3] ca +n help. [3]: http://www.perlmonks.org/
Here's the code I'm using:
#!/usr/bin/perl use strict; use warnings; use diagnostics; my $text; local $/; $text = <>; my @url_list = ($text =~ m/\[.*?\]\:.*/g); $text =~ s/\s+\[.*?\]\:.*//g; foreach my $line (split /^/, $text) { print $line; foreach ($line =~ m/\[.*?\]\[(.*?)\]/g) { my $link_number = $_; print "\n"; print grep(/(\[$link_number\]\:.*)/, @url_list); print "\n"; } }
I've tried chomp on all the relevant variables.
In reply to Preventing Blank Lines Between Printed Array Elements by immamanatee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |