in reply to Array condition always true

my @header_present=" "; #clearing the data here

This places one element into @header_present, which is a string consisting of a single space. Arrays are true if they contain at least one item, that's the case after this piece of code.

The right thing would be not to assign anything; my @var automatically creates a new, fresh, empty array.

If you want to clear an array later on, you can write

# recommended: @var = (); # or a bit more excotic: $#var = -1;

You can read more about that in perldata.

You would do well to adapt a consistent code indenting style. See perlstyle for example.

Replies are listed 'Best First'.
Re^2: Array condition always true
by Anonymous Monk on Mar 20, 2011 at 11:36 UTC

    How to free it its a scalar variable instead of an array meaning if @header_present is $header_present

    Will $header_present=" "; work?

      What do you want to achieve? $header_present = ''; will set $header_present to an empty string. $header_present = undef; will set $header_present to undef which is the uninitialised state. The one you need depends on code you've not shown us.

      True laziness is hard work