Sending Perl variabels from the command-line


Results 1 to 3 of 3

Thread: Sending Perl variabels from the command-line

  1. #1
    Christian Guest

    Sending Perl variabels from the command-line

    How do I get a variable from the parameters I start the Perl code with? Like "perlscrip.pl parameter" and i want "parameter" to get in $variabel. Also i wonder how I could get random numbers in C++.

  2. #2
    TheLinuxDuck Guest
    Originally posted by Christian:
    How do I get a variable from the parameters I start the Perl code with? Like "perlscrip.pl parameter" and i want "parameter" to get in $variable.
    @ARGV is the global variable that contains all the arguments passed from the command line. You can display them as:

    Code:
    #!/usr/bin/perl -w
    use strict;
    
    die "No command line arguments given.\n" if(!@ARGV);
    
    for(0..$#ARGV) {
      print $_ . " $ARGV[$_]\n";
    }
    ------------------
    TheLinuxDuck
    Wait... that's a penguin?!?!?
    :wq

  3. #3
    EyesWideOpen Guest
    Originally posted by Christian:
    Also i wonder how I could get random numbers in C++.
    Take a look at these posts: http://www.linuxnewbie.org/ubb/Forum14/HTML/000083.html (see takshaka's post)

    http://www.linuxnewbie.org/ubb/Forum14/HTML/000562.html

Posting Permissions

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