about foreach

about foreach

am 19.09.2007 11:38:09 von 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

Re: about foreach

am 19.09.2007 11:51:52 von Dave Weaver

On Wed, 19 Sep 2007 09:38:09 -0000, Amir wrote:
> 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) ) { ...