×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Hashes

Hashes

(OP)
Hi,
   I've just started trying to use hashes. Basically I want to use a modules package name as the index to the hash so that when a trace function is called it checks to ensure that tracing has been turned ON in that package.

   So I have an initialisation function whereby I read a text file of the form:

package1=ON
package2=ON
package3=OFF
...etc

    And then these are split on the = and the hash set up:

e.g.
%myhash = ();
while(<TRACECONFIGFILE>)
{
    ($package_name, $trace_value) = split(/=/,$_);
    $myhash{'$package_name', $trace_value);
}


   So when the trace call is made, inside the trace function I want to do something like:

if ($myhash{$package_name} eq "ON")
{
    trace a message to a file
}
else
{
    don't do anything
}


   Is doesn't work at the moment as in the if isn't returning true, even when the text file sets that hash to "ON"...

    Hopefully that made sense! Really I just need to know how to use a scalar as the name of a hash key.. is this even possible?

Thanks for staying with me!
Loon

RE: Hashes

$myhash{'$package_name', $trace_value);

It may be to much to hope that it is this simple, but,
the brace is closed with a paren.




keep the rudder amid ship and beware the odd typo

RE: Hashes

(OP)
Hmmmm....


while(<INF>)
{
    ($package_name,$trace_value) = split(/=/,$_);
    $tracing_area{'$package_name',$trace_value);
}


gave me:

syntax error at TRACING.pm line 54, near "$trace_value)"
Missing right bracket at TRACING.pm line 127, at end of line
BEGIN failed--compilation aborted at htc_parser.pl line 15.

Am I doing it right?! :-/
Cheers
Loon

RE: Hashes

I'm not familiar with building a hash in the manner you appear to be using.....
If it will work that way, you will need to close the brace with a brace.  As written, you are closing a brace with a paren.

I add pairs to hashes like....
#                   key              value
$tracing_area{$package_name} = $trace_value;


also, I think that enclosing the variables in your braces in single quotes will prevent then from being evaluated.  Instead of getting the value contained in $package_name you're getting the string '$package_name', including the dollar sign.




keep the rudder amid ship and beware the odd typo

RE: Hashes

my %myhash;
while(<TRACECONFIGFILE>)
{
  my ($package_name, $trace_value) = split(/=/,$_);
  $myhash{$package_name} = $trace_value;
}

Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close