Eskir has asked for the wisdom of the Perl Monks concerning the following question:

Greetings everyone! I've been running into a bit of a pickle as of late. I've recently set up a router on a ZBOX, running PFSense. Now, I want to use PERL to write a little monitoring script that pushes messages to SLACK (a service my company is using to communicate) Now, to get to the point, I'm using the module DateTime in my script. However:
 Can't locate DateTime/Format/Parse.pm in @INC (you may need to install the DateTime::Format::Parse module) (@INC contains: /root/.cpan /usr/local/bin /usr/local/lib/perl5/site_perl/mach/5.20 /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/5.20/mach /usr/local/lib/perl5/5.20 /usr/local/lib/perl5/site_perl/5.20 /usr/local/lib/perl5/site_perl/5.20/mach .) at /usr/local/test/LogfileMonitor/LogfileMonitor.pl line 8.

So far, most of my perl modules were installed using the FreeBSD package manager, which always worked favorably since I'm too... helpless to get CPAN to work on this particular installation. That is, CPAN itself is working, downloads things, builds them, installs them all no problem as far as I can tell. But whenever I try to use them in my code they aren't found. I tried fiddling with the paths too, which is why /root/.cpan is in my @INC path. I'm not quite sure how to phrase a concrete question here, but does anyone have an idea on how I could go about fixing this?

Here is the full code:
package LogfileMonitor; use strict; use warnings; use IO::File; use File::ReadBackwards; use DateTime; use DateTime::Format::DateParse; use LWP::UserAgent; #Don't forget trailing slash. my $filePath = '/var/log/'; my @fileNames = ('gateways.log', 'system.log'); my $slackHandle = my handle my $token = my token # main Function sub LFM(){ my $run = 1; my $test = 0; while($run && $test < 2){ for(my $i = 0; $i <= @fileNames; $i++){ sendMessage($slackHandle, scanFile($filePath,$fileNames[$i +])); sleep(300); } $test++; } } # get relevant Lines from Logfile sub scanFile(){ my $currentTime = DateTime->now(time_zone => "local"); my $handle = File::ReadBackwards->new($_[0] . $_[1]); #print $handle; print "\n"; print $_[0].$_[1]; print "\n\n\n"; for(my $i = 0; $i <= 15; $i++) { my $line = $handle->readline; if(defined $line) { my $messageTime = substr($line, 0, 15); my $messageAgent = substr($line, 16, index($line, ':')); my $message = substr($line, index($line, ':', 16)); $messageTime = DateTime::Format::DateParse->parse_datetime +($messageTime); my $diff = $currentTime->substract($messageTime); if ($diff->minutes() <= 5){ return $line; } else { return undef; } } } } # push Message to Slack sub sendMessage(){ my $Messages = $_[1]; #my $slackHandle = @_[0]; #my $userAgent = LWP::UserAgent->new(); #my $data = qq{{ "text" : "@_[1]"}}; #my $httpRequest = HTTP::Request->new(POST=>$slackHandle); #$httpRequest->header('content-type' => 'application/json'); #$httpRequest->content($data); #my $response = $userAgent->request($httpRequest); #if ($response->is_success){ # print $response->decoded_content; #} #else #{ # print $response->code; # print $response->message; #} print $Messages; } #Call main Function LFM();

It's nowhere near done, and probably not efficient, but it should suffice to produce some kind of output, shouldn't it? EDIT: I fixed up the code some, now I get another error though.
Can't call method "time_zone" on an undefined value at /usr/local/lib/ +perl5/site_perl/mach/5.20/DateTime.pm line 1376.

Replies are listed 'Best First'.
Re: CPAN, FreeBSD (PFSense), Environment?
by toolic (Bishop) on Dec 03, 2015 at 13:27 UTC
    Can't locate DateTime/Format/Parse.pm in @INC
    I can't find a module named DateTime::Format::Parse on CPAN. Is that a private module that you created? Later in your code, you use
    $messageTime = DateTime::Format::DateParse->parse_datetime +($messageTime);

    I do see a DateTime::Format::DateParse on CPAN. I think you want to change:

    use DateTime::Format::Parse;
    to:
    use DateTime::Format::DateParse;
      .. Such a simple mistake. Thanks, that actually fixed it. I feel rather stupid now.
      I think if I was using an IDE it might have notified me of missing/redundant packages in my code, oh well. You never stop learning.

        Don't feel stupid, we all make simple mistakes ;)

        As far as an IDE catching these issues, you don't need one. Your original error stated exactly what you needed to know... I have never used an IDE (just vi/vim) up until recently. On my home Mint Linux laptop, I've started using IntelliJ with the IdeaVim and Camelcade (Perl5) plugins. Works very well. I use PyCharm at work, so I figured having similar IDEs for my Python coding and Perl coding would be handy... it is.