./ipdec2oct.pl 10.m55.000.001 ##```## octal 012.0.0.1 ##``````## Argument "m55" isn't numeric in lt at ./ipdec2oct.pl line 22. ##``````## \$octet10 =~ /^\d{1,3}\$/ ##``````## if ( \$octet10 < 0 ) { &USAGE("\"\$address{decimal}\" don't cut it: \"\$octet10\" is less than 0"); } ##``````## &USAGE("\"\$address{decimal}\" don't cut it: \"\$octet10\" is greater than 255"); ##``````## &USAGE(qq["\$address{decimal}" don't cut it: "\$octet10" is greater than 255]); ##``````## &USAGE(qq."\$address{decimal}" don't cut it: "\$octet10" is greater than 255.); ##``````## if ( \$octet10 > 255 ) { print qq/"\$address{decimal}" don't cut it: /, qq/"\$octet10" is greater than 255./; &USAGE; } ##``````## if (\$octet8 > 7) { \$octetpadded = "0\$octet8"; } else { \$octetpadded = \$octet8; } ##``````## \$octetpadded = (\$octet8 > 7) ? "0\$octet8" : \$octet8; ##``````## \$octetpadded = (\$octet8 > 7) ? "0\$octet8" : \$octet8; push @octets8, \$octetpadded; ##``````## push @octets8, (\$octet8 > 7) ? "0\$octet8" : \$octet8; ##``````## for my \$octet10(@octets10) { ##``````## for (@octets10) { ##``````## my @octets10 = split /\./, \$address{decimal}; for (@octets10) { ##``````## for (split /\./, \$address{decimal}) { ##``````## \$address{octal} = join '.', @octets8; print "\n decimal \$address{decimal}\n octal \$address{octal}\n\n"; ##``````## print "\n decimal ", \$address{decimal}, "\n octal ", join('.',@octets8), "\n\n"; ##``````## #!/usr/bin/perl -w use strict; my @octets8; my \$ip = shift; unless (defined \$ip) { print 'Enter *something* for input'; usage(); } for (split /\./, \$ip) { my \$err = "\$ip don't cut it: \$_"; if ( !/^\d{1,3}\$/ ) { print "\$err ain't a number."; usage(); } elsif ( \$_ > 255 ) { print "\$err is greater than 255."; usage(); } else { my \$oct = sprintf "%lo", \$_; push @octets8, (\$oct > 7) ? "0\$oct" : \$oct; } } print "\n decimal ", \$ip, "\n octal ", join('.',@octets8), "\n\n"; sub usage { print join "\n ", "\n Usage: ipdec2oct.pl dottedquad_decimal_ipaddr\n", \$0, "Perl \$]", \$^O, "\n"; exit; } ```