Wednesday 20 July 2016

PERL MERGE JSON

Merging multiple JSON files into one using JSON::XS IN PERL


$json1 =

[
   {
      "name" : "bob",
      "title" : "janitor",
      "email" : "",
      "iq" : "180",
      "favorite_food" : "wagyu steak"
   },
   {
      "name" : "joe",
      "title" : "software engineer",
      "email" : "",
      "iq" : "80",
      "favorite_food" : "raw hamburger"
   }
]
 
$json2 =  
{
   "People" : [
      {
         "name" : "bob",
         "title" : "janitor",
         "email" : "",
         "iq" : "180",
         "favorite_food" : "wagyu steak"
      },
      {
         "name" : "joe",
         "title" : "software engineer",
         "email" : "",
         "iq" : "80",
         "favorite_food" : "raw hamburger"
      },
      {
         "name" : "sandy",
         "title" : "dishwasher",
         "email" : "",
         "iq" : "240",
         "favorite_food" : "filet mignon"
      },
      {
         "name" : "george",
         "title" : "software engineer",
         "email" : "",
         "iq" : "14",
         "favorite_food" : "tacos"
      }
   ]   
}

CODE IS,
 
my @fields;
my $uuts = {};
while(<$fh>) {
    chomp;
    next if !-e "/tmp/files/$_.json";
    my $decoded = decode_json( read_file("/tmp/files/$_.json") );
    push @fields, $decoded;
}
$uuts->{People} = [ @fields ];
[download]

to just this:

