Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Find and replace using regex

by prasadbabu (Prior)
on Jul 13, 2006 at 12:48 UTC ( [id://560931]=note: print w/replies, xml ) Need Help??


in reply to Find and replace using regex

Hi rsriram,

Here is one way to do it.

use strict; use warnings; my $str = do { local $/, <DATA> }; my @fnote = qw(<FN1>footnote1</FN1> <FN2>footnote1</FN2> <FN3>footnote +1</FN3>); #Already retrived footnotes my %hash; for (@fnote) { $hash{$1} = $_ if ($_ =~ /<(FN\d+)>/); } $str =~ s|<(FN\d+)ref>|$hash{$1}|g; print $str; __DATA__ <p> Here some text <FN1ref> and some text Here some text <FN2ref> and some text Here some text <FN3ref> and some text </p> <FN1>afsdfsaf</FN1> <FN2>afsdfsaf</FN2> <FN3>afsdfsaf</FN3> outputs: -------- <p> Here some text <FN1>footnote1</FN1> and some text Here some text <FN2>footnote1</FN2> and some text Here some text <FN3>footnote1</FN3> and some text </p> <FN1>afsdfsaf</FN1> <FN2>afsdfsaf</FN2> <FN3>afsdfsaf</FN3>

* My 200th post :)

Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://560931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-26 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found