[Israel.pm] FW: FW: FW: check if hash is defined - without the keys

Avishalom Shalit avishalom at gmail.com
Thu Jan 22 06:36:06 PST 2009


someone already did,
read the replies

i think it is 1 key / 8 keys allocated.

2009/1/22 bc.other <bc.other at gmail.com>:
> Also can anyone tell me what the code:
> My $scalar = %hash;
> Does ? since I can't find these examples over the docs web page.
> Thanks
> Chanan
>
> -----Original Message-----
> From: bc.other [mailto:bc.other at gmail.com]
> Sent: Thursday, January 22, 2009 4:23 PM
> To: 'Perl in Israel'
> Subject: RE: [Israel.pm] FW: FW: check if hash is defined - without the keys
>
> I will try to explain what is my purpose:
>
> I have a script that parsing the ARGV argumemts: tvc1=value tvc2=value...tvc5=value or tvc=value (which sets all tvc1..tvc5 to specific value).
> Now, I don't know if the arguments exists in the command line of not...since it an optional arguments.
>
> So....
>
> I can do 2 things:
> 1) my $found = 1;
>   Foreach (keys %tvc))
>   {
>      $found = 0;
>   }
>
>   "Do something" if ($found);
>
> 2) "Do something" if (%tvc);
>
> My question is should option 2 will be OK ? I thought it might send a warnings
> but it did when I tried to do: "Do something" if (defined(%tvc));
> which is I believe to be a mistake....since defined doesn't loop on hash keys - which I thought at start
>
> I found that option 2 is OK by me - no warnings :-)
> Thanks
> Chanan
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Avishalom Shalit
> Sent: Thursday, January 22, 2009 4:02 PM
> To: Perl in Israel
> Subject: Re: [Israel.pm] FW: FW: check if hash is defined - without the keys
>
> i really really recommend the perldoc pages.
> "perldoc perltoc" may be a good place to start
>
> i think that you would really find it useful to study the "context"
> aspect of perl
> try answering these
>
> 1) what do you get when you evaluate a list in hash context ? (how
> about the other way around?)
> 2) what do you get when you evaluate a hash in scalar context?
>
> ---
>  as for your first question ,
> i am not sure why you don't like the idea of looping or why a warning
> is better than an explicit check .
>
> ---
> perldoc -f grep
> perldoc -f keys
>
> 2009/1/22 bc.other <bc.other at gmail.com>:
>> OK, found that I can use the if (%tvc or %tvw) with use strict / warnings it
>> works (no need for defined function).
>> I understood it returns a value ? but can anyone tell me what this value
>> represent ?
>>
>> I tried this code:
>> my %tvc = (1 10);
>> my $sc = %tvc;
>>
>> print $sc; --> printing 1/8 (does it means 1 key, 8 bytes) ?
>> Thanks
>> Chanan
>>
>> -----Original Message-----
>> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf
>> Of Chanan Berler
>> Sent: Thursday, January 22, 2009 3:31 PM
>> To: 'Perl in Israel'
>> Subject: [Israel.pm] FW: check if hash is defined - without the keys
>>
>>
>> Hi All,
>>
>> I got a hash with key1…key25, I am looking to know if the keys are defined
>> or not.
>> But I don't like the way like: if defined($hash{key1}) or …..
>> defined($hash{key5})
>>
>> I also don't like much the idea of looping over the keys…
>> Q: is there a way to check if hash was defined or not….using the defined
>> function showed a warning…
>>
>> PS: I can stop using the use strict / warnings – and try this if (%tvc or
>> %tvw) – and it works…
>>      But I still want to use them…
>>
>> Thanks
>> Chanan
>>
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://perl.org.il/mailman/listinfo/perl
>>
>> _______________________________________________
>> Perl mailing list
>> Perl at perl.org.il
>> http://perl.org.il/mailman/listinfo/perl
>>
>
>
>
> --
> -- vish
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
-- vish



More information about the Perl mailing list