• Complain

Sundeep Agarwal - Perl one-liners cookbook

Here you can read online Sundeep Agarwal - Perl one-liners cookbook full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2021, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover

Perl one-liners cookbook: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Perl one-liners cookbook" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Sundeep Agarwal: author's other books


Who wrote Perl one-liners cookbook? Find out the surname, the name of the author of the book and a list of all author's works by series.

Perl one-liners cookbook — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Perl one-liners cookbook" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Perl one-liners cookbook
Perl one-liners cookbook

Sundeep Agarwal

Preface

This book focuses on Perl usage from the command line, similar to grep, sed and awk usage. Syntax and features of these tools (along with languages like C and bash) were inspirations for Perl, so prior experience with them would make it easier to learn Perl.

You'll learn about various command line options and Perl features that make it possible to write compact cli scripts. Learning to use Perl from the command line will also allow you to construct solutions where Perl is just another tool in the shell ecosystem.

Prerequisites

You should be comfortable with programming basics and have prior experience working with Perl. You should know concepts like scalar, array, hash and special variables, be familiar with control structures, regular expressions etc. If you need resources to get started with Perl and regular expressions, you can start with these links:

  • perldoc: perlintro
  • learnxinyminutes: perl
  • perldoc: perlretut

You should also have prior experience working with command line, bash shell and be familiar with concepts like file redirection, command pipeline and so on.

Conventions
  • The examples presented here have been tested with Perl version 5.32.0 and includes features not available in earlier versions.
  • Code snippets shown are copy pasted from bash shell and modified for presentation purposes. Some commands are preceded by comments to provide context and explanations. Blank lines have been added to improve readability, only real time is shown for speed comparisons and so on.
  • Unless otherwise noted, all examples and explanations are meant for ASCII characters
    • See also stackoverflow: why does modern perl avoid utf-8 by default
  • External links are provided for further reading throughout the book. Not necessary to immediately visit them. They have been chosen with care and would help, especially during re-reads.
  • The learn_perl_oneliners repo has all the code snippets and files used in examples and exercises and other details related to the book. If you are not familiar with git command, click the Code button on the webpage to get the files.
Acknowledgements
  • perl documentation manuals, tutorials and examples
  • /r/perl/ helpful forum for beginners and experienced programmers alike
  • stackoverflow for getting answers to pertinent questions on Perl, one-liners, etc
  • tex.stackexchange for help on pandoc and tex related questions
  • LibreOffice Draw cover image
  • pngquant and svgcleaner for optimizing images
  • Warning and Info icons by Amada44 under public domain
  • softwareengineering.stackexchange and skolakoda for programming quotes

A heartfelt thanks to all my readers. Your valuable support has significantly eased my financial concerns and allows me to continue writing books.

Feedback and Errata

I would highly appreciate if you'd let me know how you felt about this book, it would help to improve this book as well as my future attempts. Also, please do let me know if you spot any error or typo.

Issue Manager: https://github.com/learnbyexample/learn_perl_oneliners/issues

E-mail:

Twitter: https://twitter.com/learn_byexample

Author info

Sundeep Agarwal is a freelance trainer, author and mentor. His previous experience includes working as a Design Engineer at Analog Devices for more than 5 years. You can find his other works, primarily focused on Linux command line, text processing, scripting languages and curated lists, at https://github.com/learnbyexample. He has also been a technical reviewer for Command Line Fundamentals book and video course published by Packt.

List of books: https://learnbyexample.github.io/books/

License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License

Code snippets are available under MIT License

Resources mentioned in Acknowledgements section above are available under original licenses.

Book version

1.5

See Version_changes.md to track changes across book versions.

One-liner introduction

This chapter will give an overview of perl syntax for command line usage and some examples to show what kind of problems are typically suited for one-liners.

Why use Perl for one-liners?

I assume you are already familiar with use cases where command line is more productive compared to GUI. See also this series of articles titled Unix as IDE.

A shell utility like bash provides built-in commands and scripting features to easily solve and automate various tasks. External *nix commands like grep, sed, awk, sort, find, parallel, etc can be combined to work with each other. Depending upon your familiarity with those tools, you can either use perl as a single replacement or complement them for specific use cases.

Here's some one-liners (options will be explained later):

  • perl -pe 's/(?:\x27;\x27|";")(*SKIP)(*F)|;/#/g' change ; to # but don't change ; within single or double quotes
  • perl -MList::Util=uniq -e 'print uniq <>' retain only first copy of duplicated lines, uses built-in module List::Util
  • perl -MRegexp::Common=net -nE 'say $& while /$RE{net}{IPv4}/g' extract only IPv4 addresses, using a third-party Regexp::Common module
  • Some stackoverflow Q&A that I've answered over the years with simpler perl solution compared to other cli tools
    • replace string with incrementing value
    • sort rows in csv file without header & first column
    • reverse matched pattern
    • append zeros to list
    • arithmetic replacement in a text file
    • reverse complement DNA sequence for a specific field

The selling point of perl over tools like grep, sed and awk includes feature rich regular expression engine and standard/third-party modules. If you don't already know the syntax and idioms for sed and awk, learning command line options for perl would be the easier option. Another advantage is that perl is more portable, given the many differences between GNU, BSD, Mac and other such implementations. The main disadvantage is that perl is likely to be verbose and slower for features that are supported out of the box by those tools.

Picture 1 See also unix.stackexchange: when to use grep, sed, awk, perl, etc

Installation and Documentation

If you are on a Unix like system, you are most likely to already have some version of Perl installed. See cpan: Perl Source for instructions to install the latest perl version from source. perl v5.32.0 is used for all the examples shown in this book.

You can use perldoc command to access documentation from the command line. You can visit https://perldoc.perl.org/ if you wish to read it online, which also has a handy search feature. Here's some useful links to get started:

  • perldoc: overview
  • perldoc: perlintro
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Perl one-liners cookbook»

Look at similar books to Perl one-liners cookbook. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
Sundeep Agarwal - Eagle Luck
Eagle Luck
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
No cover
No cover
Sundeep Agarwal
Reviews about «Perl one-liners cookbook»

Discussion, reviews of the book Perl one-liners cookbook and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.