Snowman11 has asked for the wisdom of the Perl Monks concerning the following question:

I cant figure out why this doesnt work...
#if the fields are not filled in do this while(scalar @data{value} eq ""){ &adduser;#goes back to asking for array members }do(@data{value} != "" || null){ #if the Values are p +resent Print 'em for ($c1 = 0; $c1 < scalar @data; ++$c1){ print "The", $data[$i]{value} . "\n"; }#end of for(); };#end of else{};
i just changed it to a while loop...

Replies are listed 'Best First'.
Re: Testing Hash Arrays
by ikegami (Patriarch) on Jun 27, 2005 at 16:24 UTC
    I cant figure out why this doesnt work...

    I can't figure ou what you are trying to do.
    while (EXPR) { ... } do (EXPR) { ... }
    is not even close to valid Perl. I think you need to reread perlsyn before proceeding.

    Also, you should use $data{key}, not @data{key}.

    @data{value} != "" || null
    is also quite wrong.
    Fix the sigil:
    $data{value} != "" || null
    Use ne for string comparisons:
    $data{value} ne "" || null
    You can't do $var == value || value. It needs to be expanded to $var == value || $val == value: $data{value} ne "" || $data{value} == null
    The logic makes no sense. Fixed:
    $data{value} ne "" && $data{value} != null
    Use defined to check if something is not null: (It's called undef in Perl.)
    $data{value} ne "" && defined($data{value}
    You need to check defined first to avoid a warning:
    defined($data{value}) && $data{value} ne ""

      Not valid..might help if i give u the entire code this is where im at now.
      #!/perl/bin/perl sub adduser{ print "\nI am in the adduser array now"; } #create the array my @data = ( { query => 'First Name',}, { query => 'Firt Name', }, { query => 'School', }, { query => 'Phone', }, { query => 'Position', }, { query => 'Role', }, ); while (1) { #greeting system("cls"); print "iT For Dominica User Database:\n", "Enter the Number then enter the value.\n"; #number the amt of items in list for (my $i = 0; $i < scalar @data; ++$i) { print "\t", $i + 1, ". ", $data[$i]{query}, ": ", $data[$i]{value} + || "", "\n"; } print "\t0. Done\n"; print "Type a number to choose to change: "; my $number = <STDIN>; chomp($number); if ($number > 6){ print "Type a number to choose to change: "; $number = <STDIN>; chomp($number); next; } elsif ($number == 0 || $number > 6) { last; } --$number; print "\n\nPlease enter your ", $data[$number]{query}, ": "; $data[$number]{value} = <STDIN>; chomp($data[$number]{value}); }; print "While statement"; #if the fields are not filled in do this while(scalar @data{value} eq "" || null){ &adduser;#goes back to asking for array members last; if(scalar @data{value} ne "" || null){ #if the Value +s are present Print 'em for ($c1 = 0; $c1 < scalar @data; ++$c1){ print $data{value} . "\n"; }#end of for(); };#end of if{}; }
        Untested, but lots of stuff fixed. Changes marked with "!!!!"
Re: Testing Hash Arrays
by Fletch (Bishop) on Jun 27, 2005 at 16:24 UTC

    Erm, probably because it's not valid Perl and won't even compile. Not to mention you use a one element array slice. And you mean ne not != when you do a string comparison.

    --
    We're looking for people in ATL

Re: Testing Hash Arrays
by Snowman11 (Novice) on Jun 27, 2005 at 16:53 UTC
    ive fixed my problem so no need to reply thx anyway
      I really think you should tell us how you fixed your problem.