Relative Content

Tag Archive for perlargv

Why does Perl behave as if a deep copy wasn’t made only when using <>?

In my code, I first stored the values of @ARGV in @argv, then iterated over @argv using foreach. Inside the loop, I assigned each element of @argv to @ARGV and used <<>> to process files one by one. After the loop finished, I intended to run another loop over @argv to rename the processed files as hidden files. I expected this to work correctly, but just before the final foreach loop, I found that @argv was empty. I tested similar scenarios using shift and delete, but in those cases, the original array was unaffected, as if a deep copy had been made. I’m not sure why using <<>> affects the original array when it doesn’t happen with shift or delete.

Why does Perl behave as if a deep copy wasn’t made only when using <>?

In my code, I first stored the values of @ARGV in @argv, then iterated over @argv using foreach. Inside the loop, I assigned each element of @argv to @ARGV and used <<>> to process files one by one. After the loop finished, I intended to run another loop over @argv to rename the processed files as hidden files. I expected this to work correctly, but just before the final foreach loop, I found that @argv was empty. I tested similar scenarios using shift and delete, but in those cases, the original array was unaffected, as if a deep copy had been made. I’m not sure why using <<>> affects the original array when it doesn’t happen with shift or delete.