As per advice given to me in Find Ethernet Card Manufacturer, I've created my first real module. My module mirrors a copy of a remote file the location specified in my module's variable $oui_location. I would like the script that uses my module to be able to change that value.

I tried including $oui_location in the @EXPORT_OK array and then doing something like this in the calling script:

use OUILookup ('get_oui_owner', 'oui_location'); $oui_location = "oui2.txt";

but it didn't work.

What do I have to do?


package OUILookup; require Exporter; use LWP::Simple; use strict; use warnings; our @ISA = qw(Exporter); our @EXPORT = qw(get_oui_owner); our $VERSION = 1.00; my $oui_address = "http://standards.ieee.org/regauth/oui/oui.txt"; my $oui_location = "oui.txt"; sub get_oui_owner { my ($mac) = @_; my $oui = validate_input($mac); my $oui_entry; my $foundit = 0; if ($oui eq "invalid address format") { return $oui; } else { if (update_ouidb()) { open(OUI, $oui_location) or die "Unable to locate $oui_loc +ation: $!\n"; while (<OUI>) { chomp; if (/$oui/) { $oui_entry = $_; $foundit = 1; last; } } close(OUI); if (!$foundit) { return "OUI not found"; } else { $oui_entry =~ s/\w{2}-\w{2}-\w{2}|^\w{6}//g; $oui_entry =~ s/\(hex\)|\(base 16\)//g; $oui_entry =~ s/^\s+//g; return $oui_entry; } } } } sub update_ouidb { my $errcode = mirror("http://standards.ieee.org/regauth/oui/oui.tx +t", $oui_location); if (!($errcode eq "200" || "304")) { die "problem updating OUI database: $!\n"; } else { return 1; } } sub validate_input { my ($input) = @_; my @bytes; my $oui; if ($input =~ /\w{2}-\w{2}-\w{2}-\w{2}-\w{2}-\w{2}/) { @bytes = split '-', $input; $oui = join '-', $bytes[0], $bytes[1], $bytes[2]; return $oui; } else { return "invalid address format"; } } 1; =head1 NAME OUILookup =head1 SYNOPSIS Find the owner of the IEEE Organizationally Unique Identifier (OUI) for a particular MAC address. OUILookup uses the IEEE database from <http://standards.ieee.org/regau +th/oui/oui.txt>. It will create a local copy of that database if one does not already e +xist, and update a the local copy if it does exist. By default, the local copy will be stored as oui.txt in the same direc +tory as the script. This location is set by the module variable $oui_location. =head1 USAGE use OUILookup; $mac = "00-10-5A-1B-C3-30"; $owner = get_oui_owner($mac); =head1 REQUIRES LWP::Simple =head1 TESTED Perl 5.6.0 on Windows NT (Service Pack 6) =head1 AUTHOR Micah Valine <mvaline@buffnet.net> =cut

In reply to Allowing user to change module variables by mvaline

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.