Click to See Complete Forum and Search --> : Adding a value to an array...


Mike Burdick
09-07-2004, 12:07 AM
I need to make an array of state names, but my array won't work with state names that have two separate words like New York.

@state_names=(Alabama,Alaska,......,New York)

I can get it to work by adding an underscore ( New_York) but since I want the names to appear on screen, it looks bad. Is there any thing I can do?


Thanks

Mike

fredmv
09-07-2004, 12:26 AM
Try instead:my @state_names = ("Alabama", "Alaska", "New York");

Charles
09-07-2004, 05:49 AM
Or, if you want to minimize the load on the compiller:

@state_names = ('Alabama', 'Alaska','New York')

But you might want to use:

@state_names = qw(Alabama Alaska New York)

fredmv
09-07-2004, 03:43 PM
Is Perl kind of like PHP in that if you use double-quotes around a string of text it'll automatically interpret variables within it? I just wasn't sure if single and double quotes in Perl were interchangeable. Thanks for the suggestion.

Charles
09-07-2004, 06:19 PM
Originally posted by fredmv
Is Perl kind of like PHP in that if you use double-quotes around a string of text it'll automatically interpret variables within it? I just wasn't sure if single and double quotes in Perl were interchangeable. Thanks for the suggestion. I think its more that PHP is following Perl - which has something like five different types of quotes.

Nedals
09-07-2004, 11:36 PM
I just wasn't sure if single and double quotes in Perl were interchangeableYes and No.

my $username = 'Charlie';

my $variable = 'Your username is $username'; ## Variable not interpreted.
Will return... Your username is $username

my $variable = "Your username is $username";
Will return... Your username is Charlie