WHY NOT FINDING HASH KEY????

Discussion in 'Perl Misc' started by jason@cyberpine.com, Sep 7, 2006.

  1. Guest

    Hello.

    I'm trying to merge two files by a common key field.

    filea.csv format:
    B1,B2,B3,B4,BK

    fileb.csv format:
    A1,AK,A3,A4


    Need to produce:
    filec.csv:
    A3,A4,B2,B3,B4,BK

    Where file1.csv is using BK=AK to lookup A3 and A4. Every record in
    filea.csv must end up in filec.csv

    Here's the code I have :



    #!/usr/bin/perl
    open FILEC, '>filec.csv' or die "could not open 'matched.csv' $!";
    my %a;
    open FILEA, 'filea.csv' "could not open 'filea' $!";
    while ( <FILEA> ) {
    $_ =~ s/"([^"]*)"/&comma_fixer($1)/ge;
    my @f = split /,/;
    my $key = $f[4];
    #print $key;
    if ( exists $a{$key} )
    {
    print "Duplicate key found in ", $key ," ",$_," ", @f,"\n";
    }
    else
    {
    $a{$key} = \@f;
    }
    }

    open FILEB, 'fileb.csv' or die "could not open 'fileb' $!";
    while ( <FILEB> ) {
    my @b = split /,/;
    my $key = $b[1];
    #BELOW IS THE SUSPECT LINE
    if ( exists $a{$key} ) {
    my $m = join ',', $key,
    $a{$key}[2],
    $b[1],
    $b[2],
    $b[3];
    print FILEC "$m\n";
    print "entry found\n";
    }
    else
    {
    # print "key not found ",$key,"\n";
    }

    }

    close FILEA;
    close FILEB;
    close FILEC;

    sub comma_fixer {
    $string = @_[0];
    $string =~ s/,/ /g; ## replace , with blank,
    return $string;


    =====

    Every single line spits out "key not found".
    What am I doing wrong and is there a better way to approach this?
    , Sep 7, 2006
    #1
    1. Advertising

  2. Paul Lalli Guest

    Paul Lalli, Sep 7, 2006
    #2
    1. Advertising

  3. Guest

    My bad.
    Clearly I'm desperate.

    Any help or information is greatly appreciated.

    Michele Dondi wrote:
    > On 7 Sep 2006 05:03:31 -0700, wrote:
    >
    > >Subject: WHY NOT FINDING HASH KEY????

    >
    > Reposting with an impolite subject line is not going to help you!
    >
    >
    > Michele
    > --
    > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    , Sep 7, 2006
    #3
  4. Paul Lalli Guest

    wrote:
    > My bad.
    > Clearly I'm desperate.


    Which is massively not an excuse for rudeness. This topic is now
    going on in two separate threads on clpm, and one more on
    perl.beginners.

    > Any help or information is greatly appreciated.


    Is this a joke? Is the help you've already been given in these three
    threads somehow deficient?!

    Paul Lalli
    Paul Lalli, Sep 7, 2006
    #4
  5. <> wrote:

    > Subject: WHY NOT FINDING HASH KEY????



    Why is your thread invisible?

    Because it hits *two* scorerules that indicate it can be ignored
    without missing anything of consequence:


    % foolish subjects (no lower case letters)
    Score: -9000
    ~Subject: \c[a-z]

    % foolish subjects
    Score:: -9000
    Subject: ^perl$
    Subject: ^help!?$
    Subject: ^question!?$
    Subject: ^perl question!?$
    Subject: (none)
    Subject: no subject
    Subject: ^$
    Subject: !!!
    Subject: ###
    Subject: ~~~
    Subject: \?\?\?
    Subject: \$\$\$



    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Sep 7, 2006
    #5
  6. "Paul Lalli" <> wrote in news:1157634187.902985.101410
    @m79g2000cwm.googlegroups.com:

    > wrote:
    >> My bad.
    >> Clearly I'm desperate.

    >


    You are about to get a little more desperate.

    Sinan
    A. Sinan Unur, Sep 7, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,842
    Smokey Grindel
    Dec 2, 2006
  2. rp
    Replies:
    1
    Views:
    517
    red floyd
    Nov 10, 2011
  3. ee
    Replies:
    11
    Views:
    396
    Jeffrey Moss
    Jun 15, 2005
  4. Une bévue
    Replies:
    5
    Views:
    149
    Une bévue
    Aug 10, 2006
  5. Replies:
    4
    Views:
    115
    Gary E. Ansok
    Sep 7, 2006
Loading...

Share This Page