Just started learning perl about three days ago.
I have an array of strings loaded from a text file like this:
my @fileContents;
my $fileDb = 'junk.txt';
open(my $fmdb, '<', $fileDb);
push @fileContents, [ <$fmdb> ];
It is known that the file has a length of 1205 lines, but I can not get the size of the array, i.e. the number of rows loaded into the array.
I tried three different methods, described here and in other sections, on how to determine the number of elements in an array of strings and cannot make them work.
Below is my code commented out to include three different ways I found in my research to find the number of elements in an array.
use v5.10.1;
use warnings;
use strict;
my @fileContents;
my $fileDb = 'junk.txt';
open(my $fmdb, '<', $fileDb) or die "cannot open input file $!";
my $sizeBeforeLoading = @fileContents;
say "size of fileContents before loading is $sizeBeforeLoading.";
push @fileContents, [ <$fmdb> ];
close( $fmdb );
my $sizeAfterLoading = @fileContents;
say "size of fileContents after loading is $sizeAfterLoading.";
$sizeAfterLoading = scalar @fileContents;
say "size of fileContents after loading is $sizeAfterLoading.";
$sizeAfterLoading = $#fileContents + 1;
say "size of fileContents after loading is $sizeAfterLoading.";
$sizeAfterLoading = 1204;
say "The file contents are:";
foreach my $i( 0..$sizeAfterLoading )
{
print $fileContents[ 0 ][ $i ];
}
( diff , ), ( ).
, $fileContents - . , "print $fileContents [$ i];" ; [0] [$ i]. , .
- , ?