I have written a PERL script to read files from directory that the filename contains OT. It then takes each line of each file and prints the first 5 characters before the first occurence of a /.

Currently I am getting the error:

Use of uninitialized value in string at rowGrab.pl line 43.

Use of uninitialized value in pattern match (m//) at rowGrab.pl line 41.

#!/usr/bin/perl use strict; my $log_dir = '/home/user1'; my $trans_dir = '/data/directoy1'; my $file; my $participant; my @files; my $line; if (!open(LOG, " >>$log_dir/trans.log")) { syslog("Warning:","Cannot open log file called: $log_dir/trans.log" +); die "Cannot open the file $log_dir/trans.log, $!"; } undef (@files); opendir(DIR,$trans_dir); my @files = grep { /(OT)/ # Filename contains OT && -f "$trans_dir/$_" # and is a file } readdir(DIR); foreach $file (@files) { print STDERR "File: $file\n"; open(FILE,"<$trans_dir/$file") or die "Cannot open $file"; print "$file\n"; for $line (<FILE>) { ($participant) =~/(.....)\//; print "$participant"; close (FILE); } } closedir(DIR);
Can anyone provide some guidance?

Also prior to putting in string matching, I just printed the filename. This however got the error "Out of memory".

The directory contains 5487 files and each file averages 119 MB.

I understand this is a genuine memory issue, I was just wondering if anyone knew a way round it?

Thanks Chris

In reply to Use of uninitialized value in pattern match (m//) by chris01010

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.