Efficient Code

F

friend.05

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.
 
D

david

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
 
T

Ted Zlatanov

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
 
T

Tad J McClellan

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>;
 
F

friend.05

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
 
T

Ted Zlatanov

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top