Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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

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?
[james28909]: i thiught you were going to say make both hands into a fist and puch yourself in the face
[atcroft]: .oO(Sorry, I probably should have said take two normal hands....)
[atcroft]: james28909: No, unless you are a politician, I wouldn't say that (and even if you are, I still probably wouldn't say that).
[james28909]: i mean how hard can it be? its just subtracting days lol
[atcroft]: james28909: What about October 5, 1582?
[stevieb]: atcroft: "Make both hands into fists..."... is something my Ma taught me in our native lang, but I was to ignorant and young to pay attention. Thanks for that :)
[atcroft]: stevieb: Sad to say that I only recently learned that particular trick, but I have since found it very useful.... :)
[james28909]: ill be back with a solution eventually
[stevieb]: it's a reminder to re-inforce it :P

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2017-04-29 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (531 votes). Check out past polls.