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

Dear monks,

In my program i have to use the pragma use strict, and also i have to store in array the following elements a to z. If i use the below code i am getting Bareword error. If i omit the line use strict i get array values from a to z. How to solve this.

use strict; my @a = (A..Z); print join "\n", @a;

Replies are listed 'Best First'.
Re: How to solve this using use strict ?
by GrandFather (Saint) on Jul 06, 2005 at 04:37 UTC

    my @a = ('A'..'Z');

    Without the quotes A and Z are "bare words" that could be interpreted as something other than the manafest constant strings that you intended. Consider for example:

    sub A { 'K'; } my @a = (A..'Z'); print join "\n", @a;

    Perl is Huffman encoded by design.
Re: How to solve this using use strict ?
by virtualsue (Vicar) on Jul 06, 2005 at 04:50 UTC
    Whenever you see a bareword error, it usually means that you have a string in your code that needs to be quoted. Put quotes around the two strings that your Perl interpreter identified as bare words and see if that doesn't make the problem go away.
Re: How to solve this using use strict ?
by jbrugger (Parson) on Jul 06, 2005 at 04:39 UTC
    #!/usr/bin/perl -w use strict; my @a = ("A".."Z"); print join "\n", @a;
    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
      I might have just changed the double-quotes to single-quotes to avoid unnecessary interpolation of the vars...
      my @a = ('A'..'Z');
      rather than
      my @a = ("A".."Z");


      Update: I overlooked the post by GrandFather, which mentioned the single quotes. oops.
Re: How to solve this using use strict ?
by rinceWind (Monsignor) on Jul 06, 2005 at 15:31 UTC

    This brings to mind merlyn's recent meditation: Why use strict is good, and barewords are bad

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)