in reply to part - split up files according to column value

There are a couple minor POD errors in version 6:
perldoc part ... POD ERRORS Hey! The above document had some coding errors, which are expla +ined below: Around line 29: '=item' outside of any '=over' Around line 77: You forgot a '=back' before '=head1'
Here is a patch:
--- part.6 2011-02-09 10:44:22.000000000 -0500 +++ part.fix 2011-02-09 10:45:32.000000000 -0500 @@ -26,6 +26,8 @@ =head1 OPTIONS +=over + =item B<--out> - set the output template If the output template is not given it is guessed from @@ -74,6 +76,8 @@ =item B<--version> - output version information +=back + =head1 CAVEAT The program loads the whole input into RAM
Also, it would be helpful if you could add a few example command lines in your POD, like the one you showed in Re^6: part - split up files according to column value.

Replies are listed 'Best First'.
Re^2: part - split up files according to column value
by sl7020 (Initiate) on Jul 10, 2012 at 21:26 UTC

    Monks: Trying to modify script to give me a subtotal of column 14 (see below.)

    while (<>) { s/\r?\n$//; my @c = split /$sep/o; my $sub_total = 0; $sub_total += $c[14]; my $key = join $sep, @c[ @col ]; if (not defined $lines{ $key }) { $lines{ $key } ||= []; }; push @{ $lines{$key}}, $_ push @{ $totals{$key}}, $sub_total }

    My code is failing with the following: "my" variable %lines masks earlier declaration in same scope at ./part-v2.pl line 179. "my" variable $key masks earlier declaration in same statement at ./part-v2.pl line 180. syntax error at ./part-v2.pl line 176, near "$_ push" syntax error at ./part-v2.pl line 176, near "}}" Global symbol "$sub_total" requires explicit package name at ./part-v2.pl line 177.

    syntax error at ./part-v2.pl line 191, near "}" Execution of ./part-v2.pl aborted due to compilation errors.

    ========================

    Any help would be appreciated.

      Statements end with semicolons. Blocks do not:

      } push @{ $lines{$key}}, $_; push @{ $totals{$key}}, $sub_total; }

      You also have a problem in that you instantiate $sub_total with a value of zero every time through the loop, right before you add a value to it, so it will always equal that value. This is probably not what you want. You should move the my line that creates it to before your loop, so it can accumulate inside the loop.

      Aaron B.
      Available for small or large Perl jobs; see my home node.