values() Function in Perl returns the list of all the values stored in a Hash. In a scalar context it returns the number of elements stored in the Hash.
Note: Values returned from the value() Function may not always be in the same order.
Syntax: values Hash
Returns: list of values in the list context and number of values in the scalar context
Example 1:
%sample_hash = ( 'Geeks' => 'A' ,
'for' => 'B' ,
'Geek' => 10,
'World' => 20);
@values = values ( %sample_hash );
print ( "Values in the Hash are: " ,
join ( "-" , @values ), "\n" );
$values = values ( %sample_hash );
print "Number of values in Hash are: $values" ;
|
Output:
Values in the Hash are A-B-10-20
Number of values in Hash are: 4
Example 2:
%sample_hash = ( 1 => 'Welcome' ,
2 => 'to' ,
3 => 'Geeks' ,
4 => 'World' );
@values = values ( %sample_hash );
print ( "Values in the Hash are " ,
join ( "-" , @values ), "\n" );
$values = values ( %sample_hash );
print "Number of values in Hash are: $values" ;
|
Output:
Values in the Hash are Welcome-World-to-Geeks
Number of values in Hash are: 4
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 May, 2019
Like Article
Save Article