Why are you replying to me? My post did use the three-argument form of
open(). Also:
- It is bad form to use upper case letters for lexical variables
- Passing / / as the first parameter of split() will split on the first
single space in the string. It is better to use ' ' instead which
discards leading whitespace and splits on the next contiguous
sequence of whitespace
- IMO it is bad manners and contrary to the spirit of the list to offer
only an enigmatic handle to identify the author
Cheers,
Rob
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');
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;
for (@pieces) {
say;
}
--output:--
hello
world goodbye
At the command line, you can always type:
perldoc -f <a function name>
to get more information about a function. For instance:
$ perldoc -f split
c) To access the first element of an array, you do this:
my @data = ('hello', 'world', 'goodbye');
say $data[0];
Compare the second line to the expression: $1[$i]. Just like $data[0]
is accessing an element of the array @data, the expression $1[$i] is
trying to access an element of the array @1. And unless you defined
an array called @1 in your code, that will cause an error.
perl does automatically define variables called $1, $2, etc., which
are assigned portions of a regex match, however they are not arrays.
The $ sign in front of the names 1, 2, etc. tells you that they are
variables that store scalar values (= a single value).
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/