perl newbie

Discussion in 'Perl' started by Gunnar Hjalmarsson, Jan 24, 2004.

  1. ABE wrote:
    > How to open or read a file passed as a parameter.
    >
    > Example. myperl.pl myconfigfile
    >
    > $cfgfile = ***** what to put here.....


    my ($cfgfile) = @ARGV;

    See perldoc perlvar

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jan 24, 2004
    #1
    1. Advertising

  2. ABE wrote:
    > How to open


    perldoc -f open

    > or read a file


    You could use
    perldoc -f read

    But I would suggest to use the more standard method of processing the file
    line by line
    while (<MyFile>) {
    # do whatever you want with each line, to be found in $_
    }

    > passed as a parameter.


    > Example. myperl.pl myconfigfile
    >
    > $cfgfile = ***** what to put here.....


    Do you want to access the value of the parameter?
    $cfgfile = $_[0];
    However, that would be just the file name, not the file itself.
    Further details please see 'perldoc perlvar'.

    > if ( -e $cfgfile )


    Well, I guess you weren't looking for how to open or read a file after all.
    You just wanted to know how to access command line parameters. Why all the
    fuzz about files and opening and reading?

    jue
    Jürgen Exner, Jan 24, 2004
    #2
    1. Advertising

  3. Jürgen Exner wrote:
    > Do you want to access the value of the parameter?
    > $cfgfile = $_[0];


    Ooops, sorry, that should have been
    $cfgfile = $ARGV[0];

    jue
    Jürgen Exner, Jan 24, 2004
    #3
  4. Jürgen Exner wrote:
    > ABE wrote:
    >>Example. myperl.pl myconfigfile
    >>
    >>$cfgfile = ***** what to put here.....

    >
    > Do you want to access the value of the parameter?
    > $cfgfile = $_[0];


    Suppose you mean

    $cfgfile = $ARGV[0];

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jan 24, 2004
    #4
  5. Gunnar Hjalmarsson

    ABE Guest

    How to open or read a file passed as a parameter.

    Example. myperl.pl myconfigfile

    $cfgfile = ***** what to put here.....

    if ( -e $cfgfile )
    {
    print "Ok\n";
    }
    else
    {
    print "Not found.\n";
    }
    ABE, Jan 24, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,792
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    298
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    677
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    292
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    680
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page