Example 5-6. examples/intro/t03_calc.t
#!/usr/bin/perl
use strict;
use warnings;
my $result;
$result = `./mycalc 1 + 1`;
if ( $result == 2 ) {
print "ok\n";
}
else {
print "not ok\n";
}
$result = `./mycalc 2 + 2`;
if ( $result == 4 ) {
print "ok\n";
}
else {
print "not ok\n";
}
$result = `./mycalc 2 + 2 + 2`;
if ( $result == 6 ) {
print "ok\n";
}
else {
print "not ok\n";
}
# We replaced the "system" calls with backtick in order to catch the STDOUT
# It is extreamly verbose and we are repeating the same code a lot of times
Output:
| Prev | Home (Copyright Gabor Szabo) Perl Training Israel | Next |
| More difficult output | Up | Write the ok function |