w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘
Check with another constructor for htmlView: ContentType mimeType = new System.Net.Mime.ContentType("text/html"); var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage, mimeType);

Categories : Asp Net Mvc

Build hash of hash in perl
To get a reference, you have to use : $hoh{$id} = \%hash; %hash is the hash, not the reference to it. In scalar context, it returns the string X/Y wre X is the number of used buckets and Y the number of all the buckets in the hash (i.e. nothing useful).

Categories : Perl

Perl:Access values of hash inside a hash
If the syntax is keys %hash for a hash, it's keys %{ ... } for a hash reference. In this case, the reference is stored in $box{$box_key}, so you'd use keys %{ $box{$box_key} } Also, you're accessing elements named box_key and inside_key in a couple of places where you actually want the elements named by $box_key and $inside_key. Finally, you can use curlies around variable names to instruct Perl where the variable name ends. for my $box_key (keys %box) { for my $inside_key (keys %{ $box{$box_key} }) { print "${box_key}_$inside_key is for rupees $box{$box_key}{$inside_key} "; } }

Categories : Perl

How to incorporate hash inside hash in perl?
You can copy the keys/values of the %book into the %chapter: @chapter{keys %book} = values %book; Or something like %chapter = (%chapter, %book); Now you can say $chapter{name}, but changes in %book are not reflected in %chapter. You can include the %book via reference: $chapter{book} = \%book; Now you could say $chapter{book}{name}, and changes do get reflected. To have an interface that allows you to say $chapter{name} and that does reflect changes, some advanced techniques would have to be used (this is fairly trivial with tie magic), but don't go there unless you really have to.

Categories : Perl

Filtering a hash of hash in perl
You first need to find the keys of the elements you want to remove: grep { $HoH{$_}{town} eq 'springfield' } keys(%HoH) Then you delete them: delete $HoH{$_} for grep { $HoH{$_}{town} eq 'springfield' } keys(%HoH); Or using a hash slice: delete @HoH{ grep { $HoH{$_}{town} eq 'springfield' } keys(%HoH) };

Categories : Perl

Can Build.PL be used for Enterprise Perl based application having multiple Perl Modules
is it possible to have Build.PL include all of these Modules, and then be able to Build, test and cover ? Yes. I could not find any evidence where Build.PL has been used for Multiple Packages. You haven't looked very hard. A third of CPAN does so. How do we declare these Modules in Build.PL ? ./Build manifest Do i have to Build and test All these Modules individually ? No, as a whole. Perl should have a builder that can handle not only building, but also testing, code coverage and deployment. There are several.

Categories : Perl

perl: strip html tags, manipulate text, and then return html tags to their original positions
The module HTML::Strip uses the XS glue language to connect the Perl code with C code. You can find the XS file e.g. on (meta-)cpan. It includes a file strip_html.c that implements the actual algorithm. Due to the definitions in the XS file, a strip_html sub is available in the Perl code as part of the HTML::Strip package. Therefore, it can be invoked as a method on an appropriate object. Explanation of that piece of code my $stripped = $self->strip_html( $text ); This will invoke the C function on the contents of $text to strip all the HTML tags. The stripped data will then be assigned to $stripped. if( $self->decode_entities && $_html_entities_p ) { $stripped = HTML::Entities::decode($stripped); } Suffixing variable names with -p is a lispish tradition to indicate

Categories : HTML

