Hi Shifus, I was trying to parse a csv and replace cell content according another text file. I was using this:

# This script was excerpted from http://stackoverflow.com/questions/11 +678939/replace-text-based-on-a-dictionary use strict; use warnings; use Text::CSV; open my $fh, '<', 'kegg_pathway_title.txt' or die $!; my %dict = map { chomp; split ' ', $_, 2 } <$fh>; my $re = join '|', keys %dict; open $fh, '<', 'Orthogroups_3.csv' or die $!; while (<$fh>) { next if $. < 2; s/($re)/$dict{$1}/g; print; }

It gives me near expected output but changed the dimension of the original file. Now I can't load the parsed csv in R to do other stuff. Is there anyway to replace cell content of csv without changing dimension?

> grpsTbl <- read.csv("Orthogroups_3.csv", header=T, sep = "\t", row. +names = 1, stringsAsFactors=F) > dim(grpsTbl) [1] 5791 13
> grpsTbl <- read.csv("parsed_with_perl.csv", header=T, sep = "\t", r +ow.names = 1, stringsAsFactors=F) Error in read.table(file = file, header = header, sep = sep, quote = q +uote, : more columns than column names

My orthogroups_3.csv contain multicolumn, each cell may contain 0/1/many values(name). I want exact same csv just values in each cell(names) will be replaced according do the 1st file. Best Regards Zillur


In reply to Parsing csv without changing dimension of original file by zillur

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.