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
4 1526
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.
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 - #!/usr/bin/perl
-
use strict;
-
use warnings;
-
require myfile.pl
-
%main::my_hash=(1=>"one",2=>"two");
-
foreach (keys %main::my_hash)
-
{
-
print "$_\t$main::my_hash{$_}\n";
-
}
and myfile.pl contains
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
Thanks for the reply... But I am unable to get the changes. This is what I am trying to do - #!/usr/bin/perl
-
use strict;
-
use warnings;
-
require myfile.pl
-
%main::my_hash=(1=>"one",2=>"two");
-
foreach (keys %main::my_hash)
-
{
-
print "$_\t$main::my_hash{$_}\n";
-
}
and myfile.pl contains
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).
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.... :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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' =>...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...........
|
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....
|
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',...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
| |