Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Perl vs C

by Tanktalus (Canon)
on Mar 14, 2009 at 21:19 UTC ( [id://750658]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl vs C
in thread Perl vs C

That depends on how you define "pointers."

If you're simply doing Node* n = &currentNode; in C, then that works fine in perl, too: my $ref = \$list[$n];. Now, granted, in C, you know what's next and what's before (assuming doubly-linked), but I have to admit to not needing that very often. And, besides, you can create a linked list in Perl, too, if that's what you really want. Each node is just an array, where the first element (0) is a reference to the data, the second is a reference to the previous node, and the third is a reference to the next node.

If, however, your pointer in Perl is an index, well, yes, that's silly. You don't take an index of your linked list in C, so comparing them isn't quite fair. Of course, if you're using a STL linked list, then you can take an index, but you don't. Well, not if you expect it to survive insert/delete operations elsewhere.

Like I said, I don't find the need for surviving insert/delete operations too often. I usually use map to transform list A to list B, and survivability is moot. Generally, my object is either transforming a list (usually via map), or my object cares about a particular value/object (which I can retain via reference or copy, as is appropriate). Doing both at the same time is pretty rare. I suppose I've just changed my thinking ("paradigm shift") to fit idiomatic perl. Works for me and my little projects ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://750658]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2026-01-19 00:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.