473,387 Members | 1,891 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,387 software developers and data experts.

Modifying a hash in some other file

mehj123
55
Hi friends,

Please clear my doubt. Suppose we have a hash variable in a file, and we are accessing the same hash and adding some more keys to the hash in some other script. Will this change be reflected in the first file? Is there a way to do this so that change is reflected without deleting the old file and creating the file again with the new value?

Thanks
Mehjabeen
Dec 28 '07 #1
4 1526
KevinADC
4,059 Expert 2GB
if the hash variable is in a file, and a script changes the file, all other scripts that access that file will see the change. You would need to use a seperate file for each script if you want to change the actual file and not have the change seen by other scripts.
Dec 28 '07 #2
mehj123
55
if the hash variable is in a file, and a script changes the file, all other scripts that access that file will see the change. You would need to use a seperate file for each script if you want to change the actual file and not have the change seen by other scripts.
Thanks for the reply... But I am unable to get the changes. This is what I am trying to do
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. require myfile.pl
  5. %main::my_hash=(1=>"one",2=>"two");
  6. foreach (keys %main::my_hash)
  7. {
  8. print "$_\t$main::my_hash{$_}\n";
  9. }
and myfile.pl contains
Expand|Select|Wrap|Line Numbers
  1. %my_hash = ();
  2. 1;
The script prints the key value pairs. But the hash value is not being updated in the myfile.pl file. Or am I doing it wrongly??

Thanks
Mehjabeen
Dec 28 '07 #3
KevinADC
4,059 Expert 2GB
Thanks for the reply... But I am unable to get the changes. This is what I am trying to do
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. require myfile.pl
  5. %main::my_hash=(1=>"one",2=>"two");
  6. foreach (keys %main::my_hash)
  7. {
  8. print "$_\t$main::my_hash{$_}\n";
  9. }
and myfile.pl contains
Expand|Select|Wrap|Line Numbers
  1. %my_hash = ();
  2. 1;
The script prints the key value pairs. But the hash value is not being updated in the myfile.pl file. Or am I doing it wrongly??

Thanks
Mehjabeen

The way you are doing it only changes the hash that is stored in memory when the program runs, you are not writing/changing anything in the actual file (myfile.pl). For that to work you would need to use a database module, like AnyDBM_File and perls tie() function. But really, that is not done much in perl programs anymore, most people prefer to use a databse like MySQL. So to answer your last question, yes, you are doing it wrong(ly).
Dec 28 '07 #4
mehj123
55
The way you are doing it only changes the hash that is stored in memory when the program runs, you are not writing/changing anything in the actual file (myfile.pl). For that to work you would need to use a database module, like AnyDBM_File and perls tie() function. But really, that is not done much in perl programs anymore, most people prefer to use a databse like MySQL. So to answer your last question, yes, you are doing it wrong(ly).
Thanks a lot for your reply.... :)
Dec 31 '07 #5

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: suresh | last post by:
Hi all, I have a hash table and I want to modify the value of a key. Please let me know how can that be acheived. Thanks Suresh
1
by: sympatico | last post by:
Hi, I am trying to compare 2 images to check if they are exactly identical (in terms of data), I thought this would be quicker than analysing pixels of the images. I have found lots of examples...
6
by: pycraze | last post by:
Hi , I am using Fedora Core -3 and my Python version is 2.4 . kernel version - 2.6.9-1.667smp There is some freakish thing that happens with python hashes when i run a python script my...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
5
by: lavu | last post by:
I am trying to provide some security to text files, by adding a signature at the end of each text file. this signature needs to be generated by some kind of hashing algorithm. so while sending...
5
numberwhun
by: numberwhun | last post by:
Ok, I have a ".csv" file that contains two lines (VERY LONG lines). Basically, the first line is the headers defining what each field in the second line is. ie: Name1,Name2,Name3,...........
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
5
by: nirmal1349 | last post by:
Hi, I have a hash in hash file in perl which looks some thing like this: $FIELDS = { 'abc' => { 'Description' => { 'Purpose' => 'some data is present',...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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,...

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.