How to Hash in Perl
store a listref in your hashing directory: $uniqueURLs{$line[9]} = [ <avg response time>, <count> ]; adjust the elements accordingly, eg. the count: if (defined($uniqueURLs{$line[9]})) { # url known, increment count, # update average response time with data from current log entry $uniqueURLs{$line[9]}->[0] = (($uniqueURLs{$line[9]}->[0] * $uniqueURLs{$line[9]}->[1]) + ($line[7] + 0.0)) / ($uniqueURLs{$line[9]}->[1] + 1) ; $uniqueURLs{$line[9]}->[1] += 1; } else { # url not yet known, # init count with 1 and average response time with actual response time from log entry $uniqueURLs{$line[9]} = [ $line[7] + 0.0, 1 ]; } to print results: # Go through the hash table and print the keys # which are the unique I

Categories : Perl

Allow acts_as_taggable_on to work with hash tags
Though not verified in practice, here is a solution. According to README, you can set the following in initializer to remove special characters in tag name: ActsAsTaggableOn.force_parameterize = true It seems acts_as_taggable_on doesn't have an installation command and a default initializer. You can put above setting in any file in /initializers/, and preferred a new file dedicated to this gem. By setting that, all of your tag name inputs will be processed after saving like my_string.parameterize Test "radical)(cc".parameterize #=> "radical-cc" "#Happy".parameterize #=> "happy"

Categories : Ruby On Rails

Different declaration of hash in Perl
The difference is how you express the content of the hash. With the array notation below, for example; you do it like this: my %hash = ( 'key 1' => 'value 1', 'key 2' => 'value 2'); The %{ } is a cast operator. It is used typically when you have a reference to something that is not obviously a hash. Typically a reference to a has: Example: my $hashref; $hashref->{'key 1'}='value 1'; $hashref->{'key 2'}='value 2'; my %hash = %{$hashref};

Categories : Perl

How to reference a hash in Perl?
Assigns a hash reference to a hash. This doesn't make sense. Assigns a list to a hash. This is how you normally handle hashes. Assigns a hash reference to a scalar. This is how you normally handle hash references. Assigns a list to a scalar. You'll end up with the last value being stored. To assess a scalar value in a hash (2): $hash{'foo'} To access a scalar value in a hashref (3): $hash->{'foo'} See perldoc perlref for more about references

Categories : Perl

How can I return a whole hash map in Perl?
It would be nice to return the hash reference instead of hash,what you need to do is First stote the hash into the hash ref then return it like sub getvalues { my %values = (test => "SO"); my $values = \%values; return $values; }

Categories : Perl

Why is Perl hash value added as a key?
While it would need you posting your code to make certain, judging by the output you appear to be iterating the hash as though it were an array; Perl will let you do this, but it's almost never what you want. Instead, try something like this: foreach my $key (keys %read_data) { my $value = $read_data{$key}; print "$key = $value "; };

Categories : Perl

Hash variable used in perl
See perlreftut - Mark's very short tutorial about references for explanation. returns a reference to its operand. The example would create a hash of hashes.

Categories : Perl

Perl Hash Trouble
You can use exists. http://perldoc.perl.org/functions/exists.html Given an expression that specifies an element of a hash, returns true if the specified element in the hash has ever been initialized, even if the corresponding value is undefined. foreach my $fruit (@array) { if (exists $hash{$fruit}) { $hash{$fruit}++; } }

Categories : Arrays

perl how to reference hash itself
What you've got there is some nested array references, not hashes. Let's assume you actually meant that you have something like this: my $h = { A => {...}, B => {...}, ..., EXPAND() }; In that case, you can't reference $h from within its own definition, because $h does not exist until the expression is completely evaluated. If you're content to make it two lines, then you can do this: my $h = { A=> {...}, B => {...} }; $h = { %$h, EXPAND( $h ) };

Categories : Perl

Foreach on hash variables in Perl
Quoting perldata - Perl data types: Hashes are unordered collections of scalar values indexed by their associated string key. You can sort the keys, or, if you want to preserve the order given in the initialization, use Tie::Hash::Indexed or Tie::IxHash.

Categories : Perl

How to put data from CSV file to Perl hash
Huh? Why so complicated? First, we fetch the header outside of the loop: my $headers = $csv->getline($fh) or die "no header"; Assign these to be the column names: $csv->column_names(@$headers); Then, each call to getline_hr will provide a hashref: while (my $hashref = $csv->getline_hr($fh)) { push @$result, $hashref; } We can also use getline_hr_all: $result = $csv->getline_hr_all($fh); In other words, it ain't complex, most pieces are already provided by Text::CSV, and it can be done in very few lines. Also, a module like this seems to already exist: Text::CSV::Slurp. (note: reverse dependency search through metacpan is awesome)

Categories : Perl

convert csv in perl hash of arrays
Something like: while ( my $line = readline($fh) ) { chomp $line; my ( $emp_no, $birth_date, $first_name, $last_name, $gender, $hire_date ) = split /,/, $line; push @{ $employee->{emp_no} }, $emp_no; #etc. }

Categories : Perl

Initializing hash reference in perl
Initialize an empty hash reference. #!/usr/bin/perl use warnings; use strict; my $Hash = {}; Init($Hash); printf("Value:%d ",$Hash->{Key}); sub Init { my ($Hash) = @_; $Hash->{Key}=10; }

Categories : Perl

Create a Perl hash with an array as the key
Regular hashes can only have string keys, so you'd need to create some kind of hashing function for your arrays. A simple way would be to simply join your array elements, e.g. $h{join('-', @a)} = @a; # A nice readable separator $h{join($;, @a)} = @a; # A less likely, configurable separator ("34") But that approach (using a sentinel value) requires that you pick a character that won't be found in the keys. The following doesn't suffer from that problem: $h{pack('(j/a*)*', @a)} = @a; Alternatively, check out Hash::MultiKey which can take a more complex key.

Categories : Perl

How to work with hash of hashes in Perl?
Use the following syntax. If a hash reference is passed, the old content is forgotten, if you supply two arguments, a key - value pair is added. $hash_of_structs{one}->hash({'A', 'a', 'B', 'b'}); $hash_of_structs{one}->hash('key', 'value');

Categories : Perl

Perl : Data structure, is this a hash?
This subroutine returns a hash reference (pointer to a hash.) Curly braces used in this fashion construct an anonymous hash and return a reference to it. Assuming you call the subroutine something like this: my $results = _relation(); You would access the elements using the -> dereferencing operator: $results->{player1} # 0 $results->{player2} # 1 If you want to copy the anonymous hash into a named one, you can dereference the entire thing at once with my %regular_hash = %$results; See the Perl References Tutorial for more.

Categories : Perl

How do I sort hash of hashes by a sub key/value using perl?
You can't sort a hash. Can you make do with having the names of the views in the specific order? my $views = $VAR1->{views}; my @sorted_view_keys = sort { $views->{$a}{__displayorder} cmp $views->{$b}{__displayorder} } keys(%$views); Or maybe you want the sorted views? my @sorted_views = map { $views->{$_} } @sorted_view_keys; -or- my @sorted_views = @$views[@sorted_view_keys];

Categories : Perl

Can a hash key have multiple 'subvalues' in perl?
If you know you are going to have duplicates you can create your hashes in this format: use strict; use warnings FATAL => 'all'; use Data::Dumper; my %hash; push @{$hash{key1}}, 'Value1'; push @{$hash{key2}}, 'Value2'; push @{$hash{key1}}, 'Value3'; print Dumper ( \%hash ); Perl has a property called autovivification, which will allows it to create the hash value if it doesnt exist, and append to one if it does. (assuming you are using list-context) $VAR1 = { 'key2' => [ 'Value2' ], 'key1' => [ 'Value1', 'Value3' ] }; You can now get arrayref from your hash key and examine all of the Xlocs (whatever that is).

Categories : Perl

How to remove keys from hash in Perl?
Use delete for deleting the hash keys: if (exists $sampleMap{1}) { delete $sampleMap{1}; #Here I want remove the "1" key from sampleMap. } For more details, take a look at delete.

Categories : Perl

Perl hash to json conversion?
The first four lines in Mojo::JSON's SYNOPSIS will tell you. use Mojo::JSON; my $json = Mojo::JSON->new->encode( $VAR1 );

Categories : Json

Perl hash containing multiple arrays
An array in Perl has the following properties: It is indexed by a continuous range of positive integers, starting with 0. It holds scalars as values They are indexed with square brackets, e.g. $array[0] = $val. A hash on the other hand has the properties It is indexed by unique strings. The key-value pairs have no guaranteed order. It holds scalars as values. They are indexed with curlies, e.g. $hash{"some key"} = $val. If the key is a valid identifier, the quotes are optional: $hash{some_key} = $val. Neither hashes nor arrays are scalars, but you can take a reference with the unary operator, which then is a scalar. Do not get confused by other languages using the name “associative array” for what Perl calls hashes, or by having the same syntax for hashes and arrays. For you

Categories : Perl

How should I assigned the same value to two different keys in this Perl hash?
The second form is possible and some people use it frequently $x = $y = $z; The first form does not do what you need. It only assings the value to the first variable. ($x, $y) = $z; You need two member list on the right hand side as well: ($x, $y) = ($z) x 2; Update: In your case, you can use the x operator only if the methods involved return the same values for both invocations, otherwise, you can use ($x, $y) = map $obj->method, 1, 2;

Categories : Perl

Dereference hash list in Perl
{ ... } returns already a reference to an hash, so { ... } returns a reference to a reference to an hash (double pointer). Said so you could then deference it using ${$table}->{'key'}.

Categories : Perl

Slicing hash of hashes perl
Try this code, that will do the trick : #!/usr/bin/perl use strict; use warnings; my %data_final = ( 2010 => { Jan => { group1 => { Type1 => { Total1 => 12, Total2 => 10 }, Type2 => { Total1 => 17, Total2 => 14 }, }, }, } ); my $total1_sum; $total1_sum += $data_final{2010}{Jan}{group1}{$_}{Total1} for keys $data_final{2010}{Jan}{group1}; my $total2_sum; $total2_sum += $data_final{2010}{Jan}{group1}{$_}{Total2} for keys $data_final{2010}{Jan}{group1}; print <<EOF; total1_sum=$total1_sum total2_sum=$total2_sum EOF Output : total1_sum=29 total2_sum=24

Categories : Perl

Multi level hash ref in perl
You didn't show what you have tried, and your question isn't exactly clear which may mean that your question will be closed. I'm not going to do too much programming for you, but I suggest you look into Perl Object Oriented Programming. Each forum can be an object, and one of the fields can be a hash of other forums. Programming OO Perl isn't that hard if you already understand about references. By defining each forum as a member of your forum class, you remove the tricky part of operating on a hash of hashes. I would also suggest that you break your problem down into smaller pieces. Drag and Drop can be added once you have the basics of your code down. Do you want to output XML? It's not exactly clear what you're trying to do. If you merely want to store your structure, you can use St

Categories : Perl

Curl PHP parsing hash tags results in 400 bad request
The anchor fragment (# and everything after) is not part of the request URL. It should never be sent to the server. cURL has nothing to do with this. Only the browser cares about this part. If this page is doing some AJAX or otherwise dynamically loading content based on the anchor fragment, then you will need a browser to run that page and execute the JavaScript. You can use PhantomJS for this task.

Categories : PHP

Fast method of "marking up" URL's and hash tags in text
My first idea were two calls to String.replaceAll(), one for tags, one for links. The code will be readable and quite fast. My second idea is something faster, but more ugly. Something that does everything in one pass. General idea: final String message = "This is some #text with for http://mysite.com/"; for (int i = 0; i < message.length; i++) { if (message[i] == '#') { // mark a hashtag } else if (i < message.length - 6 && (message[i] == 'h' || message[i + 1] == 't' || message[i + 2] == 't' || message[i + 3] == 'p' || message[i + 4] == ':' || message[i + 5] == '/' || message[i + 6] == '/')) { // mark a link } }

Categories : Java

Perl: Is is possible for a Hash to store mixed variables?
Yes, it is possible, and most easily done with lexical variables: sub mysub { my %hash1; my %hash2; my %hash3; my @array1; my @array2; my @array3; ... my %all = ( hash1 => \%hash1, hash2 => \%hash2, array1 => @array1, # etc ); return \%all; } You return a single scalar value which is a hash reference, containing all the data.

Categories : Arrays

Perl hash Data::Dumper output
You can print the output anywhere you want. If you already have a log file open in your program, you can just print $log Dumper $myhash; But in general there is nothing special about log files. If you don't have one open you can just open a temporary file. open my $temp, '>', 'myhash.txt' or die $!; print $temp Dumper $myhash; close $temp; and you will have a new text file myhash.txt that contains the data structure. By the way, the Data::Dump module is more recent and tends to generate more compact and more readable output. If you want to try it (it may need installing on your system) use this use Data::Dump 'dump'; open my $temp, '>', 'myhash.txt' or die $!; print $temp dump $myhash; close $temp;

Categories : Perl

How to print hash of anonymous hashes in perl?
The problem is that the members of %HoA are arrays, not hashes. In fact, what you have is a hash with one element. The key of that element is a reference to an array holding two elements: "stones" and "ruby". The value of that element is a reference to an array holding two elements: "metal" and "gold". I'm guessing you want a hash that will contain a list of stones, a list of metals etc. The way to do that is: %HoA = ( stones => ["ruby"], metal => ["gold"], ); Now $HoA{stones} is a reference to an array containing the single element "ruby". print @($HoA{stones}); should give you: ruby

Categories : Misc

perl 101 - iterating hash causes never ending looping
The keys (and also the values) functions reset the iterator used by the each function. As the keys do not change you could retrieve them outside of the loop.

Categories : Perl

Perl- print hash values while the key is matched
my $value = @_; This will put the number of elements of @_ in $value - evaluating a list in scalar context returns its number of elements. You can use this instead: my ($value) = @_;

Categories : Perl

Unable to get desired hash for CSV format in perl
Rewrite this line push @{hash->{@columnNames}} ,@columnValues; to: foreach my $columnName (@columnNames) { my $columnValue = shift @columnValues; push @{ $hash{$columnName} }, $columnValue; }

Categories : Perl



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.