How to initialize an array of String using Perl qw()

Posted by Joys of Programming on in Perl

The perl function qw() is the simplest way by which strings can be initialized.


my @day1 = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');

my @day2 = qw (Sunday Monday Tuesday Wednesday Thursday Friday Saturday);

print $day1[6];

See how day1 and day2 are initialized. qw does not require each string to be declared in quotes and separated by commas

Reblog this post [with Zemanta]


Tags: , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.