[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Perl coding questions

Posted on 2012-03-10
8
Medium Priority
?
284 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
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!

 
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 1000 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

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.
Make the most of your online learning experience.
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…
Simple Linear Regression

656 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