Hello,

I am not a programmer by any stretch of the imagination but was recently volunteered to anonymize several thousand binary files, which involves replacing a 1,2,or 3 digit number with a different 1,2,or 3 digit number. so i thought now would be a good time to learn perl.

After some experimentation I have a script that does what I want but the output files are recognized as corrupted by the software I use to compile them. They are each about 4kb larger than original, and when I look at them in hexeditor I see original had 0a line separator and the output has 2 characters I think it was 0a 0d. I am working in win xp with strawberry; not sure what os original files were on.

After more reading I thought I could use -l012 on command line but that had the effect of adding additional blank lines, effectively double spacing the file.
thanks. Heres my code:

#!/usr/local/bin/perl -w #use strict; #####Point these paths to original cel files and an empty new folder $oripath = "r://cel file anonymization//original cel files//"; $anonpath = "r://cel file anonymization//anonymized cel files//"; #####read in the link file; store it in array and close the file open(linkfile,"r://B27 cel file anonymization//B27anonymizationlinkfil +e.txt") or die ("CAnt open link file!\n"); @link=<linkfile>; shift(@link); close(linkfile); #####loop through the cel files, replacing the names and creating new +anonymized cels foreach $sample (@link) { chomp($sample); ($infile,$labno,$out,$anonno)=split(/\t/,$sample); print("Anonymizing $infile\n"); open (INFILE, $oripath.$infile) or die "can't open file $oripath $ +infile $!" ; binmode (INFILE); open OUTPUTFILE, ">", $anonpath.$out or die "cant open outputfile" +; while(<INFILE>) { $_=~s?B27-\d\d\d|B27-\d\d|B27-\d?B27-$anonno?g; print OUTPUTFILE $_; } close (INFILE); close (OUTPUTFILE); }

In reply to end of line help by p789123

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.