CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...: Re: [gopsi1234] Generate a C file from CSV file using perl: Edit Log



Zhris
Enthusiast

Jul 1, 2014, 3:38 AM


Views: 50874
Re: [gopsi1234] Generate a C file from CSV file using perl

Hi Gopsi,

Perhaps you could try and write the script yourself based on what you have learnt so far and if you get stuck post the code / problem. I'm sure you will agree that this is the best approach if you want to develop your Perl skills.

With regards to using the header to fetch the associated values, you will probably want to use hash slices http://perldoc.perl.org/perldata.html#Slices.


Code
my @head_list_print = qw( vendorid conf_width ); 

...

my %row_hash;
@row_hash{@head_list} = @row_list; # head_list and row_list being the corresponding rows split into lists.
printf "%s, %s\n", @row_hash{@head_list_print};


Even better though, use a CSV parsing module such as Text::CSV (https://metacpan.org/pod/Text::CSV) to do the hard work for you, Note the getline_hr method to achieve the above.

Regards,

Chris


(This post was edited by Zhris on Jul 1, 2014, 3:51 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Jul 1, 2014, 3:40 AM
Post edited by Zhris (Enthusiast) on Jul 1, 2014, 3:44 AM
Post edited by Zhris (Enthusiast) on Jul 1, 2014, 3:48 AM
Post edited by Zhris (Enthusiast) on Jul 1, 2014, 3:51 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives