Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Corrupt Data? by spickles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-18 19:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found