in reply to insert null in missing places of csv

Hello ukhare

what have you tried so far? I'm not a csv expert but you can do for sure something similar to:

@current_row = map { $_ ? $_ : qq(NULL) } @current_row

you can also do the job in a oneliner

perl -lanF',' -e "print join',',map {$_ ? $_ : 'NULL'} @F " testcsvnul +l.txt A,NULL,D,E,F L,T,NULL,G,Q C,D,E,NULL,L

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: insert null in missing places of csv
by ukhare (Novice) on Feb 19, 2016 at 16:42 UTC

    NOT WORKING :

    <$ perl -lanF',' -e "print join',',map {$_ ? $_ : 'NULL'} @F " 1.txt Bareword found where operator expected at -e line 1, near "1.txt" (Missing operator before txt?) Bareword found where operator expected at -e line 1, near "1.txt" (Missing operator before txt?) syntax error at -e line 1, near "1.txt " Execution of -e aborted due to compilation errors.

      My impression is that Discipulus's
          perl -lanF',' -e "print join',',map {$_ ? $_ : 'NULL'} @F " testcsvnull.txt
      is running under Windoze, and your
          <$ perl -lanF',' -e "print join',',map {$_ ? $_ : 'NULL'} @F " 1.txt
      is running under *nix. Fix the quoting as appropriate to your OS shell and give it another try.


      Give a man a fish:  <%-{-{-{-<

        is my impression too ;=)

        thanks for defending my -c honorability. Once i used to post oneliners in both quoting flavors but now i became too lazy. Maybe a comment like #warning winz doublequotes can be used.

        The real pity is that is impossible (from what i know) to convince that os to accept another quoting character.

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        PERFECT