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

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

by swampyankee (Parson)
on Aug 21, 2006 at 17:56 UTC ( #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.


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

Vernon Sanders Law

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2021-05-06 12:04 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (73 votes). Check out past polls.