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

Dear Monks,

I am looking for an ‘off the shelf’ method to enable a user of a Perl program to specify the flat file name to be read by the Perl program and the output file name to be produced by the program. This should be specifiable in the system call. Can anyone point me in the direction of examples of good practice in relation to this?

Replies are listed 'Best First'.
Re: System call input and output files
by gellyfish (Monsignor) on Dec 09, 2004 at 12:02 UTC

    You are looking at either accessing the command line arguments directly in the @ARGV array or using a module such as (the standard) Getopt::Std or Getopt::Long

    /J\

Re: System call input and output files
by zentara (Cardinal) on Dec 09, 2004 at 12:07 UTC
    "Off the shelf" ? You mean you want someone to write it for you for free?

    To pass files to a perl script, you read it's arguments.

    myperlscript inputfile outputfile
    In myperscript
    #!/usr/bin/perl use warnings; use strict; my $inputfile = $ARGV[0]; my $outputfile = $ARGV[1]; print "$inputfile\t$outputfile\n"; #or process them here
    To run it thru system:
    system( "myperlscript $inputfile $outputfile");

    I'm not really a human, but I play one on earth. flash japh
Re: System call input and output files
by Happy-the-monk (Canon) on Dec 09, 2004 at 12:03 UTC

    die qq(usage: $0 infile outfile\n) unless @ARGV == 2; my ( $infile, $outfile ) = @ARGV; open ( IN, "< $infile ... open ( OUT, "> $infile ...

    Cheers, Sören