in reply to Text manipulation

please give us example of your input data.
and output desired

Replies are listed 'Best First'.
Re^2: Text manipulation
by Win (Novice) on Jul 08, 2004 at 18:31 UTC
    Input data:

    94 THI11 YDL244W THI11 YFL058W THI11 YJR156C THI1 +1 YNL332W

    Ouput data:

    102 94 1 THI11 YDL244W 103 94 2 THI11 YFL058W 104 94 3 THI11 YJR156C 105 94 4 THI11 YNL332W
      something like this:
      #!perl use strict; use warnings; # open a file for reading in the current directory open(FILEHANDLE,"< input_file.txt") or die $!; open(OUTFILE,"+> outfile_file.txt") or die $!; my $record_count = 0; while (<FILEHANDLE>){ my @data = split /\s+/; my $first = shift @data; $record_count++; for (my $i = 0; $i < @data; $i+=2) { print OUTFILE "$record_count\t$first\t", $i/2+1, "\t$data[$i] +", $data[$i+1], "\n"; } }
      May be I've missed some details, but the way is correct
      As for me, I prefer -n flag in such cases:
      #!perl -lwn my @data = split /\s+/; my $first = shift @data; for (my $i = 0; $i < @data; $i+=2) { print join "\t", $., $first, $i/2+1, $data[$i], $data[$i+1]; }
      usage:
      this_script.pl input_file.txt >> output_file.txt
      
      Here is the golf version of your program
      #!perl -lawn $f = shift @F; $i = 1; print join "\t", $., $f, $i++, shift @F, shift @F while @F;
      see perldoc perlrun, perldoc perlvar for details