Professional Web Applications Themes

array of arrays - PERL Beginners

Hi! How do I read data out of a table-file in an array-of-arrays? Problem: I have to compare two tables with pairs of start-stop-Positions. I want to find out, which pair of Start-Stop-Position in table_1 is entirely within the range marked by a pair of start-stop-positions of the second table. 2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on. Jane...

  1. #1

    Default array of arrays

    Hi!

    How do I read data out of a table-file in an array-of-arrays?

    Problem: I have to compare two tables with pairs of start-stop-Positions.
    I want to find out, which pair of Start-Stop-Position in table_1 is
    entirely within the range marked by a pair of start-stop-positions of
    the second table.
    2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on.

    Jane


    Christiane Nerz Guest

  2. #2

    Default RE: array of arrays

    > How do I read data out of a table-file in an array-of-arrays?
    >
    > Problem: I have to compare two tables with pairs of start-stop-Positions.
    > I want to find out, which pair of Start-Stop-Position in table_1 > is
    > entirely within the range marked by a pair of start-stop-positions of
    > the second table.
    > 2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on.
    Mornin,
    how are you getting those ranges? From a database using the DBI module or from a text file etc?

    __________________________________________________ ______________________
    This email has been scanned for all viruses by the MessageLabs Email
    Security System. For more information on a proactive email security
    service working around the clock, around the globe, visit
    [url]http://www.messagelabs.com[/url]
    __________________________________________________ ______________________
    Stephen Hardisty Guest

  3. #3

    Default Re: array of arrays

    .... from two text files.
    Output of a pattern-searching-program and data out of a DB (genebank).
    No prob to read in those data in a textfile too.

    Stephen Hardisty wrote:
    >>How do I read data out of a table-file in an array-of-arrays?
    >>
    >>Problem: I have to compare two tables with pairs of start-stop-Positions.
    >>I want to find out, which pair of Start-Stop-Position in table_1 > is
    >>entirely within the range marked by a pair of start-stop-positions of
    >>the second table.
    >>2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on.
    >>
    >
    > Mornin,
    > how are you getting those ranges? From a database using the DBI module or from a text file etc?
    >
    > __________________________________________________ ______________________
    > This email has been scanned for all viruses by the MessageLabs Email
    > Security System. For more information on a proactive email security
    > service working around the clock, around the globe, visit
    > [url]http://www.messagelabs.com[/url]
    > __________________________________________________ ______________________
    >
    >


    Christiane Nerz Guest

  4. #4

    Default Re: array of arrays

    On Mon, Oct 20, 2003 at 12:33:00PM +0200 Christiane Nerz wrote:
    > How do I read data out of a table-file in an array-of-arrays?
    >
    > Problem: I have to compare two tables with pairs of start-stop-Positions.
    > I want to find out, which pair of Start-Stop-Position in table_1 is
    > entirely within the range marked by a pair of start-stop-positions of
    > the second table.
    > 2..5 would be in 2..6 or 1..7, 45..46 in 23..47 or 40..46 and so on.
    Do these strings show up in the table like that? In this case, it should
    not be so hard:

    my $range1 = "2..5";
    my $range2 = "2..6";

    my ($start1, $stop1) = $range1 =~ /(\d+)\.\.(\d+)/;
    my ($start2, $stop2) = $range2 =~ /(\d+)\.\.(\d+)/;

    print "$range1 within $range2" if
    $start1 >= $start2 and
    $stop1 <= $stop2;

    Is it something like that you were asking for? I am not yet sure where
    array of arrays are involved.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+ii ixesixeseg;y~\n~~dddd;eval

    Tassilo Von Parseval Guest

  5. #5

    Default RE: array of arrays

    Alright then,
    first you want to think about how you are going to populate the arrays. For example, if I have a file that contains the following data:
    1|10
    5|7

    I would do this:

    open(FH, "< bob.txt");

    my file_list;

    while(<FH>)
    {
    # add a reference of the 2 file columns to file_list
    push(file_list, [split(/\|/, $_)]);
    }

    -------------------

    Doing the same thing with a database is a more contentious issue as there are many different ways to go about it, but I would do the following:

    my $dbh = DBI->connect(); # however you want to connect to the database

    my $sth = $dbh->prepare('SOME SQL HERE');
    $sth->execute; # run the sql

    my db_list;

    while($sth->fetchrow_arrayref)
    {
    # assuming you only select 2 rows in your sql
    push(db_list, $_);
    }

    ----------------

    So now we have 2 arrays of array references we need to compare them. Ofcourse, it would be much more efficient to do this within the second loop but for the sake of simplicity we'll do this in another loop again:

    foreach(file_list)
    {
    my $file_start = $_->[0];
    my $file_end = $_->[1];

    foreach(db_list)
    {
    my $db_start = $_->[0];
    my $db_end = $_->[1];

    # check to see whether the 2 numbers taken from the
    # file exist between the 2 numbers taken from the
    # database, this might not be what you want but you
    # get the idea, right?
    if(($file_start >= $db_start) &&
    ($file_end <= $db_end))
    {
    # do whatever you want to do with
    # your matches here
    }
    }
    }

    Hope this send you along the right path, if not and you've read this far then I can only apologise.

    Cheers!

    __________________________________________________ ______________________
    This email has been scanned for all viruses by the MessageLabs Email
    Security System. For more information on a proactive email security
    service working around the clock, around the globe, visit
    [url]http://www.messagelabs.com[/url]
    __________________________________________________ ______________________
    Stephen Hardisty Guest

  6. #6

    Default Re: array of arrays

    [email]shardistymessagelabs.com[/email] (Stephen Hardisty) wrote in message news:<B5F4AA2037F7A74CA628A1B0DE5AB2BA05053Fuks24 1.int.star.net.uk>...
    > my file list;
    What is the word "list" that appears after all your uses of arrays? It
    doesn't p in my perl.
    Roy Johnson Guest

Similar Threads

  1. Array Of Arrays - Cape Generated WSDL with .NET
    By Ravi Singh (UCSD) in forum ASP.NET Web Services
    Replies: 10
    Last Post: December 22nd, 10:55 PM
  2. Build multidimensional array from arrays
    By Kevin Old in forum PERL Beginners
    Replies: 5
    Last Post: January 29th, 07:47 PM
  3. Antwort: array of arrays
    By Manfred Beilfuss in forum PERL Beginners
    Replies: 0
    Last Post: October 20th, 10:54 AM
  4. += vs << when appending arrays to an array
    By Doug Beaver in forum Ruby
    Replies: 1
    Last Post: July 16th, 08:57 AM
  5. Removing Arrays With Certain Keys From Larger Array
    By Jwulff in forum PHP Development
    Replies: 1
    Last Post: July 8th, 09:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139