in reply to Replacing text in a string
Assuming this is not HTML and thus is appropriate for a simplistic search and replace the following code should get you started:
use warnings; use strict; my $str = <<TEXT; All businesses, regardless of their size, location, or mission, operat +e within a larger external environment. This external environment consists of eve +rything outside an organization’s boundaries that might affect it. Not surprisingly, the external environment plays a major role in determini +ng the success or failure of any organization. Managers must therefore have a + complete and accurate understanding of their environment and then strive to ope +rate and compete within it. Of course, businesses can also influence their envi +ronments. To better explain the environment of business, we begin by discussing organizational boundaries, and then we introduce the concept of multip +le 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 bec +oming increasingly complicated and hard to pin down. Consider the simple cas +e of a small neighborhood grocery that includes a retail customer area, a sto +rage 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> TEXT my @footnotes; push @footnotes, [$1, $2] while $str =~ m|<fn\s+id="(\w+)">((?:(?!</fn +>).)*)</fn>|gms; $str =~ s| <fref\s+id="\Q$_->[0]\E"/> | <footnote id="$_->[0]"$_->[1]<\/para><\/footnote> |gxms for @footnotes; print $str;
Prints:
All businesses, regardless of their size, location, or mission, operat +e within a larger external environment. This external environment consists of eve +rything outside an organization’s boundaries that might affect it. Not surprisingly, the external environment plays a major role in determini +ng the success or failure of any organization. Managers must therefore have a + complete and accurate understanding of their environment and then strive to ope +rate and compete within it. Of course, businesses can also influence their envi +ronments. To better explain the environment of business, we begin by discussing organizational boundaries, and then we introduce the concept of multip +le organizational environments. Quite simply, an organizational boundary +is that which separates the organization from its environment. <footnote id="fn1"See Waren J. Keegan, Global Marketing Management</para></footnote> But whereas boundaries were once relatively easy to identify, they are bec +oming increasingly complicated and hard to pin down. Consider the simple cas +e of a small neighborhood grocery that includes a retail customer area, a sto +rage room, and an owner/manager’s office. <footnote id="fn2"See James J. Kellenberger, Global Warming Management</para></footnote> 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>
The replacement text looks rather broken to me, but that's from an HTML perspective so probably isn't relevant and is easily fixed in any case (probably). The main trick is to generate a list of footnote pairs up front, then perform a global search and replace for each footnote.
|
|---|