in reply to Perl Parser, need help

It would have been nice if you'd specified exactly what you wanted, plus the example. But guessing at the format (untested):
#!/your/perl/here use strict; use warnings; my $sequence; while (my $line = <>) { # Sequence keyword if ($line =~ /^Sequence:\s+(contig\d+)/) { $sequence = $1; # save the sequence next; } # Parameter keyword next if ($line =~ /^Parameters:\s+(.*)$/); # print any other non-blank lines if ($line != /^\s*$/) { print "$sequence $line"; next; } }
I don't know what your spec is for line breaks, or whether blank lines have meaning, or what to do for lines that don't begin with Parameter or Sequence keywords.

Please use <code> tags to show code and output, otherwise we have to check the page source to see the actual format. (And I still might have got the input format wrong.)

Update: Corrected Parameters: error as pointed out by Ovid. The Parameters: line is just skipped.

Update 2: Adding missing semicolon to Parameter line.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Replies are listed 'Best First'.
Re^2: Perl Parser, need help
by Ovid (Cardinal) on May 14, 2005 at 04:27 UTC

    Bleh. I think your's is a bit nicer. I read all of the data into memory as a quick hack. I should have iterated over the lines. Still, I'm wondering what you're doing with parameters. The OP appears to be discarding that information. Did I miss something?

    Cheers,
    Ovid

    New address of my CGI Course.

      Still, I'm wondering what you're doing with parameters. The OP appears to be discarding that information. Did I miss something?
      No, I think I missed something. Didn't check the page source close enough. I thought the Parameters: 2 7 7 80 10 50 50 was part of the line following it.

      I'll go update it now to correct that.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

Re^2: Perl Parser, need help
by joomanji (Acolyte) on May 19, 2005 at 03:06 UTC
    #!/your/perl/here
    use strict;
    use warnings;
    my $sequence;

    while (my $line = <>)
    {
    # Sequence keyword
    if ($line =~ /^Sequence:\s+(contig\d+)/)
    {
    $sequence = $1; # save the sequence
    next;
    }

    # Parameter keyword
    #next if ($line =~ /^Parameters:\s+(.*)$/)

    # print any other non-blank lines
    if ($line != /^\s*$/)
    {
    print "$sequence $line";
    next;
    }
    }

    QM..

    I have tried your script, before i mark the parameter keyword out, the script have compilation error at line 24. After i mark that line, i manage to run the script with error, the compiler stated : isn't numeric in numeric ne (!=) at trf.pl line 19. But I still manage to get the output, after edited in excel. But funny thing is that, for those result starting from 1 (eg: 1 45 7 6.4 7 97 0 72 35 44 4 15 1.67 CCTAAAC CCTAAACCCTAAACCCTAAACCCTAAACCCTAAGCCCTAAGCCCT, it won't show in the parsed result... i wonder what's with this.. but anyway thank u so much!
      I did mention that it was untested.

      That line is missing a terminating semicolon, fixed.

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        Hi QM.. thanks for everything! After some modification on the matching of the "Sequence : Contig.." part, the script finally working! I disable the warning output, so it looks abit nicer when running the script.. here is the modified one. Thank u again QM! And thanks to everyone who helped!

        #!/bin/perl/
        my $sequence;

        while (my $line = <>)
        {
        # Sequence keyword
        if ($line =~ /^Sequence:\s+(\S+)/)
        {
        $sequence = $1; # save the sequence
        next;
        }

        # Parameter keyword
        next if ($line =~ /^Parameters:\s+(.*)$/);

        # print any other non-blank lines
        if ($line != /^\s+$/)
        {
        print "$sequence $line";
        next;
        }
        }

        Thanks again everyone!