This is getting a touch off base from where I wanted to go, but the jist
of what I started with is this.
Open a .csv file, enter every record into the array, one at a time, then
copy the first value to the third last value, then print this value back
to a new .csv file, including the comma separating the values.  I have
all of these bases covered, except that it is not outputting to the new
file with the commas intact. Below is the original snip, as this problem
is still needing a final solution.

___Snip___
#!/usr/bin/perl

open (FIN, "<statsfinal2.csv") || die "cant open INPUT file"; @data =
<FIN>; close (FIN);

open (FOUT, "> STATS_output.csv") || die "cant open OUTPUT file";

my $output;

print "Starting !\n";
$count = "1";
foreach $line (@data) {
        chomp;
      if ( $line eq "" ) { next; }
        else {
        my @string = split(/,/, $line);
                if (@string[0,1] eq "" ) { next; }
                else {
                $copy_data = $string[0];
                $string[34] = $copy_data;
                #print join( ',', @output),"\n";
                #print (@output);
                @string =~ join( ',', @string),"\n";
                push (@output, "@string");
                print "Line $count parsed with FIRST -> $string[0] and
LAST -> $string[34]\n"; # visual aide
                }
                $count++;
        }
print FOUT @output;

close (FOUT);


-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 18, 2001 4:35 PM
To: [EMAIL PROTECTED]
Subject: Re: output into a csv file


Jenda Krynicky wrote:
>
> But don't ever forget to reset it back! :
>
>         { local $, = ", ";
>         print @output;
>         }
>
> IMHO using join() is safer. I'd only use something like this if I
> needed to interpolate several arrays in a HERE-DOC string. I'd change
> $" then of course :
>
>         { local $" = ', ';
>         print <<"*END*";
>         Blah blah blah
>         Users: @users
>         Groups: @groups
>         *END*
>         }
>
> and even then I'd probably do something like :
>
>         use Interpolation '=' => 'eval';
>         print <<"*END*";
>         Blah blah blah
>         Users: $={join ', ', @users}
>         Groups: $={join ', ', @groups}
>         *END*
>
> Strange as well, but a bit safer.


Or if you don't have the Interpolation module:

         print <<"*END*";
         Blah blah blah
         Users: @{[join ', ', @users]}
         Groups: @{[join ', ', @groups]}
         *END*



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to