[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

syntax

I have a perl script that calls the following function, passing in an array by reference.

my @array;
func(\@array);

Inside func, it calls another function which again passes this array by reference into another function.  I want the original array to be modified by func.

sub func
{
      my @array_local = $_[0] ;
        func2( \@{$array_local[0]} );
}

The problem is that I think that Perl doesn't like my handling of the array this way - I see an error in the Apache2 error log like:

Win32::OLE(0.17): GetOleObject() Not a Win32::OLE object at c:/woc/Perl/site/lib//Win32/OLE/Lite.pm line 154 during global destruction.

My question is: is there a friendlier way to do what I need to do, that Perl won't get upset over?

Thanks!
0
kesea
Asked:
kesea
  • 9
  • 7
  • 2
  • +3
1 Solution
 
keseaAuthor Commented:
In case the problem is inside func2, here it is:

sub func2
{
      my @array_local = $_[0] ;

      # reset/zero input array
      @$array_local = ();

      my $sth_pm = $dbh_pm->prepare(qq(SOME QUERY IN HERE)) ;
      $sth_pm->execute or die "Can't execute: $DBI::errstr\n";
      @{$array_local[0]} = $sth_pm->fetchrow_array();
}
0
 
Kim RyanIT ConsultantCommented:
You are turning the ref back into an unreferecned array, try

sub func
{
     my $array_local_ref = $_[0] ;
        func2( $array_local_ref );
}

sub func2
{
     my $array_local_ref = $_[0] ;

    # and now say something like
   $array_local_ref->[0] = $sth_pm->fetchrow_array();

0
 
ozoCommented:
Did you mean either
my @array_local = @{$_[0]} ;
or
my $array_local = $_[0];
?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
keseaAuthor Commented:
Not sure who you're asking Ozo?  Me or Teraplane?  If for me, can you clarify, I'm not sure what you're asking.
0
 
keseaAuthor Commented:
teraplane,

The code I posted does work to modify the orginal array (besides getting this error in the Apache log file), so I'm not sure that I turned the reference into an unreferenced array or it wouldn't have kept the reference and modified the original array.

kesea

0
 
ozoCommented:
Actually, the way you are doing it
$array_local[0] is the array ref, (and $array_local[1] etc. are unused, which makes it useless and possibly deceptive to use an array there instead of a scalar)
fetchrow_array() returns a list in list context, calling it in scalar context like
 $array_local_ref->[0] = $sth_pm->fetchrow_array();
may be undefined whether it returns the first column or the last, so that's probably not a good idea
0
 
ozoCommented:
  my @array_local = $_[0] ;

     # reset/zero input array
     @$array_local = ();
$array_local is different from @array_local

my @array_local = $_[0] ;
is the same as
my @array_local;
$array_local[0] = $_[0] ;
0
 
keseaAuthor Commented:
Ozo,

Can you post the proper working syntax for func and func2?  Would really appreciate it.  This reference stuff is really confusing to me.

Thanks,
kesea
0
 
ozoCommented:
Although there seems to be a confusion between arrays, scalar, references,
the original code looks like it should work, except that @$array_local = (); does nothig useful, unless $array_local was defined  elsewhere

the problem may be when you exit func2 and $sth_pm goes out of scope
0
 
ozoCommented:
You might try doing
  $sth_pm->finish();
before exiting func2
0
 
keseaAuthor Commented:
am using mod_perl and the database connection should be persistent, so not sure if this would accomplish anything?

do you still think it might be contributing to the error in the log file?
0
 
ozoCommented:
$dbh_pm may be persistent, but my $sth_pm  is destroyed when the function exits.
If $sth_pm does not know how to finish itself when it is destroyed, you may need to do it explicitly.
I'd suggest at least trying it.
0
 
keseaAuthor Commented:
Hi Ozo,

Adding that line unfortunately did not get rid of that log in the error file.

Any other suggestions?

kesea
0
 
ozoCommented:
can we verify whether the fetchrow_array line really is the one it is dieing on?
can you add
$|=1;
print "before fetchrow_array\n";
@{$array_local[0]} = $sth_pm->fetchrow_array();
print "after fetchrow_array\n";
and see if any of them print?
0
 
keseaAuthor Commented:
Hi Ozo,

Those lines print out, and it is not that the code ever dies or that I or a user would ever see an indication that it didn't work.  I just see that error in the log file.  Seems like it works, but then when it's done and goes to clean something up, is when it complains.

Also, the problem is that sometimes it prints that error when running a script, sometimes it doesn't when running the same script.  I will try to isolate what line exactly is having the problem and report back.

kesea
0
 
ahoffmannCommented:
> .. am using mod_perl and the database connection should be persistent,
silly questiuion: have you designed you perl code with mod_perl in mind? Means, does you perl code ensure that global varaibles are really global to all functions and calls, nevertheless how many connections you have. Do you ensure that such global variables are *never* changed within any function?
I guess you just saw a single instance of doing things wrong with mod_perl, while the problem is buried deep in the design of your code. Please correct me if my guess is wrong.
0
 
keseaAuthor Commented:
Want to clarify where my use of mod_perl for a persistent db connection is wrong?
0
 
clockwatcherCommented:
What exactly is in your array?  Why do you think that's where you're getting your error?  The error is being thrown by Win32::OLE.  And the code you seem to be messing with is DBI-- completely unrelated to Win32::OLE.  Does your array contain references to Win32::OLE objects?  

I would bet that you're implicitly releasing some COM objects somewhere that you still have a perl reference to and when perl goes to garbage collect them it finds out that they no longer point to valid COM objects.  I would concentrate on your Win32::OLE use.  Or at least post the portion of your code that deals with it, as that is where it looks like your error (probably actually a carp'd warning) appears to be coming from.
0
 
ahoffmannCommented:
>  Want to clarify where my use of mod_perl for a persistent db connection is wrong?
you're right, that should be done in mod_perl
But my qustion was about *all* your variables, not just the db handle.
0
 
keseaAuthor Commented:
ok I found out what the problem was.  Because I am using mod_perl, it doesn't like connecting to the MS SQL database with ADO, I guess something in there is not multi-threaded-friendly.

I guess I will close the question...
0
 
AnnieModCommented:
PAQed with points refunded (500)

AnnieMod
Cleanup Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 7
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now