Search Results

Search found 3659 results on 147 pages for 'sorted hash'.

Page 17/147 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • How can I share Perl data structures through a socket?

    - by pavun_cool
    In sockets I have written the client server program. First I tried to send the normal string among them it sends fine. After that I tried to send the hash and array values from client to server and server to client. When I print the values using Dumper, it gives me only the reference value. What should I do to get the actual values in client server? Server Program: use IO::Socket; use strict; use warnings; my %hash = ( "name" => "pavunkumar " , "age" => 20 ) ; my $new = \%hash ; #Turn on System variable for Buffering output $| = 1; # Creating a a new socket my $socket= IO::Socket::INET->new(LocalPort=>5000,Proto=>'tcp',Localhost => 'localhost','Listen' => 5 , 'Reuse' => 1 ); die "could not create $! \n" unless ( $socket ); print "\nUDPServer Waiting port 5000\n"; my $new_sock = $socket->accept(); my $host = $new_sock->peerhost(); while(<$new_sock>) { #my $line = <$new_sock>; print Dumper "$host $_"; print $new_sock $new . "\n"; } print "$host is closed \n" ; Client Program use IO::Socket; use Data::Dumper ; use warnings ; use strict ; my %hash = ( "file" =>"log.txt" , size => "1000kb") ; my $ref = \%hash ; # This client for connecting the specified below address and port # INET function will create the socket file and establish the connection with # server my $port = shift || 5000 ; my $host = shift || 'localhost'; my $recv_data ; my $send_data; my $socket = new IO::Socket::INET ( PeerAddr => $host , PeerPort => $port , Proto => 'tcp', ) or die "Couldn't connect to Server\n"; while (1) { my $line = <stdin> ; print $socket $ref."\n"; if ( $line = <$socket> ) { print Dumper $line ; } else { print "Server is closed \n"; last ; } } I have given my sample program about what I am doing. Can any one tell me what I am doing wrong in this code? And what I need to do for accessing the hash values?

    Read the article

  • Ruby 1.9: turn these 4 arrays into hash of key/value pairs

    - by randombits
    I have four arrays that are coming in from the client. Let's say that there is an array of names, birth dates, favorite color and location. The idea is I want a hash later where each name will have a hash with respective attributes: Example date coming from the client: [name0, name1, name2, name3] [loc0, loc1] [favcololor0, favcolor1] [bd0, bd1, bd2, bd3, bd4, bd5] Output I'd like to achieve: name0 => { location => loc0, favcolor => favcolor0, bd => bd0 } name1 => { location => loc1, favcolor => favcolor1, bd => bd1 } name2 => { location => nil, favcolor => nil, bd => bd2 } name3 => { location => nil, favcolor => nil, bd => bd3 } I want to have an array at the end of the day where I can iterate and work on each particular person hash. There need not be an equivalent number of values in each array. Meaning, names are required.. and I might receive 5 of them, but I only might receive 3 birth dates, 2 favorite colors and 1 location. Every missing value will result in a nil. How does one make that kind of data structure with Ruby 1.9?

    Read the article

  • eXML-PARSER output contains unwanted hash references

    - by seaworthy
    So I wrote a parser routine to take one xml file and reparse into another one. This code I later modified to split a large xml file into many small xml files. I am having a problem with an output. Parsing works fine the only thing output also includes unwanted strings like HASH(0x19f9b58), I am not sure why and need set of friendly eyes. use Encode; use XML::Parser; my $parser = XML::Parser->new( Handlers => {Start => \&handle_elem_start, End => \&handle_elem_end,Char => \&handle_char_data,}); my $record; my $file = shift @ARGV; if( $file ) {$parser->parsefile( $file );} exit; sub handle_elem_start { my( $expat, $name, %atts ) = @_; if ($name eq 'articles'){$file="_data.xml";unlink($file);} $record .= "<"; $record .= "$name"; foreach my $key (keys %atts){$record .= " $key=\"$atts{$key}\"";} $record .= ">"; } sub handle_char_data { my( $expat, $text ) = @_; $text = decode_utf8( $text ); $record .= "$text"; } sub handle_elem_end { my( $expat, $name ) = @_; $record .= "</$name>"; if( $name eq 'article' ) { open (MYFILE, '>>'.$file); print MYFILE $record; close (MYFILE); print $record; $record = {}; } return unless( $name eq 'article' ); } Sample output: ... </article>HASH(0x19f9b40) <article doi="10.1103/PhysRevSeriesI.9.304"> <journal short="Phys. Rev. (Series I)" jcode="PRI">Physical Review (Series I)</journal> <volume>9</volume> <issue printdate="1899-11-00">5</issue> <fpage>304</fpage> <lpage>309</lpage> <seqno>1</seqno> <price></price><tocsec>Articles</tocsec> <arttype type="article"></arttype><doi>10.1103/PhysRevSeriesI.9.304</doi> <title>An Investigation of the Magnetic Qualities of Building Brick</title> <authgrp> <author><givenname>O.</givenname><middlename>A.</middlename><surname>Gage</surname></author> <author><givenname>H.</givenname><middlename>E.</middlename><surname>Lawrence</surname></author> </authgrp> <cpyrt> <cpyrtdate date="1899"></cpyrtdate><cpyrtholder>The American Physical Society</cpyrtholder> </cpyrt> </article>HASH(0x19f9b58) ... HASH strings are not wanted, please advise.

    Read the article

  • passing hashes to a subroutine

    - by Vishalrix
    In one of my main( or primary) routines,I have two or more hashes. I want the subroutine foo() to recieve these possibly-multiple hashes as distinct hashes. Right now I have no preference if they go by value, or as references. I am struggling with this for the last many hours and would appreciate help, so that I dont have to leave perl for php! ( I am using mod_perl, or will be) Right now I have got some answer to my requirement, shown here From http://forums.gentoo.org/viewtopic-t-803720-start-0.html # sub: dump the hash values with the keys '1' and '3' sub dumpvals { foreach $h (@_) { print "1: $h->{1} 3: $h->{3}\n"; } } # initialize an array of anonymous hash references @arr = ({1,2,3,4}, {1,7,3,8}); # create a new hash and add the reference to the array $t{1} = 5; $t{3} = 6; push @arr, \%t; # call the sub dumpvals(@arr); I only want to extend it so that in dumpvals I could do something like this: foreach my %k ( keys @_[0]) { # use $k and @_[0], and others } The syntax is wrong, but I suppose you can tell that I am trying to get the keys of the first hash ( hash1 or h1), and iterate over them. How to do it in the latter code snippet above?

    Read the article

  • comparing salt and hashed passwords during login doesn't seem work right....

    - by Pandiya Chendur
    I stored salt and hash values of password during user registration... But during their login i then salt and hash the password given by the user, what happens is a new salt and a new hash is generated.... string password = collection["Password"]; reg.PasswordSalt = CreateSalt(6); reg.PasswordHash = CreatePasswordHash(password, reg.PasswordSalt); These statements are in both registration and login.... salt and hash during registration was eVSJE84W and 18DE22FED8C378DB7716B0E4B6C0BA54167315A2 During login it was 4YDIeARH and 12E3C1F4F4CFE04EA973D7C65A09A78E2D80AAC7..... Any suggestion.... public static string CreateSalt(int size) { //Generate a cryptographic random number. RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] buff = new byte[size]; rng.GetBytes(buff); // Return a Base64 string representation of the random number. return Convert.ToBase64String(buff); } public static string CreatePasswordHash(string pwd, string salt) { string saltAndPwd = String.Concat(pwd, salt); string hashedPwd = FormsAuthentication.HashPasswordForStoringInConfigFile( saltAndPwd, "sha1"); return hashedPwd; }

    Read the article

  • Comparing lists of field-hashes with equivalent AR-objects.

    - by Tim Snowhite
    I have a list of hashes, as such: incoming_links = [ {:title => 'blah1', :url => "http://blah.com/post/1"}, {:title => 'blah2', :url => "http://blah.com/post/2"}, {:title => 'blah3', :url => "http://blah.com/post/3"}] And an ActiveRecord model which has fields in the database with some matching rows, say: Link.all => [<Link#2 @title='blah2' @url='...post/2'>, <Link#3 @title='blah3' @url='...post/3'>, <Link#4 @title='blah4' @url='...post/4'>] I'd like to do set operations on Link.all with incoming_links so that I can figure out that <Link#4 ...> is not in the set of incoming_links, and {:title => 'blah1', :url =>'http://blah.com/post/1'} is not in the Link.all set, like so: #pseudocode #incoming_links = as above links = Link.all expired_links = links - incoming_links missing_links = incoming_links - links expired_links.destroy missing_links.each{|link| Link.create(link)} One route I've tried: I'd rather not rewrite Array#- and such, and I'm okay with converting incoming_links to a set of unsaved Link objects; so I've tried overwriting hash eql? and so on in Link so that it ignored the id equality that AR::Base provides by default. But this is the only place this sort of equality should be considered in the application - in other places the Link#id default identity is required. Is there some way I could subclass Link and apply the hash, eql?, etc overwriting there? The other route I've tried is to pull out the attributes hash for each Link and doing a .slice('id',...etc) to prune the hashes down. But this requires writing seperate methods for keeping track of the Link objects while doing set operations on the hashes, or writing seperate Collection classes to wrap the incoming_links hash-list and Link-list which seems a bit overkill. What is the best way to design this interaction? Extra credit for cleanliness.

    Read the article

  • SPFileVersionCollection - why versions are sorted in mixed order?

    - by Janis Veinbergs
    SPFileVersionCollection and SPListItemVersionCollection versioning seems inconsistent to me. Inconsistency wouldn't be a problem to me, but sort order is. SPListItemVersionCollection I can understand versioning of ListItems as they are stored in descending order: SPContext.Current.ListItem.Versions.Count -> 5 SPContext.Current.ListItem.Versions[0].VersionId -> 1026 (2.2 latest version) SPContext.Current.ListItem.Versions[1].VersionId -> 1025 (2.1) SPContext.Current.ListItem.Versions[2].VersionId -> 1024 (2.0) ... [4].VersionId -> (oldest version) SPFileVersionCollection However I can't understand how version numbers are saved for a document library item: SPContext.Current.ListItem.File.Versions.Count -> 4 SPContext.Current.ListItem.File.Versions[0].ID -> 512 (1.0 oldest one) SPContext.Current.ListItem.File.Versions[1].ID -> 513 (1.1) SPContext.Current.ListItem.File.Versions[2].ID -> 1025 (2.1 latest version) SPContext.Current.ListItem.File.Versions[3].ID -> 1024 (2.0 (EDIT: IsCurrentVersion = True)) They are nor in ascending order, nor descending, but something mixed. Is there any reason for SharePoint team to decide to store SPFile versions like that? And do they expect that I write my own method to get latest version or is there a builtin one for that? A note: Let me point out that SPListItem.File is not null for document library items.

    Read the article

  • save xml object so that elements are in sorted order in saved xml file

    - by scot
    Hi , I am saving a xml document object and it is saved in a xml file as shown below . <author name="tom" book="Fun-II"/> <author name="jack" book="Live-I"/> <author name="pete" book="Code-I"/> <author name="jack" book="Live-II"/> <author name="pete" book="Code-II"/> <author name="tom" book="Fun-I"/> instead i want to sort the content in document object so that when i persist the object it is saved by grouping authors then book name as below: <author name="jack" book="Live-I"/> <author name="jack" book="Live-II"/> <author name="pete" book="Code-I"/> <author name="pete" book="Code-II"/> <author name="tom" book="Fun-I"/> <author name="tom" book="Fun-II"/> I use apache xml beans..any ideas on how to achieve this? thanks.

    Read the article

  • Use of double pointer in linux kernel Hash list implementation

    - by bala1486
    Hi, I am trying to understand Linux Kernel implementation of linked list and hash table. A link to the implementation is here. I understood the linked list implementation. But i am little confused of why double pointers is being used in hlist (**pprev). Link for hlist is here. I understand that hlist is used in implementation of hash table since head of the list requires only one pointer and it saves space. Why cant it be done using single pointer (just *prev like the linked list)? Please help me.

    Read the article

  • location.hash in an iframe scrolls the parent window

    - by Ben Clayton
    Hi all. I have a page with an iframe. Inside the iframe is code (that I can't change) that sets location.hash to the id of an element in the iframe window. This has the unwanted effect of scrolling my outermost browser window so that the top of the window touches the top of the iframe. This is quite annoying as I have a toolbar above the iframe that is vital to my app. Is there any way of preventing the setting of location.hash affecting the scroll position of the main window? Will preventDefault help me out here? Thanks!

    Read the article

  • Search algorithm for a sorted double linked list

    - by SalamiArmi
    As a learning excercise, I've just had an attempt at implementing my own 'merge sort' algorithm. I did this on an std::list, which apparently already had the functions sort() and merge() built in. However, I'm planning on moving this over to a linked list of my own making, so the implementation is not particuarly important. The problem lies with the fact that a std::list doesnt have facilities for accessing random nodes, only accessing the front/back and stepping through. I was originally planning on somehow performing a simple binary search through this list, and finding my answer in a few steps. The fact that there are already built in functions in an std::list for performing these kinds of ordering leads me to believe that there is an equally easy way to access the list in the way I want. Anyway, thanks for your help in advance!

    Read the article

  • php selecting hash using wildcards

    - by tipu
    Say I have a hashmap, $hash = array('fox' => 'some value', 'fort' => 'some value 2', 'fork' => 'some value again); I am trying to accomplish an autocomplete feature. When the user types 'fo', I would like to retrieve, via ajax, the 3 keys from $hash. When the user types 'for', I would like to only retrieve the keys fort and fork. Is this possible? What I was thinking was using binary search to isolate the keys with 'f', instead of brute-force searching. Then continue eliminating the indexes as the user types out their query. Is there a more efficient solution to this?

    Read the article

  • How to sort a list alphabetically and have additional lists sorted in the same order

    - by Carl
    I have 3 lists, each with equal elements: email addresses, salaries and IDs I'd like to sort the email addresses alphabetically and in some way sort the other 2 lists (salaries and IDs). E.g., Emails: [email protected] [email protected] Salaries: 50000 60000 IDs: 2 1 The puzzle: I'd like to sort Emails such that [email protected] is first and [email protected] is last and Salaries is 60000 then 50000 and IDs is 1 then 2. Additional detail: 1. Length of lists are the same and can be longer than two elements. 2. I will subsequently pass IDs to functions to retrieve further lists. Those lists won't need sorting as they will adopt the order of the IDs list.

    Read the article

  • Hashes vs Numeric id's

    - by Karan Bhangui
    When creating a web application that some how displays the display of a unique identifier for a recurring entity (videos on YouTube, or book section on a site like mine), would it be better to use a uniform length identifier like a hash or the unique key of the item in the database (1, 2, 3, etc). Besides revealing a little, what I think is immaterial, information about the internals of your app, why would using a hash be better than just using the unique id? In short: Which is better to use as a publicly displayed unique identifier - a hash value, or a unique key from the database? Edit: I'm opening up this question again because Dmitriy brought up the good point of not tying down the naming to db specific property. Will this sort of tie down prevent me from optimizing/normalizing the database in the future? The platform uses php/python with ISAM /w MySQL.

    Read the article

  • Delphi : Sorted List

    - by Sethu
    I need to sort close to a 1,00,000 floating point entries in delphi. I am new to delphi and would like to know if there are any readymade solutions available. I tried a few language provided constructs and they take an inordinate amount of time to run to completion.(a 5-10 sec execution time is fine for the application)

    Read the article

  • Mysql results sorted by list which is unique for each user

    - by ADAM
    Ive got a table of thousands of products and 50 or so authenticated users. These users all show the products on their own web sites and they all require the ability to have them ordered differently. Im guesing i need some kind of seperate table for the orders which contains the product_id, user_id and order column? How do i do this the most efficiently in mysql so as to be very fast, and not slow down if i get millions of products in the database. Is it even wise to do it in mysql or should i be using some kind of other index like solr/lucene? My Product table is called "products" My User table is called "users" A good example of the functionality i need is google search where you can order/supress the results if you are logged in. edit: the product results will be paginated and the users have the authority to edit the products, so its not just ready only

    Read the article

  • Sorting nested hash in ruby

    - by Rabbott
    Provided the following ruby hash: { cat: { 1: 2, 2: 10, 3: 11, 4: 1 }, wings: { 1: 3, 2: 5, 3: 7, 4: 7 }, grimace: { 1: 4, 2: 5, 3: 5, 4: 1 }, stubborn: { 1: 5, 2: 3, 3: 7, 4: 5 } } How can I sort the hash by the sum of 'leaf' excluding "4", for instance the value to compare for "cat" would be (2 + 10 + 11) = 23, the value for "wings" would be (3 + 5 + 7) = 15 so if I was comparing just those two they would be in the correct order, highest sum on top. It is safe to assume that it will ALWAYS be {1: value, 2: value, 3: value, 4: value} as those are keys for constants I have defined. It is also safe to assume that I will only ever want to exclude the key "4", and always use the keys "1", "2", and "3"

    Read the article

  • maintaing a sorted list that is bigger than memory

    - by tcurdt
    I have a list of tuples. [ "Bob": 3, "Alice: 2, "Jane": 1, ] When incrementing the counts "Alice" += 2 the order should be maintained: [ "Alice: 4, "Bob": 3, "Jane": 1, ] When all is in memory there rather simple ways (some more or some less) to efficiently implement this. (using an index, insert-sort etc) The question though is: What's the most promising approach when the list does not fit into memory. Bonus question: What if not even the index fits into memory? How would you approach this?

    Read the article

  • Getting a sorted distinct list from mySQL

    - by Stomped
    Goal I'l like to get a list of unique FID's ordered by the the one which has most recently been changed. In this sample table it should return FIDs in the order of 150, 194, 122 Example Data ID FID changeDate ---------------------------------------------- 1 194 2010-04-01 2 122 2010-04-02 3 194 2010-04-03 4 150 2010-04-04 My Attempt I thought distinct and order by would do the trick. I initially tried: SELECT distinct `FID` FROM `tblHistory` WHERE 1 ORDER BY changeDate desc # Returns 150, 122, 194 using GROUP BY has the same result. I'm just barely a SQL amateur, and I'm a bit hung up. What seems to be happening is the aggregating functions find the first occurrence of each and then perform the sort. Is there a way I can get the result I want straight from mySQL or do I have to grab all the data and then sort it in the PHP?

    Read the article

  • NSFetchedResultsController sections localized sorted

    - by Gerd
    How could I use the NSFetchedResultsController with translated sort key and sectionKeyPath? Problem: I have ID in the property "type" in the database like typeA, typeB, typeC,... and not the value directly because it should be localized. In English typeA=Bird, typeB=Cat, typeC=Dog in German it would be Vogel, Katze, Hund. With a NSFetchedResultController with sort key and sectionKeyPath on "type" I receive the order and sections - typeA - typeB - typeC Next I translate for display and everything is fine in English: - Bird - Cat - Dog Now I switch to German and receive a wrong sort order - Vogel - Katze - Hund because it still sorts by typeA, typeB, typeC So I'm looking for a way to localize the sort for the NSFetchedResultsController. I tried the transient property approach, but this doesn't work for the sort key because the sort key need to be in the entity. I have no other idea. But I can't believe that's not possible to use NSFetchedResultsController on a derived attribute required for localization? There are related discussions like http://stackoverflow.com/questions/1384345/using-custom-sections-with-nsfetchedresultscontroller but the difference is that the custom section names and the sort key have probably the same order. Not in my case and this is the main difference. At the end I would need a sort order for the necessary NSSortDescriptor on a derived attribute, I guess. This sort order has also to serve for the sectionKeyPath. Thanks for any hint.

    Read the article

  • SimpleXML adding html into Hash tree

    - by Miriam Raphael Roberts
    Question: I have an xml file that I am pulling from the web and parsing. One of the items in the xml is a 'content' value that has HTML. I am using SimpleXML/XMLin to parse the file like so: $xml= eval { $data-XMLin($xmldata, forcearray = 1, suppressempty= +'') }; When I use Dumper to dump the hash, I dsicovered that SimpleXML is parsing the HTML into the hash tree. 'content' => { 'div' => [ { 'xmlns' => 'http://www.w3.org/1999/xhtml', 'p' => [ { 'a' => [ { 'href' => 'http://miamiherald.typepad.com/.a/6a00d83451b26169e20133ec6f4491970b-pi', 'style' => 'FLOAT: left', 'img' => [ etc..... This is not what I want. I want to just grab content inside of this entry. How do I do this?

    Read the article

  • sorting nested list, allow only li to be sorted witin the same ul

    - by Y.G.J
    what i want to achive is: sorting the main ul is working but not all the time - i will try to fix that my own but if there is a problem with the code here and not the one in proccess-sortable - tell me. moving li in the main ul is ok but the sub or the sub of the sub is having problem - i can drag something from one sub to it's sub or the other way too - i don't want that to happend. i want to be able to drag li and by selecting that one that only this ul group will send to proccess-sortable to be updated - how can i catch the specific ul of li i am draging? $(document).ready(function() { $("#test-list").sortable({ items: "> li", handle : '.handle', axis: 'y', opacity: 0.6, update : function () { var order = $('#test-list').sortable('serialize'); $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); } }); $("#test-sub").sortable({ containment: "ul", items: "li", handle : '.handle2', axis: 'y', opacity: 0.6, update : function () { var order = $('ul').sortable('serialize'); $("#info").load("process-sortable.asp?"+order+"&id=catid&order=orderid&table=tblCats"); } }); }); this is the html part <ul id="test-list"> <li id="listItem_10">first<img align="middle" src="Themes/arrow.png" class="handle" /></li> <li id="listItem_8">second<img align="middle" src="Themes/arrow.png" class="handle" /> <ul id="test-sub"> <li id="listItem_4><img align="middle" src="Themes/arrow.png" class="handle2" /></li> <li id="listItem_3"><img align="middle" src="Themes/arrow.png" class="handle2" /></li> <ul id="test-sub"> <li id="listItem_9"><img align="middle" src="Themes/arrow.png" class="handle2" /></li> </ul> </li> </ul> </li> </ul>

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >