Solved

array, init, qw - how to include empty string

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
use perl to insert into MySQL database 9 144
instmodsh - listing perl modules 2 86
Insert Text into odbc.ini file 15 67
Get a Perl script to return content from a module 7 82
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

828 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