perl - 另一个数组中的数组perl
问题描述
my @ana = ("Godfather", "Dirty Dancing", "Lord of the Rings", "Seven", "Titanic");
my @dana = ("American Pie", "Harry Potter", "Bruce Almighty", "Jaws 1", "Solaris");
my @mihai = ("Fight Club", "Gladiator", "Troy", "Eternal Sunshine of the Spotless Mind", "Lord of the Rings");
my @daniel = ("Independence Day", "Finding Nemo", "Gladiator", "Godfather", "Schindler’s List");
my @structure = (@ana,@dana,@mihai,@daniel);
如何从@structure 获取一部电影?
my $subarray = @{$structure[3]}[3];
此行不起作用,我需要有关此语法的更多信息
解决方案
数组在列表上下文中被展平,因此您的@structure 包含@ana 的元素,后跟@dana 的元素等。使用数组引用嵌套数组:
my @structure = (\@ana, \@dana, \@mihai, \@daniel);
my $movie = $structure[3][3];
推荐阅读
- twilio - 如何将 Twilio 中已接受的呼叫重定向到另一个工作人员?
- java - 过滤 ListView IndexOutOfBoundsException
- r - windows10无法正确安装Rtools
- unity3d - Gradle 在 Unity 中构建错误并出现错误无法获取未知属性“unityStreamingAssets”
- java - 在 Spring Boot 中使用模拟存储库测试 void 服务方法?
- javascript - html / css / javascript 悬停文本'字典'
- jenkins - 使用文件参数远程触发 jenkin 作业
- java - 我如何获得输出字符串之类的输出?
- python - 如何获取文本 BeautifulSoup
- django - Django:遍历所有对象填充所有内存