lazy has asked for the wisdom of the Perl Monks concerning the following question:

how to delete a column name from file actual file would be like this i'm using Tie::File to write it as an array of columns, columns are written seperately and so the data

col1,col2,col3,col4,col5,col6

33,12dxc,fvgdf,dfgv,sdfvd

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

expected is

col1,col2,col3,col4,col5

33,12dxc,fvgdf,dfgv,sdfvd

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

22,12cvb,gfbsd,fddg,fdvdf

open (MYFILE, "$filename"); $ColumnNames = <MYFILE>; $array[0] = $ColumnNames;

Replies are listed 'Best First'.
Re: Deleting a Column name from file
by hippo (Archbishop) on Jul 16, 2014 at 08:52 UTC

    perlrun explains the runtime switches and in this case it is likely that -i and -p could prove useful.

    You'll probably also want to look at the s/// operator as explained in perlop.

    Have you tried writing out what you want to acheive as an algorithm instead of just the starting and ending datasets? This exercise will usually prove helpful.

Re: Deleting a Column name from file
by Anonymous Monk on Jul 16, 2014 at 08:52 UTC

    A question true to your username, so here's a very lazy answer:

    perl -i.orig -pe 's/,col6//' FILENAME

    It does what you specified by clobbering all instances of ",col6" in the file.

    If you want more, read and follow this: How do I post a question effectively?

Re: Deleting a Column name from file
by Anonymous Monk on Jul 16, 2014 at 08:55 UTC
    you don't need perl for this, its one line in one file :)

      thanks for the replies... actually i write this file using perl using module Tie::File ! which runs fast but writing last column takes longer time! so just placed another column name it ran fast, now i have a prob of removing column name so i just posted. i have no clue why it writes so slow i shuffled coulmns but everytime the last column written in file is v slow. i tried it for 1 million records !

      i use the following code to fetch the column names, i need to delete that last column (dummy) to be deleted while writing it in file

       $ColumnNames = <MYFILE>;
Re: Deleting a Column name from file
by Anonymous Monk on Jul 16, 2014 at 16:38 UTC
    You are going to massive amounts of unnecessary effort. This file can be read one line at a time, each line split by comma, then the resulting array spliced to remove the column before joining it again by comma. There are no brownie-points for needless complexity.