while ($line=<INFILE>) {
chomp $line;
if ($line=~/^COMPND[\s]{3}3/) {
$line=join(' ',split(' ',$line)); # 1
chop $line; # 2
$chain=substr($line,length($line)-1,1); # 3
$lastchain=$chain; # 4
print OUTFILE ("$chain\n");
} else {
$lastchain='@'; # 5
}
}
Okaaaay. I suspect that lines 1-5 are not doing what you think they're doing.
This splits on a single space, then joins on a single space ... giving you back the same line. I suspect you were looking for $line = join ' ', split /\s+/, $line; instead.
Update: gmax has kindly informed me that this is a special case. I would still recommend splitting on /\s+/ instead, as it makes your intent obvious. (And special cases have a habit of unspecialing themselves in later releases ...)
- Why are you chopping the line again? You've already chomped it ...
- This line gives you the last character. If that's what you're looking for, then $chain = substr $line, -1; would work better, and faster.
- Why are you creating $chain just to assign it to $lastchain and print it out? Do you mean to concatenate instead? (That's .=, not =)
- And, like #4, I suspect to meant to concatenate, not assign.
The else statement looks just fine, to me.
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
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.