in reply to Re^3: Playing with non-localized $_ in nested loops.
in thread Playing with non-localized $_ in nested loops.
Perl dwims nicely when you use a float in other situations where an int is expected.
my @a = 0 .. 9; print $a[3.5]; 3
It could do the same here. If the number involved required advancing from the current position, it just reads and discards enough lines to get to where you want to be.
The problem arises if you want to backup. That would require keeping the file positions of every line seen so far. On large files, that's a lot of storage. If you store integers in a perl array, they take as much space as storing the lines themselves until the lines get greater than 20 chars or so.
You can save some space by storing the offsets in a C-style array (eg. pack them into a string) but with if your going to handle files greater than 2/4GB, then you need to store 8 bytes/line, and that still chews a substantial amount of memory to provide a rarely used facility.
Though, I guess if it rewound to the beginning and discarded until it reached the position required it wouldn't require extra storage. It would simply be doing what you have to do yourself to achive the same results, but hiding it behind a simple assignment... which might be nice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Playing with non-localized $_ in nested loops.
by QM (Parson) on Aug 23, 2004 at 23:37 UTC |