Hello World using Perl

Mohd Mohtashim
Updated on 28-Nov-2019 06:54:29

981 Views

Perl is a programming language developed by Larry Wall, specially designed for text processing.Just to give you a little excitement about Perl, I'm going to give you a small conventional Perl Hello World program,You can try it using the Demo link.Example Live Demo#!/usr/bin/perl # This will print "Hello, World" print "Hello, world";

Features of Perl Language

Mohd Mohtashim
Updated on 28-Nov-2019 06:51:56

2K+ Views

Perl is a programming language developed by Larry Wall, specially designed for text processing. There are following great feature of Perl LanguagePerl takes the best features from other languages, such as C, awk, sed, sh, and BASIC, among others.Perl's database integration interface DBI supports third-party databases including Oracle, Sybase, Postgres, MySQL, and others.Perl works with HTML, XML, and other mark-up languages.Perl supports Unicode.Perl is Y2K compliant.Perl supports both procedural and object-oriented programming.Perl interfaces with external C/C++ libraries through XS or SWIG.Perl is extensible. There are over 20, 000 third party modules available from the Comprehensive Perl Archive Network (CPAN).The Perl ... Read More

Why to Learn Perl

Mohd Mohtashim
Updated on 28-Nov-2019 06:47:48

328 Views

Perl is a programming language developed by Larry Wall, specially designed for text processing. It stands for Practical Extraction and Report Language. It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX Following great features make this language necessary for the Programmers to learn −Perl is a stable, cross-platform programming language.Though Perl is not officially an acronym few people used it as Practical Extraction and Report Language.It is used for mission-critical projects in the public and private sectors.Perl is an Open Source software, licensed under its Artistic License, or the GNU General ... Read More

Reasons to Choose Jasmine Over Jest

Ayush Gupta
Updated on 27-Nov-2019 12:31:17

104 Views

There is no solid reason to choose jasmine over jest. Both are excellent libraries that have been around for a while and have an opinionated way of doing things that are quite similar. Jest is built on top of jasmine.One reason why you might choose jasmine over jest is that it is faster. (https://github.com/facebook/jest/issues/6694)

Use of Sinon.js in JavaScript Testing

Ayush Gupta
Updated on 27-Nov-2019 12:21:19

537 Views

SinonJS provides stand-alone test spies, stubs and mocks. It is a library that we can use to create object mocks for unit testing.Spies − Fake functions that we can use to track executions.Stubs −Functions replacements from which we can return whatever we want or have our functions work in a way that suites us to be able to test multiple scenarios.Mocks −Fake methodsAll these objects help in unit testing our code.

Create Object Property from Variable Value in JavaScript

Ayush Gupta
Updated on 27-Nov-2019 12:20:26

9K+ Views

JS has 2 notations for creating object properties, the dot notation and bracket notation.To create an object property from a variable, you need to use the bracket notation in the following way −Exampleconst obj = {a: 'foo'} const prop = 'bar' // Set the property bar using the variable name prop obj[prop] = 'baz' console.log(obj);OutputThis will give the output −{    a: 'foo',    bar: 'baz' }ES6 introduces computed property names, which allow you to do −Exampleconst prop = 'bar' const obj = {    // Use a as key    a: 'foo',    // Use the value of prop ... Read More

Terminate JavaScript forEach Loop

Ayush Gupta
Updated on 27-Nov-2019 12:17:48

527 Views

You can't break from the forEach method and it doesn't provide to escape the loop (other than throwing an exception).You can use other functions like _.find from lodash instead −_.find − it breaks out of the loop when the element is found. For example,Example_.find([1, 2, 3, 4], (element) => {    // Check your condition here    if (element === 2) {       return true;    }    // Do what you want with the elements here    // ... });Throw an exception from forEach. For example,Exampletry {    [1, 2, 3, 4].forEach((element) => {       // Check your condition here       if (element === 2) {          throw new Error();       }       // Do what you want with the elements here       // ...    }) } catch (e) {    // Do nothing. }

Most Efficient Method to Group By on an Array of Objects in JavaScript

Ayush Gupta
Updated on 27-Nov-2019 10:48:44

7K+ Views

The most efficient method to group by a key on an array of objects in js is to use the reduce function.The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.Exampleconst people = [    { name: 'Lee', age: 21 },    { name: 'Ajay', age: 20 },    { name: 'Jane', age: 20 } ]; function groupBy(objectArray, property) {    return objectArray.reduce((acc, obj) => {       const key = obj[property];       if (!acc[key]) {          acc[key] = [];     ... Read More

Trigger OnChange Event Manually in JavaScript

Ayush Gupta
Updated on 27-Nov-2019 10:46:10

28K+ Views

You can dispatch events on individual elements using the dispatchEvent method. Let's say you have an element test with an onChange event −Event handler −document.querySelector('#test').addEventListener('change', () => console.log("Changed!"))Triggering the event manually −const e = new Event("change"); const element = document.querySelector('#test') element.dispatchEvent(e);This will log the following −Changed!

Delete LocalStorage Item When Browser Tab is Closed

Ayush Gupta
Updated on 27-Nov-2019 10:44:59

2K+ Views

To clear a localStorage data on browser close, you can use the window.onunload event to check for tab close.Let's say you have a local storage object called MyStorage as a global for the sake of this example. Then you can write an event handler −Examplewindow.onunload = () => {    // Clear the local storage    window.MyStorage.clear() }This will clear the local storage on the tab/window close.

Advertisements