Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/Variables and Data Types/Casting
From NetSec
Revision as of 01:00, 19 July 2012 by Chantal21I (Talk | contribs) (moved Perl/Basics/Casting to Perl/Basics/Variables and Data Types/Casting)
Casting is the process of transitioning from one data type to another. This is typically done using curly brackets {} preceeded by a data type designator ($,%, or @).
- To cast a hash reference back to a hash:
my %hash; my $hashref = \%hash; #create the hash reference my %casted = %{$hashref}; #Cast back to a hash. |
- To cast a list of keys in a hash into an array:
my @casted = @{keys %hash}; |
- To cast a scalar value to an integer:
my $integer = int($scalar); |