Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: TEXT TO CSV

by Tux (Monsignor)
on Jun 28, 2013 at 11:13 UTC ( #1041221=note: print w/ replies, xml ) Need Help??


in reply to TEXT TO CSV

You are being too vague here.

  • What is the format of the text?
  • Did you search this site for a solution?
  • What have you tried so far?
  • Did you trie readinbg the documentation for Text::CSV and/or Text::CSV_XS already?

Enjoy, Have FUN! H.Merijn


Comment on Re: TEXT TO CSV
Replies are listed 'Best First'.
Re^2: TEXT TO CSV
by Anonymous Monk on Jun 28, 2013 at 11:22 UTC
    hey I saw the code , actually I am new to perl . so from what I see that it is for csv to text , nor the other war around

      the other war around

      Don't mention the war!

      But please do check out Text::CSV which allows you to read and write CSV files.
      ... as brother Tux's pointed out.

      Cheers, Sören

      (hooked on the Perl Programming language)

        sorry about the typo :) text to csv code which is
        use Text::CSV; my @rows; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary att +ribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", "test.csv" or die "test.csv: $!"; while ( my $row = $csv->getline( $fh ) ) { $row->[2] =~ m/pattern/ or next; # 3rd field should match push @rows, $row; } $csv->eof or $csv->error_diag(); close $fh; $csv->eol ("\r\n"); open $fh, ">:encoding(utf8)", "new.csv" or die "new.csv: $!"; $csv->print ($fh, $_) for @rows; close $fh or die "new.csv: $!"; # # parse and combine style # $status = $csv->combine(@columns); # combine columns into a string $line = $csv->string(); # get the combined string $status = $csv->parse($line); # parse a CSV string into field +s @columns = $csv->fields(); # get the parsed fields $status = $csv->status (); # get the most recent status $bad_argument = $csv->error_input (); # get the most recent bad argum +ent $diag = $csv->error_diag (); # if an error occured, explains + WHY $status = $csv->print ($io, $colref); # Write an array of fields # immediately to a file $io $colref = $csv->getline ($io); # Read a line from file $io, # parse it and return an array # ref of fields $csv->column_names (@names); # Set column names for getline_ +hr () $ref = $csv->getline_hr ($io); # getline (), but returns a has +href $eof = $csv->eof (); # Indicate if last parse or # getline () hit End Of File $csv->types(\@t_array); # Set column types
        there is a demarcation on this line # parse and combine style. so like is this entire code helps in converting text to csv or just a part of it
        hey can you elaborate the steps with any example , so that I can get a hang of it

        Hey anonymous monk , I am having the same trouble , what I did is break it into words and print , but it is a crude and a bad way , when there is a comma as a part of text file itself . so if you find any better alternative please do share , hopefully these knowledgeable monks can help you out , they have rescued me a number of times . cheers

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2015-07-28 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls