in reply to stuck at "Use of uninitialized value in length at ..."

You never assign anything to $_. Therefore, it is uninitialized.

"while" isn't suited for looping over an array. When looping over a filehandle, as:

    while (<$fh>)

the while implicitly assigns each line to $_ in turn. However, in the following:

    while (@foo)

the contents of the while expression are taken to be a boolean expression, which is true as long as there are elements in @foo, and doesn't assign anything to $_.

You may want to use the foreach keyword:

    foreach (@foo)

This will assign each element of @foo, in turn, to $_.

Replies are listed 'Best First'.
Re^2: stuck at "Use of uninitialized value in length at ..."
by ikegami (Patriarch) on Jun 04, 2009 at 17:03 UTC

    You may want to use the foreach keyword:

    In general, that's a good solution. In this case, you'd end up with

    my @all_words = <FH1> ; foreach (@all_words) {
    which is a needless waste of memory. The following is much more appropriate:
    while (<FH1>) {
    which is short for
    while (defined($_ = <FH1>)) {