in reply to Text::xSV question - could this be written better?

You can use a hash slice for the first part, and just a foreach loop for the second part, but the key is to just store the key names so they aren't repeated -- also you now just have a single place to make changes in, so much easier to maintain.
my %fields; #$csvIn is a Text::xSV object. my @field_names = qw/ partner kampagne keywordCluster keyword clic +ks leads orders jaronVerguetung partnerVerguetung profit /; while ($csvIn->get_row()) { @fields{@field_names} = $csvIn->extract( @field_names ); foreach my $k ( @field_names ){ $fields{$k} = "" unless defined $fields{$k}; } }
Update: changed @k to @field_names to be a little more descriptive.

Replies are listed 'Best First'.
Re^2: Text::xSV question - could this be written better?
by tphyahoo (Vicar) on May 20, 2005 at 14:15 UTC
    Yes davidrw, very nice indeed, I just dropped it in and it worked. Only I wound up using @field_names instead of @k. Any particular (idiomatic) reason for that variable name?

    Now, going back to bone up on hash slices... which I was already doing when other stuff came in to distract me... Is this a hash slice?

    Thanks again.