Hi Shawn,
Here is the revised code fragment: open ( DATA, "< $INBOX/nlsrysows001_2090125.dat") || die "Cannot open source file: $!"; open ( FILE, "> $INBOX/request.dat") || die "Cannot open request file: $!"; chomp(@list=<DATA>); foreach $entry(@list) { $entry =~ /\[([a-z0-9]{5})\]/; $req_id=$1; print "$req_id\n"; } But I still get errors !! 8252c Use of uninitialized value in concatenation (.) or string at ./magic.pl line 19, <DATA> line 1044. 8252c Use of uninitialized value in concatenation (.) or string at ./magic.pl line 19, <DATA> line 1044. 8252d Use of uninitialized value in concatenation (.) or string at ./magic.pl line 19, <DATA> line 1044. 8252d Use of uninitialized value in concatenation (.) or string at ./magic.pl line 19, <DATA> line 1044. What is especially puzzling is that I have seen notation such as 'print "$1\n";' in other scripts. Regards, Bill Harpley -----Original Message----- From: Mr. Shawn H. Corey [mailto:shawnhco...@magma.ca] Sent: Monday, January 26, 2009 4:32 PM To: Bill Harpley Cc: beginners@perl.org Subject: Re: Simple regex problem has me baffled On Mon, 2009-01-26 at 16:20 +0100, Bill Harpley wrote: > foreach $entry(@list) > { > > $entry =~ /\[([a-z0-9]{5})\]/; > > print "$1\n"; # print to screen > > # print FILE "$1\n"; # print to file > } If there is no match, you are printing a uninitialized value; try: foreach my $entry ( @list ){ if( $entry =~ m{ \[ ( [a-z0-9]{5} ) \] }msx ){ my $request_id = $1; # ... } } -- Just my 0.00000002 million dollars worth, Shawn "It would appear that we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years." --John von Neumann, circa 1960 -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/