Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello, i have the following input file :

1212123x534534534534xx4545454x232322xx 0901001x876879878787xx0909918x212245xx 1212123x534534534534xx4545454x232323xx 1212133x534534534534xx4549454x232322xx 4352342xx23232xxx345545x45454x23232xxx

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)

The code i have so far is

#!/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; }

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?

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?

In reply to Perl - Remove duplicate based on substring and check on delimiters by bopibopi

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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 or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-29 09:07 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.