Hello
I am processing a lot of files in a directory. I tested the parsing
and it works fine.
open(my $out, ">C:/Documents and Settings/mydir/Desktop/ltvec_data.txt +"); my $first_line = <DATA>; chomp $first_line; while(<DATA>){ chomp; my @fields = split /\t/; my $well_position = $fields[0]; my $sample = $fields[1]; $sample =~ /(\d+)(.*)/; my $barcode = $fields[2]; my $block_id = $fields[3]; my $name = substr($block_id,11); print $out "$well_position\t$1\t$2\t$barcode\t$name\n"; } close $out; __DATA__ Position Sample Barcode A01 12032 B1 NUBI825632 XXXXX Glyc 01/07/2009 B01 12032 L1 NUBI825757 XXXXX Glyc 01/07/2009 C01 12032 L2 NUBI825872 XXXXX Glyc 01/07/2009 D01 12032 L3 NUBI825997 XXXXX Glyc 01/07/2009 E01 12166 B1 NUBI826118 XXXXX Glyc 01/07/2009

This works fine. I have to perform the same parsing on 20+ files in a dir.
I revised the code to process the files files.
my $_dir = 'C:/Documents and Settings/mydir/Desktop/current/Test_Files +'; open(my $out, ">C:/Documents and Settings/mydir/Desktop/current/Test_F +iles/data.txt"); opendir my $dh, "$dir"; # read files in dir #my $first_line = <IN>; #chomp $first_line; #my $i=1; while(my $f = readdir($dh)){ chomp; my @fields = split /\t/; my $well_position = $fields[0]; my $sample = $fields[1]; $sample =~ /(\d+)(.*)/; my $barcode = $fields[2]; my $block_id = $fields[3]; my $name = substr($block_id,11); my $outfile = "$out$name"; print $outfile "$well_position\t$1\t$2\t$barcode\t$name\n"; } closedir($dh); </readmore>

I am getting several errors that are basically telling me that I using uninitialized variables($sample, $name, $_ in scalar chomp and split).
Any clues?

In reply to processing a lot of files by lomSpace

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.