I have the following string in a file and want to truncate the string to no more than 6 char. how to do that using regular expression in perl?
the original file is:
cat shortstring.in:
<value>[email protected]</value>
<value>[email protected]</value>
I want to get file as:
cat shortstring.out
<value>1234@g</value>
<value>1235@g</value>
I have a code as follows, is there any more efficient way than using
s/<value>(\w\w\w\w\w\w)(.*)/$1/;
?
Here is a part of my code:
while (<$input_handle>) { # take one input line at a time
chomp;
if (/(\[email protected])/) {
s/(<value>\w\w\w\w\w\w)(.*)</value>/$1/;
print $output_handle "$_\n";
} else {
print $output_handle "$_\n";
}
}