Hello Wise Monks,

Please see the code below and let me know what I am doing wrong here.

sub values; @X; use strict; # P is a package which has some subroutines and variables that I need +to use in my script. use P qw( $CurDir $a2 &guest &guest2 ); my $test = "TEST"; my $testdir = "$CurDir/$test"; # QUESTION: Do I need to use 'my' for these variables? # ERROR: If I don't use 'my' I get the error saying that $test require +s explicit package name. # If I don't use 'my' don't they automatically become global? Are they + not available for use? &values(); &guest(); &guest2( @X, "$test"); # QUESTION: I get an error saying that @X requires explicit package na +me. # How are global variable defined in a perlscript and how can they be +used, for the stuff I am doing in this script? sub values{ @X = ( something something ); # QUESTION: Same error as above! Need Explicit Package name. }

What am I doing here? Why do I keep getting the errors as mentioned above. Don't these variables come under the main Package?

What can I do to resolve these conflicts?

Thank you for your wisdom.

A Learning Monk!


In reply to What am I doing wrong here? by ginju75

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.