In the attached code, I am trying to reference a hash contained in an array. However, each time I try to reference the hash, it says it is not a Hash. I'm following the examples with no luck. Can you help? Specifically with the ftp_sessions() array. Thanks This code is being put together to monitor multiple, long-running FTP jobs. I don't have that code in here ... basically stubbing it out with sleep statements.
#!/usr/local/bin/perl -w ###################################################################### +#################################### # + # # Program: GetDCBillingsFiles + # # + # # Description: Programs collects DC billings files from all the serv +ers located at the DC. This # # script is NOT intended to be a production application +. # # + # # Date: 12/27/03 + # # + # ###################################################################### +#################################### use strict; use threads; # Define global variables for program. my @locations = (); my @ftp_sessions = (); my $INTERVAL = 5; my $ACTIVE = 1; my $INACTIVE = 0; ###################################################################### +#################################### # + # # Subroutine: monitor_ftp + # # + # # Description: Subroutine collects information about active FTP sess +ions. # # + # ###################################################################### +#################################### sub monitor_ftp() { my $nbr = 0; my $status = 'status'; my $active_sessions = 0; sleep 1; print "Monitoring FTP sessions ... \n\n\n"; #printf "Sessions status <%d> and location <%s>\n", $ftp_sessions[ +0]->{status}, $ftp_sessions[0]->{loc}; do { my $session; $active_sessions = 0; for $session (@ftp_sessions) { $active_sessions += 1; $nbr++; } print "Active Sessions: $active_sessions\n"; # Check the list size and exit if all threads are complete. if ($active_sessions > 0) { # Monitor the sessions at fixed intervals. sleep $INTERVAL; } } until $active_sessions == 0; } ###################################################################### +#################################### # + # # Subroutine: start_ftp + # # + # # Description: Subroutine starts FTP sessions to collect data from l +ocations. # # + # ###################################################################### +#################################### sub start_ftp($$) { my ($nbr, $location) = @_; my $id = threads->self->tid; printf "FTP session: <%d> <%s>\n", $id, $location; $ftp_sessions[$nbr] = { status => 1, loc => $location }; ############# Insert FTP commands here ######################## my $time_delay = $id*5; sleep $time_delay; ############# Insert FTP commands here ######################## # Session complete. Reset the status and exit the session. $ftp_sessions[$nbr]{status} = 0; printf "Session <%d> complete.\n", $id; } ###################################################################### +#################################### # + # # Main Routine + # # + # ###################################################################### +#################################### $locations[0] = "awd1"; # Loop through the locations, starting a process to extract the data r +equired from each DC. my $loc = 0; my $nbr = 0; foreach $loc (@locations) { # Use threads to manage the FTP sessions. $ftp_sessions[$nbr] = threads->create("start_ftp", $nbr, $loc); $nbr++; } monitor_ftp(); sleep 40;

In reply to data structure question by mjmaresca

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.