[SOLVED] Perl ( Print $_ ) Incorrect output for characters || forparam loop

Issue

This Content is from Stack Overflow. Question asked by Bassem Abd Elmaksoud

I am having the below lines of perl cgi code that suppose to iterate through a file lines and print each line. The issue is what is printed to the stdout for a specific line (in[ 41: ]) is not the same in the file.

Note : This is a perl cgi script.

code :

for (param('menu')) {
  /^(1)$/ and do {
                        $Sample="cat /tmp/int_rej_sample.txt";
                        @Sample=`$Sample`;
                        foreach (@Sample) {print $_,p}
   }

   }

cat /tmp/int_rej_sample.txt is :

 in[ 37: ]<22222222222>
 in[ 39: ]<91>
 in[ 39: ]<91>
 in[ 41: ]<BBBBBBBB44444444>
 in[ 42: ]<9999999999     >

output to cgi window is :

in[ 37: ]<22222222222>

in[ 39: ]<91>

in[ 39: ]<91>

in[ 41: ]

in[ 42: ]<9999999999 >



Solution

I have added a space between "<" and any character after it in the file before entering the print loop .That solved the issue.

sed -e 's/</< /g' /tmp/int_rej_sample_dev.txt | sed -e 's/>/ >/g' > /tmp/int_rej_sample.txt
 


This Question was asked in StackOverflow by Bassem Abd Elmaksoud and Answered by Bassem Abd Elmaksoud It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?