I need to subtract one digit from the last octet of the first ip and i need to add one to the last octet of the second ip address.
I am obviously struggling with this as my current code will dictate.
SAMPLE STRING: 192.168.1.1-192.168.1.254 needs to be 192.168.1.0-192.168.1.255
I have many strings of text that are random but the format is similar but the sample string can be 172.15.29.21-172.15.30.23 needs to be 172.15.29.20-172.15.30.24. These are all made up. In the first octet there will never be a zero as the last digit so only the very last digit in the octet needs to be regexed and subracted.
#!C:/Perl/bin/perl.exe
use strict;
use warnings;
my $ip_1 =~ m/(\d)-/g;
$ip_1 = int($ip_1);
my $ip_2 = $ip_1 - 1;
my $input_file = 'CrystalReportViewer1.csv';
my $output_file = 'CrystalReportViewer2.csv';
open(my $output_fh, '>', $output_file)
or die "Failed to open $output_file - $!";
open(my $input_fh, '<', $input_file)
or die "Failed to open $input_file: $!";
while ( <$input_fh> ) {
s/$ip_1/$ip_2/;
print {$output_fh} $_;
}
close $output_fh;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.