passed params as filename

A

Andrew

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

Jürgen Exner

Andrew said:
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');[/QUOTE]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top