in reply to Re^3: Function call in regex replacement string
in thread Function call in regex replacement string
use strict; use warnings; use Data::Dumper; use Tie::File; # open the file if it exists, but fail if it does not exist use Fcntl 'O_RDWR'; our @array = (); our $file = 'hai'; tie @array, 'Tie::File', $file, mode => O_RDWR or die $!; our $SearchString = 'HAI WORLD Times ([0-9]+).*$'; our $ReplaceString = '"\t\t<exML LOLZ = \"" . unpack(\'a1\', $1) . "\" +/>"'; my $elementIdx = 0; while($elementIdx <= $#array) { if($array[$elementIdx] =~ $SearchString) { # Maintain only the first character $array[$elementIdx++] = eval $ReplaceString; } else { splice @array, $elementIdx, 1; # we don't want this in the output } } untie @array; # all done!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Function call in regex replacement string
by tilly (Archbishop) on Feb 26, 2009 at 01:23 UTC |