Solved

Perl coding questions

Posted on 2012-03-10
8
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
LVL 84

Expert Comment

by:ozo
ID: 37705311
it is a hash of arrays of anonymous  subs
0
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

691 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