Quicker? Not in the long run as it turns out :-)

Anyway, if the order is different my original code will not work. Try this instead.

use strict; use warnings; use Data::Dumper; open my $firstFH, q{<}, \ <<END1 or die qq{open: < HEREDOC: $!\n}; DISTINGUERE TRA;1;14;507;0,000000242475382686773;0,0000033946553576148 +2;0,000122935019022194;0,00000000041732202096217;9,18246152003019;9,1 +8246152003019 MANCANTE DI;1;56;507;0,000000242475382686773;0,0000135786214304593;0,0 +00122935019022194;0,00000000166928808384868;7,18246152003019;7,182461 +52003019 APPLICARE SU;1;64;507;0,000000242475382686773;0,0000155184244919535;0, +000122935019022194;0,00000000190775781011278;6,9898164420878;6,989816 +4420878 MONTATO IN;1;78;507;0,000000242475382686773;0,0000189130798495683;0,00 +0122935019022194;0,00000000232507983107495;6,70441422322555;6,7044142 +2322555 IMPIEGATO IN;2;180;507;0,000000484950765373545;0,0000436455688836191;0 +,000122935019022194;0,00000000536556884094218;6,49796334575812;12,995 +9266915162 RAGGRUPPARE IN;1;109;507;0,000000242475382686773;0,0000264298167128582 +;0,000122935019022194;0,00000000324915002034832;6,22163211731087;6,22 +163211731087 END1 my $recCt = 0; my @arr1 = (); my %arr1Order = (); while( <$firstFH> ) { chomp; my( $col1, $lastVal ) = ( split m{;} )[ 0, -1 ]; $arr1Order{ $col1 } = $recCt ++; push @arr1, $lastVal; } close $firstFH or die qq{close: < HEREDOC: $!\n}; open my $secondFH, q{<}, \ <<END2 or die qq{open: < HEREDOC: $!\n}; MONTATO IN;1;78;507;0,000000242475382686773;0,0000189130798495683;0,00 +0122935019022194;0,00000000232507983107495;6,70441422322555;6,7044142 +2322555 APPLICARE SU;1;64;507;0,000000242475382686773;0,0000155184244919535;0, +000122935019022194;0,00000000190775781011278;6,9898164420878;6,989816 +4420878 IMPIEGATO IN;2;180;507;0,000000484950765373545;0,0000436455688836191;0 +,000122935019022194;0,00000000536556884094218;6,49796334575812;12,995 +9266915162 DISTINGUERE TRA;1;14;507;0,000000242475382686773;0,0000033946553576148 +2;0,000122935019022194;0,00000000041732202096217;9,18246152003019;9,1 +8246152003019 END2 my @arr2 = ( 0 ) x scalar @arr1; while( <$secondFH> ) { chomp; my( $col1, $lastVal ) = ( split m{;} )[ 0, -1 ]; $arr2[ $arr1Order{ $col1 } ] = $lastVal; } close $secondFH or die qq{close: < HEREDOC: $!\n}; print Data::Dumper->Dumpxs( [ \ @arr1, \ @arr2 ], [ qw{ *arr1 *arr2 } ] ); print q{[} . join( q{; }, @arr1 ) . qq{]\n[} . join( q{; }, @arr2 ) . qq{]\n};

The output is the same.

@arr1 = ( '9,18246152003019', '7,18246152003019', '6,9898164420878', '6,70441422322555', '12,9959266915162', '6,22163211731087' ); @arr2 = ( '9,18246152003019', 0, '6,9898164420878', '6,70441422322555', '12,9959266915162', 0 ); [9,18246152003019; 7,18246152003019; 6,9898164420878; 6,70441422322555 +; 12,9959266915162; 6,22163211731087] [9,18246152003019; 0; 6,9898164420878; 6,70441422322555; 12,9959266915 +162; 0]

Cheers,

JohnGG


In reply to Re^3: Importing data to build an array by johngg
in thread Importing data to build an array by remluvr

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.