I have a string of characters ex: fhjhejfherhfehk ehkeh
I want to retain the first "h" and delete all the other characters how do i do it ?
I want to retain the first "h" and delete all the other characters how do i do it ?
while(<IN1>) {
chomp($_);
if (/cat(?=\s)/) {
s/cat/dog/;
}
}
D:\perl>type test.pl
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
my $str = 'catacatbcatccatdagduefgvdcat sfjjgja';
if ($str =~ s/cat(?=\s)/dog/) {
say $str;
}
else {
say "no match";
}
#!/usr/bin/perl -w
my $testlist = $ARGV[0];
open(IN, "$testlist") || die "cannot open test list:$testlist";
open(OUT, ">$outfile") || die "cannot open output file:$outfile";
while(<IN>) {
chomp($_);
if (/cat(?=\s)/){
s/cat/dog/;}
printf OUT <<EOF
$_
EOF
;
}
close(IN);
close(OUT);
Comment