Asigning an array to a list of variables is a common way to give meaning full names to the items in an array. You can use it to make handling the returns of functions like local time easyer.
IE:
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
as opposed to
@time = localtime(time);
and having to remeber that $time[2] is the hour.
If you have an array in the list on the left side of the = it will gobble up all the remaing items in the array on the right side.
You need to be careful of this, because anything following the array will not have anything asigned to it.
IE:
($one, $two, @three, $four) = ('one', 'two', 'three', 'four');
$one will equal 'one'
$two will equal 'two'
@three will equal ('three', 'four')
and $four will be undefined
There are many ways to use this feature of perl.
You will probably see
sub do_stuff {
my ($foo, $bar) = @_;
}
to get the arguments sent to a subroutine into named variables often.
| [reply] [d/l] [select] |
Basically, whenever you assign to a list, each element gets assigned to, all in parallel. So, in parallel, the value of the first gets assigned to the second, and the value of the second (which isn't *yet* the previous value of the first) gets assigned to the first; thus, they get exchanged. See? | [reply] |
This is otherwise known as DWIM, Do What I Mean.
Cool aint it?
| [reply] |
push @INC, $first, $second; # not a temporary since it already exists!
$_= pop @INC foreach ($first, $second);
| [reply] [d/l] |
or, uhm...
$x = substr($x.$y, -(length($y) * ($y =~ s/^$y$/$x/)), length($y));
update: substr, not suystr. sorry. Thanks John.
| [reply] [d/l] |
| [reply] |