Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
A text file with a single line consisting of ~155e6 characters, all 0's and N's, is read in as a scalar variable. Each character is assigned to a single element of an array

As a scalar, your 155e6 file will require ~ 150 MegaBytes of memory.

As an array, 1 char per element, it will require ~ 10 GigaBytes of memory. Assuming you have that available.

But for your stated goal:

The goal: change all elements of the @info array that lie outside of my intervals to N's.

There is no need to go through the time and memory costly process of spliting your string to an array. And no need to iterate over 155 million characters one at a time.

You can easily and quickly overwrite the characters outside your ranges with 'N's, in-place in the scalar:

open( SEQ, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_fil +es/mask_files/mask."."$population".".chr.23.txt" ) or die "can't open masked file\n"; my $bigScalar = <SEQ>; close SEQ; open (INTERVAL, "<$filtered_sites") or die "can't open $filtered_sites +"; my $lastEnd = 0; while( <INTERVAL> ) { my( $start, $end ) = split "\t", $_; ## change everything from the end of the last range ## to the start of this range to 'N' substr( $bigScalar, $lastEnd, $start ) =~ tr[\x00-\xff][N]; $lastEnd = $end; } close INTERVAL; ## change everything from the end of the last range to the end of stri +ng to 'N' substr( $bigScalar, $lastEnd, length( $bigScalar ) ) =~ tr[\x00-\xff][ +N]; ## do something with $bigScalar ...

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: A question About Array Indexing by BrowserUk
in thread A question About Array Indexing by ccelt09

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-25 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found