I love to use the one you recommend but I am just a beginner so not sure how to apply See if you can help me to edit my code below I like to change the value in column one to a fix value. Any number should reduced by 1 except "1" becomes "P". I am trying to learn how to use map or grep not creating the hash, that the guys showed me. Thanks Macy
"Header1","Header2",Header3" "A123","1","valueB1" "B234","1","valueB2" "C345","2","valueB3" "D456","3","valueB4" "E567","4","valueB5" "F678","5","valueB6"
and the output should be
"Header1","Header2",Header3" "A123","P","valueB1" "B234","P","valueB2" "C345","1","valueB3" "D456","2","valueB4" "E567","3","valueB5" "F678","4","valueB6"
here is my code
open my $fh1,'<',"NRoomch.txt"; my @a = <$fh1>; my @arr; for $i (0..$#a){ my @b = split(/,/,$a[$i]); for $j (0..$#b) { $b[$j] =s~/"//g; if ($j==1 && my @arr = grep { $_ =~ /\"1"$/ } @b); @arr = map{$_ = "P"} @arr; else @arr = map {$b[$j] - 1} (1..$#b); print @arr; }; }; close($fh1);
In reply to Re^4: Replace value in the text file
by mhoang
in thread Replace value in the text file
by mhoang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |