well split!!!

[email protected] Tue, 6 Mar 2001 19:03:01 -0500
Newsgroups perl.macperl.webcgi
Message-ID <p05010400b6cb266b9edb@[64.194.142.225]>
>Try it this way:
>
>  while (<DATA>) {
>     @line = split /\t/;      # $_ is implied
>     # ...
>
>   - Bruce

- Bruce :

Okay, I tried it. But, the following code is what I had to do to 
fill, and print, all the variables I wanted from a multi-record 
database:

	open(DATA,$datafile) || &open_error($datafile);
	while (<DATA>)
		{
		for (split(/\t/))
			{
    			@line = split (/\t/);      # $_ is implied
    
			$database_id = $line[0];
			$category = $line[1];
			$variable_name = $line[2];
			$price = $line[3];
			$description = $line[4];
			$item_number = $line[5];

			print "$database_id\n";
			print "$category \n";
			print "$variable_name \n";
			print "$price \n";
			print "$description \n";
			print "$item_number \n";
			print "<p></p>\n";
			}
		}

Now, is there a simpler way to do this? You see, I had to put a "for 
(split(/\t/))" loop in to cycle through all the records -- it seems 
redundant, but without the loop, it would only grab the first record.

Also, while I can fill those variables with what I want, the 
following code doesn't deliver the variables into a table (the table 
is formed before this section of code).

	open(DATA,$datafile) || &open_error($datafile);
	while (<DATA>)
		{
		for (split(/\t/))
			{
    			@line = split (/\t/);      # $_ is implied
    
			$database_id = $line[0];
			$category = $line[1];
			$variable_name = $line[2];
			$price =  $line[3];
			$description = $line[4];
			$item_number =  $line[5];

			print "<TR>";
      			print "<TD>$variable_name</TD>";
			print "<TD>\$$price</TD>";
      			print "<TD>$description</TD>";
      			print "</TR>";
			}
		}

However, the following will deliver the assignments to the table:

	open(DATA,$datafile) || &open_error($datafile);
	while (<DATA>)
		{
		for (split(/\t/))
			{
    			@line = split (/\t/);      # $_ is implied
    
			$variable_name = "Apple";
			$price = "123.50;
			$description = "It's a computer";

			print "<TR>";
      			print "<TD>$variable_name</TD>";
			print "<TD>\$$price</TD>";
      			print "<TD>$description</TD>";
      			print "</TR>";
			}
		}

What's the difference? I don't see why one would work and the other 
doesn't? Why would printing the variables work, but trying to display 
them in a table wouldn't?

IHYCATQ

Many thanks.

tedd
-- 
http://sperling.com/