p789123 has asked for the wisdom of the Perl Monks concerning the following question:
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); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: end of line help
by roboticus (Chancellor) on Nov 17, 2010 at 20:25 UTC | |
|
Re: end of line help
by ww (Archbishop) on Nov 17, 2010 at 21:54 UTC | |
|
Re: end of line help
by oko1 (Deacon) on Nov 18, 2010 at 02:18 UTC | |
by mjscott2702 (Pilgrim) on Nov 18, 2010 at 09:29 UTC | |
|
Re: end of line help
by aquarium (Curate) on Nov 18, 2010 at 00:44 UTC | |
|
Re: end of line help
by p789123 (Initiate) on Nov 18, 2010 at 12:29 UTC |