[pm-h] populate an array from data in a text file
Russell L. Harris
rlharris at oplink.net
Sun Apr 20 19:24:19 PDT 2008
I am trying to read data from a text file into an array, the goal
being to copy various elements from the array. From chapter 2 (pages
66-67) of the third edition of "Programming Perl", it appears to me
that the text file is termed a "here-document".
Because of the need to read a file, I suspect that I should be using
the diamond operator, but I haven't been able to figure out how it
would fit into this script.
Here is my Perl script:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#!/usr/bin/perl
@ARGV = qw# words #; # read the here-document
@phonetic = <<EOF =~ m/^\s*.+/gm;
EOF
print $phonetic[0];
print $phonetic[1];
print $phonetic[2];
print $phonetic[3];
print $phonetic[4];
print $phonetic[5];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Here is the content of my here-document, which is a text file named
"words":
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
able
baker
charlie
delta
echo
foxtrot
EOF
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
More information about the Houston
mailing list