perlquestion
bopibopi
<p> Hello, i have the following input file : </p>
<code>
1212123x534534534534xx4545454x232322xx
0901001x876879878787xx0909918x212245xx
1212123x534534534534xx4545454x232323xx
1212133x534534534534xx4549454x232322xx
4352342xx23232xxx345545x45454x23232xxx
</code>
<p> Delimited with x, and the column of interest is 0-7, see below. I m trying to write a script that reads each line, checks the amount of x's and compares it against a number, if the amount if != the set number then i want the output into fh1 (output.control). Then it ll check a specific substring on each line, and print only the first encountered. (Remove duplicates but maintain order)
</p>
<p> The code i have so far is </p>
<code>
#!/usr/bin/perl
use strict;
# use warnings qw/ all FATAL /;
my %seen;
my $delimiter = 'x';
my $delim_amnt_per_line = 5;
open(my $fh1, ">>", "outputcontrol.txt");
open(my $fh2, ">>", "outputoutput.txt");
while ( <> ) {
my $count = ($_ =~ y/x//);
print "$count \n";
# print $_;
if ( $count != $delim_amnt_per_line )
{
print fh1 $_;
}
my ($prefix) = substr $_, 0, 7;
next if $seen{$prefix}++;
print $fh2;
}
</code>
<p>
My problem is that it doesnt print anything on either filename, whereas if it was just print and i had redirected the script from the command line, it would output as normal. Can someone help me?
</p>
<p>
EDIT : I think i ve located the problem. Neither of the produced files had write permission. They were just set on read, is there a way to change this from inside the code?
</p>