Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Re: Optimizing existing Perl code (in practise)

by smalhotra (Scribe)
on Aug 19, 2002 at 16:16 UTC ( #191225=note: print w/replies, xml ) Need Help??


in reply to Re: Optimizing existing Perl code (in practise)
in thread Optimizing existing Perl code (in practise)

my $text = `cat $file`;
If you're gonna do that, you might as well do
my $text = join '', <FileHandle->new($file)> and still do it in perl. Frankly I don't know which is faster but I would choose to do it the second way because I think it would be faster.

Replies are listed 'Best First'.
Re: Optimizing existing Perl code (in practise)
by Abigail-II (Bishop) on Aug 19, 2002 at 16:22 UTC
    I'd never choose the second method. With the first, it's immediately clear what it does. With the second, it isn't. And somehow I doubt it's faster - it certainly doesn't look like it, as you first make a list of all the lines, then join them together, meaning you get more than double the memory usage. I'd rather do
    my $text = do {local (@ARGV, $/) = $file; <>};

    "Still do it in Perl" isn't a goal, IMO.

    Abigail

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2019-05-23 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (146 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!