Perl doesn't do pointers or structures.
You can have a reference to a hash which is functionally equivalent.
But you'd be better off describing what you are trying to achieve.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
Sounds like you're looking for Perl references. Check out the perlref and perlreftut pages using the perldoc command.
As a quick example:
my @array = qw( hello world );
my $array_ref = \@array;
print $array[0], "\n"; # prints hello
print $array_ref->[0], "\n"; # prints hello
| [reply] [d/l] |
| [reply] |
Perl references are similar to C pointers unless you are working with strings. A perl string in a scalar, not an array of characters as in C. One of perl's greatest strengths is its string manipulation, but note that it is quite different from C. There is no such thing as a pointer/reference to a charater withing a string.
| [reply] |
Indeed, the secret-sauce that you are looking for here is “references.”
The concept here is several levels above the concept that you see in “C,” this being of course the language in which Perl was implemented. A reference is, if you want to think of it this way, “a pointer to” a complete, self-describing Thing, that is also well-known to the Perl interpreter and fully part of the environment that it creates. Perl can look at a reference , and know everything that needs to be known about what it refers to. It knows how many references currently exist to that same thing, therefore it knows whether-or-not that object is eligible to be garbage-collected. The Perl language does not have the concept of a “structure,” in the C/C++ sense, but it does have the concept of a list, array, and hash.
The environment that has been created by the Perl interpreter is intended to focus upon providing an efficient solution to the same problem that one might use “pointers to structures” in bare-bones C to address, but to do so in a way that is much less reliant upon the program-in-question to “do everything in just the right way, or else.” There exist several layers of well-tested software that any Perl programmer can rely upon the existence of, that a C-programmer cannot. All of us here fully-understand both environments.
| |
pack, look for letter 'P', the pointer is useless (no core func or operator other than unpack and syscall will take it) in Perl except for syscall. You probably want to read perlxstut. | [reply] |
Other people have wibbled about references, but in case you're trying to deal with data in some machine-specific C-generated format, or to generate data to pass to such (believe it or not there are some crazy programs that expect you to drive them by dropping a C struct in a file, or even pass them a struct on STDIN), then you might want Convert::Binary::C.
I've not used it myself, but trying it out is on my to-do list for solving one of those thorny problems.
| [reply] |