in reply to Re: map question (hash slice)
in thread map question
sub array_minus (\@\@) { my ( $got, $required ) = @_; my %required; @required{@required}=@required; delete @required{@got}; return values %required; }
Note also that this function is not correct because the $got $required array references passed as arguments are never used. As it stands, the code here works only because @required @got within the function access file-scope lexicals defined earlier in the code. Also, the prototype array_minus(\@\@) needs to be declared (or the function itself needs to be defined) before the function is invoked for prototyping to be effective.
c:\@Work\Perl\monks>perl use strict; use warnings; sub array_minus (\@\@); my @got = qw(blue_shirt hat jacket preserver ); my @required = qw(preserver sunscreen water_bottle jacket); # ---------- as custom function warn "Skipper is missing: ", array_minus(@got,@required); sub array_minus (\@\@) { my ( $ar_got, $ar_required ) = @_; my %required; @required{@$ar_required} = @$ar_required; delete @required{@$ar_got}; return values %required; } __END__ Skipper is missing: water_bottlesunscreen at - line 11.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: map question (hash slice)
by LanX (Saint) on Jul 29, 2019 at 14:30 UTC |