단위, 인치 및 센티미터 등으로 변환해야하는이 perl 프로그램이 있습니다. 그러나 루프 중에 변수를 인쇄하지는 않습니다. 그것은 단지 표준 "같다"인쇄와 $은 Unit2는 여기에 내 코드 여기Perl 텍스트 분석 변수가 인쇄되지 않습니다.
#!/usr/bin/perl
#usage: perl convert.pl
use Path::Class;
use warnings;
use autodie; # die if problem reading or writing a file
my $dir = dir("./");
my $file = $dir->file("distances.txt");
# Read in the entire contents of a file
my $content = $file->slurp();
# openr() returns an IO::File object to read from
my $file_handle = $file->openr();
# Read in line at a time
while(my $line = $file_handle->getline()) {
# parses string into value and unit
my ($val, $unit) = split /[\n]/, $line;
# initialize values
my ($val2, $unit2) = "";
# check unit and apply corresponding math
if ($unit eq "in") {
$val2 = $val * 2.54;
$unit2 = "cm";
}
else {
if ($unit eq "ft") {
$val2 = $val * 0.3048;
$unit2 = "m";
}
else {
if ($unit eq "yd") {
$val2 = $val * 0.9144;
$unit2 = "m";
}
else {
if ($unit eq "mi") {
$val2 = $val * 1.609347;
$unit2 = "km";
}#close mile if statement
}#close else statement
}#close 2nd else statement
}#close 1st else statement
print $val, " ", $unit, " is equal to ", $val2, " ", $unit2, "\n";
}
내가 사용하고 텍스트 파일입니다
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 1.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 2.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 3.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 4.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 5.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 6.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 7.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 8.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 9.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 10.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 11.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 12.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 13.
is equal to
Use of uninitialized value $unit2 in print at convert.pl line 47, <GEN1> line 14.
is equal to
초기화되지 않은 것을 말한다.
74 in
10 in
10 ft
10 yd
10 mi
72 in
6 ft
2 yd
300 ft
100 yd
158400 in
13200 ft
4400 yd
2.5 mi
'사용 경고;' – toolic
https://metacpan.org/pod/Math::Units – toolic
* ** 항상 *** 엄격한 사용 및 경고 사용 'all'' – Borodin