So it is probably simple and a question of scoping but it is bugging me.
Here is a simple example of my question:
Code:
$ echo "hello world" | ruby -pe '$_.split[1] = "help"'
hello world
Now to me the expected output should have been:
My thinking is that $_ is defined as follows:
Quote:
$_ The last input line of string by gets or readline.
|
So in our example this would mean it equals "hello world".
Now the split will use the default separator ($;) which is whitespace as this
value is set to nil. Therefore I would expect the second element of the array
created by split to be "world" which bears true and can be tested with:
Code:
$ echo "hello world" | ruby -pe 'puts $_.split[1]'
world
hello world
So my question is, if I am setting the second part of the array to "help"
why does this not show in the results?