kaka_2 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I am not getting why i am getting an empty array when using if else condition.
i have a simple script as below.
#!/usr/bin/perl my $SP4binconfig = "/etc/SPECdaemons.list"; open (my $fh, '<', $SP4binconfig) or die "cant open the file : $!"; my @SPECores = <$fh>; close $fh; print "@SPECores";
this script print the array correctly. but when i use the same codes with If Else condition it does not and i cant figure out what is wrong with this
#!/usr/bin/perl my $SP4binconfig = "/etc/SPECdaemons.list"; if (-e $SP4binconfig) { open (my $fh, '<', $SP4binconfig) or die "cant open the file : $!"; my @SPECores = <$fh>; close $fh; } else { print "mmmmm"; } print "@SPECores";
Could someone help?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array is empty when using if else condition
by AppleFritter (Vicar) on Aug 28, 2014 at 11:39 UTC | |
by jellisii2 (Hermit) on Aug 28, 2014 at 20:28 UTC | |
by kaka_2 (Sexton) on Aug 28, 2014 at 14:25 UTC | |
|
Re: Array is empty when using if else condition
by flexvault (Monsignor) on Aug 28, 2014 at 10:59 UTC |