Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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?
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 chilling in the Monastery: (5)
As of 2014-10-22 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (112 votes), past polls