Comments on: Perl Versus Ruby on CSV https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/ Linux. GNU. Freedom. Sun, 13 May 2018 18:21:35 +0000 hourly 1 https://wordpress.org/?v=5.0-alpha-43006 By: Harley Pig https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24242 Thu, 04 Jan 2007 14:45:45 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24242 My server went south. I'm on a Linode and the last image they had was 2005.0 ... they've since upgraded to 2006.1 but with all the changes the installation wasn't quite right.

I've been working on a HowTo for Gentoo and Linode and having to re-install a bunch of times to get everything working.

It should be back up in a couple of weeks (I can't spend more than a few hours a week on it).

BTW, a preview button would be nice. :]

]]>
By: Aaron https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24128 Wed, 03 Jan 2007 15:19:50 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24128 phoenyx- The Perl script is reading the file line by line.

harleypig- Whatever happened to your blog, eh?

]]>
By: Harley Pig https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24126 Wed, 03 Jan 2007 14:32:06 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24126 No, the construct that's being used in the perl examples is reading a line at a time.

]]>
By: phoenyx https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24070 Tue, 02 Jan 2007 21:59:57 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24070 The ruby version is reading the file in a line at a time, whereas it looks like the Perl version reads the whole file into memory at the beginning. That may explain some of slowness of the ruby version.

]]>
By: Harley Pig https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24042 Tue, 02 Jan 2007 15:15:41 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24042 Oops ... get rid of the ', $maxfields' in the split command. Since you're getting rid of a newline at the end of the line and field 182--your last field--it's apparent that you only have that many fields in your record.

]]>
By: Harley Pig https://pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24040 Tue, 02 Jan 2007 15:11:36 +0000 http://www.pthree.org/2006/12/29/perl-versus-ruby-on-csv/#comment-24040 #!/usr/bin/perl -w

use strict;

open my $IN, "UNIVERSE.csv";
open my $OUT, ">UNIVERSE_WEIGHTED.csv";

my $counter = 0;

my @names = qw( ppp00 ppp04 pri01 pri03 pri05 pri99 );
my @fields = qw( 154 155 161 163 165 182 );

while ( <$IN>) {

chomp; # This strips the newline from the line less expensively
# than s/\n//

if ( $counter == 1 ) {

print $OUT "$_,\"weight\"\n";
next;

}

my %vtr;
@vtr{ @names } = ( split /,/, $_, $maxfields )[@fields];

$weight = 0;
$counter++;

$weight += .5 if $vtr{ 'ppp00' } eq '"R"');

for ( @fields ) {

$weight += $vtr{ $_ } eq '"D"' ? -1 :
$vtr{ $_ } eq '"R"' ? 1 :
0;

}

print $OUT "$_,\"$weight\"\n";
print "Processed: $counter\r";

}

print "\n";

]]>