Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2016-10-22 01:51 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.