in reply to Re: column counter and printf question
in thread column counter and printf question

Thanks so much for that! I had also found this suggestion somewhere and tried it, but there was no context given so I found myself trying it the wrong way and it was then discarded as "not working".

I have updated my question with a new attempt I made at counting the columns, do you think I'm getting a bit closer...? Also, should I put it in a separate post too instead of just an update to the original post?

Thank you again :)

  • Comment on Re^2: column counter and printf question

Replies are listed 'Best First'.
Re^3: column counter and printf question
by Athanasius (Archbishop) on Oct 28, 2015 at 14:58 UTC

    toolic and scorpio17 have given you two ways to print out the columns. Here’s a variation on the theme:

    while (my $line = <$input>) { next if 1 .. $line =~ /\@TYPE xy/; my @columns = split /\s+/, $line; printf $output "%8.3f", $columns[2]; printf $output " %10.3f", $columns[$_] for 3 .. $#columns; print $output "\n"; }

    This makes use of the fact that for any array @array, the variable $#array contains the value of the highest array index. (Note that this is one less than the number of elements in the array, because array indices start at 0.)

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,