A v B = ?

[email protected] Wed, 7 Mar 2001 18:58:45 -0500
Newsgroups perl.macperl.webcgi
Message-ID <p05010403b6cc7816ff6d@[64.194.142.225]>
Hi again:

A different question (using the previous "well split" code, but not 
regarding split() ).

Given the following routines A and B, why does A work and B does not?

The only difference between the two routines is where the "ROW" block 
is placed. In example A the ROW variables appear within the "read 
data loop", but in example B they are only printed within the "read 
data loop" -- why does that make a difference?

#--- start of code --- A (works)

#!/usr/bin/perl

	print "Content-type: text/html\n\n";
	print "<HTML><HEAD><TITLE>$title</TITLE>";

	print <<DB; # create table with title
	<table border="1" cellpadding="5" cellspacing="2" width="600">
	<TR>
	<TH>ID</TH>
	<TH>Category</TH>
	<TH>Variable Name</TH>
	<TH>Price</TH>
	<TH>Name</TH>
	<TH>Description</TH>
	<TH>Item Number</TH>
	</TR>
DB

$datafile = "Database/outlet.data";
open DATA, "$datafile" or die "Can't open $datafile: $!";
	while (<DATA>)
  		{
		next if /^$/;  # skip empty lines
		chomp;         # remove the "line ending"
		for (split(/\r/)) # find returns
			{
			# find tabs
			my ($database_id, $category, $variable_name, 
$price, $name, $description, $item_number) = split(/\t/);

			print <<ROW; # place variables into table
				<TR>
				<TD>$database_id</TD>
				<TD>$category</TD>
				<TD>$variable_name</TD>
				<TD>\$$price</TD>
				<TD>$name</TD>
				<TD>$description</TD>
				<TD>$item_number</TD>
				</TR>
ROW
			}
		}

close DATA;

print "	</table>";

__END__

#---- end of code ----

---------------------------

#--- start of code --- B (does not work)

#!/usr/bin/perl

	print "Content-type: text/html\n\n";
	print "<HTML><HEAD><TITLE>$title</TITLE>";

	print <<DB; # create table with title
	<table border="1" cellpadding="5" cellspacing="2" width="600">
	<TR>
	<TH>ID</TH>
	<TH>Category</TH>
	<TH>Variable Name</TH>
	<TH>Price</TH>
	<TH>Name</TH>
	<TH>Description</TH>
	<TH>Item Number</TH>
	</TR>
DB

$list = <<ROW; # place variables into table
	<TR>
	<TD>$database_id</TD>
	<TD>$category</TD>
	<TD>$variable_name</TD>
	<TD>\$$price</TD>
	<TD>$name</TD>
	<TD>$description</TD>
	<TD>$item_number</TD>
	</TR>
ROW

$datafile = "Database/outlet.data";
open DATA, "$datafile" or die "Can't open $datafile: $!";
	while (<DATA>)
  		{
		next if /^$/;  # skip empty lines
		chomp;         # remove the "line ending"
		for (split(/\r/)) # find returns
			{
			# find tabs
			($database_id, $category, $variable_name, 
$price, $name, $description, $item_number) = split(/\t/);

			print $list;

			}
		}

close DATA;

print "	</table>";

__END__

---------------------- end of question --------------

Thanks for any comment.

tedd
-- 
http://sperling.com/