Your code (after the off by one error is fixed) does work, but you aren't getting much "mileage" out of ParseWords. I recoded without that below.

A few comments:
-don't push when you could print.
-there is no need to save all the output in an array.
-using a hash allowed me to get rid of variables like $Nr_1 and put code in same lingo as the file itself.
-this kind of "anonimization" is easily cracked - not so anon.
-you will need a better scheme if this data is sensitive.

#!/usr/bin/perl -w use strict; my $header_line = <DATA>; print $header_line; $header_line =~ s/\s*$//; # no trailing blanks or \n # a bit better than chomp() here # (chomp only gets rid of \n) # since words will be hash keys + my %index; # field name to index number my $i=0; foreach ( split /;/,$header_line ) { $index{$_}=$i++; } while(<DATA>) { next if /^\s*$/; # skip blank lines chomp; my @parts = split(/;/,$_); $parts[$index{Number}] =~ tr/0123456789/9876543210/; $parts[$index{Number_1}] =~ tr/0123456789/9876543210/; $parts[$index{Name}] =~ tr/A-Za-z/B-Wzb-w/; print join (";",@parts),"\n"; } =output Number;Name;Age;Gender;Number_1 876;Brhviw;54;m;876;AAA 765;Kslr;43;m;765;JJJ 654;Iipir;23;w;654;HHH =cut __DATA__ Number;Name;Age;Gender;Number_1 123;Andrew;54;m;123;AAA 234;John;43;m;234;JJJ 345;Helen;23;w;345;HHH

In reply to Re: Parsing Header Last Field by Marshall
in thread Parsing Header Last Field by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.