我仍在学习如何使用 map 命令,并且无法弄清楚如何将以下代码从以下代码转换为使用 map 命令:
单线
perl -MData::Dumper -wE'
$_ = "Alpha,Beta,Gamma|Alpha,Beta";
say;
($first,$second)=split/\|/;
@first=split /,/,$first;
@second=split /,/, $second;
print Dumper({FIRST=>\@first, SECOND=>\@second})
'
完整脚本:
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use v5.10;
$_ = "Alpha,Beta,Gamma|Alpha,Beta";
say;
my ($first,$second)=split/\|/;
my @first=split /,/,$first;
my @second=split /,/, $second;
warn Dumper({FIRST=>\@first, SECOND=>\@second});
我希望使用 map 函数将下面的行转换为两个数组:
阿尔法,贝塔,伽玛|阿尔法,贝塔
$VAR1 = {
'FIRST' => [
'Alpha',
'Beta',
'Gamma'
],
'SECOND' => [
'Alpha',
'Beta'
]
};