Perl de-reference code reference variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl de-reference code reference variable
# 1  
Old 08-29-2012
Perl de-reference code reference variable

Guys,

May i know how can we de reference the code reference variable.?

Code:
my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";};
print $a->(4,5);

How can we print the whole function ?
Please suggest me regarding this.

Thanks for your time Smilie

Cheers,
Ranga Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl :: reading values from Data Dumper reference in Perl

Hi all, I have written a perl code and stored the data into Data structure using Data::Dumper module. But not sure how to retreive the data from the Data::Dumper. Eg. Based on the key value( Here CRYPTO-6-IKMP_MODE_FAILURE I should be able to access the internal hash elements(keys) ... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Shell Programming and Scripting

Reference of hash (Perl)

Hi Perl users, Could somebody help me to find the solution of my problem below. Here is my data: __DATA__ =================================================== NameOfipaddress ippair_1 propertiesx y propertiesy x... (1 Reply)
Discussion started by: askari
1 Replies

3. Shell Programming and Scripting

Perl: accessing reference to variable inside hash.

Below is hash which contains reference to variables: my %mandatoryFields = ( 1 => \$msgtype, 2 => \$switchtype, 3 => \$card_nbr, 4 => \$natv_tran_type_code, 5 => \$amt_1 ); This... (0 Replies)
Discussion started by: som.nitk
0 Replies

4. Shell Programming and Scripting

Perl reference

Hi all, I have a reference named $test. it points to the data structure as follows 'test' => }, ... (1 Reply)
Discussion started by: Damon sine
1 Replies

5. Shell Programming and Scripting

subsequently reference variable

Hello, This is not homework. It is a question that I received on a recent interview for a linux position. Can someone shed some light on the right answer? I got it wrong. Thanks, jaysunn (3 Replies)
Discussion started by: jaysunn
3 Replies

6. Shell Programming and Scripting

Unix Variable Reference and Substitution

I can't seem to make what appears to be a simple substitution. I want to define a list of systems for which daily reports need to be filed systems="systemA systemC systemZ" I then want to run a loop for i in ${systems} Analyze statistics Create the reports mailx (8 Replies)
Discussion started by: mugsymark
8 Replies

7. Shell Programming and Scripting

Perl: Getting back reference from s modifier

My input text has the following pattens: func_a(3, 4, 5); I want to replace it with this: func_b(3, 4, 5, 6); I'm trying the following expression, but it does not work: perl -p -e "s/func_a\((.*)?\);/func_b(\1,\n6)/s" <... (8 Replies)
Discussion started by: cooldude
8 Replies

8. Shell Programming and Scripting

Reference Variable

Hi! I need to determin the most efficient way to do something (rather simple, I thought). I'm currently echo(ing) a series of menu options, and reading the command input as the number associated with the entry. What I need to do is when the option 1 is selected, that it references a list and... (18 Replies)
Discussion started by: cchaloux
18 Replies

9. Shell Programming and Scripting

How to reference a variable within sed?

Hi all, How can I use sed to perform a substitution if the string that I'm going to substitute is stored in a variable: Let's say: sed 's/abcdefg/good' VS tmp="abcdefg" sed 's/$tmp/good' The second case doesn't work. Guess it's due to the single quotes on the outside. How can I... (1 Reply)
Discussion started by: rockysfr
1 Replies
Login or Register to Ask a Question
FormArticle(3pm)					User Contributed Perl Documentation					  FormArticle(3pm)

NAME
News::FormArticle - derivative of News::Article SYNOPSIS
use News::FormArticle; See below for functions available. DESCRIPTION
Like News::Article, but designed to be constructed from a file containing form text with substitutions. Currently, the source text is substituted as follows: Variables are denoted by $NAME or @NAME (where NAME is any simple identifier). (The sequences $$ and @@ denote literal $ and @ characters.) Variables of the form $NAME are expected to supply scalar values which are interpolated; variables of the form @NAME are expected to supply lists (or references to arrays) which are interpolated with separating newlines. Values of variables are found by consulting the list of sources supplied. Each source may be either a reference to a hash, or a reference to code. Source hashes may contain as values either the desired value (scalar or reference to array), or a typeglob, or a code reference which will be called to return the result. (Since typeglobs are allowed values, it is possible to supply a reference to a module symbol table as a valid source.) Code references supplied as sources are invoked with the variable name (including the leading $ or @) as the only parameter. In the degenerate case, all variables accessible in the source scope may be made available for interpolation by supplying the following as a source: sub { eval shift } If multiple sources are supplied, then each is consulted in turn until a defined value is found. USAGE
use News::FormArticle; Exports nothing. Constructor new ( FILE [, SOURCE [...]] ) Construct an article from the specified file, performing variable substitution with values supplied by the "SOURCE" parameters (see Description). FILE is any form of data recognised by News::Article's read() method. AUTHOR
Andrew Gierth <andrew@erlenstar.demon.co.uk> COPYRIGHT
Copyright 1997 Andrew Gierth <andrew@erlenstar.demon.co.uk> This code may be used and/or distributed under the same terms as Perl itself. perl v5.10.1 2010-04-03 FormArticle(3pm)