linux - Splice an array ref -


if have array reference how can a: splice($array, 0, $num); since splice should not used on array refs according documentation?
update: problem splice on array ref pass in function on exit array not modified.

update
if splice(@$array, 0 ,$num) break recommendation not use array ref in splice? confused on this. snippet works me (for array ref pass in function , splice) not sure if @$array against docs

use on derefenced arrayref instead:

my $arr = [1,2,3]; splice @$arr, 0, 1, 3, 4; print join '-', @$arr; # 3-4-2-3 

it's same approach join here - when used on arrayref, dereference it.

it works same way inside sub obviously:

sub splice_it {   splice @{$_[0]}, 0, 1, 3, 4; }  $arr_ref = [1,2,3]; splice_it $arr_ref; print join '-', @$arr_ref; # still 3-4-2-3 

demo.


oh, , there's big chance able splice arrayrefs directly (without derefencing) - please just don't:

starting perl 5.14, splice can take scalar expr, must hold reference unblessed array. argument dereferenced automatically. aspect of splice considered highly experimental. exact behaviour may change in future version of perl.

to avoid confusing would-be users of code running earlier versions of perl mysterious syntax errors, put sort of thing @ top of file signal code work on perls of recent vintage:

use 5.014;    # push/pop/etc work on scalars (experimental) 

it's still there, though: same behaviour use 5.020;


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -