Perl links and hash values ​​of deferment when moving to a subroutine?

I have been staring at this topic for 5 hours, I am very upset and need some help.

I am writing a Perl script that pulls jobs from a MySQL table and then predicts various database administration tasks. The current challenge is creating databases. The script successfully creates the database, but when I get to creating the configuration file for PHP developers, it will explode.

I believe this is a problem with reference and dereference variables, but I'm not quite sure what exactly is happening. I think after this function call something happens with the $$ result {'Databasename'}. This is how I get the result:$result = $select->fetchrow_hashref()

Here is my function call and function implementation:

Function call (line 127):

generateConfig($$result{'databaseName'}, $newPassword, "php");

Function Execution:

sub generateConfig {
    my($inName) = $_[0];
    my($inPass) = $_[1];
    my($inExt)  = $_[2];

    my($goodData) = 1;
    my($select)   = $dbh->prepare("SELECT id FROM $databasesTableName WHERE name = '$inName'");
    my($path)     = $documentRoot.$inName."_config.".$inExt;
    $select->execute();

    if ($select->rows < 1 ) {
            $goodData = 0;
    }

    while ( $result = $select->fetchrow_hashref() )
    {
            my($insert) = $dbh->do("INSERT INTO $configTableName(databaseId, username, password, path)".
                                   "VALUES('$$result{'id'}', '$inName', '$inPass', '$path')");

    }

    return 1;
    }

Errors:

Use of uninitialized value in concatenation (.) or string at ./dbcreator.pl line 142.
Use of uninitialized value in concatenation (.) or string at ./dbcreator.pl line 154.

Line 142:

        $update = $dbh->do("UPDATE ${tablename}
                        SET ${jobStatus}='${newStatus}' 
                        WHERE id = '$$result{'id'}'");

Line 154:

 print "Successfully created $$result{'databaseName'}\n";

, , , , , , !

- , , .

,

p.s. , , . = P

+5
3

$result, fetchrow_hashref, .

, , generate_config, .

$result generate_config ? " " generate_config.

      while ( my $result = $select->fetchrow_hashref() )
      #       ^^  #add my

, , .

:

  • generate_config , . .
  • undef, , 'use strict;'. !
  • $result my.
  • $$ hashr {key} , $hashr → {key}.
  • dbh- > prepare, .

    sub generateConfig {
      my($inName, inPass, $inExt) = @_;
    
      my $goodData = 1;
      my $select   = $dbh->prepare("SELECT id FROM $databasesTableName WHERE name = ?");
      my $insert   = $dbh->prepare("
                        INSERT INTO $configTableName(
                          databaseID
                          ,username
                          ,password
                        ,path) 
                        VALUES( ?, ?, ?, ?)" );
      my $path     = $documentRoot . $inName . "_config." . $inExt;
      $select->execute( $inName );
    
      if ($select->rows < 1 ) {
            $goodData = 0;
      }
    
      while ( my $result = $select->fetchrow_hashref() )
      {
        insert->execute( $result->{id}, $inName, $inPass, $path );
      }
    
     return 1;
    

    }

+2

EDIT:

, $$result. $result - fetchrow_hashref, :

$result = $select->fetchrow_hashref()

:

 print "Successfully created " . $result{'databaseName'} . "\n";

    $update = $dbh->do("UPDATE ${tablename}
                    SET ${jobStatus}='${newStatus}' 
                    WHERE id = '$result{'id'}'");

:

generateConfig :

generateConfig(\$result{'databaseName'},$newPassword, "php");

($$ ; \ , ).

, , :

 print "Successfully created $result->{'databaseName'}->{columnName}\n";

, fetchrow_hashref ( ).

.

, $dbh, , . , generateConfig? generateConfig?

0

This drove me crazy when I ran hetchrow_hashref from the Oracle result set. Running column names are always returned in uppercase. Therefore, as soon as I started to refer to the columbus in upper case, the problem disappeared: insert-> execute ($ result → {ID}, $ inName, $ inPass, $ path);

0
source

All Articles