首页 > 解决方案 > use of perl @ARGV

问题描述

In a perl application I'm passing variables around with @ARGV. When there were always two variables and always the same two no problems. Now it's got more complicated so I need to "empty" @ARGV before adding to it. So I thought this would work:

    foreach (@ARGV)
            {
                pop @ARGV;
            }

It doesn't. When there are four elements it removes only two. Any idea why that should be? Or any other way of emptying it?

标签: perlargv

解决方案


In a perl application I'm passing variables around with @ARGV.

This is a poor design and should be avoided. If you need to pass values around, use function arguments, or at least your own global variable. Don't (ab)use a special variable for this.

Now it's got more complicated so I need to "empty" @ARGV before adding to it.

If you want to make an array empty, assign an empty list to it:

@ARGV = ();

推荐阅读