On Jun 27, 8:14 am, [EMAIL PROTECTED] (Alma) wrote:

> I have written a display subroutine in my package .

And you have re-written it here.  Please don't do that.  Copy and
paste your code.  Do not retype it.  For one, you're going to get
comments about the typos you've made rather than your actual problem.
For two, we have no way of knowing what other mistakes you've made
here that you didn't make in your original.

> abc.pm
>
> sub display

No opening curly-brace.  This code does not compile.

> my $self = shift;
> $id [EMAIL PROTECTED];

This does not do what you think it does.  This assigns $id to be the
number of arguments passed into this method (not counting $self, which
you shifted off already).  You meant one of these:
my $id = shift;
my ($id) = @_;
my $id = $_[0];

I also notice that you're not declaring $id here.  That means that
every object of your abc.pm class has the same $id value, and when you
change it for one, you change it for every one.

> my $sth=$dbh->prepare("select title,name,status from table where
> id=emp_id and status ='P'");
> $sth->execute() or die $databasehandle->errstr;

The fact that you're using `or die...` on the execute() implies that
$dbh->{RaiseError} is not turned on, yet you're not checking the
return value of prepare().  If the prepare() fails, Perl will silently
continue and you'll get no useful error message from the execute() (it
will tell you you can't call execute() on an undefined value)

> while( my @row=$sth->fetchrow_array()) {
> foreach($i=0;$i<3;$i++) {
> return @row;

This is non sensical.  You're returning out of the function
immediately after the first iteration of foreach within the first
iteration of while.

If you want to return all three rows, create an array before your
while loop, and each time through the while statement, push a
reference to @row onto your array, and return that array at the very
end.


Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to