fun with list and array variables
This commit is contained in:
parent
2ba7140b77
commit
8e16c41973
48
cli/array_variables.pl
Normal file
48
cli/array_variables.pl
Normal file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my ($length, $width, $depth) = (10, 20, 15);
|
||||
|
||||
print "The values are: ", $length, $width, $depth, "\n";
|
||||
|
||||
my ($name1, $name2, $name3, $name4) = ('Paul', 'Michael', 'Jessica', 'Megan');
|
||||
|
||||
print "Names are: $name1, $name2, $name3, $name4\n";
|
||||
|
||||
($name1, $name2, $name3, $name4) = qw/Paul Michael Jessica Megan/;
|
||||
|
||||
print "Names are: $name1, $name2, $name3, $name4\n";
|
||||
|
||||
($name1, $name2, $name3, $name4) = qw(Paul Michael Jessica Megan);
|
||||
|
||||
print "Names are: $name1, $name2, $name3, $name4\n";
|
||||
|
||||
|
||||
my @nums = (1, 2, 3, 4, 5);
|
||||
print "\@nums=@nums\n";
|
||||
my @more = 6 .. 1000;
|
||||
print "\@more=@more\n";
|
||||
my @none = ();
|
||||
print "\@none=@none\n";
|
||||
my @names = qw/Paul Michael Jessica Megan/;
|
||||
print "\@names=@names\n";
|
||||
my @all = (@nums, @more);
|
||||
print "\@all=@all\n";
|
||||
my @nested = (@nums, \@more);
|
||||
print "\@nested=@nested\n";
|
||||
|
||||
my $all_len = @all;
|
||||
my $nested_len = @nested;
|
||||
|
||||
print "\@all has length $all_len\n";
|
||||
print "\@nested has length $nested_len\n";
|
||||
|
||||
|
||||
my @array = (1, 2, 3, 4, 5);
|
||||
print $array[0] . "\n";
|
||||
print $array[3] . "\n";
|
||||
print $array[-1] . "\n";
|
||||
print $array[4] . "\n";
|
||||
print $array[-1] . "\n";
|
||||
print $array[$#array] . "\n";
|
Loading…
Reference in New Issue
Block a user