Solved

Perl coding questions

Posted on 2012-03-10
8
268 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
Comment Utility
push @{$cfg->{rrdargs}{$log}{$png}{args}}, @arg2;  #this also adds to @args
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
\@args is a reference to @args
see
perldoc perlref
0
 

Author Comment

by:Marc_Engrie
Comment Utility
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
Comment Utility
it is a hash of arrays of anonymous  subs
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Marc_Engrie
Comment Utility
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
Comment Utility
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
Comment Utility
Thx a lot!!

I understand it all now
0
 
LVL 84

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

13 Experts available now in Live!

Get 1:1 Help Now