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

Instead of listing the individuals values you could use a hash slice:

Something like: @fields{qw/partner kampagne keywordCluster keyword ..../}

And maybe it would be better to use another construct then 'map'... 'for' can be useful, since it alias the element which would mean you need to write $fields{partner} only once instead of twice (when setting the default value).

Something like:

for (@fields{qw/partner kampagne .../}) { $_ = "", unless (defined $_) +; }

Updated, added second code-example

Update2: instead of listing each element in the for you could also use values %fields. This will ensure that there are no undefS in the hash

Replies are listed 'Best First'.
Re^2: Text::xSV question - could this be written better?
by jeffa (Bishop) on May 20, 2005 at 13:46 UTC

    Exactly! A hash slice, but i would also use an array for the field names:

    # untested my @fields = qw( partner kampagne keywordCluster keyword clicks leads orders jaronVerguetung partnerVerguetung profit ); @fields{@fields} = $csvIn->extract(@fields);

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)