use strict;
use warnings;
use Data::Dumper;
use Tie::File;
# open the file if it exists, but fail if it does not
use Fcntl 'O_RDWR';
our @array = ();
our $file = 'taste';
tie @array, 'Tie::File', $file, mode => O_RDWR or die $!;
our $SearchString = 'HAI WORLD Times ([0-9]+).*$';
#our $ReplaceString = "\t\t'; # we could use such a statement ONLY if we figured out what something() would be
my $elementIdx = 0;
while($elementIdx <= $#array)
{
if($array[$elementIdx] =~ $SearchString)
{
# Maintain only the first character
#$array[$elementIdx] = unpack ('a' . (1 + length("\t\t")), something($ReplaceString)); # I would love to know what something() could be so that I can separate the configuration from the logic
$array[$elementIdx++] = "\t\t';
#++$elementIdx;
}
else
{
splice @array, $elementIdx, 1;
# we don't want this in the output
}
}
untie @array; # all done!
####
HAI WORLD Times 0
HAI WORLD Times 1
HAI WORLD Times 2
HAI WORLD Times 3
HAI WORLD Times 4
HAI WORLD Times 5
HAI WORLD Times 6
HAI WORLD Times 7
HAI WORLD Times 8
HAI WORLD Times 9
HAI WORLD Times 10
HAI WORLD Times 11
HAI WORLD Times 12
HAI WORLD Times 13
HAI WORLD Times 14
HAI WORLD Times 15
HAI WORLD Times 16
HAI WORLD Times 17
HAI WORLD Times 18
HAI WORLD Times 19
HAI WORLD Times 20
HAI WORLD Times 21
HAI WORLD Times 22
HAI WORLD Times 23
HAI WORLD Times 24
HAI WORLD Times 25
####