[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


how to use Inotify2.pm with perl

Posted on 2010-01-07
Medium Priority
Last Modified: 2013-11-05
I am noob in perl.

I am reading this : http://www.ibm.com/developerworks/linux/library/l-ubuntu-inotify/index.html
and its saying, perl coder can use Inotify2.pm , with perl code

question is, how will i use thie inotify2.pm with perl code ?? [ http://search.cpan.org/~twerner/Linux-Inotify-0.05/lib/Linux/Inotify.pm]

when i run its ,its say

Can't locate Linux/Inotify2.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at iwatch.pl line 3.
BEGIN failed--compilation aborted at iwatch.pl line 3.

that mean i dont have Inotify2.pm,

from where will i get Inotify2.pm and how will i run this code ??


use Linux::Inotify2;

my $inotify = new Linux::Inotify2
        or die "Unable to create new inotify object: $!";

 # for Event:
 Event->io (fd =>$inotify->fileno, poll => 'r', cb => sub { $inotify->poll });

 # for Glib:
 add_watch Glib::IO $inotify->fileno, in => sub { $inotify->poll };

 # manually:
 1 while $inotify->poll;

 # add watchers
 $inotify->watch ("/tmp/ifile.txt", IN_ACCESS, sub {
    my $e = shift;
    my $name = $e->fullname;
    print "$name was accessed\n" if $e->IN_ACCESS;
    print "$name is no longer mounted\n" if $e->IN_UNMOUNT;
    print "$name is gone\n" if $e->IN_IGNORED;
    print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW;

    # cancel this watcher: remove no further events

Open in new window

Question by:fosiul01
  • 5
  • 4
  • 2
LVL 39

Accepted Solution

Adam314 earned 1000 total points
ID: 26200540
To install, run:  cpan Linux::Inotify2

If this is the first time running cpan, you will be asked some questions: unless you know otherwise, accept the default.  You need to run this as root.
LVL 29

Author Comment

ID: 26201242
hi thanks
its installed but now its saying

[root@web perl]# perl iwatch.pl
Can't locate object method "io" via package "Event" (perhaps you forgot to load "Event"?) at iwatch.pl line 9.

what does it meant??
LVL 39

Expert Comment

ID: 26201683
The code:
means run the io subroutine in the Event package.  The error is telling you that it can't find this subroutine in this package, and that it might be because you forgot to load the Event module.  To load the Event module, add this code to the top of your program:
    use Event;
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 29

Author Comment

ID: 26202088
Thanks, now its saying this

[root@web perl]# perl iwatch.pl
Can't locate object method "add_watch" via package "Glib::IO" (perhaps you forgot to load "Glib::IO"?) at iwatch.pl line 13.

i tryed to use Glib;
but its not workig

what shall i do now ??

Expert Comment

ID: 26202726
Try:  use Glib::IO;

BTW, You can try to have perl install all dependent packages this way:

PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Linux::Inotify2"
LVL 29

Author Comment

ID: 26204126
Hi sorry, if i add Glib::IO
its say

[root@web perl]# perl iwatch.pl
Can't locate Glib/IO.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at iwatch.pl line 5.
BEGIN failed--compilation aborted at iwatch.pl line 5.

now, i tryed

cpan Glib/IO.pm, but it does not find anything

if i execute this
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Linux::Inotify2"

it say, it up2 date

Assisted Solution

sakman earned 1000 total points
ID: 26204422
Anytime you see something like "Can't locate Glib/IO.pm in @INC" for a module then either that module is missing or is located someplace not included in the search path (the array @INC).

Since Linux::Inotify2 is up to date, try,

PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Glib::IO"
LVL 29

Author Comment

ID: 26204703
Sorry to continue with the same problem for long...

i executed your command

[root@web ~]# PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Glib::IO"
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Thu, 07 Jan 2010 00:31:40 GMT
Warning: Cannot install Glib::IO, don't know what it is.
Try the command

    i /Glib::IO/

to find objects with matching identifiers.


Expert Comment

ID: 26205237
OK, it looks like the package name is just called "Glib" - which includes IO and other packages.

So try to install "Glib" or just download the source at http://search.cpan.org/~tsch/Glib-1.222/Glib.pm.

Expert Comment

ID: 26310915
Did this work out for you?
LVL 29

Author Comment

ID: 26341356
Sorry i was working on another project, so did not able to look into this

I will try today

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month19 days, 12 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question