Due to your remarques, my script works properly now :
Does it? It does not meet your original specification. This is what it outputs for me:
header: path: subject:bscs header: path: subject:bscs header: path: subject:bscs
#/usr/local/bin/perl -w
--^^ Please copy and paste, and do not re-type code that you post to the list.
$i=0; $k=0;
That should be
use strict; my $k = 0;
(you are not using any $i variable outside the for loop).
while( my $line = <INDATA> ) { chomp $line; my @fields = split(",", $line); for (my $i = 0; $i <= $#fields; $i++) { if( $fields[$i]=~ /subject/ ) { $k=$i} }
$line = join(":", $fields[0], $fields[2], $fields[$k], $fields[$k+1]); print OUTDATA "$line\n"; }
For the sake of comparison, all that can be replaced with
print OUTDATA /(.+)attribute.+( subject.+)/s while <INDATA>;
(assuming that you still want the program to meet your original specification).
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>