Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: user input file

by kennethk (Abbot)
on Jun 19, 2013 at 13:36 UTC ( #1039778=note: print w/ replies, xml ) Need Help??


in reply to user input file

The correct method for taking command line parameters into a Perl script is to use the @ARGV array. Your example might look like

open(FILE,"<", $ARGV[0]) or die "Open failed for $ARGV[0]: $!"; + my @lines=<FILE>;
which the user would invoke as
$ perl script.pl Working_On.csv
Note as well that I've added a test to see if the file open succeeded, and added a diagnostic in case it didn't. See Simple Opens in perlopentut.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: user input file
Select or Download Code
Replies are listed 'Best First'.
Re^2: user input file
by torres09 (Acolyte) on Jun 19, 2013 at 13:47 UTC

    I am working on windows , not unix so there will be no invocation . I tried your way but it does not work , may be because of OS

      If you drag a csv file on to the script, it can be configured to read the file name from @ARGV. How are you planning to have the user invoke it?

      --MidLifeXis

        I am working on Padre , here the script has been written so I wish that user should input the file name on command prompt , when we run it . In padre we have an option to run the script , which gives a cmd with result on it , we can also give inputs from cmd as well

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (18)
As of 2015-07-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (257 votes), past polls