Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

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

In reply to Re^4: Looking for ideas: Converting a binary 'flags' field into something human readable by GotToBTru
in thread Looking for ideas: Converting a binary 'flags' field into something human readable by Monk::Thomas

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 studying the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found