小编CJC*_*egg的帖子

perl:确定字符串数组大小的方法似乎不起作用

刚开始学习perl大约三天前.

我有一个字符串数组,我从文本文件加载:

my @fileContents;
my $fileDb = 'junk.txt';
open(my $fmdb, '<', $fileDb);
push @fileContents, [ <$fmdb> ];
Run Code Online (Sandbox Code Playgroud)

该文件已知长1205行,但我无法检索数组的大小,即加载到数组中的行数.

我在这里和其他地方尝试了三种不同的方法,关于如何确定字符串数组中的元素数量,并且似乎无法使它们中的任何一个起作用.

以下是我的代码,评论包括我在研究中发现的三种不同方式,以查找数组中的元素数量.

#!/usr/bin/perl
#
# Load the contents of a text file into an array, one line per array element.

# Standard header stuff.
# Require perl 5.10.1 or later, and check for some typos and program errors.
#
use v5.10.1;
use warnings;
use strict;

# Declare an array of strings to hold the contents of the files.
#
my @fileContents;

# …
Run Code Online (Sandbox Code Playgroud)

perl

4
推荐指数
1
解决办法
157
查看次数

标签 统计

perl ×1