On 10/8/09 Thu Oct 8, 2009 9:00 AM, "Raheel Hassan" <raheel.has...@gmail.com> scribbled:
> Hello, > > I have problems in understanding $...@$ use ????? > > 1- my $ref = $$temp_sth -> fetchall_arrayref({}); > for(my $i=0; $i <= $...@$ref}; $i++) { For any array @a, the largest index is given by $#a. $ref is a reference to an array, as returned by the fetchall_arrayref method. @{$ref} is the array returned. Therefore, $...@$ref} is the largest index of the returned array, i.e., the index of the last element of the array. > push(@$temp_table,$ref->[$i]);} > > Can some one explain the under given function. It looks like a function that queries a database, getting all of the data from a table called "Sensors". Then for each row in that table, checks the value of the column labeled "StatusID", and, if the value of that column is "1", adds an entry to a hash with the contents of the "IP" column as key, and the value taken from the column "SensorID". The function returns a list, consisting of a reference to the hash and the value of the $error variable, which will be 0 if no error occurred, and 1 if an error did occur. > 2- sub buildSensorsHashtable > { > > my ($dbh) = @_; > my $error = 0; > > my $query = "SELECT * FROM Sensors"; > my $sth = $dbh->prepare($query); > if(!$sth || !($sth->execute())) { $error = 1 ; > } > > my $ref = $sth->fetchall_arrayref({}); > my %s; > my @s = @$ref; > foreach (@s) > { > if($_->{"StatusID"} eq "1") { $s{$_->{"IP"}} = $_->{"SensorID"}; } > } > > return (\%s,$error); > > 3- Which is the best tool for debuging perl programs having CGI support. I > used DDD but that does not support CGI. Debugging CGI programs can be difficult. You need access to the HTTP logs. You can help yourself by following the advice given in the FAQ "How can I get better error messages from a CGI program?" (see 'perldoc -g CGI'). Try to set up a test environment, either by executing the CGI program from the command line (by supplying the various parameters needed) or by running the program first on a local server where you have access to the logs. Good luck. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/