
Laurent_R
Enthusiast
Feb 10, 2013, 6:35 AM
Post #4 of 4
(288 views)
|
|
Re: [b3asttt] skip new lines and some other beginner questions
[In reply to]
|
Can't Post
|
|
Iterating over a file one line at a time:
while (my $line = <FILE>) { chomp($line); # ... The main advantage it that your code will continue to work even if your file has 100 million lines, whithout concuming more memory than what is needed to store one line. While your version slurping all lines into an array will use very large amount of memory if the file is big. If you want to call a subroutine, from the command line, you'll have to code that explicitly with something like:
my $arg1 = shift; chomp $arg1; foobar() if ($arg1 eq "foo"); barfoo() if $arg1 eq "bar"; Of course using a module like GetOpt may simplify the analysis or the command line arguments, but you still have to explicitly implement the function call. If you have more than a couple of possibilities as above, you may want to implement a dispatch table (i.e. a hash containing code references to functions).
|