Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

array, init, qw - how to include empty string

Posted on 2003-11-16
4
Medium Priority
?
896 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
kandura earned 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans

597 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