Hi. I'm trying to define two functions differently depending on the user's OS. My code currently looks like this:
package XAMP; use strict; use warnings; use Milkbone; my $commit = 0; my $last_text; # # Some rather kludgy OS-specific code follows # if($^O =~ /Win32/) { eval ' package XAMP; use Win32::GuiText qw(FindWindowLike GetWindowText); sub get_text { } '; } else { eval " use Xmms::Remote; my $rem = Xmms::Remote->new; sub get_text { my $text = $rem->get_playlist_title($rem->get_playlist_pos); $commit = 1 if $text ne $last_text; $last_text = $text; return $text; } " or die $@; } return $text; } " or die $@; } # and then the code continues and later makes use of get_text()
But the problem is that running this gives me errors like:
Couldn't require XAMP.pl for XAMP: Global symbol "$rem" requires expl +icit package name at plugins/XAMP.pl line 30. Global symbol "$text" requires explicit package name at plugins/XAMP.p +l line 30.Global symbol "$rem" requires explicit package name at plug +ins/XAMP.pl line 30. Global symbol "$rem" requires explicit package name at plugins/XAMP.pl + line 30. Global symbol "$text" requires explicit package name at plugins/XAMP.p +l line 30.Global symbol "$text" requires explicit package name at plu +gins/XAMP.pl line 30.Global symbol "$text" requires explicit package +name at plugins/XAMP.pl line 30.Compilation failed in require at (eva +l 26) line 1. main::main() called at /home/bill/milkbone/mos.pl line 64
Any idea why this happens?

TIA,
Bill


milkbone - perl/tk instant messaging - it's the only way to fly

In reply to defining functions at runtime by batkins

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.