Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
use strict; # for actual use, read from an open file handle line this: #while (my $line = <$input> { # for testing, read from special DATA file handle # (data will come from end of file, below DATA tag) while( my $line = <DATA>) { chomp $line; # remove end-of-line character $line =~ s/^\s+//; # strip leading whitespace next unless $line; # skip blank lines # skip first 12 lines next unless $. > 12; # $. contains current line number my @columns = split(/\s+/, $line); # split columns on whitespace my $col1 = shift @columns; # column 1 (throw away) my $col2 = shift @columns; # column 2 (throw away) my $col3 = shift @columns; # column 3 (special - keep this one) my $result = sprintf("%8.3f", $col3); # special format for col 3 # loop over remaining columns, appending to result string for my $c (@columns) { my $data = sprintf("%10.3f", $c); $result .= " $data"; # note the space character (ch +ange if required) } print "$result\n"; # print the final result (note + end of line character)" } # my guess at the input data __DATA__ SKIP 1 SKIP 2 SKIP 3 SKIP 4 SKIP 5 SKIP 6 SKIP 7 SKIP 8 SKIP 9 SKIP 10 SKIP 11 SKIP 12 Line_1 0.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 Line_2 0.0 0.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 Line_3 0.0 0.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0 Line_4 0.0 0.0 4.0 5.0 6.0 7.0 8.0 9.0 1.0 2.0 Line_5 0.0 0.0 5.0 6.0 7.0 8.0 9.0 1.0 2.0 3.0

update: fixed typo in "strip whitespace" regex (added '^' character)


In reply to Re: column counter and printf question by scorpio17
in thread column counter and printf question by fasoli

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 chanting in the Monastery: (3)
As of 2024-04-25 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found