Re: [MacPerl-WebCGI] well split!!!
[email protected] (Bruce Van Allen) Wed, 7 Mar 2001 09:05:38 -0800
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <p05010400b6cc177b4a64@[205.179.215.44]> |
At 9:43 AM -0500 3/7/01, [email protected] wrote: >- Bruce: >However, the following code generates an error: > >open(DATA,$datafile) || &open_error($datafile); > while (<DATA>) { > next if /^$/; > my ($database_id, $category, $variable_name, $price, >$description, $item_number) = split(/\t/); > > print <<ROW; > <TR> > <TD>$variable_name</TD> > <TD>$description</TD> > </TR> > ROW >} > >Why? > Because in that expression the last 'ROW" about must be on a line with no other characters, even whitespace. This method of quoting is known as a "here doc" or "heredoc". It quotes from the line after the initial token down to the line before the final token. Think of it as being like the statement print $row; Notice that this statement, as in most cases, ends in a semi-colon ';'. Remember to put your semi-colon in the equivalent place when using heredoc quoting. print <<ROW; <TR> <TD>$variable_name</TD> <TD>$description</TD> </TR> ROW If you really can't stand breaking your indenting rules, then quote the heredoc token ('ROW' here) and pad it with the same number of spaces (not tabs), a la: print <<" ROW"; # ^^^ <--padding <TR> <TD>$variable_name</TD> <TD>$description</TD> </TR> ROW Use double quotes to quote the initial heredoc token, or else your variables won't interpolate. HTH 1; -- - Bruce __bruce_van_allen__santa_cruz_ca__