Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to get ARGV to work in Perl

    Hello, I am using a new install of cygwin that has Perl and everything works fine, but not ARGV.

    If I try to print this:

    print "$ARGV[0]";
    I get this message:
    Use of uninitialized value $ARGV[0] in string at line 9, <> line 1.

    If I run it with this:
    foreach ("at"ARGV) {
            print "$_\n";
    nothing happens at all, it's like there's no arguments at all.

    This is what I'm typing into the shell to run it:
    perl free.cpp hello

    (since I don't have 15 posts or more, I can't post an "at" sign, so that is why it is written in above.)
    Last edited by vendetta1; 05-06-2013 at 03:20 AM.

  2. #2

    can you show your entire code?

    on my Cygwin/Perl install, this code:
      print "arg: $_\n";
    run like this:
    perl /tmp/ one two three
    outputs this:
    arg: one
    arg: two
    arg: three
    are you using the version of perl that comes with Cygwin or a separate Perl, like ActiveState Perl? What about making the script executable and just executing it directly?

  3. #3
    Thanks, I had quotes around the variables. Your code ran good for me.

  4. $spacer_open
  5. #4
    Quote Originally Posted by vendetta1 View Post
    Thanks, I had quotes around the variables.
    glad it is sorted, but would mind terribly sharing exactly what you mean by that? i'd like to be able to replicate your issue, so that I (and future visitors to this thread) can understand exactly both the problem and the solution.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts