>>>>> "e" == evan9021 <evan9021@[EMAIL PROTECTED]
> writes:
e> The following script is to read 4 consecutive lines at a time from a
e> file, concatenate the first 3 lines
e> (with a ", "), and print the result to STDOUT. If the 3 lines aren't
e> concatenated they print correctly, however
e> if they are, the result is gibberish. Any suggestions. thx., EC.
e>
--------------------------------------------------------------------------------------------------------------------------------------------------
e> #!/bin/perl
e> # Read a series of 4 rows from a file and print the first 3 on
e> # the same line.
e> $file = 'example.txt'; # Name the file
e> open(INFO, $file); # Open the file
e> $row_num = 0;
you forgot to comment on that line. maybe # assign 0 to $row_num?
e> while (<INFO>) {
e> $i = $row_num%4;
you don't need a row num. $. will do that for you. perldoc perlvar.
e> if ($i <= 2) {
e> $col[$i] = "$_";
useless use of quotes.
e> }
e> if ($i <= 1) {
e> chomp ($col[$i]);
e> }
e> if ($i == 2) {
e> #$row = join (', ', @[EMAIL PROTECTED]
);
e> printf ("%s", $col[0]);
why use printf there? print $col[0] does the SAME thing. this is not c
and printf is rarely used (especially when compared to print).
e> printf (", ");
e> printf "%s, ", $col[1];
e> printf "%s\n", $col[2];
print join( ',', @[EMAIL PROTECTED]
), "\n" ;
e> }
e> $row_num++;
e> }
e> close(INFO); # Close the file
another informative comment. who taught you that style? seriously, why
do your comments say exactly what the code says? a useful rule is code
is what and comments are why.
uri
--
Uri Guttman ------ uri@[EMAIL PROTECTED]
-------- http://www.sysarch.com
--
----- Perl Code Review , Architecture, Development, Training, Sup****t
------
--------- Free Perl Training --- http://perlhunter.com/college.html
---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com
---------


|