in reply to text processing
G'day DAVERN,
Welcome to the monastery.
You originally wrote:
"i need the next result
xxx=DATA00, xxx=DATA10, xxx=DATA20; "
This is easy:
#!/usr/bin/env perl -l use strict; use warnings; while (<DATA>) { next unless /^DATA/; print 'xxx=', join(', xxx=' => split), ';'; } __DATA__ TABLE NAME HEAD0 HEAD1 HEAD2 DATA00 DATA10 DATA20 DATA01 DATA11 DATA21 END
Output:
xxx=DATA00, xxx=DATA10, xxx=DATA20; xxx=DATA01, xxx=DATA11, xxx=DATA21;
You then showed some unformatted code:
"print {$OUT} "xxxxx", $data[0], "yyy", $data2,";","\n";"
Guessing that's supposed to be:
print {$OUT} "xxxxx", $data[0], "yyy", $data[2],";","\n";
This is only slightly less easy. Just change the print line to:
print 'xxxxx', join('yyy' => (split)[0,2]), ';';
Output:
xxxxxDATA00yyyDATA20; xxxxxDATA01yyyDATA21;
Please give careful consideration to what you are attempting to achieve before posting. You'll find monks may be less inclined to help if you keeping changing what you want.
Your code for opening files seems absolutely fine. Change <DATA> to <$your_input_filehandle> and print ... to print {$your_output_filehandle} ... and that should do what you want.
-- Ken
|
|---|