Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Generating csv file.

by maestromani (Initiate)
on Mar 03, 2011 at 10:36 UTC ( [id://891191]=perlquestion: print w/replies, xml ) Need Help??

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

Hi There,

I’m in the process of export records from clearquest in csv file using perl. Since I’m using cqperl to run my perl script I can’t use any extra function like “Text::CSV”, normal perl I can’t use because I use lot of Clearquest API.


Problem I’m facing is some of the field in CQ has value as “bob Carriage return tom Carriage return Mike” while impoting in csv these guys are moving as separate row. This is causing unwanted problem for me. How can I move these values as bob-tom-mike or move it to different column.

Replies are listed 'Best First'.
Re: Generating csv file.
by jethro (Monsignor) on Mar 03, 2011 at 11:07 UTC

    Whatever perl you are using, you can always copy the source code of a module from CPAN and incorporate it into your script. If Text::CSV solves your problem then use it.

      In the case of Text::Csv you can certainly copy the source code provided you clearly attribute its original source and licensing terms on the copied file. - it is licensed under the same terms as perl. From the GPL

      You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy.

      However, I'd be cautious, however, generalizing that to all CPAN modules. There are quite a number of licensing models for CPAN modules. Some, for example, do not allow commercial use. So as a general rule, one should always check the licensing before copying, and sometimes even using a CPAN module.

        So if the script is distributed, it needs to a GPL license. It doesn't force one to start distributing the script, so you're the OP is in the clear if it's for internal use.
Re: Generating csv file.
by Neighbour (Friar) on Mar 03, 2011 at 14:09 UTC
    Assuming your CSV-data is RFC4180-compliant, there's only a few things you need to take heed of:
    • There is a special character that delimits fields (usually ,).
    • There is a special character that delimits records (rows) (usually LF, but CRLF also tends to happen)
    • When any of those special characters is used as data in a field, the field's data is surrounded by another special character (usually "). In such a case, any occurrence of this character (") in that same field's data needs to be doubled. (So any " in the data becomes "")
    In order to be able to detect CRLF's in your data when reading the csv line-by-line, you only need to count the number of times the special character " occurs in the line read. If this is an odd amount, there was a CRLF in the data, and you need to continue reading lines until you encounter another line with an odd amount of "'s. Otherwise the data's all there.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://891191]
Approved by chrestomanci
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found