Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through properties of an object 1

Status
Not open for further replies.

rawkin

Programmer
Sep 23, 2003
11
AU
Hi,

I'm wanting to perform a series of regex's on a number of properties for an object. I've tried something similar to;

# ------------------------
my $object = class->new("xxxxxx");

foreach my $field (@fields) {
my $item = $object->{$field};
# .. then perform regex's on $item
}

# ------------------------

When I try to assign the value of "$object->{$field}" to "$item", I receive the error;

"Can't use string ("1") as a HASH ref while "strict refs"
in use at."

Would anyone be able to provide the correct way to reference "$object->{$field}" ?

Any help is appreciated! :)

--- Pete
 
Ok, after having a little break from the code, and re-reading it a little later, I did some debugging further up the code (between the object creation, and the foreach loop).

The creating of the object "my $object = class->new(.." was causing the error, and therefore didn't have the correct data when it got to the foreach loop.

After fixing up the object class, it's all working fine.. this explains why perfectly logical code seemed to just not work.. :)

thanks,

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top