That is exactly what I want. It works. Thanks.
>From: "$Bill Luebkert" <[EMAIL PROTECTED]> >To: SolHai Haile <[EMAIL PROTECTED]> >CC: [email protected] >Subject: Re: Some Help please >Date: Tue, 18 Jul 2006 23:58:15 -0700 > >$Bill Luebkert wrote: > > > Here's the +1 part if I understand your Q : > > > > my $mac = "00:14:85:50:A3:CF"; > > my @f = split /:/, $mac; > > $f[-1] = sprintf "%02X", hex ($f[-1]) + 1; > > my $newmac = join ':', @f; > > print $newmac, "\n"; > >Note that this solution doesn't handle rollover after FF. >I'm not usre what your intent is there - you could set it >to 00 and add one to the prior field etc. or treat the >last 3 fields as an integer which you increment and then >store back into 3 fields. > >my $mac = "00:14:85:50:A3:CF"; >my @f = split /:/, $mac; > ># convert last 3 bytes to integer > >my $tmp = (hex ($f[-3]) << 16) + (hex ($f[-2]) << 8) + (hex ($f[-1])); >$tmp += 1; # add 1 > >$f[-3] = sprintf "%02X", $tmp >> 16 & 0xff; >$f[-2] = sprintf "%02X", $tmp >> 8 & 0xff; >$f[-1] = sprintf "%02X", $tmp & 0xff; >my $final_mac = join ':', @f; >print $final_mac, "\n"; > >$tmp += 1; >$f[-3] = sprintf "%02X", $tmp >> 16 & 0xff; >$f[-2] = sprintf "%02X", $tmp >> 8 & 0xff; >$f[-1] = sprintf "%02X", $tmp & 0xff; >$final_mac = join ':', @f; >print $final_mac, "\n"; > > > _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
