Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I am having the following problem. Currently we use a perl script as a driver to other scripts. This setup has worked fine before, with the various versions of the program being executed via the following specification : -V prod, -V test, -V devl

Recently, I have noticed based on a user inquiry into this problem that the specification wasn't being used.

Upon further investigation, it appears that @ARGV is being corrupted but I am not sure how. when I split up @ARGV to look at the character count specifically of each argument, where the "devl" should only have 4, it now has 5.

What is even stranger is that if I implement it this way:

perl <thedriver> -V devl

it works fine.

Any ideas or at least an arrow saying what to take a look at?

Thanks!

Replies are listed 'Best First'.
Re: @ARGV being corrupted
by gellyfish (Monsignor) on Jul 22, 2004 at 14:10 UTC

    The smallest snippet of code that demonstrates the behaviour that you are talking about would be useful.

    /J\

      Here is a snippet:
      if ( $ARGV[$i] eq "devl" ) { print "$ARGV[$i]\n"; }
      Thats all the code is. i can actually transplate the specific code and run it seperate and it works fine so what my question is what possibly could have changed in a library, etc that would cause this? maybe a conflict between versions?

      Edit by castaway - added code tags

        To reiterate others: You need to tell us which operating system you are using; and show us a command line that fails, rather than one that succeeds.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
        brackets should be around $i
Re: @ARGV being corrupted
by dragonchild (Archbishop) on Jul 22, 2004 at 14:24 UTC
    Also, specifying the Perl version and the OS you're running on would be very helpful.

    Plus, is there a reason why you're not using Getopt::Std or Getopt::Long to parse command-line arguments? This is a solved problem, with solutions that are part of the mainline Perl distribution ...

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      This method of option processing has been historic. Full reasons as to why not sure. The version we are using is 5.6.1
Re: @ARGV being corrupted
by roju (Friar) on Jul 22, 2004 at 14:25 UTC
    If you use one of the Getopt modules, say Getopt::Std, does it work then? It could be a problem with your argument handling code.

    In place of your current argument grokking code, try:

    use Getopt::Std; my %args; getopts ('V:', \%args); print $args{'V'};
    Do you get the expected results?
Re: @ARGV being corrupted
by husker (Chaplain) on Jul 22, 2004 at 14:33 UTC
    If it hurts when you do that, don't do that. Instead, as the other Wise Ones have said, look at Getopt::Std. There's no excuse to re-invent that wheel, not even "that's the way we've always done it!" :)
      This fails on both Solaris ( not sure the version at this time ) and Windows 2000 . Using Perl version 5.6.1 . The line of code did detect the option but my previous detect for -V does that too, I will look and see how I can gather the "devl" specification.
        Found the problem. Since this is utilized across platforms someone must have modified it on windows. had the ^M characters on the ending lines. removed them and it worked.