in reply to uninitialized value in split

What are you splitting $line on? The first argument to split is the delimiter to split on. The second argument is the scalar to split up. If it's unspecified, it defaults to $_, which is undefined in your examples. You probably want my @words = split ' ', $line; - try that out and see if it helps.

I want to commend you on using strict and warnings. Excellently done!


  • In general, if you think something isn't in Perl, try it out, because it usually is. :-)
  • "What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?"

Replies are listed 'Best First'.
Re^2: uninitialized value in split
by jjohhn (Scribe) on May 17, 2005 at 03:07 UTC
    I thought that after a shift in a subroutine, $_ contains the value of the shift.
    But I did what you said, and now have a different problem which I will look at for awhile.
      According to perldoc -f shift
      shift ARRAY shift Shifts the first value of the array off and returns it, shortening the array by 1 and moving everything down. If t +here are no elements in the array, returns the undefined value. + If ARRAY is omitted, shifts the @_ array within the lexical s +cope of subroutines and formats, and the @ARGV array at file sc +opes or within the lexical scopes established by the "eval ''", "BEGIN {}", "INIT {}", "CHECK {}", and "END {}" constructs +. See also "unshift", "push", and "pop". "shift" and "unshif +t" do the same thing to the left end of an array that "pop" and +"push" do to the right end.

      No mention of setting $_

      TheStudent
        I guess I confused shifting the value from @_ with setting the value of $_. Thanks.