Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: print the array using command line arguements

by Fengor (Pilgrim)
on Nov 30, 2006 at 07:48 UTC ( #586890=note: print w/ replies, xml ) Need Help??


in reply to print the array using command line arguements

The problem in your code is the line my @new = @array[join(",",@ARGV)]; because the first element of @ARGV is the program name Fengor writes a 100 times ksh is not perl try

#!/usr/bin/perl use strict; use warnings; my @array = ( 11,12,13,14,15); #my @new = @array[join(",",@ARGV)]; #my @new = @array[1,3]; my @new = @array[$ARGV[0],$ARGV[1]]; print "@new\n";

--
"WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
-- Terry Pratchett, "Reaper Man"


Comment on Re: print the array using command line arguements
Select or Download Code
Re^2: print the array using command line arguements
by lidden (Deacon) on Nov 30, 2006 at 07:57 UTC
    The first argument of @ARGV is not the progname
    perl -wle 'print "@ARGV"' 3 4
    The progname is in $0
      oh right.

      --
      "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN"
      -- Terry Pratchett, "Reaper Man"

Re^2: print the array using command line arguements
by reneeb (Chaplain) on Nov 30, 2006 at 08:00 UTC
    nope

    #!/usr/bin/perl use strict; use warnings; print "@ARGV\n";


    Output:
    ~/entwicklung 14> perl argv.pl 1 1 (reneeb) Thu Nov 30 09:05:18 [-bash] ~/entwicklung 15> perl argv.pl 1 3 1 3 (reneeb) Thu Nov 30 09:06:06 [-bash] ~/entwicklung 16> ./argv.pl 1 1 (reneeb) Thu Nov 30 09:06:10 [-bash] ~/entwicklung 17> ./argv.pl 1 3 1 3
    Edit: This is an answer to Fengor, not lidden

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://586890]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2014-07-23 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (130 votes), past polls