neo33 neo33 - 13 days ago 5
Perl Question

How to replace the following character contained in a perl variable?

Hello I need to customize a perl script that is used to generate reports,

First it uses a variable called report to write a csv as follows:

open report ,">report";


Then this script perform a while, inside the while code just uses

print report $tpISAAddress."\n";


to write every line of the script and it generates the following output:

$ cat report
ZZ:BCGROUP
ZZ:ABGROS
ZZ:AGROUP
13808610


I would like to obtain instead this output, with two columns, the separator is ":", as follows:

ZZ,BCGROUP
ZZ,ABGROS
ZZ,AGROUP
13808610


The only thing that I wish is to replace ":" to ",", the problem is that I am not sure how to achieve this since I am more familiar with bash, in bash you could do this inside the while:

tpISAAddress=$(echo $tpISAAddress | sed s/:/,/g)


to replace this character, however I am not sure the process in perl to achieve this, I would like to appreciate support,

Answer

Like this

$tpISAAddress =~ s/:/,/;
print report $tpISAAddress."\n";
Comments