I am trying to figure out a way to assign a line from <STDIN> to an array. For example, the user is prompted for a line of text and he enters something like: 'a b c d' on one line and hits enter.
I want to assign to an array such that a[0] = a, a[1] = b, a[2] = c, and a[3] = d
All I have been able to find out so far is that when you assign <STDIN> to an array, each line is an index, and the user must type control-d to end the input. This is not what I'm trying to do. I can assign the input as a string to a variable; is there a way to then use that variable and assign the pieces separated by a space to different elements of the array, sort of like you can do with '@array = qw/a b c d/; ?
Thanks in advance for any help.
I want to assign to an array such that a[0] = a, a[1] = b, a[2] = c, and a[3] = d
All I have been able to find out so far is that when you assign <STDIN> to an array, each line is an index, and the user must type control-d to end the input. This is not what I'm trying to do. I can assign the input as a string to a variable; is there a way to then use that variable and assign the pieces separated by a space to different elements of the array, sort of like you can do with '@array = qw/a b c d/; ?
Thanks in advance for any help.