passed params as filename

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew

    passed params as filename

    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

  • Jürgen Exner

    #2
    Re: passed params as filename

    Andrew wrote:[color=blue]
    > 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


    Comment

    Working...