yueli711 has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I just want to substitute the space to 0. Spaces were separated by tab. Thanks in advance! For example
1 2 2 5 4 4 4 4 4 3 4 4 1 1 5 6 4 change 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
#use strict #use warning open(IN1, "tmp01") || die "Cannot open this file"; @lines = <IN1>; $i = 0; for (@lines) { $lines[$i]=~s/\s\s+/\t0\t/g; $thislines[$i]=$lines[$i]; print $thislines[$i]; $i++; } open(OUT, ">tmp02") || die "Cannot open this file"; for $thisline(@thislines){ print OUT $thisline;} close(OUT); close(IN1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: substitute space to 0
by tybalt89 (Monsignor) on Aug 17, 2018 at 15:59 UTC | |
by yueli711 (Sexton) on Aug 17, 2018 at 18:29 UTC | |
by tybalt89 (Monsignor) on Aug 17, 2018 at 20:02 UTC | |
| |
|
Re: substitute space to 0
by AnomalousMonk (Archbishop) on Aug 17, 2018 at 15:49 UTC | |
|
Re: substitute space to 0
by LanX (Saint) on Aug 17, 2018 at 15:38 UTC | |
|
Re: substitute space to 0
by AnomalousMonk (Archbishop) on Aug 18, 2018 at 05:11 UTC | |
|
Re: substitute space to 0
by kcott (Archbishop) on Aug 18, 2018 at 09:40 UTC | |
by AnomalousMonk (Archbishop) on Aug 18, 2018 at 17:04 UTC | |
by kcott (Archbishop) on Aug 19, 2018 at 10:41 UTC |