Please bottom post...
> That's what i've tried (may be it is not the best approch);
> Any way, My script doesn't work, it returns an error message (Use of
uninitialized value at formater.pl line 22, <INDATA> chunk 4.)
>
> -----------------------------------------------------
> #!/usr/local/bin/perl -w
>
use strict; # ALWAYS!
> $i=1;
> $k=1;
why declare these way up here?
>
> open (INDATA, "<in_file.txt") || die("Can't open in file");
>
> open (OUTDATA, ">out_file.txt") || die("Can't open out file");
>
>
>
> while( $line = <INDATA> ) {
>
> chomp;
your line of input data is in $line, but you are chomping $_, what does
it have in it?
>
> @fields = split(",", $_);
>
Splitting $_, but your input is in $line??
> for ($i = 0; $i < 400; $i++) {
> if( $fields[$i]=~ /subject/ ) { $k=$i}
So i was originally 1, then you set it to 0, then you set k to the value
of i... where did 400 come from?
> }
>
> $line = join(":", $fields[0], $fields[2],$fields[$k], $fields[$k+1]);
>
You could use a slice in the above, though there really isn't a
difference other than typing,
$line = join(':', @fields[0,2,$k,$k+1]);
Note that you have just clobbered your input string, re-using $line may
not be the best idea, though so far it doesn't matter.
> print OUTDATA "$line\n";
>
>
> }
>
> close INDATA;
> close OUDATA;
>
I suspect turning on the strictures will clear up the issue.
HTH,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>