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

Hi folks

I desperately need your help. I was looking all evening for a solution to my problem. I'm using Perl 5.10.1 on a 64Bit Ubuntu.

I wanted to play around with Net::Pcap, so I have installed it the command apt-get install libnet-pcap-perl

For my test, I wanted to use an example shown on the CPAN page of Net::Pcap

#!/usr/bin/perl -w use Net::Pcap; my $err = ''; my $dev = pcap_lookupdev(\$err); # find a device # open the device for live listening my $pcap = pcap_open_live($dev, 1024, 1, 0, \$err); # loop over next 10 packets pcap_loop($pcap, 10, \&process_packet, "just for the demo"); # close the device pcap_close($pcap); sub process_packet { my($user_data, $header, $packet) = @_; # do something ... }

If I try to run that script, I get this Answer: "Undefined subroutine &main::pcap_lib_version called at ./test.pl line 7"

However, if I expand the pcap-commands to e.g my $dev = Net::Pcap::pcap_lookupdev(\$err); I don't get any error. It just does nothing because the script is not finished yet, but that's not the point.

Has anyone an Idea what my problem is?

SOLUTION: The funtions need to be exported by request  use Net::Pcap qw(:funtions); Thank you Corion!

Replies are listed 'Best First'.
Re: Can't use moduels by 'use' directive
by Corion (Patriarch) on May 30, 2011 at 20:58 UTC

    See Net::Pcap. The functions are only exported on request. Either list them all on the use line, or import them all:

    use Net::Pcap qw(:functions);
      Omg... Thank you very much Corion. I could bang my head at the wall that I didn't see this. To bad the example on that page is not complete.
Re: Can't use moduels by 'use' directive
by JavaFan (Canon) on May 30, 2011 at 21:02 UTC
    Are you sure the code you posted is the code you tried to run? Line 6 of the posted program is my $err = ''; - it seems unlikely that that line triggers the error.
      You're right, I'm sorry that output wasn't correct. It should be line 7. Thank you