Dipit Sethi Dipit Sethi - 6 months ago 7
Perl Question

What is the meaning of these empty array assignments in perl?

foreach my $tp (@tpList)
{
print "inside function 14";
my $result1_fail = "";
$_=$tp;
next if(/^$/);
print "TP : $tp\n";
$result.="<h3>$tp</h3><BR>\n";
$result1_fail.="<h3>$tp</h3><BR>\n";
#------------------------------#
print "inside function 15";
***my @emptytables=();
my @tables=();***
@tables= getAllTables4TP($tp);



  • Please explain the meaning of my @emptytables=();

  • And also my @tables=();

  • is this used for defining some empty array?

  • if it is, then what is its use?


Answer
  • my @tables; creates an empty array
  • my @tables = (); creates an empty array, then replaces its contents with nothing (empties it).
  • my @tables = (); @tables = getAllTables4TP($tp); creates an empty array, then replaces its contents with nothing, then replaces its contents with something else.

I would use just the following:

my @tables = getAllTables4TP($tp);