rsriram has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I have tagged file stored in a string $str and I want to pick up all the footnotes placed at the end of the file and place it next to its reference inside the text. My code to do this is:
for ($i=0; $i <= $cnt; $i++)
{
$str =~ s/<fn id="fn$i">(.+)<\/fn>//g;
$found=$1;
$str =~ s/<fref id="fn${i}"\/>/<footnote id="en${i}">$found<\/footnote>/g;
}
$cnt contains the number of occurrences of footnotes. The first replacement of the footnote works well, but the subsequent replacements are not done correctly. Can anyone tell me what is the problem in the above syntax. The contents of $str is:
All businesses, regardless of their size, location, or mission, operate within a larger external environment. This external environment consists of everything outside an organization’s boundaries that might affect it. Not surprisingly, the external environment plays a major role in determining the success or failure of any organization. Managers must therefore have a complete and accurate understanding of their environment and then strive to operate and compete within it. Of course, businesses can also influence their environments. To better explain the environment of business, we begin by discussing organizational boundaries, and then we introduce the concept of multiple organizational environments. Quite simply, an organizational boundary is that which separates the organization from its environment.<fref id="fn1"/> But whereas boundaries were once relatively easy to identify, they are becoming increasingly complicated and hard to pin down. Consider the simple case of a small neighborhood grocery that includes a retail customer area, a storage room, and an owner/manager’s office.<fref id="fn2"/> In many ways, the store’s boundary coincides with its physical structure: When you walk through the door, you’re crossing the boundary into the business, and when you go back onto the sidewalk, you cross the boundary back into the environment.<fn id="fn1">See Waren J. Keegan, Global Marketing Management</fn><fn id="fn2">See James J. Kellenberger, Global Warming Management</fn>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replacing text in a string
by rodion (Chaplain) on Jul 19, 2006 at 11:50 UTC | |
|
Re: Replacing text in a string
by GrandFather (Saint) on Jul 19, 2006 at 11:23 UTC |