Hi Team,
I need to make multiple substitutions in a file.There could be a
situation where there are more than one substitution on a single
line.I want to count the total # of substituitions.I need to use
subroutines:
I have 3 questions:
1) Do I have to make 3 separate Regex.How can it be done in a single line?
2)How to use Subroutines with this?If I just want the Sub to
substitute the value and return the line?
3)Is it a good practice to open the file using Sub? If so, how to do that?
here is my code:
!/usr/bin/perl -w
use strict;
my $line;
my ($count,$count1,$count3,$count2);
open FILE, "data.txt" or die"cnt open $!";
foreach $LINE(<FILE>) {
if ($var =~ s/cellomics/array/g) {
$count1++;
}
if ($var=~ s/perkin almer/janus/g) {
$count2++
}
if ($var =~ s/dell/laptop/g) {
$count3++
}
}
close FILE;
***********
Thanks a lot in advance
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/