Solved

array, init, qw - how to include empty string

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now