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

Hi, I have an excel sheet with (direction of pin) in one column and pin names in the second column. Like this I have 1000 pins. I converted xls into. Csv file. Now I want a text file with direction followed by pin name. I also want to change the directions of pin name into different string, remaining pin name as it is.
  • Comment on How to process. csv file into a text file

Replies are listed 'Best First'.
Re: How to process. csv file into a text file
by Tux (Canon) on Jul 31, 2017 at 12:53 UTC

    Can you show us what you have tries so far?

    Show data snippets and explain in more detail how you'd like you output to be and what you did to achieve that.


    Enjoy, Have FUN! H.Merijn
Re: How to process. csv file into a text file
by AnomalousMonk (Archbishop) on Jul 31, 2017 at 17:04 UTC
Re: How to process. csv file into a text file
by dbander (Scribe) on Aug 01, 2017 at 01:48 UTC

    $ cat pins.pl #!/usr/bin/perl use strict; use warnings; sub changePinDirectionString { my $newLength = int(rand(10))+2; my $newDirectionString = ''; for (my $newGen = 0; $newGen < $newLength; $newGen++) { my $newChar = chr int(rand(26))+ord('a'); if ($newGen == 0) { $newChar = uc $newChar; } $newDirectionString .= $newChar; } return $newDirectionString; } open my $inputFile, '<', 'pins.csv' or die "$!"; open my $outputFile, '>', 'newpins.csv' or die "$!"; my $inputLine = 0; my $outputLine = 0; while (my $inputCSV = <$inputFile>) { chomp $inputCSV; my ($oldDirection, $oldName) = split /\,/, $inputCSV, 2; my $outputCSV = ''; if ($inputLine == 0) { $outputCSV = 'DirectionString,Name'; } else { my $newDirectionString = changePinDirectionString($oldDirectio +n); $outputCSV = join ',', ($newDirectionString, $oldName); print " Changing $oldName\'s Direction $oldDirection to Direc +tionString $newDirectionString\n"; $outputLine++; } print $outputFile "$outputCSV\n"; $inputLine++; } print "$outputLine lines converted.\n"; close $outputFile; close $inputFile; $ cat pins.csv Direction,Name North,Frank Northeast,George East,Mary Southeast,Bella South,Donna Southwest,Michael West,Leroy Northwest,Bojangles $ ./pins.pl Changing Frank's Direction North to DirectionString Lzihwnot Changing George's Direction Northeast to DirectionString Wigk Changing Mary's Direction East to DirectionString Ma Changing Bella's Direction Southeast to DirectionString Voqnykoqe Changing Donna's Direction South to DirectionString Mfyoaqudlgd Changing Michael's Direction Southwest to DirectionString Cjdyugbzx Changing Leroy's Direction West to DirectionString Vck Changing Bojangles's Direction Northwest to DirectionString Ajk 8 lines converted. $ cat newpins.csv DirectionString,Name Lzihwnot,Frank Wigk,George Ma,Mary Voqnykoqe,Bella Mfyoaqudlgd,Donna Cjdyugbzx,Michael Vck,Leroy Ajk,Bojangles

Re: How to process. csv file into a text file
by QM (Parson) on Aug 03, 2017 at 15:15 UTC
    It may be as simple as a regex, or a bit trickier with Text::CSV. But do give a useful example.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of