NEWBIE Question Subroutine help

D

Dayton

I can't determine what I am doing wrong. I get to this point in my program
but my subroutine &S_print_sls_detail doesn't work. I have all my
variables decalred also my split command seems to work properply.
I took that while statement piece of code and ran it by itself and printed
the
variables. That worked fine. But when I try to put it into a table and a
subroutine I get nothing. Also when I display my page I get my
&S_sales_heading
below my &S_print_inv_wrapup. Not what I expected.

Any help or direction I can get would be greatly appreciated.
T.I.A.


$f_dtype = $q->param("f_dtype");

if ($f_dtype eq "S") {
open(FH_Sales,$fn_sal_file);
&S_sales_heading(); #display Sales
heading

while (defined($p_line = <FH_Sales>)) {
chomp($p_line);
($pn,$qty,$unit,$desc) = split(/\|/,$p_line);
&S_print_sls_detail();
}

&S_print_inv_wrapup();
close(FH_Sales);

} else





###########################################################
sub S_print_sls_detail {
###########################################################
print "<tr">\n";
print "<td>$pn</td>\n";
print "<td>$desc</td>\n";
print "<td>$unit</td>\n";
print "<td>$qty</td>\n";
print "</tr>";
}
 
B

Beable van Polasm

Dayton said:
I can't determine what I am doing wrong. I get to this point in my program
but my subroutine &S_print_sls_detail doesn't work. I have all my
variables decalred also my split command seems to work properply.
I took that while statement piece of code and ran it by itself and printed
the
variables. That worked fine. But when I try to put it into a table and a
subroutine I get nothing. Also when I display my page I get my
&S_sales_heading
below my &S_print_inv_wrapup. Not what I expected.

The heading below the wrapup might be because you didn't close
your table or something. It's hard to tell, because you didn't
post a working program.

You didn't "use strict", or "use warnings" did you?
Any help or direction I can get would be greatly appreciated.
T.I.A.

# At the start of your program, always put these two lines:
# then declare your variables using "my".
use strict;
use warnings;
$f_dtype = $q->param("f_dtype");

if ($f_dtype eq "S") {
open(FH_Sales,$fn_sal_file);
&S_sales_heading(); #display Sales
heading

while (defined($p_line = <FH_Sales>)) {
chomp($p_line);
($pn,$qty,$unit,$desc) = split(/\|/,$p_line);
&S_print_sls_detail();

# You don't need to put an ampersand to call a subroutine. Also, why
# not pass those variables into the subroutine so that it can see
# them? Try this:

S_print_sls_detail($pn, $qty, $unit, $desc);
}

&S_print_inv_wrapup();
close(FH_Sales);

} else





###########################################################
sub S_print_sls_detail {
###########################################################
# read the parameters passed in to the subroutine
my $pn = shift;
my $qty = shift;
my $unit = shift;
my $desc = shift;
print "<tr">\n";
print "<td>$pn</td>\n";
print "<td>$desc</td>\n";
print "<td>$unit</td>\n";
print "<td>$qty</td>\n";
print "</tr>";
}



--
 
B

Ben Morrow

There's no need for these lines of #s: they *really* don't help
readability.
# read the parameters passed in to the subroutine
my $pn = shift;
my $qty = shift;
my $unit = shift;
my $desc = shift;

my ($pn, $qty, $unit, $desc) = @_;

Ben
 
G

gnari

and as a matter of style, I prefer not to put extra quotemarks
in example code posted on this group. they work best
in pairs.

gnari
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top