my $uuts;
while (<$fh>) {
    chomp;
    next if ! -e "/tmp/files/$_.json";
    push @{$uuts->{People}}, @{decode_json(read_file("/tmp/files/$_.js
+on"))};
}  
 
I'm not really in a position to test that; however, here's a small test that shows the technique involved:

$ perl -Mstrict -Mwarnings -le '
    use Data::Dumper;
    my @jsons = ([{a=>1}, {b=>2}], [{c=>3}, {d=>4}]);
    my $combo;
    for (@jsons) {
        print Dumper $_;
        push @{$combo->{People}} => @$_;
    }
    print Dumper $combo;
'
$VAR1 = [
          {
            'a' => 1
          },
          {
            'b' => 2
          }
        ];

$VAR1 = [
          {
            'c' => 3
          },
          {
            'd' => 4
          }
        ];

$VAR1 = {
          'People' => [
                        {
                          'a' => 1
                        },
                        {
                          'b' => 2
                        },
                        {
                          'c' => 3
                        },
                        {
                          'd' => 4
                        }
                      ]
        };

Wednesday 27 April 2016

Perl Basics

Perl Basics has two main goals. First, it provides a succinct summary of major Perl elements. Second, it provides perspective and relates features to one another. Thus, you may think of it as an extended and structured checklist, with commentary.
The discussion is oriented toward answering two questions:
  • What are the things Perl provides you to work with?
  • What can you do to those things?
The discussion includes six major sections:
  1. Variables and their Related Operators
  2. Control structures
  3. Functions
  4. Regular Expressions
  5. Input/Output
  6. System Operators

1. Variables and their Related Operators

Perl provides three kinds of variables: scalars, arrays, and associative arrays. The discussion includes the designation of these three types and the basic operators provided by Perl for their manipulation.

2. Control Structures

Perl is an iterative language in which control flows from the first statement in the program to the last statement unless something interrupts. Some of the things that can interrupt this linear flow are conditional branches and loop structures. Perl offers approximately a dozen such constructs. Each of these basic constructs are described along with examples illustrating their use.

3. Functions

Functions are a fundamental part of most programming languages. They often behave like an operator, producing a change in the value of some variable or returning a value that can be assigned to a variable. They also control the flow of execution, transferring control from the point of invocation to the function definition block and back. Thus, they combine properties of the two preceding discussions. The discussion will cover both the designation of functions and their invocation and use.

4. Regular Expressions and Related Operators

Regular expressions are strings that can be recognized by a regular grammar, a restricted type of context-free grammar. Basically, they are strings that can be parsed left to right, without backtracking, and requiring only exact symbol matching, matching of a symbol by a category of symbols, or matching of a symbol by a specified number of sequential occurrences of a symbol or category. Perl provides a general mechanism for specifying regular expressions. It also provides several operators that manipulate strings based upon the evaluation of a regular expression.
The discussion will begin by describing the various mechanism for specifying patterns and then discuss expression-based operators.

5. Input/Output

Perl provides basic I/O for both the standard input (keyboard) and output (display) devices and for files in the UNIX file system. More sophisticated I/O is provided through the UNIX DBM library. These various I/O capabilities are discussed.

6. System Operators

Perl offers a number of operators that mimic or call UNIX system operators or analogous operators for other operating systems. The discussion here will be cast in the context of UNIX and will assume familiarity with basic UNIX facilities. Perl system operators can be roughly divided into two large categories: file/directory operators and process operators. Both types are discussed.

Wednesday 30 March 2016

What is Memcached?

Free & open source, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.
Memcached is simple yet powerful. Its simple design promotes quick deployment, ease of development, and solves many problems facing large data caches. Its API is available for most popular languages.


Quick Example

Cache Results

function get_foo(foo_id)
    foo = memcached_get("foo:" . foo_id)
    return foo if defined foo

    foo = fetch_foo_from_database(foo_id)
    memcached_set("foo:" . foo_id, foo)
    return foo
    end

Play with telnet

$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get foo
VALUE foo 0 2
hi
END
stats
STAT pid 8861
(etc)

Need more information? Check out --> https://memcached.org/about

Wednesday 10 February 2016

Perl Programming.. How to Use Regular Expressions in your code by prem 10-2-2016.


Qus : Here given one date 2016-02-10. How to convert  date-month-year format via perl programming?
(for example 2016-02-10 to 10-02-2016).


$date = "2012-10-02";

if($date =~ m/(\d{4})\-(\d{2})\-(\d{2})/))
{
    $year = $1;
    $month =$2;
    $date = $3;
    $converted_date = $date . "-" . $month . "-" . $year;
    print "$converted_date\n";
  }

----------------------------------program completed-------------------------------------------


Here $1,$2 and $3 is special varibles which contains group values from regular expressions. \d is refers to digits and \d{4} is refers to digits should be contain with 4 digit.

Saturday 30 May 2015


Logical Thinking: How to use your brain to your advantage


Logical thinking! You might have heard that phrase a couple of times before, but do you really know what it implies? Logical thinking is to think on the basis of knowledge, what we know, and certainties, what we can prove. The past two centuries have witnessed an unparalleled reliance on the logical approach to thinking. It is the basis on which modern technology is founded. But the flaw in logical thinking is that it relies on the conscious brain and this is the most limited and vulnerable part of our thinking.




Left-Brain Thinking

                            Logical thinking is the part of the brain that relates to its left-hand side (“l” for “left” and “l” for “logical”). It was Professor Roger Sperry of the University of California who discovered that different sides of the brain were responsible for different functions. He discovered that the left-brain…
  • governs the right side of the body
  • governs the right field of vision
  • deals with input sequentially
  • perceives the parts more than the whole
  • perceives time

Right Brain Thinking

                     Just as he explained the workings of the logical, left-sided brain, so Roger Sperry also discovered that the right-hand side is responsible for romantic types of thinking (“r” for “romantic” and “right-sided”). In contrast to the left, he discovered that the right brain…
  • governs the left side of the body
  • governs the left field of vision
  • deals with inputs simultaneously
  • perceives the whole more than the parts
  • perceives space
  • is the seat of visual skills
  • is the seat of intuitive and kinaesthetic perception
  • is responsible for imagination and visualisation
  • formulates symbol and metaphor.

Logical Thinking

                     Logical (or left-brain) thinking comes into its own when we are working with verifiable and reasonably certain information. This is information we can be sure about because it has been confirmed scientifically. Using “scientific” information allows us to develop our knowledge by making logical deductions. It is the kind of thinking used in playing games of chess, (where there are quite definite rules) and solving puzzles for which there is an answer. Logical thinking uses 5 steps:
1. A clear goal or solution: Working towards clear goals is often described by the mnemonic SMART. These are goals which are Specific, Measurable, Achievable, Realistic and Time-bounded.
2. Systematic planning: Systematic planning is the second step in the SMART process towards a goal. We know the “what?” because we have defined a clear goal; systematic planning tells us the “how?” to get us there. Systematic planning aims to find the correct method, the correct procedure, the correct system that can logically take us to our goal.
3. Using information: The remaining steps in the SMART process involve using our left-sided brains to work towards our goals. Information is key to this process. We need to group it, organize it, rank it, fit it into the bigger picture, and make connections with it.
4. Reasoning
5. Checking conclusions


Our brain in a fast-paced world

                            The logical, or scientific, approach to thinking relies on information about the world around us. From it, we can create the most wonderful inventions and manifestations. But, in a fast-paced world, this information is quickly out-of-date, quickly inaccurate, and quickly useless. If we are to rely on logical thinking to succeed in life, then we need to be masters of left-brain thinking.

Monday 29 September 2014

The iPhone 6 and iPhone 6 Plus are iOS smartphones developed by Apple Inc. The devices are part of the iPhone series, and were released on September 19, 2014. The iPhone 6 series jointly serves as a successor to the iPhone 5S. The iPhone 6 series includes a number of major changes over its predecessor, including a streamlined design, models with larger 4.7-inch and 5.5-inch displays, a faster processor, upgraded cameras, improved LTE and Wi-Fi connectivity, and support for a near-field communications-based mobile payments offering.[6][7]
Pre-orders of the iPhone 6 series exceeded 4 million within its first 24 hours of availability—an Apple record.[8] More than 10 million iPhone 6 series devices were sold in the first three days, another Apple record.[9]

                    

Hardware

iPhone 6 unboxed
The design of the iPhone 6 line is influenced by that of the iPad Air, with a glass front that is curved around the edges of the display, and an aluminium rear that contains two plastic strips for the antenna.[18] Both models come in gold, silver, and "space gray" finishes. The iPhone 6 has a thickness of 6.9 millimetres (0.69 cm), while the iPhone 6 Plus is 7.1 millimetres (0.71 cm) in thickness; both are thinner than the iPhone 5S, with the iPhone 6 being Apple's thinnest phone to date. The most significant changes to the iPhone 6 line are its displays; both branded as "Retina HD Display" and "ion-strengthened", the iPhone 6 display is 4.7 inches in size with a 16:9 resolution of 1334x750 (326 PPI, minus one row of pixels), while the iPhone 6 Plus includes a 5.5-inch 1080p display (401 PPI). To accommodate the larger physical size of the iPhone 6 line, the power button was moved to the side of the phone instead of the top to improve its accessibility.[7][6] The iPhone 6 features a non-removable 1810 mAh battery, while the iPhone 6 Plus features a non-removable 2915 mAh battery. Unlike the previous model, the rear-facing camera is not flush with the rear of the device, and has a slight "bulge" around the lens.[19]
Both models include an Apple A8 system-on-chip, and an M8 motion co-processor—an update of the M7 chip from the iPhone 5S. The main difference between the M8 and the original M7 coprocessor is that it also collects data from the barometer to measure altitude changes. Phil Schiller touted that the A8 chip would provide, in comparison to the 5S, a 25% increase in CPU performance, a 50% increase in graphics performance, and less heat output. Early hands-on reports suggested that the A8's GPU performance might indeed break away from previous generations doubling of performance at each yearly release, scoring 21204.26 in Basemark X compared to 20253.80, 10973.36 and 5034.75 on respectively the 5S, 5 and 4S