Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

how to match figure and chapter no?

by virudinesh (Acolyte)
on May 06, 2013 at 10:03 UTC ( #1032226=perlquestion: print w/ replies, xml ) Need Help??
virudinesh has asked for the wisdom of the Perl Monks concerning the following question:

<code> input s: $a='figure1 vdfsvh figure3 vdsvjjh'; $b='chapter 3 svbjjvfh chapter5'; need output is a href="chapter 3.html#figure 3>figure 3

Comment on how to match figure and chapter no?
Replies are listed 'Best First'.
Re: how to match figure and chapter no?
by hdb (Prior) on May 06, 2013 at 10:17 UTC

    Assuming you want output only if there is a matching chapter and figure number:

    use strict; use warnings; # avoid using $a and $b my $f='figure1 vdfsvh figure3 vdsvjjh'; my $ch='chapter 3 svbjjvfh chapter5'; my @figs = $f =~ /figure\s*(\d+)/g; my %chaps; $chaps{$_}++ for ( $ch =~ /chapter\s*(\d+)/g ); for my $i (@figs) { print "href=\"chapter $i.html#figure $i\">figure $i\n" if exis +ts $chaps{$i}; }
Re: how to match figure and chapter no?
by Anonymous Monk on May 06, 2013 at 10:24 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1032226]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (9)
As of 2015-07-28 11:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls