10 More Discussions You Might Find Interesting
1. UNIX for Beginners Questions & Answers
I am trying to figure out to find word count of each word from my file
sample file
hi how are you
hi are you ok
sample out put
hi 1
how 1
are 1
you 1
hi 1
are 1
you 1
ok 1
wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies
2. Shell Programming and Scripting
echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} |
awk 'gsub(/^|abc,|$/,"") {print}'
Required output
{grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies
3. Shell Programming and Scripting
Hi All,
I have a XML file which is looks like as below. <<please see the attachment >>
<?xml version="1.0" encoding="UTF-8"?>
<esites>
<esite>
<name>XXX.com</name>
<storeId>10001</storeId>
<module>
... (4 Replies)
Discussion started by: Rajeev_hbk
4 Replies
4. Shell Programming and Scripting
hi all, I'm new there, I'm just playing with perl and lwp and I just successfully created a script for log in to a web site with post. I have a response but I would like to have something like this:
I have in my response lines like:
<div class="sender">mimi020</div>
<some html code.....>... (3 Replies)
Discussion started by: vogueestylee
3 Replies
5. UNIX for Dummies Questions & Answers
I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL.
I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies
6. Shell Programming and Scripting
Hi,
i've a string
/u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD/TESi T_11_HD_120/hd-12
i need to get string, like
/u/user/DTE/T_LOGS/20110622_011532_TEST_11_HD_120/HD
the words from HD should get deleted, i need only a string till HD, i dont want to use any built in... (4 Replies)
Discussion started by: asak
4 Replies
7. Shell Programming and Scripting
Hi,
In Perl, is it possible to use a range of numbers with '..' as a key in a hash?
Something in like:
%hash = (
'768..1536' => '1G',
'1537..2560' => '2G'
);
That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies
8. UNIX for Advanced & Expert Users
Hi,
The task i have to do is to
1- create a database contains the Names .run the query and store results in hash make the Name field is the hash key
2- in the same time i have a txt which i will loop through it word by word and check for each word if a hash key ( compare it with the Names in... (0 Replies)
Discussion started by: eng_shimaa
0 Replies
9. Shell Programming and Scripting
cat shell_script.ksh
x=$A
y=$B
export x
export y
echo $x
echo $y
when i am running this with a command
ksh shell_script.ksh -A 10 -B 20
its not showing anything ....
could you let me know how i can use key word type paramter (2 Replies)
Discussion started by: dr46014
2 Replies
10. Shell Programming and Scripting
Hi,
I am trying automate couting number of spell and typo errors in MS Word document using perl script.
In perl script, i am using Win32::OLE module of perl to read MS word document.
Can anybody tell me are there any modules available in perl which can be imported into my script to... (0 Replies)
Discussion started by: 123an
0 Replies
ShadowHash(3pm) User Contributed Perl Documentation ShadowHash(3pm)
NAME
Tie::ShadowHash - Merge multiple data sources into a hash
SYNOPSIS
use Tie::ShadowHash;
use DB_File;
tie (%db, 'DB_File', 'file.db');
$obj = tie (%hash, 'Tie::ShadowHash', \%db, "otherdata.txt");
# Accesses search %db first, then the hashed "otherdata.txt".
print "$hash{key}
";
# Changes override data sources, but don't change them.
$hash{key} = 'foo';
delete $hash{bar};
# Add more data sources on the fly.
%extra = (fee => 'fi', foe => 'fum');
$obj->add (\%extra);
# Add a text file as a data source, taking the first "word" up
# to whitespace on each line as the key and the rest of the line
# as the value.
$split = sub { split (' ', $_[0], 2) };
$obj->add ([text => "pairs.txt", $split]);
# Add a text file as a data source, splitting each line on
# whitespace and taking the first "word" to be the key and an
# anonymous array consisting of the remaining words to be the
# data.
$split = sub { split (' ', $_[0]) };
$obj->add ([text => "triples.txt", $split]);
DESCRIPTION
This module merges together multiple sets of data in the form of hashes into a data structure that looks to Perl like a single simple hash.
When that hash is accessed, the data structures managed by that shadow hash are searched in order they were added for that key. This
allows the rest of a program simple and convenient access to a disparate set of data sources.
Tie::ShadowHash can handle anything that looks like a hash; just give it a reference as one of the additional arguments to tie(). This
includes other tied hashes, so you can include DB and DBM files as data sources for a shadow hash. If given a plain file name instead of a
reference, it will build a hash to use internally, with each chomped line of the file being the key and the number of times that line is
seen in the file being the value.
Tie::Shadowhash also supports special tagged data sources that can take options specifying their behavior. The only tagged data source
currently supported is "text", which takes a file name of a text file and a reference to a sub. The sub is called for every line of the
file, with that line as an argument, and is expected to return a list. The first element of the list will be the key, and the second and
subsequent elements will be the value or values. If there is more than one value, the value stored in the hash and associated with that
key is an anonymous array containing all of them.
Tagged data sources are distinguished from normal data sources by passing them to tie() (or to add() -- see below) as an anonymous array.
The first element is the data source tag and the remaining elements are arguments for that data source. For a text data source, see the
usage summary above for examples.
The shadow hash can be modified, and the modifications override the data sources, but modifications aren't propagated back to the data
sources. In other words, the shadow hash treats all data sources as read-only and saves your modifications only in internal memory. This
lets you make changes to the shadow hash for the rest of your program without affecting the underlying data in any way (and this behavior
is the main reason why this is called a shadow hash).
If the shadow hash is cleared, by assigning the empty list to it, by explicitly calling CLEAR(), or by some other method, all data sources
are dropped from the shadow hash. There is no other way of removing a data source from a shadow hash after it's been added (you can, of
course, always untie the shadow hash and dispose of the underlying object if you saved it to destroy the shadow hash completely).
INSTANCE METHODS
add(SOURCE [, SOURCE ...])
Adds the given sources to an existing shadow hash. This method can be called on the object returned by the initial tie() call. It
takes the same arguments as the initial tie() and interprets them the same way.
DIAGNOSTICS
Can't open file %s: %s
Tie::ShadowHash was given a file name to use as a source, but when it tried to open that file, the open failed with that system error
message.
Invalid source type %s
Tie::Shadowhash was given a tagged data source of an unknown type. The only currently supported tagged data source is "text".
CAVEATS
It's worth paying very careful attention to "The untie Gotcha" in perltie when using this module. It's also important to be careful about
what you do with tied hashes that are included in a shadow hash. Tie::ShadowHash stores a reference to such arrays; if you untie them out
from under a shadow hash, you may not get the results you expect. Remember that if you put something in a shadow hash, you'll need to
clean out the shadow hash as well as everything else that references a variable if you want to free it completely.
Not all tied hashes implement EXISTS; in particular, ODBM_File, NDBM_File, and some old versions of GDBM_File don't, and therefore
AnyDBM_File doesn't either. Calling exists on a shadow hash that includes one of those tied hashes as a data source may therefore result
in an exception. Tie::ShadowHash doesn't use exists except to implement the EXISTS method because of this.
Because it can't use EXISTS due to the above problem, Tie::ShadowHash cannot correctly distinguish between a non-existent key and an
existing key associated with an undefined value. This isn't a large problem, since many tied hashes can't store undefined values anyway,
but it means that if one of your data sources contains a given key associated with an undefined value and one of your later data sources
contains the same key but with a defined value, when the shadow hash is accessed using that key, it will return the first defined value it
finds. This is an exception to the normal rule that all data sources are searched in order and the value returned by an access is the
first value found. (Tie::ShadowHash does correctly handle undefined values stored directly in the shadow hash.)
AUTHOR
Russ Allbery <rra@stanford.edu>
COPYRIGHT AND LICENSE
Copyright 1999, 2002, 2010 by Russ Allbery <rra@stanford.edu>
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
perltie
The current version of this module is always available from its web site at <http://www.eyrie.org/~eagle/software/shadowhash/>.
perl v5.10.1 2010-04-03 ShadowHash(3pm)