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

how do i create a list of strings cos when i do the following
my @sportlist = qw('campus relay ' 'Archery' 'Badminton' 'Basketball' +'Cricket' 'Football' 'Hockey' 'Netball' 'Rugby' 'Snooker' 'Squash' 'S +wimming' 'Table Tennis' 'Tennis' 'Tug of War' 'Volleyball');
cos when i refer to $sportlist[0]; it returns "campus" and when i refer to $sportlist1; it returns "relay" instead of returning "archery"

Replies are listed 'Best First'.
Re: lists of strings
by lachoy (Parson) on Apr 06, 2001 at 00:47 UTC

    Don't use quotes and qw together (qw == 'quote words', meaning that whitespace acts as quotes for you). Take off the qw from the front of your list and it should be fine.

    Update: of course, you need to add commas between the quoted items, just like you would with a normal list. (Sorry for not pointing that out earlier.)

    Chris
    M-x auto-bs-mode

      If you remove the qw, you also need commas to separate the words...eg @words = ('campus field', 'football', etc...)
      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      i try that and i get a syntax error "string found where operator is expected"