I am trying to circle around what happens in this safe coding example .
I rewrote the code to better support my question:
use warnings;
use strict;
use Data::Dumper;
my $prompt = 'name%n';
my $password = 'badpass';
my $is_ok = ($password eq "goodpass");
print Dumper( $is_ok );
print "\n$prompt: Password ok? $is_ok\n";
print Dumper( $is_ok );
$is_ok = ($password eq "goodpass");
printf "\n$prompt: Password ok? %d\n" , $is_ok;
print Dumper( $is_ok );
When I execute the script, the output is as follows:
$ ./authenticate.pl
$VAR1 = '';
name%n: Password ok?
$VAR1 = '';
Missing argument in printf at ./authenticate.pl line 19.
name: Password ok? 0
$VAR1 = 5;
It is clear that it is $is_okconsumed %nin $prompt, which leaves %dwithout a corresponding argument. I would not expect, however, that the value $is_okwill change, why is it $is_okset in 5the printf statement?
source
share