CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
FOR LOOP URGENT HELP

 



phone4u
Novice

Aug 6, 2010, 4:29 AM

Post #1 of 8 (613 views)
FOR LOOP URGENT HELP Can't Post

Hi, please I need help pleaseeeeee.
Please, I want the script to save file lexo.txt in the memory of this script and the file IPv6.txt will read only from that memory.
At the present, I discovered that the content of file IPv6.txt is reading through lexo.txt from the begining each time which takes longer time like days. Its suppose to take all the files in IPv6.txt once to read through lexo.txt and all the output appears in few seconds.
here is what have done so far;
#!/usr/bin/perl

use warnings;
use strict;

use Net::IPTrie;
my $tr = Net::IPTrie->new(version=>6); # IPv6

open LEXO, "<", "lexo.txt" or die "Could not open file lexo.txt in read mode: $!\n";
open IPV6, "<", "IPv6.txt" or die "Could not open file IPv6.txt in read mode: $!\n";

my @lexo_content = <LEXO>;
my @ipv6_content = <IPV6>;

foreach my $ip (@ipv6_content) {
chomp $ip;
foreach my $line (@lexo_content) { ........think the problem is here
chomp $line; ..............think the problem is here
if($line =~ m/address=>\'(.*?)\',\s*prefix=>\'(.*?)\',\s*data=>\'(.*?)\'/){
my $address = $1;
my $prefix = $2;
my $data = $3;
my $n = $tr->add(address=>"$address", prefix=>"$prefix", data=>"$data");
my $a = $tr->add(address=>"$ip", prefix=>'128', data=>"$data");;
if (defined $a->parent && $a->parent->address eq $n->address) {
print "\$a is ". $a->address . " and parent of \$a is ". $a->parent->address ." and data of parents is: ". $a->parent->data. "\n";
}
}
}
}

close LEXO;
close IPV6;


Thanks


deepeshtronics
Novice

Aug 6, 2010, 6:34 AM

Post #2 of 8 (611 views)
Re: [phone4u] FOR LOOP URGENT HELP [In reply to] Can't Post

Hi,

Can you use the below code and let me know the performance?


Code
 
#!/usr/bin/perl

use warnings;
use strict;

use Net::IPTrie;
my $tr = Net::IPTrie->new(version=>6); # IPv6

open LEXO, "<", "lexo.txt" or die "Could not open file lexo.txt in read mode: $!\n";
open IPV6, "<", "IPv6.txt" or die "Could not open file IPv6.txt in read mode: $!\n";

my @lexo_content = <LEXO>;
my @ipv6_content = <IPV6>;

foreach my $ip (@ipv6_content) {
chomp $ip;
my $ip_parent = $1 if $ip =~ /^(.*?)\:\:/;
my @parent_addrs = grep (/$ip_parent/, @lexo_content);
if(@parent_addrs){
foreach my $line (@parent_addrs) {
chomp $line;
if($line =~ m/address=>\'(.*?)\',\s*prefix=>\'(.*?)\',\s*data=>\'(.*?)\'/){
my $address = $1;
my $prefix = $2;
my $data = $3;
my $n = $tr->add(address=>"$address", prefix=>"$prefix", data=>"$data");
my $a = $tr->add(address=>"$ip", prefix=>'128', data=>"$data");;
if ($a->parent->address eq $n->address) {
print "\$a is ". $a->address . " and parent of \$a is ". $a->parent->address ." and data of parents is: ". $a->parent->data. "\n";
}
}
}}
}

close LEXO;
close IPV6;


Thanks


deepeshtronics
Novice

Aug 6, 2010, 6:51 AM

Post #3 of 8 (605 views)
Re: [phone4u] FOR LOOP URGENT HELP [In reply to] Can't Post

Hi,

If the code, which i have posted above, does not solve the performance issue then we will use different approach for reading the file instead of opening the file in memory through 'open' system call.

What is the size of lexo.txt in mb?

Can you split up lexo.txt and use the script in loop?

Thanks


phone4u
Novice

Aug 6, 2010, 7:06 AM

Post #4 of 8 (600 views)
Re: [deepeshtronics] FOR LOOP URGENT HELP [In reply to] Can't Post

hi thanks for your help, lexo.txt is just 206.4kb, if you can be kind to give your email, I will send you both files(lexo.txt and IPv6.txt) so you can run it in details and see the output quite right.
With the above script I got just few result of about 5lines and the rest in errors:
Use of uninitialized value $ip_parent in regexp compilation at qq.pl line 19, <IPV6> line 3592.
Use of uninitialized value $ip_parent in regexp compilation at qq.pl line 19, <IPV6> line 3592.
Use of uninitialized value $ip_parent in regexp compilation at qq.pl line 19, <IPV6> line 3592.
Use of uninitialized value $ip_parent in regexp compilation at qq.pl line 19, <IPV6> line 3592.
Use of uninitialized value $ip_parent in regexp compilation at qq.pl line 19, <IPV6> line 3592.
.
Thanks


FishMonger
Veteran / Moderator

Aug 6, 2010, 8:48 AM

Post #5 of 8 (590 views)
Re: [phone4u] FOR LOOP URGENT HELP [In reply to] Can't Post

Why do you have 2 separate threads for this question (one the Beginner and one in the Intermediate area)?

The suggested solutions in both threads appear to have the same inefficiency. That is they loop over the same data multiple times and duplicate the data across multiple arrays and/or hash.

I haven't used the Net::IPTrie module, but if you provide me the data files and a sample of your desired output, I'll see if I can work up a possible solution.


phone4u
Novice

Aug 6, 2010, 9:13 AM

Post #6 of 8 (584 views)
Re: [FishMonger] FOR LOOP URGENT HELP [In reply to] Can't Post

hi, thanks for your concern, if you can please send me your email, i will inbox all the details to you.
Thanks


FishMonger
Veteran / Moderator

Aug 6, 2010, 10:15 AM

Post #7 of 8 (577 views)
Re: [phone4u] FOR LOOP URGENT HELP [In reply to] Can't Post

I got your PM with the details. I'm tied up on a couple issues at work, so I probably won't be able to work on this until I go home.


phone4u
Novice

Aug 6, 2010, 10:25 AM

Post #8 of 8 (575 views)
Re: [FishMonger] FOR LOOP URGENT HELP [In reply to] Can't Post

i dont mind, thanks for even considering to help....have got all weekends.
thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives