in reply to Spliting Table

If anyone of you wise guys out there has a solution, I would be veeeeeery grateful to hear about it.

Here is solution

shortInfile.txt person 1 2 3 4 5 6 7 8 9 abe 1 2 3 4 5 6 7 8 9 lincoln 1 2 3 4 5 6 7 8 9

Becomes

person.txt 1 2 3 4 something something abe.txt 1 2 3 4 something something lincoln.txt 1 2 3 4 something something

The solution is to describe the desired output based on representative input which is very short. After you do that, you can wrap your head around it, write code to do it.

Replies are listed 'Best First'.
Re^2: Spliting Table (a solution)
by tschelineli (Initiate) on Aug 20, 2015 at 07:53 UTC
    Thank you for your help. Your described solution is actually not my real problem as I do know, how it should look like, but I want to let the script run automatically through the whole Input.file, as there are over 100people and I do not want to give every file a name myself. My main problem is the part where it automatically counts which column to take for the next file/person:
    1st file: column 1-4 and 5-13;
    2nd file: column 1-4 and 14-22;
    3rd file: column 1-4 and 23-31;
    4th file: ...
    to give every new file a name will be the next problem.. =)

      my main problem is the part where it automatically counts which column to take for the next file/person:

      Think about it, how would you as a person do the counting?

      Now write down the description and post it here.

      Over and out

      #!/usr/bin/perl -- ## tinking.pl ## 2015-08-20-02:28:04 ## ## ## ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while for " +-otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use autodie qw/ open close /; use Data::Dump qw/ dd /; my $infile = \q{ abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz bcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyza cdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab }; Roger( $infile ); exit( 0 ); sub Roger { my( $infile ) = @_; open my( $infh ), '<', $infile; ## "or die..." by autodie my $count = 5; while( <$infh> ) { next if !/\S/; my @what = split //, $_; #~ dd( \@what ); my $right = $count + 8; @what = grep defined, @what[ 0 .. 4, $count .. $right ]; #~ dd( \@what ); Dodger( \@what ); $count = $right; } ## end while( <$infh> ) } ## end sub Roger sub Dodger { my( $arref ) = @_; print join ',', @$arref, "\n"; } ## end sub Dodger