Efficient Code

Discussion in 'Perl Misc' started by friend.05@gmail.com, Nov 26, 2008.

  1. Guest

    I have large file in following format.

    Table A {
    17.64.0.0|17;
    32.58.34.192|26;
    32.58.157.0|24;
    32.106.15.0|24;
    }

    Table B {
    32.106.80.0|21;
    32.106.88.0|24;
    32.106.192.0|20;
    }


    I want to read the file and store it in some data structure and then I
    will go through the data structure and according to some codition I
    will value I need and then I should also able to find it belongs which
    table (Table A or Table B).

    Which will efficient data structure to store this type data and then
    also retrive it fast to see in which table it exist.

    Right now I am using two dimensional array. But since it is very slow.
     
    , Nov 26, 2008
    #1
    1. Advertising

  2. david Guest

    try hashes of the format
    17.64.0.0|17 =>Table A
    I assume that each number can belong just to Table A or Table B.

    If the file gets too large for the memory then use maybe a database
    solution (sqlite) or tie::hash to a file


    On Nov 26, 4:03 pm, "" <>
    wrote:
    > I have large file in following format.
    >
    > Table A {
    >         17.64.0.0|17;
    >         32.58.34.192|26;
    >         32.58.157.0|24;
    >         32.106.15.0|24;
    >         }
    >
    > Table B {
    >                 32.106.80.0|21;
    >         32.106.88.0|24;
    >         32.106.192.0|20;
    >                 }
    >
    > I want to read the file and store it in some data structure and then I
    > will go through the data structure and according to some codition I
    > will value I need and then I should also able to find it belongs which
    > table (Table A or Table B).
    >
    > Which will efficient data structure to store this type data and then
    > also retrive it fast to see in which table it exist.
    >
    > Right now I am using two dimensional array. But since it is very slow.
     
    david, Nov 26, 2008
    #2
    1. Advertising

  3. Ted Zlatanov Guest

    On Wed, 26 Nov 2008 06:03:16 -0800 (PST) "" <> wrote:

    f> I have large file in following format.
    f> Table A {
    f> 17.64.0.0|17;
    f> 32.58.34.192|26;
    f> 32.58.157.0|24;
    f> 32.106.15.0|24;
    f> }

    f> Table B {
    f> 32.106.80.0|21;
    f> 32.106.88.0|24;
    f> 32.106.192.0|20;
    f> }


    f> I want to read the file and store it in some data structure and then I
    f> will go through the data structure and according to some codition I
    f> will value I need and then I should also able to find it belongs which
    f> table (Table A or Table B).

    f> Which will efficient data structure to store this type data and then
    f> also retrive it fast to see in which table it exist.

    f> Right now I am using two dimensional array. But since it is very slow.

    These are IPv4 net blocks. Storing net blocks efficiently is easy,
    since they are just binary strings with a mask number between 0 and 32,
    which is 5 bytes. You can then use vec() or pack()/unpack() to extract
    the data or match against it. Of course, you could just use
    Net::Netmask if your "condition" involves searches through net block
    tables as it did the last time you asked about net blocks.

    Ted
     
    Ted Zlatanov, Nov 26, 2008
    #3
  4. <> wrote:

    > have large file in following format.
    >
    > REGION Table_A {
    > 17.64.0.0|17;
    > 32.58.34.192|26;
    > 32.58.157.0|24;
    > 32.106.15.0|24;
    > 52.106.32.0|21;
    > 22.32.88.0|24;
    >
    >
    >
    > }
    >
    >
    > I want only IP address starting with 32.
    >
    > so for above list it should return 3 address:
    > 32.58.34.192|26;
    > 32.58.157.0|24;
    > 32.106.15.0|24;
    >
    >
    > what expression should I use in grep



    my @thirty_twos = grep /^\s*32\./, <FILE>;


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Nov 26, 2008
    #4
  5. Guest

    On Nov 26, 11:16 am, Ted Zlatanov <> wrote:
    > On Wed, 26 Nov 2008 06:03:16 -0800 (PST) "" <> wrote:
    >
    > f> I have large file in following format.
    > f> Table A {
    > f>   17.64.0.0|17;
    > f>   32.58.34.192|26;
    > f>   32.58.157.0|24;
    > f>   32.106.15.0|24;
    > f>   }
    >
    > f> Table B {
    > f>              32.106.80.0|21;
    > f>   32.106.88.0|24;
    > f>   32.106.192.0|20;
    > f>              }
    >
    > f> I want to read the file and store it in some data structure and then I
    > f> will go through the data structure and according to some codition I
    > f> will value I need and then I should also able to find it belongs which
    > f> table (Table A or Table B).
    >
    > f> Which will efficient data structure to store this type data and then
    > f> also retrive it fast to see in which table it exist.
    >
    > f> Right now I am using two dimensional array. But since it is very slow.
    >
    > These are IPv4 net blocks.  Storing net blocks efficiently is easy,
    > since they are just binary strings with a mask number between 0 and 32,
    > which is 5 bytes.  You can then use vec() or pack()/unpack() to extract
    > the data or match against it.  Of course, you could just use
    > Net::Netmask if your "condition" involves searches through net block
    > tables as it did the last time you asked about net blocks.
    >
    > Ted


    doubt not related to perl.

    have large file in following format.

    REGION Table_A {
    17.64.0.0|17;
    32.58.34.192|26;
    32.58.157.0|24;
    32.106.15.0|24;
    52.106.32.0|21;
    22.32.88.0|24;



    }


    I want only IP address starting with 32.

    so for above list it should return 3 address:
    32.58.34.192|26;
    32.58.157.0|24;
    32.106.15.0|24;


    what expression should I use in grep
     
    , Nov 26, 2008
    #5
  6. Ted Zlatanov Guest

    On Wed, 26 Nov 2008 10:07:28 -0800 (PST) "" <> wrote:

    f0c> On Nov 26, 11:16 am, Ted Zlatanov <> wrote:
    >> These are IPv4 net blocks.  Storing net blocks efficiently is easy,
    >> since they are just binary strings with a mask number between 0 and 32,
    >> which is 5 bytes.  You can then use vec() or pack()/unpack() to extract
    >> the data or match against it.  Of course, you could just use
    >> Net::Netmask if your "condition" involves searches through net block
    >> tables as it did the last time you asked about net blocks.


    f> doubt not related to perl.

    f> have large file in following format.

    f> REGION Table_A {
    f> 17.64.0.0|17;
    f> 32.58.34.192|26;
    f> 32.58.157.0|24;
    f> 32.106.15.0|24;
    f> 52.106.32.0|21;
    f> 22.32.88.0|24;
    f> }

    f> I want only IP address starting with 32.

    f> so for above list it should return 3 address:
    f> 32.58.34.192|26;
    f> 32.58.157.0|24;
    f> 32.106.15.0|24;

    f> what expression should I use in grep

    /bin/grep '[^0-9.]32\.' FILE

    But is that really what you are looking for, or are you trying to match
    two net blocks to each other? Your requirements have changed three
    times now and as much as I'd like to help you, you have to actually tell
    us what you're trying to do instead of asking for specific bits of
    information you can easily find in the documentation.

    Ted
     
    Ted Zlatanov, Nov 26, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. barry
    Replies:
    5
    Views:
    3,894
    Roedy Green
    Oct 16, 2003
  2. New
    Replies:
    5
    Views:
    437
    Oscar Kind
    Jan 3, 2004
  3. gonzlobo

    Writing more efficient code

    gonzlobo, Jan 1, 2007, in forum: Python
    Replies:
    13
    Views:
    473
    Hendrik van Rooyen
    Jan 3, 2007
  4. Marco
    Replies:
    19
    Views:
    853
    Dave Vandervies
    Apr 12, 2006
  5. Replies:
    10
    Views:
    526
Loading...

Share This Page