#!/usr/local/bin/perl # Copyright(C)1999,2001 by Daniel B. Sedory # # This PROGRAM creates a list of Standard IP Addresses (NO leading # zeros) from a list of "Formatted IP Numbers" by REMOVING any leading # zeros in memory before writing the new file. It reverses the process # of the program "ip2ipf.pl" For example: # # 001.023.004.056 will be listed as 1.23.4.56 # # [ SEE comments in the companion Perl program ip2ipf.pl ] # # The OUTPUT FILE will be named: ip.txt # ( INPUT file will NOT be changed ) print "\n This program makes NO changes to the INPUT file. The INPUT\n"; print " file must contain only a listing of IP Numbers (one per line!)\n"; print " It REMOVES leading ZEROs from IPs such as 001.023.004.056 by\n"; print " saving the Standard IP format (1.23.4.56) to an OUTPUT file\n"; print " called: ip.txt\n\n"; print " What is the file you wish to read? "; $inpfilename = ; chop($inpfilename); open (FILE, "$inpfilename") || die("Could not open the file $inpfilename"); @lines = ; close(FILE); open(PIP, ">ip.txt"); foreach $line (@lines) # Examine one line at a time. { @words = split(/\./, $line); # Split line into an array of 4 words # using the "dots" as separators. $words[3] =~ s/\n//; # Remove "newline char" from last. foreach $word (@words) { # REMOVE any leading zeros ... $word =~ s/^00//; $word =~ s/^0//; if ($word eq "") {$word = "0";} # Make sure we don't remove # a zero that's part of the # IP Number itself. } # Put the line back together again # using the JOIN function: $line = join (".", @words); # In the past we had a more complicated method here using a "." # between each element of @words and the decimal point (.) to # concatenate the string together! print PIP "$line\n"; # Write the new line and get another one... } close(PIP); exit; # Copyright(C)1999,2001 by Daniel B. Sedory