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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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

New User

Oct 14, 2017, 9:31 AM

Views: 5074
Re: [BillKSmith] Dereference an array

Thanks. I knew that it was possible to define an array and after that taking a reference to it. But there is apparently no possibility to do the other way around. My example was only a small test to exemplify my question. You might have the reference because you get it as a parameter to a subroutine and, naively, it would have been convenient to have a name for the object referenced by the parameter inside the subroutine, which would avoid the need to use the dereference operator (->) everywhere.

Another question, closely related but not exactly the same if I put

my @list = ("a","b","c","d"); 
my @newlist = @list;
print $list[1];
print "\n";

Then I get "b". Once again a copy of the array is made. It seems that a new copy is made each time you assign something to a new name. Coming from Python, I would be tempted to use references only (in python, everything is a reference) to avoid unexpected copies. But maybe this is my python background...

(This post was edited by Olive on Oct 14, 2017, 9:32 AM)

Edit Log:
Post edited by Olive (New User) on Oct 14, 2017, 9:32 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