dirtyholmes
Programmer
If I have a file containing data with rows of numbers as such. How can you sweep through the file and elequantly check and remove (if they exist) the numbers 2233 or 1435, if they appear at the fixed position of 47-50
eg
Before
21086600000193 592843830 2003121323270022335675762
21086600000193 592843830 2003121410190014355558355
After
21086600000193 592843830 200312132327005675762
21086600000193 592843830 200312141019005558355
I have come up with the following but im not sure how to remove the offending numbers from the line. Can anyone post a suggestion.
open MY_FH, "<mytext.txt" or die "$!";
while (<MY_FH>)
{
my $pos = 47;
my $pidx;
my $fidx;
$num;
$pidx = index $_, "2233",47; # Start looking at position 47 of the file
$fidx = index $_, "1435",47;
if(($pidx || fidx) == $pos)
{
#NEED TO REMOVE 2233 or 1435 here
}
}
eg
Before
21086600000193 592843830 2003121323270022335675762
21086600000193 592843830 2003121410190014355558355
After
21086600000193 592843830 200312132327005675762
21086600000193 592843830 200312141019005558355
I have come up with the following but im not sure how to remove the offending numbers from the line. Can anyone post a suggestion.
open MY_FH, "<mytext.txt" or die "$!";
while (<MY_FH>)
{
my $pos = 47;
my $pidx;
my $fidx;
$num;
$pidx = index $_, "2233",47; # Start looking at position 47 of the file
$fidx = index $_, "1435",47;
if(($pidx || fidx) == $pos)
{
#NEED TO REMOVE 2233 or 1435 here
}
}