Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Strange Perl Behavior
wisestone
post Jul 12 2005, 12:00 AM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 11-July 05
From: Bozeman, MT
Member No.: 7,010



I have been working on a strange problem I've been having. I am reading
a series of large files (50 mb or so) in one at a time with:
@lines = <FILE>;
or (same behavior with each)
while(<FILE>){
push(@lines, $_);
}
The first time I read a file it will read into the array in about 2
seconds. The second time I try to read a file in (the same size) it
takes about 20 seconds. Everything is declared locally inside the loop
so, everything is leaving scope. I am not sure why it is taking so much
longer the second time. I need to read the entire file in because I am doing a series of operations on the lines that is not known at compile time.

I have narrowed the problem down to a few different areas:

1. It seems that if I read the file into a large scaler by $/ = undef,
the file gets read faster. So, I assume the slow down is taking place
inside the spliting of the lines.

2. If I try to append to one large array, rather then rewritting to a
different array, the slow down does not occur. So it seems Perl has a
hard time with the memory it already has but its fine with memory it
just took from the system?

3. The problem does not seem to happen in Linux, but I'm working
Windows.

Any suggestions for a workaround? Has anyone else seen this? Thanks in
advance.

Ben
Go to the top of the page
 
+Quote Post
vizskywalker
post Jul 12 2005, 05:40 AM
Post #2


Techno-Necromancer
Group Icon

Group: Members
Posts: 1,018
Joined: 13-January 05
From: The Net
Member No.: 2,127



Could you be more specific? Is this multiple file loads in the same script? Also, how much RAM do you have? I have an idea as to why this may be occuring but I need those pieces of information to help.

~Viz
Go to the top of the page
 
+Quote Post
wisestone
post Jul 13 2005, 01:26 AM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 11-July 05
From: Bozeman, MT
Member No.: 7,010



The file loads are in the same script and I have 2 gb of ram.
Go to the top of the page
 
+Quote Post
vizskywalker
post Jul 13 2005, 04:34 AM
Post #4


Techno-Necromancer
Group Icon

Group: Members
Posts: 1,018
Joined: 13-January 05
From: The Net
Member No.: 2,127



Could you either post the script here so I can a) test it myself, and cool.gif check it out, or PM it to me if it is too large to post (more than maybe 50 or so lines tops). I promise to try and help to the best of my ability.

~Viz
Go to the top of the page
 
+Quote Post
wisestone
post Jul 15 2005, 12:21 PM
Post #5


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 8
Joined: 11-July 05
From: Bozeman, MT
Member No.: 7,010



Its seriously just reeding the file in, try:

for(1..2)
{
my @lines;
open(FILE, file1.txt);
while(<FILE>)
{
push(@lines, $_);
}
}

It doesn't have to be opening the same file again but I used that just to make it easier.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Perl, the hacker language?(6)
  2. What Is Perl?(11)
  3. Perl Script(0)
  4. Does Anyone Know To Use Movabletype (perl)(6)
  5. Perl : Help(4)
  6. Simple Problem W/ Perl(5)
  7. Sockets And Perl(1)
  8. Best Place For Information On Perl(8)
  9. Perl: Exec Or System ?(3)
  10. Help Needed To Create Login Script With Perl/cgi(21)
  11. Create Easily Modifiable Html Templates For Use In Your Perl Cgis(0)
  12. Using Perl For Newsletter Subscription(1)
  13. Simple Perl Script...(1)
  14. Just Learning Perl(6)
  15. Perl Programming Language(1)
  1. Maximum Number Of Decimal Places In Perl Language(0)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 12:42 AM