Hi Monks,
Pls help me locate the reason for the error of the following code,
#! /usr/bin/perl -w
open AA, '<',"A.txt" or die "open: $!";
foreach $line(<AA>)
{
chomp($line);
@temp=split(/\./,$line);
$new=$temp[0].'.'.$temp[1];
open BB, '<',"B.out" or die "Failed to open B.out: $!";
foreach $line1(<BB>)
{
@temp1=split(/\s+/,$line1);
if($new eq $temp1[0])
{
print $temp1[1]."\t";
print $temp1[2]."\n";
}
}
close (BB);
}
close(AA);
Small portions of both the files are as follows,
A.txt
1a6m_-.ent.dssp
b1b5e_A.ent.dssp
b1bx4_A.ent.dssp
b1bx7_-.ent.dssp
b1bxy_A.ent.dssp
B.out
b1a6m_-.ent 79K 83E 127.119
b1a6m_-.ent 80G 84A 136.545
b1b5e_A.ent 123R 127M 132.48
b1bx4_A.ent 61H 65S 145.4
Now, white space b/w column 2 and 3 of B.out is not constant. So while using split in line 11 of my code, I used
@temp1=split(/\s+/,$line1);
and got error
Use of uninitialized value in string eq at a.pl line 18, <BB> line 427.
but if I use
@temp1=split(/ +/,$line1);
it works pretty fine.
What is the reason for this err? Isn't / +/ and /\s+/
refer for same thing? Is there a better way of doing this?
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.