Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Spreadsheet::ParseExcel format help

by cyates (Novice)
on Jul 16, 2013 at 21:51 UTC ( [id://1044665]=perlquestion: print w/replies, xml ) Need Help??

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

I am using Spreadsheet::ParseExcel to read data in from an excel file, and then writing that data to a .txt file. The program runs fine, but my data is the form of: 'Part Number, ' 'Vendor, ' 'Vendor Part Number, ' 'Price, ' Is there a way to format Spreadsheet::ParseExcel or use a regex to get rid of the ' ,'?

Replies are listed 'Best First'.
Re: Spreadsheet::ParseExcel format help
by runrig (Abbot) on Jul 16, 2013 at 21:58 UTC

    Is there really comma separated values in each cell, or is the file actually a CSV file?

    Either way, you could probably use Text::CSV to parse the string into an array of values.
Re: Spreadsheet::ParseExcel format help
by ww (Archbishop) on Jul 16, 2013 at 23:55 UTC
    my @commaless_array = split /,/ record ...and then write it out to the text file of your choice with whatever formatting you want.
    See perldoc -f split from your CLI.
    If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
Re: Spreadsheet::ParseExcel format help
by Anonymous Monk on Jul 17, 2013 at 03:49 UTC

      Simplest answers are the best =] working with CSV values would be good, my problem was the annoying single quotes ' ' and this little code took care of it for me:

      #!/usr/bin/perl use strict; use warnings; my $sometext = 'somefile.txt'; open(SOME, $sometext); while(<SOME>) { chomp; $a = $_; $a =~ s/'//g; print $a; }
        Please don't use $a or $b as variable names -- NOT EVEN IN EXAMPLES; they have specialized behaviors for use when sorting... and they don't provide any indication of their content. Some short (1 letter) possibilities: $s (for "string"); $l for line; etc. etc.

        P.S: syntacticly trivial, but annoying: You changed the character you wanted removed from a comma in your OP to a single quote in your 'simplest answer.' Perhaps one was a typo, and in this thread, probably just set off my pre-coffee compulsiveness/ill-humor/whatever... but like $a, it sets a bad example for future readers.

        If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.

Log In?
Username:
Password:

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

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

    No recent polls found