Using Perl, I just want to substitute the space to 0. Spaces were separated by tab (\t). Thanks in advance! For example:
1 2 2 5 4
4 4 4 4 3
4 4 1
1 5 6 4
To
1 2 0 0 2 0 5 0 0 0 4
4 4 4 0 0 4 0 0 0 3 0
0 0 4 4 0 0 1 0 0 0 0
0 1 5 6 0 4 0 0 0 0 0
My code:
use strict;
use warnings;
open(DATA,"DATA")||die"cannot open the file: $!\n";
while( <DATA> )
{
s/(^| \K)(?!\d)/0/g;
print;
}
It comes out:
1 2 2 5 4
4 4 4 4 3
0 4 4 1
0 1 5 6 4