Sponsored Content
Top Forums Shell Programming and Scripting Perl: accessing reference to variable inside hash. Post 302665765 by som.nitk on Tuesday 3rd of July 2012 06:50:27 AM
Old 07-03-2012
Perl: accessing reference to variable inside hash.

Below is hash which contains reference to variables:

Code:
my %mandatoryFields = (
                    1  => \$msgtype,
                    2  => \$switchtype,
                    3  => \$card_nbr,
                    4  => \$natv_tran_type_code,
                    5  => \$amt_1
);


This works:

Code:
    foreach my $field (keys %mandatoryFields) {

        my $value = $mandatoryFields{$field};

        unless ($$value) {

#      do something
        }
    }



This dosen't: WHY ? The code never gets inside the unless block even though any variable inside the hash is undefined.
Code:
    foreach my $field (keys %mandatoryFields) {

        unless ($$mandatoryFields{$field}) {

#      do something
        }
    }


Last edited by som.nitk; 07-03-2012 at 08:01 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl: Pattern Matching a HASH variable

Hi All, I'm trying to test a Hash variable but it's not working. Here is my code - can anyone tell me if the test is valid? for (keys %enabled_yn) { if ($enabled_yn{$1} =~ m/\s+Y/) { $html =~ s/%(\w+)%/\<b\>\<font color\=orange\>$enabled_yn{$1}\<\/font\>\<\/b\>/g; }... (1 Reply)
Discussion started by: pondlife
1 Replies

2. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

3. Shell Programming and Scripting

hash of hashes : how to print reference and its internal structure?

#use perl 5.8.5; my %h1=(a=>'b', c=>'d'); my %h2=(a1=>'b1', c1=>'d1'); my $R1=\%h1; my $R2=\%h2; my %h= {$R1, $R2}; my $href=\%h; # hash of hashes foreach my $key (keys %$href){ print "Z::$$href{$key}\n" } When I am trying to print elements of hash of hashes, it prints HASH... (1 Reply)
Discussion started by: shristi
1 Replies

4. UNIX for Advanced & Expert Users

Passing Hash variable in to sql query in perl

Hi Everyone, Can anyone help me how do i call hash variable in to sql query in perl. Please see the script below i have defined two Hash %lc and %tab as below $lc{'REFF'}='V_RES_CLASS'; $lc{'CALE'}='V_CAP_CLASS'; $lc{'XRPD'}='V_XFMR_CLASS'; $tab{'V_RES_CLASS'}='V_MFR_SERS';... (6 Replies)
Discussion started by: jam_prasanna
6 Replies

5. Shell Programming and Scripting

Error during Accessing Global variable inside function

emailid=myemail@xyz.com taskName="DB-Backup" starttime=`date` email() { subject="$taskName" ": " $* " at `date` " mutt -s "$subject" $emailid < /dev/null } email "Starting" #do my stuff email "Finished" The above code gives following error ./dbbackup.sh: line 6: :... (5 Replies)
Discussion started by: nitiraj.rathore
5 Replies

6. Shell Programming and Scripting

Perl de-reference code reference variable

Guys, May i know how can we de reference the code reference variable.? 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 :) Cheers, Ranga :) (0 Replies)
Discussion started by: rangarasan
0 Replies

7. Shell Programming and Scripting

In Perl can i define a hash with value as variable?

Hi, Is it possible in perl to have a hash defined with variables as theirs key values, like: %account = ('username' => 'boy', 'password' => $password); Thanks (1 Reply)
Discussion started by: zing_foru
1 Replies

8. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

9. 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

10. Shell Programming and Scripting

Separate a hash variable into 2 parts in Perl

Dear Perl users/experts, Could somebody help me how to solve my problem, I have a hash variable that I want to convert into dot file (graphviz). I know how to convert it to dot file but I need some modification on the output of the hash variable before convert it to dot file. Eeach key of... (1 Reply)
Discussion started by: askari
1 Replies
WWW::Mechanize::FormFiller::Value::Callback(3pm)	User Contributed Perl Documentation	  WWW::Mechanize::FormFiller::Value::Callback(3pm)

NAME
WWW::Mechanize::FormFiller::Value::Callback - Call Perl code to fill out a HTML form field SYNOPSIS
use WWW::Mechanize::FormFiller; use WWW::Mechanize::FormFiller::Value::Callback; my $f = WWW::Mechanize::FormFiller->new(); # Create a default value for the HTML field "login" # This will put the current login name into the login field sub find_login { getlogin || getpwuid($<) || "Kilroy"; }; my $login = WWW::Mechanize::FormFiller::Value::Callback->new( login => &find_login ); $f->add_value( login => $login ); # Alternatively take the following shorthand, which adds the # field to the list as well : # "If there is no password, put a nice number there my $password = $f->add_filler( password => Callback => sub { int rand(90) + 10 } ); DESCRIPTION
This class provides a way to write a value returned by Perl code into a HTML field. new NAME, CODE Creates a new value which will correspond to the HTML field "NAME". The "CODE" is a code reference that will return the value to be written into the HTML field. The code reference will be called with two parameters, the object and the HTML::Form::Input object. name [NEWNAME] Gets and sets the name of the HTML field this value corresponds to. value FIELD Returns the value to put into the HTML field. EXPORT None by default. COPYRIGHT AND LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Copyright (C) 2002,2003 Max Maischein AUTHOR
Max Maischein, <corion@cpan.org> Please contact me if you find bugs or otherwise improve the module. More tests are also very welcome ! SEE ALSO
WWW::Mechanize, WWW::Mechanize::Shell, WWW::Mechanize::FormFiller, WWW::Mechanize::FormFiller::Value::Value, WWW::Mechanize::FormFiller::Value::Default, WWW::Mechanize::FormFiller::Value::Random, WWW::Mechanize::FormFiller::Value::Interactive perl v5.10.1 2009-04-24 WWW::Mechanize::FormFiller::Value::Callback(3pm)
All times are GMT -4. The time now is 10:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy