473,395 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help: hash key pass to subroutine as string failed

I have a sub expand() to expand the path
Expand|Select|Wrap|Line Numbers
  1. sub expand($%) {
  2.  
  3.     my $self = shift;
  4.     my ($string, %params) = @_;
  5.  
  6.     # Perform parameter checks.
  7.     die("Mandatory parameter 'string' not defined.") unless (defined $string);
  8.     //other handling
  9. }
  10.  
  11. The followng call fails
  12.  
  13. sub foo {
  14.       my $files = {
  15.         'test.in'    => 'test.out'
  16.     };
  17.  
  18.     expand($_) 
  19.         foreach ( keys( %{$files} ) );
  20. }
  21. saying the 'string' not defined.
  22. While the following codes work:
  23. sub foo {
  24.       my $files = {
  25.         'test.in'    => 'test.out'
  26.     };
  27.  
  28.    foreach my $key ( keys %{$files} )  {
  29.             expand (+$key); #expand ($key) also fails
  30.    }
  31. }
Could some one give me a hint why? I am newbie for Perl.
Thanks!
Jan 5 '09 #1
3 2576
KevinADC
4,059 Expert 2GB
As shawn on another forum said, don't use prototypes, instead of :

sub expand($%) {

use a sub:

sub expand {
Jan 5 '09 #2
Actually I tried to remove the prototype as suggested, but still failed to pass the correct string value of the key.
the following methods work as well:
method 1:
Expand|Select|Wrap|Line Numbers
  1. while ( my ($key,$value)  = each (%{$files}) ){
  2.       expand($key);
  3.     }
methods 2:
Expand|Select|Wrap|Line Numbers
  1. foreach my $key (keys  %{$files}  ) {
  2.       my $s = sprintf("%s",$key);
  3.       expand($s);
  4.    }
So I suspect foreach implmentation has sth. tricky.
Any suggestion?
Jan 8 '09 #3
KevinADC
4,059 Expert 2GB
See other forum
Jan 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christopher | last post by:
I have a hash that is several levels deep. ie: 'vars' => { '$filers' => '10.10.10.10/32', '$networksa' => '10.10.10.10/32', '$networksb' => '10.50.0.0/16', '$wintel_boxes' =>...
3
by: FLOTServer | last post by:
Here's my problem: I run a gameserver that runs the game "Medal of Honor". On the game server is log file which contains all of the data from the players for that day (kills, deaths, etc...). I...
6
by: chung.ley | last post by:
Hi, Another newbie question... I have to write a program that process a huge amount of data; the end results will be a number of different reports. I will prefer to write a separate...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
37
by: Tim Marshall | last post by:
From http://www.mvps.org/access/tencommandments.htm 9th item: Thou shalt not use "SendKeys", "Smart Codes" or "GoTo" (unless the GoTo be part of an OnError process) for these will lead you...
2
by: leo2100 | last post by:
Hi, I need help with this program. The program is supposed to take a text file and identify the words in it, then it should print them and count how many times a word is repeated. At first main...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
4
by: nitusa | last post by:
Hey Everyone, I am doing a VB6 to C# conversion and everything was going smoothly until I realized that I needed to call a Fortran 77 (.for) .dll inside my code. I have looked through everything...
1
by: pavanponnapalli | last post by:
hi , I have got a code as under : sub dbcall { my %hash; my $i=0; print "<<<<<<<@_>>>>>>> \n"; foreach(@_)
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.