"Since I am begginer I have so many questions and so many errors that I can not understand fast."
I recommend you read "Perl introduction for beginners".
You haven't shown enough of your test script but, if you're using
push (@request, ($sysDescr,$sysUpTime));
to create the @request array, that document will show you a better way:
my @request = ($sysDescr, $sysUpTime);
Perl will tell you about many of the problems in your code if you ask it to. Often these problems are the result of simple typos and have nothing to do with your proficiency with the language. Just add these two lines at the top of all your scripts (as I always do):
use strict;
use warnings;
If you're having difficulties understanding the short messages that are produced by those, you can add this (although I'd advise against leaving that line in production code):
use diagnostics;
Another useful one, if your script is performing any I/O, is this (which I often use):
use autodie;
All of those are documented in Pragmas.
"Well the problem is that I do not exactly understand the reference part ..."
I recommend you read "Perl references short introduction".
Specifically with [\@request], you're taking a reference to @request (i.e. \@request); then you create an anonymous array (with [...]) whose only element is an array reference.
By removing the '\' (i.e. [@request]), you create an anonymous array whose elements are the values in @request.
Another way of doing this would have been to remove the brackets instead of the backslash (i.e. change [\@request] to \@request). However, there's a subtle difference: [...] creates a new array reference; \@array creates a reference to an existing array.
The following script may help in understanding this.
#!/usr/bin/env perl -l
use strict;
use warnings;
my @array = (1, 2, 3);
my $array_ref_1 = \@array;
my $array_ref_2 = [@array];
my $array_ref_3 = [1, 2, 3];
my $array_ref_ref = [\@array];
use Data::Dumper;
print '*** $array_ref_1 = \@array ***';
print Dumper $array_ref_1;
print '*** $array_ref_2 = [@array] ***';
print Dumper $array_ref_2;
print '*** $array_ref_3 = [1, 2, 3] ***';
print Dumper $array_ref_3;
print '*** $array_ref_ref = [\@array] ***';
print Dumper $array_ref_ref;
my $array_ref_1_new = \@array;
my $array_ref_2_new = [@array];
my $array_ref_3_new = [1, 2, 3];
print "\n";
print 'SAME: $array_ref_1 and $array_ref_1_new';
print "SAME: $array_ref_1 and $array_ref_1_new";
print "\n";
print 'DIFF: $array_ref_2 and $array_ref_2_new';
print "DIFF: $array_ref_2 and $array_ref_2_new";
print "\n";
print 'DIFF: $array_ref_3 and $array_ref_3_new';
print "DIFF: $array_ref_3 and $array_ref_3_new";
print "\n";
print 'SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0]
+';
print "SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0]
+";
Output:
*** $array_ref_1 = \@array ***
$VAR1 = [
1,
2,
3
];
*** $array_ref_2 = [@array] ***
$VAR1 = [
1,
2,
3
];
*** $array_ref_3 = [1, 2, 3] ***
$VAR1 = [
1,
2,
3
];
*** $array_ref_ref = [\@array] ***
$VAR1 = [
[
1,
2,
3
]
];
SAME: $array_ref_1 and $array_ref_1_new
SAME: ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0f202a628)
DIFF: $array_ref_2 and $array_ref_2_new
DIFF: ARRAY(0x7fa0f2029c68) and ARRAY(0x7fa0f210e2a8)
DIFF: $array_ref_3 and $array_ref_3_new
DIFF: ARRAY(0x7fa0f2029d40) and ARRAY(0x7fa0f20ca2f0)
SAME: $array_ref_1 and $array_ref_1_new and $array_ref_ref->[0]
SAME: ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0f202a628) and ARRAY(0x7fa0
+f202a628)
|