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);
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|