well, it works in my case..
insaniac][amano: ~ : perl -we 'use strict;my @d=([0,"BE"],[3,"BUS"],[4
+,"BUS2"]);my @a=map($_ , split(/,/, "BUS2,BE") ) ; my @b=map { my $ma
+pkey=$_; map { $d[$mapkey]->[1] =~ /$a[$_]/ ? $d[$mapkey] : () } 0..$
+#a } 0..$#d; use Data::Dumper;print Dumper(@b);'
$VAR1 = [
0,
'BE'
];
$VAR2 = [
4,
'BUS2'
];
insaniac][amano: ~ : perl -we 'use strict;my @d=([0,"BE"],[3,"BUS"],[4
+,"BUS2"]);my @a=map($_ , split(/,/, "BUS2,BE") ) ; my @b=map { my $ma
+pkey=$_; map { $d[$mapkey]->[1] =~ /$a[$_]/ ? [@{$d[$mapkey]}] : () }
+ 0..$#a } 0..$#d; use Data::Dumper;print Dumper(@b);'
$VAR1 = [
0,
'BE'
];
$VAR2 = [
4,
'BUS2'
];
--
to ask a question is a moment of shame
to remain ignorant is a lifelong shame
| [reply] [d/l] |
Add @d to the Dumper() call, and you'll see the difference:
$ perl -we 'use strict;my @d=([0,"BE"],[3,"BUS"],[4,
"BUS2"]);my @a=map($_ , split(/,/, "BUS2,BE") ) ; my @b=map { my $mapk
+ey
=$_; map { $d[$mapkey]->[1] =~ /$a[$_]/ ? $d[$mapkey] : () } 0..$#a }
+0
..$#d; use Data::Dumper;print Dumper(@d,@b)'
$VAR1 = [
0,
'BE'
];
$VAR2 = [
3,
'BUS'
];
$VAR3 = [
4,
'BUS2'
];
$VAR4 = $VAR1;
$VAR5 = $VAR3;
$ perl -we 'use strict;my @d=([0,"BE"],[3,"BUS"],[4,
"BUS2"]);my @a=map($_ , split(/,/, "BUS2,BE") ) ; my @b=map { my $mapk
+ey
=$_; map { $d[$mapkey]->[1] =~ /$a[$_]/ ? [@{$d[$mapkey]}] : () } 0..$
+#a } 0
..$#d; use Data::Dumper;print Dumper(@d,@b)'
$VAR1 = [
0,
'BE'
];
$VAR2 = [
3,
'BUS'
];
$VAR3 = [
4,
'BUS2'
];
$VAR4 = [
0,
'BE'
];
$VAR5 = [
4,
'BUS2'
];
In the second case, @b is composed of refs to new arrays that have copies of the arrays referenced in @d. People often shoot themselves in the foot by leaving shared references like this in datastructures without meaning to.
If, instead of 'BUS2' et. al., you had references, forming an even deeper structure, those would still be shared, though. If you need to prevent that, use something like Storable::dclone($ref) instead of [@{$ref}]. | [reply] [d/l] [select] |
| [reply] |