Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

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

You should make every progam begin with those two lines, unless you have a very good reason not to. It will force you to write cleaner code, helping you catch errors much quicker. Originally you did that, but somewhere along the road, it seemed, you dropped these lines.

use strict; use warnings;


This looks okay.

print "\n Enter the file name :>"; chomp( my $filename1 = <STDIN> );


Because we use strict; we'll have to declare the array now. You did it right in the original code, but again, somewhere you strayed from the right path.

my @lines = ();


I really disagree with the exact wording of the error message here. As I've pointed out in the other threat. But bah. If this is how ya wanna put it, don't lemme stop ya!

open my $fh, '<', $filename1 or die "Cannot find the file $filename1: +$!";


I'm tempted to rewrite your loop so that it writes out lines as it reads them. There's really no point in keeping things in-memory, but I'll assume you have a reason for doing it this way. At any rate I'm getting rid of your $count variable. You don't really need it. This, too, has been pointed out in that other threat.

while (<$fh>) { push @lines, $_; }

Or just push @lines, $_ while <$fh>;. Or, while we're at it. @lines = <$fh>;, as has been mentioned in... you know where. Anyway, I've moved this close statement up. There's no point in keeping the file handle open if you're not using it anymore anyway.

close $fh;


This looks okay.

open my $w, '>', 'Result.txt' or die "Cannot open the file Result.txt: + $!";


I've rewritten your for loop to be more Perl-ish. This, too, has been demonstrated.

foreach my $line (@lines) { my @chr_fields = grep {$_ =~ m/^chr/} split ("\t", $line) if ( # If... @chr_fields == 2 # ...there are exactly two +chr* fields... && $chr_fields[0] ne $chr_fields[1] # ...which are not exactly +the same... ) { print $w $line; } } close $w;

In reply to Re^7: difficulty in matching 2 fields of a same line by muba
in thread difficulty in matching 2 fields of a same line by Anonymous Monk

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2018-06-24 04:04 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.