Solved

Perl coding questions

Posted on 2012-03-10
8
271 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

820 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