On Tuesday 29 June 2004 18:44, mohammed chafik wrote:
> That's what i've tried (may be it is not the best approch);

If you ask me, the general approach is quite ok...

> 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

I'd always include 
  use strict;
as first statement in your script. This saves you a lot of time.

>
> $i=1;
> $k=1;
>
> 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> ) {

You're reading each line into a variable called $line...

>
> chomp;
>
> @fields = split(",", $_);

but here you're working on $_.
You should either do

while ( $_ = <INDATA> ) {
  chomp;
  my @fields = split(",");
  ..
}

or 

while ( my $line = <INDATA> ) {
        chomp $line;
        my @fields = split(",", $line);
}

This in one source for the "uninitialized value" messages.

>
> for ($i = 0; $i < 400; $i++) {

The other source for the messages is that you're trying to access values in 
the array @fields that do not exist.
In your data file, @fields holds something like 15 records, certainly not 400.
I'd do something like

  for (my $i = 0; $i <= $#fields, $i++) {

which loops until $i has reached the last field of @fields ($#<array_name> 
holds the last index of an array).

> if( $fields[$i]=~ /subject/ ) { $k=$i}
> }
>
> $line = join(":", $fields[0], $fields[2],$fields[$k], $fields[$k+1]);
>
> print OUTDATA "$line\n";
>
>
> }
>
> close INDATA;
> close OUDATA;

Another warning message tells you that you've got a typo here ;-)

HTH,

Philipp

PS.: Please bottom-post.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to