Solved

array, init, qw - how to include empty string

Posted on 2003-11-16
4
890 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

730 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