Find the answer to your Linux question:
Results 1 to 4 of 4
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: Code: print "$ARGV[0]"; I get ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    4

    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:

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

    If I run it with this:
    Code:
    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 test1.pl 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
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    hi,

    can you show your entire assign3.pl code?

    on my Cygwin/Perl install, this code:
    Code:
    #!/usr/bin/perl
    for(@ARGV){
      print "arg: $_\n";
    }
    run like this:
    Code:
    perl /tmp/test.pl one two three
    outputs this:
    Code:
    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
    Just Joined!
    Join Date
    May 2013
    Posts
    4
    Thanks, I had quotes around the variables. Your code ran good for me.

  4. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,307
    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
  •