Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you are concerned about the performance while reading the file into an array I would recommend doing some sample code and running it against a large file (say 100MB or more) to test the speed difference between doing:
@array = <FILE>;
and doing:
while(<FILE>) { push(@array, $_); }
and run it multiple times to make sure you're not just getting the effect of the file being cached in memory.

I have found that while the version with the while loop *looks* longer it actually has always run faster in the tests I've done.

PS: a die message with your open statement like

open (DF, "test.txt") || die "Can't read 'test.txt': $!\n"
is your friend, as are:
use strict; use warnings;
at the top of your script - I'd recommend using them - they will help you by saving you time finding what's causing errors and in the long run should also help you to write better code by teaching you good habits.


update: Thanks ChOas - I've fixed it. I always use the () brackets and || myself - and vaguely recalled (like you point out) that there *was* a difference between || and 'or'.

After having Dominus do a presentation to us the other week and finding I am in th habit of using () where I don't absolutely need to, I'd thought I'd not add them here where NeilF wasn't already using them... I've put them back on now :o)


perl -MO=Deparse -e 'open (DF, "test.txt") || die "Cant read test.txt\ +n";'
tells me I *could* write it:
die "Can't read test.txt\n" unless open DF, 'test.txt';
but I won't :o)

In reply to Re: Perl always reads in 4K chunks and writes in 1K chunks... Loads of IO! by serf
in thread Perl always reads in 4K chunks and writes in 1K chunks... Loads of IO! by NeilF

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2022-01-19 08:59 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (55 votes). Check out past polls.