Please notice that
printem([@list1], [@list2]);
actually creates two anonymous arrays and copy data in memory, while
printem(\@list1, \@list2)
will pass references to the original arrays.
Copying data will prevent accidental changes of the original arrays but may be quite long and memory-hungry if the copied data is big...
Here's a small sample to picture the difference :
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @list1 = qw(a b c);
my @list2 = qw(d e f);
sub sem {
my $list1 = shift or die "no list1";
my $list2 = shift or die "no list2";
$list1->[0]='x';
@{$list2}=qw(D E F);
}
# print original data
print "list1: " . Dumper(@list1);
print "list2: " . Dumper(@list2);
# call with copy
sem([@list1], [@list2]);
print "list1: " . Dumper(@list1);
print "list2: " . Dumper(@list2);
# call by reference
sem(\@list1, \@list2);
print "list1: " . Dumper(@list1);
print "list2: " . Dumper(@list2);
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.