There's more than one way to do things PerlMonks

### Re: IP address - decimal to octal

by Petruchio (Vicar)
 on Apr 23, 2001 at 01:21 UTC ( #74600=note: print w/replies, xml ) Need Help??

```./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 l
+ess than 0");
}
```
```&USAGE("\"\$address{decimal}\" don't cut it:  \"\$octet10\" is greater t
+han 255");
```
```&USAGE(qq["\$address{decimal}" don't cut it:  "\$octet10" is greater tha
+n 255]);
```
```&USAGE(qq."\$address{decimal}" don't cut it:  "\$octet10" is greater tha
+n 255.);
```
```if ( \$octet10 > 255 ) {
print qq/"\$address{decimal}" don't cut it:  /,
qq/"\$octet10" is greater than 255./;
&USAGE;
}
```
```    if (\$octet8 > 7) {
...
else {
}
```
```    \$octetpadded = (\$octet8 > 7) ? "0\$octet8" : \$octet8;
```
```    \$octetpadded = (\$octet8 > 7) ? "0\$octet8" : \$octet8;
```
```    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   ", join('.',@octets8),
"\n\n";
```
```#!/usr/bin/perl -w

...
\$0, "Perl \$]", \$^O, "\n";
exit;
}
```

Create A New User
Node Status?
node history
Node Type: note [id://74600]
help
Chatterbox?
 usemodperl slips on a banana skin

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2018-06-24 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (126 votes). Check out past polls.

Notices?