Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^2: substr is behaving differently with small vs large strings

by perldeveloper (Scribe)
on Jul 07, 2004 at 21:32 UTC ( #372559=note: print w/replies, xml ) Need Help??

in reply to Re: substr is behaving differently with small vs large strings
in thread substr is behaving differently with small vs large strings

The offset appears to make sense in the trimmed file. That is, excluding the spaces between the columns and the line numbers. Which suggests that Augustine might aviod slurping the file, by reading one line at a time (by leaving $/ unchanged) and windowing every input sequence (exon) (a sequence of lines which covers the exon).

You could also use `seek' and `sysread' (as suggested by Belgarion, but you'd have to work out an algorithm (quite simple I would guess) which converts the address within the trimmed file to the address within the formatted file. Something like... $address_in_file = $address_in_trimmed_file + $number_of_characters_for_line_numbering_for_first_line + ($address_in_trimmed_file / 10) + ($address_in_trimmed_file / 60) * ($one_character_for_new_line + $number_of_characters_for_line_numbering). Actually, I think that is a correct and yet unabusive way to solve this (every 10 characters you get a space, every 60 characters you get a new line and a line number).

On another note, though, I have experience with slurping large files, and can say that perl handles it pretty good. For example, I could semi-parse an 8Mb Xml file into an internal tree within seconds. I'm afraid I cannot say how substring handles large offset/length parameters, I thought it would work as expected.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://372559]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2023-03-22 02:41 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.