Hi to all Monks, I am newbee in perl and badly stuck in a project with deadline hanging over my head. I need to format my input data Eg. Data to be formatted <filed1> | <field2> | <field3> | <field4>....as shown below (real data)
271479 | Papaya leaf curl Guandong virus | Geminiviridae | V1.3_105649 +:75.8 12202 | Lettuce mosaic virus | Potyviridae | V1.3_118815:65.4 116056 | Pelargonium zonate spot virus | Bromoviridae | V1_111931:65.5 45709 | Sabia virus | Arenaviridae | V1_112261:16.8
FORMAT that I need <filed1> | <field2>
271479 | Papaya leaf curl Guandong virus 12202 | Lettuce mosaic virus 116056 | Pelargonium zonate spot virus 45709 | Sabia virus 130556 | Culex nigripalpus NPV
The actual code I wrote to sort and rank...But this doesnt have the code to accomodate the input data of the form shown above and hence it fails unless I can pre process the data and then run the script. Here is the actual code;
#!/usr/bin/perl # Rank array data in accordance with their P-values # Script author: AR, 2007. my $pvalues_file = $ARGV[0]; my $MAX_TOP_ENTRIES = 20; open PVAL, "< $pvalues_file" or die "Error: Can't open $pvalues_file: +$!"; my %arrays; my @profile_names; while (my $line = <PVAL>) { chomp $line; if ($line =~ /^ARRAYS/) { my $hdr, $i; ($hdr, @profile_names) = split("\t", $line); for $i (0 ... $#{@profile_names}) { $profile_names[$i] =~ s/^\s+//; $profile_names[$i] =~ s/\s+$//; } } else { (my $array_name, @pvalues) = split("\t", $line); for $i (0 ... $#{@profile_names}) { $arrays{$array_name}{$profile_names[$i]} = $pvalues[$i]; } } } foreach $array (keys %arrays) { my $top_count = 0; print "$array\t"; %pvalues = %{$arrays{$array}}; @profiles_sorted = sort { $pvalues{$a} <=> $pvalues{$b} } ( ke +ys %pvalues ); foreach $key (@profiles_sorted) { $top_count++; if ($top_count <= $MAX_TOP_ENTRIES) { print "$key:$pvalues{$key}\t"; } } print "\n"; }
ANY HELP WILL BE GREATLY APPRECIATED. If I can just run a one line perl command to do this on command line that is also fine PLEASE HELP.......THANKS

In reply to formating data input by manu7495

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.