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

what does this do? can someone help?
our @weekly_date_list; @weekly_date_list = (@weekly_date_list , "$date");
and what does our mean in this case?
I need it inorder to understand a code!
thanks in advance

Replies are listed 'Best First'.
Re: about arrays...
by davorg (Chancellor) on Sep 27, 2001 at 14:04 UTC
    our @weekly_date_list;

    This allows access to the package variable @weekly_date_list within the current block.

    @weekly_date_list = (@weekly_date_list , "$date");

    This stringizes $date and then adds it to the end of the @weekly_date_list array. I think that that author probably meant to write:

    push @weekly_date_list, $date;
    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      what do u mean by current block?
      I understand "my" is used for local variable.
      so is "our" a global variable??
        what do u mean by current block?

        A block is a set of statements that are contained between a pair of braces. Blocks can be associated with subroutines, loops, conditionals and a number of other Perl constructs. There is also an implicit block around all of the code in a file.

        our (like my) is lexically scoped, this means that its effects are only felt until the end of the innermost enclosing block.

        I understand "my" is used for local variable.
        so is "our" a global variable??

        Pretty much. It exposes package variables within a given block. The differences between package and lexical variables and the subtle differences between my, local and our can get a little complex. I recommend you read the section on "Scoped Variable Declarations" that starts on p130 of the 3rd edition of the Camel.

        --
        <http://www.dave.org.uk>

        "The first rule of Perl club is you don't talk about Perl club."

Re: about arrays...
by busunsl (Vicar) on Sep 27, 2001 at 14:00 UTC
    It appends $date to the array.

    Better would be:

    push @weekly_date_list, $date;
    Because this doesn't create a new list to replace the old.
Re: about arrays...
by Ido (Hermit) on Sep 27, 2001 at 20:38 UTC
    our() generally creates a lexcial alias to the global variable(In the current package..) in order to let you use the global with strict on.