[ Please do not top post. ]
7 wrote:
a)
open (BHF_FILE, "</home/bob/tmp/md5music")
The modern way to open a file is to:
1) Use the three argument form of open().
2) Create a variable for the file handle.
open (my $BHF_FILE, '<', '/home/bob/tmp/md4music');
You should *always* verify that the file was opened correctly.
But the person you are replying to already made this point.
while (my $line = <$BHF_FILE>) {
#do something with $line
}
close $BHF_FILE;
b) Take a look at this code:
use strict;
use warnings;
use 5.010;
my $line = 'hello world goodbye';
my @pieces = split / /, $line, 2;
You are using a regular expression that matches a *single* space
character. If your string is "hello\tworld\tgoodbye" or 'hello world
goodbye' then that won't work correctly.
The person that you are replying to used the expression:
my @fields = split ' ', $_, 2;
where a string with a single space character is special to split() in
that it acts the same as the default no-argument form of split().
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/