That's better. (And aliasing a slice is a nice twist on the theme.) But the OP wanted to be able to use simple scalars. Here's a modification that will do the trick:
It's really nothing more than a convenience function to do exactly the same thing as I suggested in my original answer in this thread. Looking at it, I'm not even sure it's that convenient. I think *alias = \$array[1]; is perfectly clear, and it doesn't require me to go check what the alias_to() sub actually does.#!/usr/bin/perl use warnings; use strict; use vars qw( $alias ); sub alias_to { \$_[0] } my @array = qw( foo bar baz ); *alias = alias_to( $array[1] ); print "alias: $alias\n"; $alias = 'QUUX'; print "array: @array\n";
-sauoq "My two cents aren't worth a dime.";
In reply to Re: Re: Re: Re: use simple scalar names to point to specific array elements
by sauoq
in thread use simple scalar names to point to specific array elements
by Sandy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |