Can't use string ("") as a HASH ref while "strict refs" in use
-
When you `split` the `$result_string` by `;` you get the list _of strings_ `('RCSoWLAN', 'ePDG-2', 'Qguest', 'ASUS_ATT_VOWIFI')`, which your `for` iterates over. As each is processed in turn it is available in `$_`. So your `$_->{...}->...` attempts to dereference (by `->`) a _string_, as if it were a hashref. – zdim May 18 '18 at 06:46
-
However, I cannot possibly guess what your intent is here. Can you explain what you are trying to do and why you have `$_->{...}...` ? – zdim May 18 '18 at 06:52
-
you have to explain what are you trying to achieve especially this line `print "SSID[$index]: $_->{$index}->{ssid}\n"; ` – Nagaraju May 18 '18 at 06:57
-
what is your expected input and output? your previous [question](https://stackoverflow.com/questions/50367575/cant-use-string-as-an-array-ref-while-strict-refs-in-use) is also something related to this. – ssr1012 May 18 '18 at 07:09
-
I am trying to store it to a Hash.. – May 21 '18 at 07:27
1 Answers
Because - as someone has already said - $result_string
is still not a hash. Neither is $_
. So using 'hash like' constructs on it, is simply never going to work.
You seem to have incorporated the advice to split
from your previous question, but you don't really seem to understand what's actually happening in your code.
split
breaks your string into a list. You then iterate the list using for
. When you use for
$_
is set to the 'current iterator', so it will be set to ('RCSoWLAN', 'ePDG-2', 'Qguest', 'ASUS_ATT_VOWIFI')
in turn.
On the first iteration - you're writing:
"RCSoWLAN" -> {1} -> {ssid}
Which is nonsensical, and is why you're getting the error that you are.
I am assuming your input string comes from another source, which includes field names - like the ssid
field you are attempting to access. But that never actually makes it into your program, so it's also meaningless.
Your best bet really is to backtrack, and figure out what you're actually trying to accomplish here, and outline input and output (along with a code example) so we actually have a chance to figure out what you're doing.

- 52,974
- 7
- 60
- 101