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
TAP::Parser::YAMLish::Writer(3pm)			 Perl Programmers Reference Guide			 TAP::Parser::YAMLish::Writer(3pm)

NAME
TAP::Parser::YAMLish::Writer - Write YAMLish data VERSION
Version 3.17 SYNOPSIS
use TAP::Parser::YAMLish::Writer; my $data = { one => 1, two => 2, three => [ 1, 2, 3 ], }; my $yw = TAP::Parser::YAMLish::Writer->new; # Write to an array... $yw->write( $data, @some_array ); # ...an open file handle... $yw->write( $data, $some_file_handle ); # ...a string ... $yw->write( $data, $some_string ); # ...or a closure $yw->write( $data, sub { my $line = shift; print "$line "; } ); DESCRIPTION
Encodes a scalar, hash reference or array reference as YAMLish. METHODS
Class Methods "new" my $writer = TAP::Parser::YAMLish::Writer->new; The constructor "new" creates and returns an empty "TAP::Parser::YAMLish::Writer" object. Instance Methods "write" $writer->write($obj, $output ); Encode a scalar, hash reference or array reference as YAML. my $writer = sub { my $line = shift; print SOMEFILE "$line "; }; my $data = { one => 1, two => 2, three => [ 1, 2, 3 ], }; my $yw = TAP::Parser::YAMLish::Writer->new; $yw->write( $data, $writer ); The $output argument may be: o a reference to a scalar to append YAML to o the handle of an open file o a reference to an array into which YAML will be pushed o a code reference If you supply a code reference the subroutine will be called once for each line of output with the line as its only argument. Passed lines will have no trailing newline. AUTHOR
Andy Armstrong, <andy@hexten.net> SEE ALSO
YAML::Tiny, YAML, YAML::Syck, Config::Tiny, CSS::Tiny, <http://use.perl.org/~Alias/journal/29427> COPYRIGHT
Copyright 2007-2008 Andy Armstrong. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.12.1 2010-04-26 TAP::Parser::YAMLish::Writer(3pm)