Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Could someone explain a piece of perl code to me?

Status
Not open for further replies.

lcs01

Programmer
Aug 2, 2006
182
US
Here is the code:

Code:
for my $key (keys %manymanyhash) {
  next if $lockedhash{$key};
  my $variable;
  if ($aihash{$key}) {
    $variable = 'split /,/, $Q::' . $typehash{$key} . '_' . $key . '_ai2';
  }
  else {
    $variable = '@Q::' . $typehash{$key} . '_' . $key;
  }
  $variable =~ /(.*)/;
  my ($dummy,$pField,$sField) = @{$dbh->selectcol_arrayref("DESCRIBE @{$manymanyhash{$key}}[1]")};@Q::pm_97408
  push @output, "DELETE FROM " . @{$manymanyhash{$key}}[1] . " WHERE $pField = $Q::docID";
  [b]for my $item (eval($1)) {[/b]
    print LOG "\$1 = $1, \$item = $item\n"; # debug
    push @output, "INSERT INTO " . @{$manymanyhash{$key}}[1] . "($pField,$sField) VALUES ($Q::docID,$item)" if($item > 0);   }
}

==============================================
Here are the debug info
-----------------------
$1 = split /,/, $Q::pm_97420_ai2, $item = 0
$1 = @Q::pm_97421, $item = 0
$1 = @Q::pm_99591, $item = 16
$1 = split /,/, $Q::pm_97381_ai2, $item = 0
[b]$1 = @Q::pm_97408, $item = 2[/b]
$1 = split /,/, $Q::pm_97368_ai2, $item = 0
$1 = split /,/, $Q::pm_97385_ai2, $item = 0
==============================================

What I don't quite understand are in bold font.

1) How does '$1' get assigned?
2) What does 'eval()' do here?
3) For '$1 = @Q::pm_97408, $item = 2', does it mean that the array '@Q::pm_97408' has only one data member which equals to '2'?

Thank you very much for your explaination
 
Sorry, the above code has a typo:

What is Wrong:

my ($dummy,$pField,$sField) = @{$dbh->selectcol_arrayref("DESCRIBE @{$manymanyhash{$key}}[1]")};@Q::pm_97408

What it should be:

my ($dummy,$pField,$sField) = @{$dbh->selectcol_arrayref("DESCRIBE @{$manymanyhash{$key}}[1]")};

thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top