OK not shortest :-/ but fastest :-), vis:

print "Writing file...\n"; open FILE, ">test.txt" or die $!; my $line = join "\t", (1..1000); print FILE $line, "\n" for (1..600); close FILE; print "File written!\n"; # Original method open PROFILES, "<test.txt" or die $!; my @matrix = (); my $start = time; while (<PROFILES>) { @profile = split (/\t/, $_); while ($j <= $#profile) { $matrix[$j]->[$i] = $profile[$i]; $j++; } $i++; $j = 0; } print "Original method takes ", time-$start, " seconds\n"; close PROFILES; # my method open PROFILES, "<test.txt" or die $!; @matrix = (); $start = time; while(<PROFILES>){ push @matrix, [split"\t"]; } print "My method takes ", time-$start, " seconds\n"; close PROFILES; # Blakem's method open PROFILES, "<test.txt" or die $!; @matrix = (); $start = time; @matrix = map[split],<PROFILES>; print "Blakem's method takes ", time-$start, " seconds\n"; close PROFILES; __DATA__ C:\>perl matrix.pl Writing file... File written! Original method takes 18 seconds My method takes 7 seconds Blakem's method takes 52 seconds

PS I slightly modified the original code to remove the infinite loop so it actually will work to test it.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Re: Re: Fast Matrix Load by tachyon
in thread Fast Matrix Load by Evanovich

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.