http://qs321.pair.com?node_id=1081242


in reply to Re: Use of uninitialized value $_ in string
in thread Use of uninitialized value $_ in string

Hi frozenwithjoy,

Yes, the line 32 is my $conf = "$_";. I've managed to remove the errors but I'm not so sure if this is the correct approach especially the declaration of the same variables under sub add_vhost. What I did was...

remove these variables from above:

my $conf = "$_"; my $conf_bn = basename($conf); my $conf_mtime = (stat($conf))[9]; my $date = strftime '%m%d%Y', localtime; my $backup = "$conf.$date"; my $backup_bn = basename("$conf.$date"); my $ltime = localtime();

then declared the $conf, $conf_bn, and $ltime variables under sub add_vhost.

sub add_vhost { my $conf; my $conf_bn; my $ltime;

and removed the comments from the variables under foreach...

foreach (@object) { my $conf = "$_"; my $conf_bn = basename($conf); my $conf_mtime = (stat($conf))[9]; my $date = strftime '%m%d%Y', localtime; my $backup = "$conf.$date"; my $backup_bn = basename("$conf.$date"); my $ltime = localtime();

The errors were gone every time I execute the script. However, after providing two required arguments, the script still does nothing. I was expecting it would start creating a backup of the existing file.

[root@wsprod01 myperl]# ./test.pl --domain google.com --client google Usage: ./test.pl --domain companydomain.com --client company [--job-co +de 12345] [--help].

Cheers,

JP