Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

A few minor comments:

  1. For clarity, why not call this 'macaddr' instead of 'chaddr'? (Same for my $chaddr, etc.)
    chaddr => 'XX:XX:XX:XX:XX:XX', # MAC Address of sending interface
  2. sleep 5; # wait for 5..., etc. is obvious. How about:
    sleep 5; # allow capture process to establish sleep 10; # allow capture
  3. In this sequence, you don't need two arrays, and you can simplify a couple things:
    #my @macaddr = split(/:/, $chaddr); my @chaddr = split(/:/, $chaddr); #push(@macaddr, 0) for (1..10); push(@chaddr,(0)x10); #my @chaddr = map { hex($_) } @macaddr; @chaddr = map { hex } @chaddr; # or combined, using the clearer(?) @macaddr: @macaddr = map { hex } (split/:/,'10:FF:2B:40:8C:FE'), (0)x10;
  4. You are modifying $i throughout this loop! In fact, you have a comment (# i = 0) that is certainly untrue the first pass, and may never be true.
    for (my $i = 0; $i <= $#options; $i++) { my $option = hex($options[$i++]); last if ($option == 255); # end of DHCP Options my $length = $options[$i++]; # i = 0 my $offset = hex($length) + $i; for (my $k = $i; $k <= ($offset - 1); $k++ ) { push(@{$opts{$option}}, $options[$k]); } $i = $offset - 1; }
  5. A thought on printing:
    for my $key (keys %opts) { print $key, " ", dhcp_option($key),"\t"; if (ref($opts{$key}) =~ m/ARRAY/) { print $_, " " foreach (@{$opts{$key}}); } # NOTE: elsif can just be else, as a string # necessarily does or does not match /ARRAY/ elsif (ref($opts{$key}) !~ /ARRAY/) { print $opts{$key}; } print "\n"; } # OR (untested): for my $key (keys %opts) { print "$key ", dhcp_option($key), "\t", ( ref($opts{$key}) =~ /ARRAY/ ? join" ", @{$opts{$key}} : $opts{$key} ) "\n"; }

In reply to Re: Advice on script by hbm
in thread Advice on script by doylebobs

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 chilling in the Monastery: (6)
As of 2024-04-16 13:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found