CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [FishMonger] Dereference an array: Edit Log



FishMonger
Veteran / Moderator

Oct 15, 2017, 10:12 AM


Views: 2310
Re: [FishMonger] Dereference an array

I left out one other example. If you want a named var for the passed-in array ref, then you can use subroutine signatures, but you then would still need to use -> to dereference.

Code
use v5.20; 
use feature qw(signatures);
no warnings qw(experimental::signatures);
use Data::Dumper;

my $letters = ["a","b","c","d"];
$letters = letter2word($letters);
say Dumper $letters;

sub letter2word ($letter) {
$letter->[1] = 'hello';
return $letter;
}


This signature also works, which surprised me.

Code
use v5.20; 
use feature qw(signatures);
no warnings qw(experimental::signatures);
use Data::Dumper;

my @letters = ("a","b","c","d");
@letters = letter2word(@letters);
say Dumper \@letters;

sub letter2word (@letter) {
$letter[1] = 'hello';
return @letter;
}



(This post was edited by FishMonger on Oct 15, 2017, 10:19 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Oct 15, 2017, 10:13 AM
Post edited by FishMonger (Veteran) on Oct 15, 2017, 10:14 AM
Post edited by FishMonger (Veteran) on Oct 15, 2017, 10:19 AM
Post edited by FishMonger (Veteran) on Oct 15, 2017, 10:19 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives