Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Perl Help
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Droozle




PostPosted: Tue Feb 08, 2011 8:31 pm   Post subject: Perl Help

In a university lab we were given this piece of code:


#!/usr/bin/perl

use strict;
use warnings;
use Text::CSV;

my $file = $ARGV[0];
my $csv = Text::CSV->new();


open (CSV, $file) or die $!;

my @fields;

while ( my $record = <CSV>) {

if ( $csv->parse($record) ) {

@fields = $csv->fields();

print "$fields[0] $fields[1] $fields[2] \n";
}

else

{
my $err = $csv->error_input;

print "Failed to parse line: $err";
}
}

close CSV;



my issue is this is the first time i had ever used perl and we were asked to modify the code. Can i please have this piece of code explained line by line.

I know in general what the lines do but not the details of how to use them. I also know that the program is supposed to parse a CSV file.

I am using windows to do this, using "Context" to check notation and notepad to program so there will be no errors when it is transfered to a mac.

Thank you for any help you can give me.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Feb 08, 2011 9:11 pm   Post subject: Re: Perl Help

Droozle @ Tue Feb 08, 2011 8:31 pm wrote:
my issue is this is the first time i had ever used perl and we were asked to modify the code.

Well, there's a first time for most things. Welcome to University! Your complementary copy of Perl documentation is available at http://perldoc.perl.org/

Your friendly TAs likely have their office hours posted on the course webpage, and will probably steer you in the direction of the intention of the assignment.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: