in reply to Re: Help w/ regex in filename
in thread Help w/ regex in filename

The flip side of the coin is that 109+ lines of code aren't really needed to reproduce the error. Ideally the code producing the error would be reduced to 5-25 lines of code, and the error message would be a copy/paste of what that 5-25 LOC example produces. Often while going through the exercise of narrowing the problem down to a brief snippet of code that can still reproduce the problem, one discovers what the problem is, eliminating the reason to ask.


Dave

Replies are listed 'Best First'.
Re^3: Help w/ regex in filename
by kcott (Archbishop) on Jul 06, 2013 at 05:52 UTC

    Yes, I absolutely agree and that's why I included the link to "How do I post a question effectively?" (for any follow-up questions) as it recommends posting:

    "... a minimal script that reproduces your problem ..." [original emphasis]

    The main thrust of my first paragraph was to highlight the fact that the error message didn't marry up with the posted code and my following comments were very much guesses.

    I have just noticed that the second version of the OP's code (Re^2: Help w/ regex in filename) has about 40 lines but the error message shows "at script.pl line 112". There's clearly something else going on there that we're not privy to: maybe that's script.pl and the OP is removing part of it; maybe script.pl is a completely different piece of code that's requiring the posted code; maybe it's neither of those.

    -- Ken

Re^3: Help w/ regex in filename
by dcthehole (Novice) on Jul 06, 2013 at 05:20 UTC
    I just have alot of code commented out. Thats why it is at 109+ lines. I havent found anything in those links to help me fix this problem.

      Here's an example of what I mean by "reduce the problem to 5-25 lines of code". The portion of the code you're having trouble with could be reduced to the following test:

      use strict; use warnings; use File::Tail; use POSIX (); my $filename = POSIX::strftime('ServerLog(%m-%d-%Y).log', localtime ); print "\$filename = <<<$filename>>>\n"; my $log = "D:\\ServerTools\\Logs\\$filename"; print "\$log = <<<$log>>>\n"; my $file = File::Tail->new($log); while( defined( my $line = $log->read ) ) { print "\$line = <<<$line>>>\n"; } unlink $log or die $!;

      And then it would become quite clear to see that $log contains a file path. A file path is not a File::Tail object. Your File::Tail object is referred to by $file. Therefore, if you want to invoke the read method on your File::Tail object, you should be invoking it as:

      while( defined( my $line = $file->read ) ) { ...

      It's pretty obvious that the database stuff wasn't the problem you're asking about. So as you're trying to nail down what the issue is by creating some test code, you can immediately eliminate it. Eliminating that, and any other unrelated code-noise, you're left with just the problem, and it becomes easier to see. I hope this exercise is helpful to you.


      Dave