in reply to stuck at "Use of uninitialized value in length at ..."
Ooops the deadly "off by one problem!". I guess length counts the "\n" at the end of line!#!/usr/bin/perl -w use strict; #This script selects only the five-letter and six-letter words from a +list of words open FH1, "all_words.txt" or die $!; open (FH2, '>>trimmed_words.txt') or die $!; while (<FH1>) { if (length ==5 or length==6) {print FH2 }; }
while (<DATA>) { if (length ==6 or length==7) {print;} } __DATA__ 123 1234 12345 123456 1234567 12345678 ============== prints: 12345 123456
|
|---|