Will Lee
Will Lee

Reputation: 13

perl not print properly/incomplete

i tried to print something variable. but sometime it will print delay or incomplete. below is my part of my code.

my $ltc1v = $data->{PartNumber}->{rev} . "\n";
chomp $ltc1v;

($result)=$check1=~ /:\s*(.+)$/; 

print "{{ $result }}\n";
print "{{ $ltc1v }}\n";

if ($result eq $ltc1v ) 
{}

sometime result show good and able to match if condition.

{{ 0x000b }}
{{ 0x000b }}

but sometime it will show as below and not able to match if condition.

 }}0x000b
{{ 0x000b }}

FYI, i used below command to auto flushing as well

$| = 1;

Upvotes: 0

Views: 105

Answers (3)

tinita
tinita

Reputation: 4336

I will add my standard recommendation here:

Whenever you are not sure why your output doesn't look like you expect, check what your data contains.

use Data::Dumper;
local $Data::Dumper::Useqq = 1;
print Dumper $result;
# print Dumper \@array, \%hash;

perldoc Data::Dumper

Upvotes: 1

ikegami
ikegami

Reputation: 385789

$check1 contains a Carriage Return.

If you have chomp($check1);, replace it with $check1 =~ s/\s+\z//;.

If you don't have chomp($check1);, just add $check1 =~ s/\s+\z//;.

Upvotes: 0

ysth
ysth

Reputation: 98398

Looks like sometimes your data ends with a carriage return character. You can remove that with $result =~ y/\r//d;.

Or don't include it in what you match:

($result)=$check1=~ /:\s*(.+?)\r?$/;

Upvotes: 1

Related Questions