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

 $strings = ($argv[0], $argv[1], $argv[2]);

When I want to run the script "perl runprogram foo, bar, test"

I just want the foo, bar and test as strings.

Replies are listed 'Best First'.
Re: strings with multiple parameters
by davido (Cardinal) on Nov 07, 2011 at 16:29 UTC
    $strings = join '', @ARGV

    See perldoc -f join.

    Update:

    On second read of your original question I noticed that your code snippet may not have been illustrating what you actually intended to do. Maybe you wanted to retain the strings as separate scalar units:

    ( $this, $that, $the, $other ) = @ARGV;

    But if that's what you need, what's wrong with keeping them in the original array, or assigning them to a new array?


    Dave

Re: strings with multiple parameters
by toolic (Bishop) on Nov 07, 2011 at 16:30 UTC
    use strict and warnings to get hints regarding your problem.

    Uppercase @ARGV is what you want.

    perl runprogram foo, bar, test

    Also, the commas are preserved by some (all?) shells.

Re: strings with multiple parameters
by starface245 (Novice) on Nov 07, 2011 at 17:46 UTC
    I went with a different way and use STDIN instead
    my $line0 = <STDIN>; my $line1 = <STDIN>; my $line2 = <STDIN>; chomp $line0; chomp $line1; chomp $line2; @strings = ($line0, $line1, $line2);
    Now I am trying to write a loop for it and stuck....
    print "How many line" my $num = <STDIN>; for ($count = $num; $count>=1; $count--) { my $line; chomp ($line = <STDIN>); }
    I am stuck after chomp with STDIN...
      push
      use warnings; use strict; my @strings; print "How many line"; my $num = <STDIN>; for my $count (1 .. $num) { my $line; chomp( $line = <STDIN> ); push @strings, $line; }
        Thank you so much! works perfectly now, I dont know why I didn't think of push...