On Jan 19, Andrew Koper said:
>I am working on an org chart app. It is easy to loop through an
>employee list and get an array of everyone who reports to a given user
>ID (say, a vice president), but my logic breaks when I try and loop
>through the list again and get arrays of everyone who reports to the
>managers in the initial array. Any help?
>
>$name = 'bsmith';
>
>open (FH);
What file are you opening? I guess you have a variable named $FH that has
a filename in it?
>while (<FH>) {
> (@junk, $sup) = split(/\,/,$_);
Here's the primary problem. The array slurps up everything returned by
split(), so nothing is put in $sup. Since, by the name, you don't want
@junk, you should do:
$sup = (split /,/)[-1];
Meaning, "get the last element of split() and put it in $sup."
> if ($sup eq '$name') {
You don't want to put single quotes around a variable, and you don't need
any quotes at all.
> push (@underlings, $_);
> }
>}
>close (FH);
>
>foreach $under (@underling) {
> open (FH);
> while (<FH>) {
> (@junk, $sup) = split(/\,/,$_);
Likewise.
> if ($sup eq '$under') {
Quoting is a problem here, too.
>#this is where it breaks, I need a separate array of underlings for each
>
>#CDS ID in underlings, but it doesn't know which CDS IDs will be in
>#underlings before it begins. This throws all into one array.
>#Useless for my purpose.
> push (@under_underlings, $_);
> }
> }
> close (FH);
>}
Once these problems have been fixed, it will be easier to assess the
situation to decide what type of data structure you need.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]