http://qs321.pair.com?node_id=697542

spickles has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to create a subroutine that will take in an array of MAC addresses and simply return a different format to match that of the device I'm telnetted into. For example, the MAC 001589F453CA needs to be changed to AP0015.89F4.53CA I can get this to work fine with a static scalar, but run into problems when I try to pass an array to the subroutine. I'm not sure what everyone feels is a lot of code, so I'll post this code as this is my first post. I have done extensive rewrites to this over the last several days before asking anyone else for help (I've read about folks just dumping their problems and expecting someone else to find it). You'll see from some of my print statements I'm trying to track the values of my variables within my code to find out where it breaks. But at this point, I'm just getting garbage by the third iteration of my loop.
#!c:/Perl/bin/perl my @mac_addrs = ("0015FAA3F03A", "0015FAA3F03B", "0015FAA3F03C"); # CONVERT THE MAC ADDRESS ############################################ +############## sub convert () { my @array = @_; print "Inside convert: @array\n"; my @hold; my $j = 0; my $length = scalar(@array); #Number of records in the input array print "Length of inner array: $length\n"; for ($j; $j<$length; $j++) { #This loop is setup so that its iteration +s equal the number of elements in the input array print "Value of j is: $j\n"; $element = lc($array[$j]); #Convert uppercase MAC to lowercase print "Inside element: $element\n"; my $i = 0; @hold = (); #Reset the temporary hold array used to create the $ou +t variable while ($i<length($element)) { #for each element of the array, brea +k it up into the 3 groups of 4 letters each push (@hold, substr($element, $i, 4)); print "While substring: " . substr($element, $i, 4) . "\n"; $i += 4; print "Just finished substring: @hold\n"; } my $out = "AP" . $hold[0] . "." . $hold[1] . "." . $hold[2]; #Store th +e results to a variable to be added to output array print "Out: $out\n"; push (@array, $out); #Add the newly converted MAC address to our array shift (@array); #Remove the original MAC addresses one at a time as th +ey're not needed outside the sub } return @array; print @array; } # CONVERT THE MAC ADDRESS ############################################ +##############
Thanks, Scott