Can you pl. take a look here?
am 23.11.2007 10:02:42 von clearguy02
Hi all,
Here is the problem description.
__DATA__
# user_id name email user_uid manager_uid
jcarter john a@gmail.com 00206251 00207609
mstella mary b@yahoo.com 00207609 00220458
msmith martin c@gmail.com 00202227 00207609
bborders bob d@gmail.com 00220458 00202003
swatson sush e@yahoo.com 00224981 00207609
rcasey rick f@gmail.com 00202003 00201009
------------------------------------------------------------ ------
mstella is the boss of jcarter, msmith and swatson;
bborders is the boss of mstella;
rcasey is the boss of bborders;
Now I need to replace the manager uid's with the boss id's; for the
top-most manager's id, you can replace his manager uid with his user
id itself (in this case rcasey is the top-most guy).
i.e the output file should be as follows:
++++++++++++++++++++++++++++++++++++++++++++++++++++
# user_id name email manager_id
jcarter john a@gmail.com mstella
mstella mary b@yahoo.com bborders
msmith martin c@gmail.com mstella
bborders bob d@gmail.com rcasey
swatson sush e@yahoo.com mstella
rcasey rick f@gmail.com rcasey
+++++++++++++++++++++++++++++++++++++++++++++++++++++
Here is my code:
while ()
{
$line = $_;
@lineArray = split (/\s+/, $line);
if ($lineArray[3] == $lineArray[2])
{
s/$lineArray[3]/$lineArray[0]/g;
}
print "$lineArray[0]\t\t$lineArray[1]\t\t$lineArray[3]\n";
}
I am struggling with the part of replacing the the numerical
manager_uid with the manager_id.
Thanks in advance,
JC
Re: Can you pl. take a look here?
am 23.11.2007 15:25:37 von 1usa
clearguy02@yahoo.com wrote in
news:66e8698f-caef-4e09-8202-cfc81e692bd1@e6g2000prf.googleg roups.com:
> Subject: Can you pl. take a look here?
Please do read the posting guidelines for this group and spend some time
composing a meaningful subject line.
I only looked at this post by accident (I had figured it for a Viagra ad
based on the subject line).
> Here is the problem description.
Are you assigning homework now?
> __DATA__
> # user_id name email user_uid manager_uid
>
> jcarter john a@gmail.com 00206251 00207609
> mstella mary b@yahoo.com 00207609 00220458
> msmith martin c@gmail.com 00202227 00207609
> bborders bob d@gmail.com 00220458 00202003
> swatson sush e@yahoo.com 00224981 00207609
> rcasey rick f@gmail.com 00202003 00201009
> ------------------------------------------------------------ ------
>
> mstella is the boss of jcarter, msmith and swatson;
> bborders is the boss of mstella;
> rcasey is the boss of bborders;
>
> Now I need to replace the manager uid's with the boss id's; for the
> top-most manager's id, you can replace his manager uid with his user
> id itself (in this case rcasey is the top-most guy).
So, if manager_uid is not in the user_uid's supplied, then assume user
answers to higher authority than the mortals in this set.
> i.e the output file should be as follows:
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> # user_id name email manager_id
>
> jcarter john a@gmail.com mstella
> mstella mary b@yahoo.com bborders
> msmith martin c@gmail.com mstella
> bborders bob d@gmail.com rcasey
> swatson sush e@yahoo.com mstella
> rcasey rick f@gmail.com rcasey
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
But now you are contradicting yourself. rcasey has a manager. The
manager's id is 00201009. rcasey answers to someone who is not him.
> while ()
> {
> $line = $_;
> @lineArray = split (/\s+/, $line);
Don't forget to chomp.
No need for silly intermediate assignments. Are you being paid by the
line?
while ( ) {
chomp;
my @lineArray = split /\s+/;
> if ($lineArray[3] == $lineArray[2])
You are using numeric comparison when the input data are really strings
(i.e. things like ZIP codes, badge numbers etc -- even when they consist
entirely of digits -- are not numbers).
> {
> s/$lineArray[3]/$lineArray[0]/g;
> }
> print "$lineArray[0]\t\t$lineArray[1]\t\t$lineArray[3]\n";
> }
>
> I am struggling with the part of replacing the the numerical
> manager_uid with the manager_id.
To my simple mind, it looks like your problem requires two passes over
data.
I assumed, based on your example, that the output had to be in the same
order as the input.
#!/usr/bin/perl
use strict;
use warnings;
my ( %users, @users );
while ( my $record = ) {
next if $record =~/^#/;
chomp $record;
next if $record =~ /^\s*$/;
my @fields = split /\s+/, $record;
$users{ $fields[3] } = $fields[0];
push @users, \@fields;
}
for my $user ( @users ) {
my ($user_uid, $manager_uid) = @$user[3,4];
my $manager = exists $users{ $manager_uid }
? $users{ $manager_uid }
: $users{ $user_uid } ;
print join("\t", @$user[0 .. 2], $manager), "\n";
}
__DATA__
# user_id name email user_uid manager_uid
jcarter john a@gmail.com 00206251 00207609
mstella mary b@yahoo.com 00207609 00220458
msmith martin c@gmail.com 00202227 00207609
bborders bob d@gmail.com 00220458 00202003
swatson sush e@yahoo.com 00224981 00207609
rcasey rick f@gmail.com 00202003 00201009
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines:
Re: Can you pl. take a look here?
am 23.11.2007 16:26:22 von clearguy02
On Nov 23, 6:25 am, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> cleargu...@yahoo.com wrote innews:66e8698f-caef-4e09-8202-cfc81e692bd1@e6g2000prf.googl egroups.com:
>
> > Subject: Can you pl. take a look here?
>
> Please do read the posting guidelines for this group and spend some time
> composing a meaningful subject line.
>
> I only looked at this post by accident (I had figured it for a Viagra ad
> based on the subject line).
>
> > Here is the problem description.
>
> Are you assigning homework now?
>
>
>
>
>
> > __DATA__
> > # user_id name email user_uid manager_uid
>
> > jcarter john a...@gmail.com 00206251 00207609
> > mstella mary b...@yahoo.com 00207609 00220458
> > msmith martin c...@gmail.com 00202227 00207609
> > bborders bob d...@gmail.com 00220458 00202003
> > swatson sush e...@yahoo.com 00224981 00207609
> > rcasey rick f...@gmail.com 00202003 00201009
> > ------------------------------------------------------------ ------
>
> > mstella is the boss of jcarter, msmith and swatson;
> > bborders is the boss of mstella;
> > rcasey is the boss of bborders;
>
> > Now I need to replace the manager uid's with the boss id's; for the
> > top-most manager's id, you can replace his manager uid with his user
> > id itself (in this case rcasey is the top-most guy).
>
> So, if manager_uid is not in the user_uid's supplied, then assume user
> answers to higher authority than the mortals in this set.
>
> > i.e the output file should be as follows:
>
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++
> > # user_id name email manager_id
>
> > jcarter john a...@gmail.com mstella
> > mstella mary b...@yahoo.com bborders
> > msmith martin c...@gmail.com mstella
> > bborders bob d...@gmail.com rcasey
> > swatson sush e...@yahoo.com mstella
> > rcasey rick f...@gmail.com rcasey
> > +++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> But now you are contradicting yourself. rcasey has a manager. The
> manager's id is 00201009. rcasey answers to someone who is not him.
>
> > while ()
> > {
> > $line = $_;
> > @lineArray = split (/\s+/, $line);
>
> Don't forget to chomp.
>
> No need for silly intermediate assignments. Are you being paid by the
> line?
>
> while ( ) {
> chomp;
> my @lineArray = split /\s+/;
>
> > if ($lineArray[3] == $lineArray[2])
>
> You are using numeric comparison when the input data are really strings
> (i.e. things like ZIP codes, badge numbers etc -- even when they consist
> entirely of digits -- are not numbers).
>
> > {
> > s/$lineArray[3]/$lineArray[0]/g;
> > }
> > print "$lineArray[0]\t\t$lineArray[1]\t\t$lineArray[3]\n";
> > }
>
> > I am struggling with the part of replacing the the numerical
> > manager_uid with the manager_id.
>
> To my simple mind, it looks like your problem requires two passes over
> data.
>
> I assumed, based on your example, that the output had to be in the same
> order as the input.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my ( %users, @users );
>
> while ( my $record = ) {
> next if $record =~/^#/;
> chomp $record;
> next if $record =~ /^\s*$/;
>
> my @fields = split /\s+/, $record;
> $users{ $fields[3] } = $fields[0];
> push @users, \@fields;
>
> }
>
> for my $user ( @users ) {
> my ($user_uid, $manager_uid) = @$user[3,4];
>
> my $manager = exists $users{ $manager_uid }
> ? $users{ $manager_uid }
> : $users{ $user_uid } ;
> print join("\t", @$user[0 .. 2], $manager), "\n";
>
> }
>
> __DATA__
> # user_id name email user_uid manager_uid
> jcarter john a...@gmail.com 00206251 00207609
> mstella mary b...@yahoo.com 00207609 00220458
> msmith martin c...@gmail.com 00202227 00207609
> bborders bob d...@gmail.com 00220458 00202003
> swatson sush e...@yahoo.com 00224981 00207609
> rcasey rick f...@gmail.com 00202003 00201009
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: - Hide quoted text -
>
> - Show quoted text -
Thanks a bunch.. Sinan.
JC