Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: The Concept of References

by dragonchild (Archbishop)
on Apr 14, 2005 at 12:43 UTC ( #447737=note: print w/ replies, xml ) Need Help??


in reply to Re^2: The Concept of References
in thread The Concept of References

You don't, because doing so would violate the guarantee that you cannot buffer overflow in Perl. But, there are good reasons why C gives you the rope to buffer overflow.

Let's say you want to iterate through the characters of a string and do something with each character. In C, that's pretty simple. Strings are just arrays of characters and arrays are just fancy pointers.

char string[] = "Hello"; char *ptr; fr ( ptr = string; *ptr; ptr++ ) { do_something_with( *ptr ); // This is a single char }
Now, let's say you want to do the same thing in Perl. There's a few ways, but none are anywhere as efficient.
foreach my $char ( split //, $string ) { ... } while ( $string =~ /(.)/g ) { my $char = $1; ... } for ( my $i = 0; $i <= length $string; $i++ ) { my $char = substr( $st +ring, $index, 1 ); ... }


Comment on Re^3: The Concept of References
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2014-07-30 05:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls