can someone help me understand why in the following code $mc_value being printed a line after $p_value and not infront of it with a tab distance of $p_value? Removing "\n" didn't help.
Also, if I want to send the ouput to a file, should I put OUT infront of every print function? Thank you so much for your hints
#!/usr/bin/perl
use strict;
use warnings;
my $file = "c:/ubuntu/regular.txt";
#open OUT,">C:/output/filded_processed.txt";
open my $fh, "<", $file or die "Unable to open $file: $!";
my($u_value, $p_value, $mc_value) = (undef) x 3;
while (my $line=<$fh>) {
if ($line=~/\n\n\n/){
($u_value, $p_value, $mc_value) = (undef) x 3;
print "\n";
} elsif ($line=~/\bProcessing\s/) {
$line=~s/\bProcessing\s\d+\.tx\.\d+: //;
$u_value = $line;
print "\n$u_value\n";
undef $p_value;
} elsif ($line=~/\bPhrase/) {
$line=~s/\bPhrase: //;
$line=~s/\"//g;
if ($p_value) {
print "\n" . ' ' x length $u_value;}
$p_value=$line;
print "\t$p_value";
undef $mc_value;
} elsif ($line=~/\s\s/ ) {
if ($mc_value) {
print "\t" . ' ' x length $p_value;}
$mc_value=$line;
print "\t$mc_value";
} else {
#die "Unexpected line format encountered, $file, @data";
}
}
close $fh;
|