web-yogini has asked for the wisdom of the Perl Monks concerning the following question:

Namaste Brethren, I am trying to remove a directory subcursively (like an rm -r) and by using File:Path I think I have it. But... the @ARGV won't accept variables in it.
# This one won't work # @ARGV = ('$mail_directory/users/$table_ext/$user\@domain.c +om') unless @ARGV; # But this one will: @ARGV = ('/home/account/users/po/username@domain.com') unless @ARGV; die "usage: $0 dir ..\n" unless @ARGV; foreach $dir (@ARGV) { rmtree($dir); } print "Deleting user's directory: @ARGV\n";
What am I missing? I feel so dumb!

Replies are listed 'Best First'.
Re: Why won't it let me place variables in here?
by Chmrr (Vicar) on Jul 13, 2001 at 08:51 UTC
    Unless I much mistake, you have some quotage problems. Specifically, you need double quotes, like so:
    @ARGV = ("$mail_directory/users/$table_ext/$user\@domain.com") unless @ARGV;
    Double quotes interpolate variables, single quotes don't.

     
    perl -e 'print "I love $^X$\"$]!$/"#$&V"+@( NO CARRIER'

      Thank you! A simple truth I can carry with me forever. ; ) Sad Gurunath Maharaj ki jai!
Re: Why won't it let me place variables in here?
by synapse0 (Pilgrim) on Jul 13, 2001 at 08:52 UTC
    @ARGV = ('$mail_directory/users/$table_ext/$user\@domain.com')
    single quotes will not expand the variables.. use double quotes..
    @ARGV = ("$mail_directory/users/$table_ext/$user\@domain.com")
    -Syn0

    update: bah! you beat me to the answer (damn slow typing :)