HI All, I am a new bee to perl. I think it shold be a simple task.But even in thatI am getting some problems :( I have a tab delimited file similar to this:
Individual 301 302 303 304 2003 a b c d a b c d a b c d a b c d 2004 a b c d a b c d a b c d a b c d 2005 a b c d a b c d a b c d a b c d
So, the first row is tab delimited, and other rows following will have four columns(separated by a space) corresponding to a column in the first row separated by a tab. What I neet to do is to get ta out pus similar to this:
Individual 301A 301B 302A 302B 303A 303B 304A 304B 2003 c d c d c d c d and similary in the other ones as well
I have split the file by new lines and have got almost solved with the rest. But thats in a very crude way. Now I have got a tab at the end of each line.below is my code. How could I get rid of my end tab. And also I have got an extra tab inserted in my second row after the first column(in all the lines after that).
#!/usr/local/bin/perl use strict; use Getopt::Long; my ($sfile, $lfile, $ofile); my (@sampleids); my($loga, $logb, $x, $y) &GetOptions("sfile=s" =>\$sfile, ); unless(open SFILE , $sfile ) {die "cannot open small file: $!\n"}; print "Individual\t"; while(<SFILE>){ chomp; my $line = $_; my @columns = split(/\n/, $line); foreach my $col (@columns) { my @array = split (/\t/, $col); foreach my $a (@array) { next if $a =~ /^Individual/; if ($a =~ /^000\d+/){ print "$a" . "A", "\t", "$a" . "B", "\t"; } } print "\n"; foreach my $b (@array) { next if $b =~ /^Individual/; next if $b =~ /^000\d+/; if($b =~ /^\w+/){ #$b =~ s/^\t//; # $b =~ s/\t$//; print "$b"; } } foreach my $c (@array) { next if $b =~ /^Individual/; next if $b =~ /^000\d+/; next if $b =~ /^\w+/ ; ($loga, $logb, $x, $y) = split (/ /,$c); #$x =~ s/^\t+//; #$x =~s/\t$//; print "$x\t$y\t"; } } }
Any suggestion or comments??? Thanks everyone!!!

In reply to rearranging the file by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.