Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^6: Looking for pointers or optimizations.

by SerZKO (Beadle)
on Aug 21, 2012 at 19:12 UTC ( #988829=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Looking for pointers or optimizations.
in thread Looking for pointers or optimizations.

Hej, You probably didn't see this (marked with ####)

open(my $fh, "<", $ARGV[0]) or die "cannot open input file: $!"; my @words = <$fh>; close $fh or die "cannot close input file: $!"; ############## my $words = @words;
On the other hand, I don't understand the last line - you read a file into array with my @words = <$fh>; and then you assign it to a scalar variablemy $words = @words;.

OK, you probably have your own reasons for that but you could manipulate array as good as scalar. And you could read a file directly in a scalar variable. my $words = <$fh>;


Comment on Re^6: Looking for pointers or optimizations.
Select or Download Code
Replies are listed 'Best First'.
Re^7: Looking for pointers or optimizations.
by chromatic (Archbishop) on Aug 21, 2012 at 19:59 UTC
    And you could read a file directly in a scalar...

    Depending on the current value of the input record separator, you might only get one record. In fact, you'll probably only get one record.

      ++ for pointing out this Chromatic.

      But if you just add undef $/; before reading file, then you get it all in a scalar variable

      undef $/; my $words = <$fh>;

Re^7: Looking for pointers or optimizations.
by choroba (Canon) on Aug 21, 2012 at 19:58 UTC
    you could read a file directly in a scalar variable.
    my $words = <$fh>;
    Not true. Have you tried it? In fact, you can, but in a different way.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2015-07-28 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls