Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to strip out the periods in an IP list, and pad the octets with 0 so I get a 12 digit number. (I'm not worried about the first octet truncating the leading zeros.) I'm getting an invalid subroutine on line 16, and am not really sure what I am doing wrong. Could you take a look?
Thanks,
Carrie
$pad_char = "0"; $pad_len = "3"; $padded = ""; open IN, '<ConvertMe.txt' or die; while (<IN>) { chomp; my($octet1, $octet2, $octet3, $octet4) = split(/./, $_, 4); foreach( $octet1, $octet2, $octet3, $octet4 ) { $padded = $pad_char x ( $pad_len - length( $_ ) ) . $_ ; substr($converted, legnth($padded ) ) = $padded; } open OUT, '>>Converted.txt' or die; print $converted; } close OUT; close IN;
Edited: ~Thu Jul 25 21:11:42 2002 (GMT) by footpad: Added <CODE> and other markup tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: simple padding of IP address
by Aristotle (Chancellor) on Jul 25, 2002 at 21:12 UTC | |
|
Re: simple padding of IP address
by thelenm (Vicar) on Jul 25, 2002 at 21:12 UTC | |
by Aristotle (Chancellor) on Jul 25, 2002 at 21:15 UTC | |
|
Re: simple padding of IP address
by BorgCopyeditor (Friar) on Jul 26, 2002 at 03:08 UTC |