Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: Looking for ideas: Converting a binary 'flags' field into something human readable

by GotToBTru (Prior)
on Jul 08, 2015 at 15:17 UTC ( #1133730=note: print w/replies, xml ) Need Help??


in reply to Re^3: Looking for ideas: Converting a binary 'flags' field into something human readable
in thread Looking for ideas: Converting a binary 'flags' field into something human readable

use strict; use warnings; my @labels = ({label=>'compressed',start=>3}, {label=>'deleted',start= +>6}, {label=>'this',start=>7}, {label=>'that',start=>12}, {label=>'other',start=>18}, {label=>'something else',sta +rt=>20}, {label=>'and another',start=>30}, {label=>'foo',start=>4 +5}, {label=>'bar',start=>47}, {label=>'up',start=>63}, {label=>'down',start=>64}, {label=>'sideways',start=>65} +); print "0b0x00xx0000x00000x0x000000000x00000000000000x0x000000000000000 +xxx\n"; my (@lines); # for each label LOOP: foreach my $lab (@labels) { # look thru the available lines foreach my $line (@lines) { my $delta = $lab->{start} - length($line); # for a line shorter than start if ($delta >= 0) { # and tack the label on there $line .= ' ' x $delta . '|' . $lab->{label}; next LOOP; } # or fit into empty space on existing line my $len = length($lab->{label}) + 1; if (substr($line, $lab->{start}, $len) eq ' ' x $len) { substr($line, $lab->{start}, $len,'|' . $lab->{label}); next LOOP; } } # or create a new line if needed push @lines, ' ' x $lab->{start} . '|' . $lab->{label}; } print "$_\n" for @lines;

UPDATE: added comments, added fitting new label into blank space, improved flow

Dum Spiro Spero
  • Comment on Re^4: Looking for ideas: Converting a binary 'flags' field into something human readable
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133730]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2022-05-29 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?