3

I have a task to convert script from Perl to PowerShell.

I read about command line argument of Perl: @ARGV. I understand that at the time of the script execution, any argument that is passed will be captured by this special array variable. We can read @ARGV and assign values to scalar variables using:

($var1,$var2) = @ARGV;

I need to understand what the statement below is doing:

($var1,$var2,@ARGV) = @ARGV;

In my script, I have an if condition on values in @ARGV, and based on @ARGV values, a respective subroutine is getting called.

As per my understanding if we have more than two values in @ARGV, then on left side in parenthesis statement is changing values of ARGV/used to rewrite @ARGV with remaining Values?

1 Answer 1

6

It chops off the first two arguments from @ARGV and puts them in $var1 and $var2.

Personally I would have written it as:

$var1 = shift @ARGV;
$var2 = shift @ARGV;

But it is a matter of taste.

Sign up to request clarification or add additional context in comments.

2 Comments

I probably wouldn't have done even that my ( $first, $second, @everything_else ) = @ARGV; is more my sort of thing :)
@Sobrique There may be a call to GetOptions later in the script, which would require the modification of @ARGV.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.