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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |