M
matt
I am currently trying to convert a vba macro to perl. The vba macros
are basically find and replaces on txt files. The problem is that there
are roughly 25000 find and replaces and they are setup to run in a
sequential order, meaning that they search for a string and if the
string is found then it will find and replace from that point on until
EOF. Once it reaches the EOF it will then reset to the start of the txt
file and continues on to the next find and replace. How can I
accomplish this type of parsing with perl. I am trying to get the vba
code out of microsoft word so I do not want to use the win32:le for
this conversion. Here is a snippet of the VBA and converted perl code.
Thanks for any help in advance.
<SNIP>
VBA code:
Set variable = New variable_Class
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("[0-9]{1,} [0-9]{1,} [0-9]") =
True Then
Selection.HomeKey wdStory
variable.FindandReplace "(^13+pg,[0-9]{1,}^13)(+l)
", " \2\1"
Call Subroutine
End If
End If
End If
End If
Perl converted code:
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/[0-9]{1,} [0-9]{1,} [0-9]/){
#Selection.HomeKey wdStory <==not sure how to convert this
to perl
$_=~s/(\n\+pg,[0-9]{1,}\n)(\+l)/ $2$1/g;
&Subroutine;
}
}
}
}
are basically find and replaces on txt files. The problem is that there
are roughly 25000 find and replaces and they are setup to run in a
sequential order, meaning that they search for a string and if the
string is found then it will find and replace from that point on until
EOF. Once it reaches the EOF it will then reset to the start of the txt
file and continues on to the next find and replace. How can I
accomplish this type of parsing with perl. I am trying to get the vba
code out of microsoft word so I do not want to use the win32:le for
this conversion. Here is a snippet of the VBA and converted perl code.
Thanks for any help in advance.
<SNIP>
VBA code:
Set variable = New variable_Class
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("<R [,]") = True Then
Selection.Collapse wdCollapseEnd
If variable.FindText("[0-9]{1,} [0-9]{1,} [0-9]") =
True Then
Selection.HomeKey wdStory
variable.FindandReplace "(^13+pg,[0-9]{1,}^13)(+l)
", " \2\1"
Call Subroutine
End If
End If
End If
End If
Perl converted code:
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/<R [,]/){
#Selection.Collapse wdCollapseEnd <==not sure how to convert
this to perl
if ($_=~/[0-9]{1,} [0-9]{1,} [0-9]/){
#Selection.HomeKey wdStory <==not sure how to convert this
to perl
$_=~s/(\n\+pg,[0-9]{1,}\n)(\+l)/ $2$1/g;
&Subroutine;
}
}
}
}