in reply to Re^2: Perl code to format the text file by inserting tag in blank line
in thread Perl code to format the text file by inserting tag in blank line
print OUTFILE "$result{$moid}{$ext}{$kpi[$jk]}\n"; perl -i -lpe "s/^\s*$/<r><\/r>/g" $OUTFILE
Command-line syntax cannot be included directly in Perl code. I'm surprised this would even compile!
Be that as it may, you seem to be trying to check if the string "$result{$moid}{$ext}{$kpi[$jk]}\n" is a blank line and output "<r></r>\n" if it is. Try (untested):
instead.my $out = "$result{$moid}{$ext}{$kpi[$jk]}\n"; $out =~ s{ \A \s* \z }{<r></r>\n}xms; print OUTFILE $out;
Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom