http://qs321.pair.com?node_id=1120398


in reply to Re^2: Use of uninitialized value in pattern match (m//)
in thread Use of uninitialized value in pattern match (m//)

Having that cleared, now you can concentrate on your regex issue in line 25 ;-)

I thought about your code and there are some other topics:

Here's an untested rewrite based upon these ideas:

#!/usr/bin/perl # http://perlmonks.org/?node_id=1120387 use strict; use warnings; my $log_dir = '/home/user1'; my $log_file = "$log_dir/trans.log"; my $trans_dir = '/data/directoy1'; # Log handles if ( not open my $loghandle, ">>", $log_file ) { # lexical hand +le and three argument form of open() # syslog ... # what's this? die "Cannot open file $log_file: $!"; } # maybe instead of opendir ... and readdir ... my @files = grep { -f } glob( "$trans_dir/*OT*" ); foreach my $file (@files) { print STDERR "File: $file\n"; print "$file\n"; open my $fh, "<", $file # same here; l +exical file handle and 3-arg-form of open() or die "Cannot open $file: $!"; while ( my $line = <$fh> ) { if ( (my $participant) = $line =~ m{(.....)/} ) { # expl +icitely use $line for regex print "$participant"; # only + print when match was found } } close $fh; }