anek77713 has asked for the wisdom of the Perl Monks concerning the following question:

Hi!
my $Npod = 'N<(.*?)>'; my $N = '<font class="footnote">'; my $n = '</font>'; open(DATA, "<file.pod"); my @file = <DATA>; s/$Npod/$N$1$n/s for @file;

file.pod:

If you have no Perl 5 installed (or if you have an old version install +ed), you can install a newer release yourself. Windows users, download Strawber +ry Perl from U<http://www.strawberryperl.com/> or ActivePerl from U<http://www.activestate.com/activeperl>. Users of other operating sys +tems with Perl 5 already installed (and a C compiler and the other development t +ools), start by installing the CPAN module C<App::perlbrew>N<See U<http://search.cpan.org/perldoc?App::perlbrew> for installation instructions.>.
question: How can I match the N<> (footnote) ? My code does not work :(

Replies are listed 'Best First'.
Re: matching POD footnote
by LanX (Saint) on Jul 18, 2013 at 08:48 UTC
    you have nested POD in your pseudo-POD

    N<See U<http://search.cpan.org/perldoc?App::perlbrew> for installation instructions.>.

    This can hardly be fully solved with a "simple" regex, better try to extend a real POD-Parser.

    Otherwise you could try to count opened and closed < > but I'm pretty sure that you'll get bitten again somewhere.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      "Otherwise you could try to count opened and closed < > but I'm pretty sure that you'll get bitten again somewhere."

      Like here...

      N< See the documentation for the fat comma (C<< => >>). >

      :-)

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      Thnx, but I really need to do it without using any POD-Parser.

        Why?

        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
Re: matching POD footnote
by anek77713 (Acolyte) on Jul 18, 2013 at 09:29 UTC

    This one works for me. :)

    my $start_Note = 'N<'; my $N = '<font class="footnote">'; my $end_Note = '\.>'; my $n = '</font>'; open(DATA, "<file.pod"); my @file = <DATA>; s/$start_Note/$N/g for @file; s/$end_Note/$n/g for @file;

      I sincerely hope that you would not receive full marks for such a solution. I intend no offense by that; only that you receive thorough feedback, if not from your teacher, then from us monks. To get you thinking, what happens when you run it on the following inputs:

      N<See U<http://example.com> now!> To include footnotes in this pseudo-POD, use this syntax: C<N<footnote +.>> N<<< Repeated angle brackets are allowed; see L<perlpod>. >>>

      Hint: Your solution produces what I would consider incorrect results for all three lines.

Re: matching POD footnote
by mtmcc (Hermit) on Jul 18, 2013 at 08:22 UTC
    What outcome are you looking for?

    -Michael

      substitute this:
      N<See U<http://search.cpan.org/perldoc?App::perlbrew> for installation instructions.>.

      whit this:

      <font class="footnote">See U<http://search.cpan.org/perldoc?App::perlbrew> for installation instructions.</font>.

        Can you explain what  my @file = <DATA>; does?

        Can you explain what  s/$Npod/$N$1$n/s for @file; does?

        At what point does $_ contain multiple lines?

        Basic debugging checklist, $_ never contains more than one line