This quite normal. You've got two errors in your code.
First, if I take your first line of input:
Code:
01/29/2013 05:02 PM 391 test2.txt
This will obviously not match your regex. You should test if a match occurred before trying to print $3.
For example, you could change your code to:
Perl Code:
Original
- Perl Code |
|
|
|
This will remove the warning you obtained.
The second error is more subtle, as your code will work nonetheless, but not the way you think and may be inefficient. If you count 38 characters from the start of the line, you get to the last digit of the file size. So, the next character is a space, not a digit. The match will nonethless occur because your regex will backtrack so that eventually the ".{38}" will match:
Code:
1/23/2013 05:08 AM 15,674,256
which, even it it works according to your wish, is not really what you expect. Also, this backtracking can be quite inefficient depending on your input (especially when match fails). I would change your regex to something like this:
Perl Code:
Original
- Perl Code |
|
|
|
$string =~
m/^.
{39}(\d\d\d\d
)(\d\d
)(\d\d
)/;
or
Perl Code:
Original
- Perl Code |
|
|
|
$string =~
m/^.
{38}\
s(\d\d\d\d
)(\d\d
)(\d\d
)/;
the important point (besides correcting the number of characters before your start of capture) being the start of string anchor at the beginning of the regex, which will prevent useless backtracking.