passed params as filename

Discussion in 'Perl' started by Andrew, Dec 29, 2003.

  1. Andrew

    Andrew Guest

    Hello, i'm new to this group and have a quick question, I tried to
    search on this topic but was unsucessful.
    I'm tring to use a parameter to name a file, actually multiple
    parameters, and perl doesn't seem to like it. Can anyone tell me what I
    am doing wrong?

    Code:
    my $employee = param('employee');
    my $filename = "$employee.txt";
    
    
    # if file exists then append to file
    if (-e $filename) {
    open(TIMELOG, ">>./$filename") || die "Can't open file.\n";
    
    [code]
    
    Thanks for your time.
    
    Andrew
    Andrew, Dec 29, 2003
    #1
    1. Advertising

  2. Andrew wrote:
    > Hello, i'm new to this group and have a quick question, I tried to
    > search on this topic but was unsucessful.
    > I'm tring to use a parameter to name a file, actually multiple
    > parameters, and perl doesn't seem to like it. Can anyone tell me
    > what I am doing wrong?
    >
    >
    Code:
    > my $employee = param('employee');[/color]
    
    You are looking for the variable @ARGV, not for the function param().
    From perldoc perlvar:
    @ARGV   The array @ARGV contains the command-line arguments intended for
    the script. [...]
    
    my $employee = $ARGV[0];
    
    Or more perlish (will remove the argument from the argument list):
    my $employee = shift;  #shift() defaults to @ARGV outside of the lexical
    scope of subroutines
    
    jue
    Jürgen Exner, Dec 29, 2003
    #2
    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. dee
    Replies:
    9
    Views:
    495
    Joseph Byrns
    Apr 15, 2005
  2. Anand
    Replies:
    2
    Views:
    889
    Anand
    Sep 11, 2003
  3. Barry
    Replies:
    9
    Views:
    427
    Ara.T.Howard
    Sep 15, 2005
  4. Raju Alluri
    Replies:
    1
    Views:
    210
    Stefan Lang
    Nov 22, 2008
  5. Michael
    Replies:
    4
    Views:
    161
    Michael
    Oct 22, 2004
Loading...

Share This Page