Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How do I get only one item out of attribute?

by swampyankee (Parson)
on Aug 21, 2006 at 17:56 UTC ( [id://568630]=note: print w/replies, xml ) Need Help??


in reply to How do I get only one item out of attribute?

If you are absolutely certain that the format position of this attribute won't change, my preference (like mscerra's) is to use split. Being slightly neurotic, I'd check whether the return value actually exists before printing it.

If you're less certain about the postion, but still certain about the general formatting, a hash may be your best bet. This seems close to the spirit of your post. Something like this code may be a reasonable start:

#!perl use warnings; use strict; my %attr; %attr = split(/\s*[,=]\s*/,'corpid=xxxxxx,ou=people,o=corp'); if exists $attr{ou} { print "value for ou is $attr{ou}\n"; } else { print "No value defined for ou...this may be an error\n"; }
What's happening here is fairly simple: the string is being split on equal signs and commas, with the items to the left of the equal signs being used as the keys to a hash.

emc

Experience is a hard teacher because she gives the test first, the lesson afterwards.

Vernon Sanders Law

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://568630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found