Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] filter data

Expand Messages
  • Shawn H Corey
    On Sat, 18 Aug 2012 13:01:38 +0300 ... No, the he said he wanted the second column, which is indexed by 1. -- Just my 0.00000002 million dollars worth, Shawn
    Message 1 of 5 , Aug 18, 2012
    • 0 Attachment
      On Sat, 18 Aug 2012 13:01:38 +0300
      Shlomi Fish <shlomif@...> wrote:

      > On Fri, 17 Aug 2012 22:28:04 -0000
      > "timmarkus498" <timmarkus498@...> wrote:
      >
      > > Dear,
      > >
      > > I am beginning and Ive been trying to compare lines between two
      > > files by one specify column in two files and put in other file
      > > (output) lines common by second column.

      ...

      > > while (<IN>){
      > > chomp;
      > > my @fields = split /\s+/,$_;
      > >
      > > #### only prints if dont have the pattern...
      > > if ($dic_pat{$fields[1]}){
      >
      > Shouldn't it be $fields[0]? The first element in an array is indexed
      > with 0.

      No, the he said he wanted the second column, which is indexed by 1.


      --
      Just my 0.00000002 million dollars worth,
      Shawn

      Programming is as much about organization and communication
      as it is about coding.

      _Perl links_
      official site : http://www.perl.org/
      beginners' help : http://learn.perl.org/faq/beginners.html
      advance help : http://perlmonks.org/
      documentation : http://perldoc.perl.org/
      news : http://perlsphere.net/
      repository : http://www.cpan.org/
      blog : http://blogs.perl.org/
      regional groups : http://www.pm.org/
    • Charles K. Clarkson
      You are writing this solution from the top down. You do not have to write it in that order. Write the core algorithm first, then add the UI and I/O after that
      Message 2 of 5 , Aug 18, 2012
      • 0 Attachment
        You are writing this solution from the top down. You do not have to
        write it in that order. Write the core algorithm first, then add the UI
        and I/O after that is done.

        Eliminating the file conversion and the user interface stuff allows you
        to write and test the record comparison algorithm. Once that you know
        works, you can move on to make it look pretty for the user.

        use strict;
        use warnings;

        # Pull this info from file 1.
        my %is_valid = (
        1 => 1,
        2 => 1,
        3 => 1,
        );


        # Test data.
        # Replace this with a while loop over file 2 or a tied array.
        my @records = (
        '1 1 0 2 -9',
        '3 8 0 2 2',
        '2 6 0 1 6',
        '1 3 0 2 -9',
        '1 4 0 2 2',
        '2 2 0 1 6',
        );

        # Replace this with a while loop over file 2 or a tied array.
        while ( my $record = shift @records ) {

        my @fields = split ' ', $record;

        if ( $is_valid{ $fields[1] } ) {
        print "$record\n";
        }
        }

        __END__



        Charles Clarkson
        --
        I'm not really a smart person. I just play one on the Internet.
        +1 (254) 434-2733
      • Markus Tim
        Thank you for help and suggestion! [Non-text portions of this message have been removed]
        Message 3 of 5 , Aug 22, 2012
        • 0 Attachment
          Thank you for help and suggestion!

          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.