CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
What is this thing and why not strict?

 



Iconx
Novice

Dec 11, 2014, 4:14 PM

Post #1 of 3 (8836 views)
What is this thing and why not strict? Can't Post

Ok what do you call these things and why dont they work with strict, whats the alternative, I'll try to explain.


Code
sub Del_Home_Dir 
{
print "Remove::Del_Home_Dir() sub \n";
my (%delete_acct) = (@_);
my $tenv;
DEL_ENV: foreach $tenv (sort keys %delete_acct)
{

DEL_PLATFORM: foreach my $tplatform (sort keys %{$delete_acct{$tenv}})
{
print "TPLATFORM: $tplatform \n";
.......etc..etc....


I'm referring to where it says "DEL_ENV:" and "DEL_PLATFORM:". When not using strict it just skips over the DEL_PLATFORM section, and when using strict it trys to process it but with the error...."Can't use string ("1") as a HASH ref while "strict refs" in use". So besides the structure of those hashes and how their passwd what is this "MY_LABEL:" business


Laurent_R
Veteran / Moderator

Dec 12, 2014, 12:01 AM

Post #2 of 3 (8583 views)
Re: [Iconx] What is this thing and why not strict? [In reply to] Can't Post

"DEL_ENV:" and "DEL_PLATFORM:" are called labels. I do not see any reason for them to create the type of errors that you saw. I think that the error you report occurred in some part of the code that you did not show.


Zhris
Enthusiast

Dec 15, 2014, 12:59 PM

Post #3 of 3 (4474 views)
Re: [Iconx] What is this thing and why not strict? [In reply to] Can't Post

Hi,

I can duplicate your problem if I supply Del_Home_Dir a single level hash:

http://codepad.org/jKNIfBWZ

Code
use strict; 

Del_Home_Dir
(
one => 1,
two => 2,
);

sub Del_Home_Dir
{
print "Remove::Del_Home_Dir() sub \n";
my (%delete_acct) = (@_);
my $tenv;
DEL_ENV: foreach $tenv (sort keys %delete_acct)
{
DEL_PLATFORM: foreach my $tplatform (sort keys %{$delete_acct{$tenv}})
{
print "TPLATFORM: $tplatform \n";
}
}
}


In this case the error is because I am attempting to use a string i.e. '1' as a hash. Here is minimal code that replicates the error:

http://codepad.org/0OVI28dS

Code
use strict; 
my %hash = ( one => 1 );
print %{$hash{one}};


I don't know enough about your code / data, but Del_Home_Dir expects a hash of hash:


Code
Del_Home_Dir 
(
one => { 1 => 'won', 2 => 'wand' },
two => { 1 => 'too', 2 => 'true' },
);


Regards,

Chris


(This post was edited by Zhris on Dec 15, 2014, 1:33 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives