Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, The following code works prefectly fine, but it doesnt complete the job, gets through approx 98% then dies. The idea is attach to a file two columns of data that come from another file using an array (array size of 42000). NOt sure what the problem is, seeing that the array does hold all data? NOt sure if a hash approach is more suitable....but i am a novice with hashs!
while (<FILE2>) { push @col, $_ =~ m/(\S+\s+\S+)/ #unless m/SN\b.*|generated\b.*|No\ +b.*|startpattern.*|endpattern.*/; } open(data, "<TRUE_OUTPUTS"); while(<data>) { $_ =~ s/^(\S\s+\S)/$1 $col[$i++]/; print OUT2 $_; }
sample input: 0 1 0 1 1 0 sample to attach: 0.85 0.20 0.65 0.50 0.23 0.48 output: 0 1 0.85 0.20 0 1 0.65 0.50 1 0 0.23 0.48
thanks

Replies are listed 'Best First'.
Re: inserting array of data into text file
by dragonchild (Archbishop) on Jul 13, 2004 at 13:22 UTC
    Add an e to the end of the regex in the second while loop.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      \e as in esc? $_ =~ s/^(\S\s+\S)/$1 $col$i++\e/; not difference in where it stops
        s/^(\S\s+\S)/$1 $col[$i++]/e; - you have code you need executed in the replacement half of the substitution. Perl doesn't do that unless you tell it to.

        ------
        We are the carpenters and bricklayers of the Information Age.

        Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

        I shouldn't have to say this, but any code, unless otherwise stated, is untested

        meant following not subs e! $_ =~ s/^(\S\s+\S)/$1 $coli++/\e;