Link to home
Start Free TrialLog in
Avatar of fosiul01
fosiul01Flag for United Kingdom of Great Britain and Northern Ireland

asked on

how to use Inotify2.pm with perl

HI,
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 ??
thanks

#!/usr/bin/perl

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
    $e->w->cancel;
 });

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fosiul01

ASKER

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??
Avatar of Adam314
Adam314

The code:
    Event->io(...)
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;
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 ??
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"
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.


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.
Did this work out for you?
HI
Sorry i was working on another project, so did not able to look into this

I will try today