in reply to Re^2: 32 Bit Perl causing segmentation fault if data is big
in thread 32 Bit Perl causing segmentation fault if data is big
Can you be bit elaborate on the sample that you have provided.
By "the sample", I presume you mean this one (reformatted for readability)?
perl -e" local $/ = '~'; push @{ $h{lines } }, $_ while <>; " huge.file
When you call readline (or use the <> operater as above), Perl determines how much to read from the file, by looking for a character (or sequence of characters), that match the current setting of the special variable $/ (also known as the $INPUT_RECORD_SEPARATOR (you'll have to scroll down aways to find it)). Normally, $/ defaults to being a newline. But...
What the sample above does is set the value of $/ = '~';. That means that readline will stop reading when it encounters a '~' in the input stream.
Ie. Instead of readline reading the whole 37 MB in as a single string; then spliting it into a big list; and then assigning that to the array on mass.
The code above, readlines just up to the first '~' character, pushes it onto the array; then loops (while), back to get the next chunk up to the next '~'.
Put another way. Setting $/ = '~';, has the effect of redefining a line, as a sequence of chars terminated by a '~'.
I hope one of those descriptions helps--ask again if it doesn't--because I know of no other langauge that has a standard library that allows you to do this. So when you first encounter it, it is definitely a bit weird.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: 32 Bit Perl causing segmentation fault if data is big
by peacelover1976 (Initiate) on Mar 19, 2010 at 04:00 UTC | |
by BrowserUk (Patriarch) on Mar 19, 2010 at 09:04 UTC |