473,811 Members | 3,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

return hash

Hello
at the end of my function i return hash:
return \%hash;

and i want to use that function to receive that hash:
my %newhash=MyFunc tion(); #line 14

but i receive error:
Reference found where even-sized list expected at line 14.

and when i try:
my \%newhash=MyFun ction(); #line 14
i receive syntax error.

Why ?

Thanx
Michal

Jul 19 '05 #1
5 15708
vertigo wrote:
Hello
at the end of my function i return hash:
return \%hash;
No, you don't. You are returning a reference.
and i want to use that function to receive that hash:
my %newhash=MyFunc tion(); #line 14

but i receive error:
Reference found where even-sized list expected at line 14.
Right. You cannot assign a scalar value to a hash variable.
and when i try:
my \%newhash=MyFun ction(); #line 14
i receive syntax error.

Why ?


Because this is not Perl syntax.

Have you tried a plain
my $hashref = MyFunction();

jue
Jul 19 '05 #2


Have you tried a plain
my $hashref = MyFunction();


ok, it works, but how can i use this reference to printf all keys/values ?
I tried:
while (my($key,$value ) = each $hashref)

but received error. How can i access object when i have it's reference ?

Thanx
Michal

Jul 19 '05 #3
vertigo wrote:
Have you tried a plain
my $hashref = MyFunction();


ok, it works, but how can i use this reference to printf all
keys/values ? I tried:
while (my($key,$value ) = each $hashref)

but received error. How can i access object when i have it's
reference ?


You use rule 1 or rule 2 from "perldoc perlreftut".
If you are dealing with references, then you really should read this first,
and then perldoc perlref.

Having said that: in your original program, why are you returning a
reference in the first place? If you are not interested in a reference to
the hash, then just return the hash itself instead of a reference to it.

jue
Jul 19 '05 #4
vertigo <no**@microsoft .com> wrote in message news:<cd******* ***@nemesis.new s.tpi.pl>...
Hello
at the end of my function i return hash:
return \%hash;

and i want to use that function to receive that hash:
my %newhash=MyFunc tion(); #line 14

but i receive error:
Reference found where even-sized list expected at line 14.

and when i try:
my \%newhash=MyFun ction(); #line 14
i receive syntax error.

Why ?

Thanx
Michal

Do you want to return the hash or a reference to a hash
return %hash #returns hash
%hash=func();
return \$hash retruns a reference.
$hashRef=func() ;
Jul 19 '05 #5
vertigo <no**@microsoft .com> wrote in message news:<cd******* ***@nemesis.new s.tpi.pl>...
Hello
at the end of my function i return hash:
return \%hash;

and i want to use that function to receive that hash:
my %newhash=MyFunc tion(); #line 14

but i receive error:
Reference found where even-sized list expected at line 14.

and when i try:
my \%newhash=MyFun ction(); #line 14
i receive syntax error.

Why ?

Thanx
Michal


Hi,

You are returning a *reference* to a hash. Thus, you need to do this:
my $newhash = MyFunction();

Then, you can access your hash like this:
print $newhash->{'key'};

Ofcourse, you can return a 'real' hash ( not a reference to it ) but
that will copy the entire structure to the calle which is not
recommended at all.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3528
by: Christopher Murtagh | last post by:
Greetings, I've got a fairly simple function that I'm trying to return a set, but seem to have come across a stumbling block. When I execute the function below (the input params are not used at the moment) I get this: chris=# select htdig('foo', 'foo'); ERROR: set-valued function called in context that cannot accept a set CONTEXT: PL/pgSQL function "htdig" line 14 at return next
2
2594
by: huey_jiang | last post by:
Hi All, I need to make DLL for my new hash function in C. In myhashdll.c file, I have a function as: char *make_hash(char *in, char *out) { ...... ...... return (out);
2
1972
by: cdg | last post by:
Could anyone tell me why a function return with this program is not returning to "main". The program will compile and should be self-explanatory. And any suggestions for improvements would be appreciated also. The function is HashMilliTime at the end of the program. #include <sys/timeb.h> #include <iostream.h> #include <string.h> #include <stdlib.h>
14
3477
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a list? I know that sets were introduced a lot later and lists/dictionaries were used instead but I think "the only correct way" now is for the dictionary keys and values to be sets. Presently {1:0,2:0,3:0}.keys() will produce but it could also...
21
3233
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code (i.e. the get_hash function) is borrowed from various snippets I found on the net. Thee free function could probably need some love. I have been thinking about having a second linked list of all entries so that the cost of freeing is in proportion to...
4
2719
by: Kerem Gümrükcü | last post by:
Hi, this is not a pure MFC/VC++ question but my apologizes at first. Well, i have a application that calculates the hash for a file. You can request a CALG_SHA1 or a CALG_MD5 for the File. The Process of Hash Calculation works fine, but i get two totally different Hash values for e.g. kernel32.dll when i try to get the hash with the following steps compared to the managed .NET MD5 Provider. The Hash "24d244d0a15ab17885d578d1c54d5294"...
12
1481
by: Matt B | last post by:
I was just wondering if there is a "best" choice from the following couple of ways of returning a value from a method: 1) private HashAlgorithm GetSpecificHashAlgorithm(string hashString){ if (hashString == "MD5") { return System.Security.Cryptography.MD5.Create(); } else { return System.Security.Cryptography.SHA512.Create(); }
1
1660
by: pavanponnapalli | last post by:
hi , I have got a code as under : sub dbcall { my %hash; my $i=0; print "<<<<<<<@_>>>>>>> \n"; foreach(@_)
2
2136
by: jmprescott | last post by:
I'm writing a program to get a MD5 hash from web page data. The hash part is working fine, but I'm having troubles getting the web page data. I threw up a couple messageboxes and I'm getting a null string return, so I'm hashing nothing. Anyone see where the problem might be? Thanks! using System; using System.IO; using System.Net; using System.Text; namespace WebFetch { public class SiteData
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.