Solved

array, init, qw - how to include empty string

Posted on 2003-11-16
4
885 Views
Last Modified: 2008-03-06

How to do initialize an array with an empty string with qw?  Can you do it with qw?

@a = qw(password1 password2 "" hotchina);

I want the 3rd value to be an empty string - no password - but
it expands as the two quotes.

@a = ("this", "that", "", "andthis");  works just find.

Just curious.

Thanks
0
Comment
Question by:hank1
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 50 total points
ID: 9760154
No, you can't do that.
qw is more or less the same as split ' ', q( STRING ) , except that your array is created at compile time.
As in the split, it is not possible to get empty strings.

You could use @a = ( qw(password1 password2), '', qw(hotchina) );
0
 
LVL 2

Expert Comment

by:ext2
ID: 9775300
You might be able to make use of this:

  @a = map {$_ eq '""' ? undef : $_} qw(password1 password2 "" hotchina);
0
 

Expert Comment

by:kerharo
ID: 9776291
This gives an "undef" rather than an empty string, use:
@a = map {$_ eq '""' ? "" : $_} qw(password1 password2 "" hotchina);
HTH
0
 
LVL 2

Expert Comment

by:ext2
ID: 9776309
yup.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question