in reply to Re^4: Nested Data Structures, OOP
in thread Nested Data Structures, OOP
It's good to see you're paying attention to deprecation warnings.
You can use the splice function to remove elements from an array. Here's an example:
$ perl -Mstrict -Mwarnings -E ' my @x = qw{a b c}; say "@x"; splice @x, 1, 1; say "@x"; ' a b c a c
If you know the value you want to delete but not the array index of that value, grep may be a better option:
$ perl -Mstrict -Mwarnings -E ' my @x = qw{a b c}; say "@x"; @x = grep { $_ ne q{b} } @x; say "@x"; ' a b c a c
Also, an empty list will not add elements to the array, e.g.
$ perl -Mstrict -Mwarnings -E ' my @x = ( qw{a}, (), qw{c} ); say "@x"; ' a c
You might use this feature in, for instance, a map statement. This example shows discarding certain values and modifying the remainder:
$ perl -Mstrict -Mwarnings -E ' my @x = qw{a b c}; say "@x"; @x = map { $_ ne q{b} ? uc : () } @x; say "@x"; ' a b c A C
You may also find the following modules useful:
-- Ken
|
---|