about foreach

A

Amir

Hi,
I want to use a foreach in PERL in a way that on of the strings inside
it is empty string.
this is my foreach:
foreach my $var ( qw ( Hi Fofo) ) {
..
..
..
}
I want to add to the foreach that the $var will be an empty string and
Hi and Fofo.
do you know how can I do it
thanks in advance

-Amir
 
D

Dave Weaver

Hi,
I want to use a foreach in PERL

That should be "Perl" (the language) or "perl" (the program), not "PERL".
in a way that on of the strings inside
it is empty string.
this is my foreach:
foreach my $var ( qw ( Hi Fofo) ) {
.
.
.
}
I want to add to the foreach that the $var will be an empty string and
Hi and Fofo.
do you know how can I do it

Your problem is that you can't specify an empty string using qw().

so try:

foreach my $var ( '', 'Hi', 'Fofo' ) { ...

or

foreach my $var ( '', qw(Hi Fofo) ) { ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,069
Members
47,675
Latest member
RollandKna

Latest Threads

Top