A little help on perl coding..

Discussion in 'Perl Misc' started by clearguy02, Nov 21, 2007.

  1. clearguy02

    clearguy02 Guest

    Hi folks,


    I am playing around on the below issue. I have a file, C:\test.txt
    with the following content:

    --------------------------------------------------------------------------------------------------------------
    user id name email employee
    uid manager uid

    jcarter john 00206251
    00207609
    mstella mary 00207609 00220458
    msmith martin 00202227 00207609
    bborders bob 00220458 00202003
    swatson sush 00224981 00207609
    rcasey rick
    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 mstella
    mstella mary bborders
    msmith martin mstella
    bborders bob rcasey
    swatson sush mstella
    rcasey rick rcasey
    --------------------------------------------------------------------------------

    I am struggling to figure it out with hashes and arrays, but not
    getting a desired result.. can some one help me out here?

    Thanks,
    JC
     
    clearguy02, Nov 21, 2007
    #1
    1. Advertisements

  2. clearguy02

    clearguy02 Guest

     
    clearguy02, Nov 22, 2007
    #2
    1. Advertisements

  3. clearguy02

    Dave Weaver Guest

    On Thu, 22 Nov 2007 10:38:18 -0800 (PST),
    What does "not working" mean? It is the most useless problem description
    ever. What does it not do that you would like it to do? What does it do
    that you don't want it to do? Where is the sample input data? What do
    you expect the output to be?

    Please read the posting guidelines for this group. They are posted
    here regularly.

    What do you think that line does?
    ITYM:
    my %users
    Don't use chop(), use chomp() which will correctly remove the input
    record separator no matter how many characters it is.
    for my $uid ( keys %users )
    That won't work, because $users{$uid} is a reference to an array, not
    a hash.
    my $uid = $users{$uid}[2];
    I've no idea what you're trying to do here, but you're not storing the
    nt_id anywhere in the values of the users hash...
    Post again, giving a *short* but *complete* program (including sample data in a
    __DATA__ section) that we can all run, that exhibits the problem you have, and
    explain what the problem is.
     
    Dave Weaver, Nov 23, 2007
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.