Solved

Perl coding questions

Posted on 2012-03-10
8
269 Views
Last Modified: 2012-03-10
Hello,

I am going through a Perl script and being not a Perl expert I come
across the following I do not understand
# an array is created and populated. That's clear
my @arg = ('one', 'two', 'three');

# however this is not so clear
# As I understand this
# $cfg is a pointer to a hash of a hash of a hash of a hash
# but what does \@args means ?
$cfg->{rrdargs}{$log}{$png}{args} = \@args;

Open in new window


And then the next question I have,
supposse I have another array
my @arg2 = ('four','five');

How can I add/push @arg2 onto
that existing without losing the stuff
that already there?

$cfg->{rrdargs}{$log}{$png}{args}

-------------------------------

Next another strange thing
How do I have to read these lines?
How does this work?
my %myrules = (
	'14all*errorpic' => [sub{$_[0] && (-r $_[0] )}, sub{"Not found/readable"}],
	'14all*grapherrorstobrowser' => [sub{1}, sub{"Internal Error"}]
    );

Open in new window

0
Comment
Question by:Marc_Engrie
  • 5
  • 3
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 37704785
push @{$cfg->{rrdargs}{$log}{$png}{args}}, @arg2;  #this also adds to @args
0
 
LVL 84

Expert Comment

by:ozo
ID: 37704819
\@args is a reference to @args
see
perldoc perlref
0
 

Author Comment

by:Marc_Engrie
ID: 37705084
Thx for far for the info.
Found the info in perldoc perlref. That's clear.

the push @{$cfg->{rrdargs}{$log}{$png}{args}}, @arg2;  I'll try later this week.

What about
my %myrules = (
	'14all*errorpic' => [sub{$_[0] && (-r $_[0] )}, sub{"Not found/readable"}],
	'14all*grapherrorstobrowser' => [sub{1}, sub{"Internal Error"}]
    );

Open in new window


How do I have to read these lines?
How does this work?
0
 
LVL 84

Expert Comment

by:ozo
ID: 37705311
it is a hash of arrays of anonymous  subs
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Marc_Engrie
ID: 37706194
Hoi ozo,

That I got but how are these sub called?

and do they return something I doe not see any in  sub{$_[0] && (-r $_[0] )}  or   sub {1}?
0
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 37706214
perldoc perlsub
...
       If no "return" is found and if the last statement is an expression, its
       value is returned. If the last statement is a loop control structure
       like a "foreach" or a "while", the returned value is unspecified. The
       empty sub returns the empty list.
0
 

Author Comment

by:Marc_Engrie
ID: 37706257
Thx a lot!!

I understand it all now
0
 
LVL 84

Expert Comment

by:ozo
ID: 37706260
# calls might look, for example, like:
print $myrules{'14all*errorpic'}[1]() unless $myrules{'14all*errorpic'}[0]("filename");
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sorting in Excel with Group Headers if the Exist 2 82
strCopies  challenge 17 82
Apps blocked by Java 9 60
C# application error "Parameter Is Not Valid". 3 79
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now