neo33 neo33 - 1 year ago 60
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

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


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 Source

Like this

$tpISAAddress =~ s/:/,/;
print report $tpISAAddress."\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download