• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Perl: Substitution to ‘foreach’ local variable changed the elements of array used for ‘foreach’ processing

Resolved: Perl: Substitution to ‘foreach’ local variable changed the elements of array used for ‘foreach’ processing

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Code Snippet:
Content inside “/home/yuerki/10.12/proj/” is : power1, power2, power3, power4, power5
Output:
FIRST: /home/yuerki/10.12/proj/power1 /home/yuerki/10.12/proj/power2 /home/yuerki/10.12/proj/power3 /home/yuerki/10.12/proj/power4 /home/yuerki/10.12/proj/power5 is powerArray
Second: 1 2 3 4 5 is powerArray
Question/Doubt: Why “SECOND: 1 2 3 4 5 is powerArray” has come in output? I was expecting it to be “SECOND: /home/yuerki/10.12/proj/power1 /home/yuerki/10.12/proj/power2 /home/yuerki/10.12/proj/power3 /home/yuerki/10.12/proj/power4 /home/yuerki/10.12/proj/power5” because we made no changes in @powerArray, and only in $powerNum?
Can anyone please explain? Also, how can i avoid the substitution changes in @powerArray? As I need to use this global array at other places as well

Answer:

Make modification like below:
Hope this helps.

If you have better answer, please add a comment about this, thank you!

arrays foreach perl substitution
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: deserializing XML list with jackson

26/03/2023

Resolved: When converting markdown to latex with pandoc, how can I end a block before the next heading?

26/03/2023

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.