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

x
?
Solved

how to use Inotify2.pm with perl

Posted on 2010-01-07
11
Medium Priority
?
2,191 Views
Last Modified: 2013-11-05
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

0
Comment
Question by:fosiul01
  • 5
  • 4
  • 2
11 Comments
 
LVL 39

Accepted Solution

by:
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.
0
 
LVL 29

Author Comment

by:fosiul01
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??
0
 
LVL 39

Expert Comment

by:Adam314
ID: 26201683
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;
0
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

by:fosiul01
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 ??
0
 
LVL 4

Expert Comment

by:sakman
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"
0
 
LVL 29

Author Comment

by:fosiul01
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
0
 
LVL 4

Assisted Solution

by:sakman
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"
0
 
LVL 29

Author Comment

by:fosiul01
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.


0
 
LVL 4

Expert Comment

by:sakman
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.
0
 
LVL 4

Expert Comment

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

Author Comment

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

I will try today
0

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