This document provides an overview of the Perl programming language. It discusses where Perl is commonly used, its key features like text processing and database access. It then covers various Perl concepts like scalars, variables, user input, strings, conditionals, loops, arrays, hashes, file handling and regular expressions. It provides examples for working with scalars, strings, conditionals, loops and arrays. It also discusses the special $_ variable and functions like pop, push, shift and unshift for manipulating arrays. The document concludes with a brief discussion of subroutines.
This document summarizes Python basics including its features, popularity in different fields and companies, data types, control flow, containers like lists and dictionaries, NumPy for numerical computing, and classes. Python is an interpreted, general-purpose language with rich library support. It is commonly used in computer science, data analysis, biology, and academic communities. Major companies like Google, Dropbox, and Instagram use Python.
This document summarizes Python basics including its features, popularity in different fields and companies, data types, control flow, containers like lists and dictionaries, NumPy for numerical computing, and classes. Python is an interpreted, general-purpose language with rich library support. It is commonly used in computer science, data analysis, biology, and academic communities. Major companies like Google, Dropbox, and Instagram use Python.
This document provides an overview of PHP (Hypertext Preprocessor), a popular server-side scripting language used for web development. It discusses key PHP concepts like server-side scripting, inclusion of files, syntax, variables, arrays, operators, functions, branching, looping, forms, MySQL integration, sessions, and cookies. The document is intended to help beginners get started with PHP.
The document discusses Perl 6 types and type checking. It shows examples of declaring scalar, array and hash variables with implicit and explicit types like Any, Int and Str. It then demonstrates type checking failures when assigning values of the wrong type. It also covers defining custom types through subtypes and multi dispatch to handle different types.
This document provides an overview of PHP and MySQL. It discusses key PHP elements like variables, arrays, conditional statements, and loops. It also covers PHP statements, naming variables, outputting values, performing calculations, working with arrays, conditional logic, and loops. The document then discusses connecting to and querying MySQL databases, and how to insert, update, delete data. It also covers building forms, getting form input, and basic file input/output in PHP.
This document provides an overview of PHP arrays, including:
- Arrays allow storing multiple elements that are accessed via numeric indexes. Elements can be of any type.
- Arrays can be iterated over using foreach loops or traditional for/while loops.
- Arrays have built-in functions for sorting, searching, merging, reversing, and more.
- Multidimensional arrays allow storing other arrays as elements.
- Associative arrays use named keys instead of numeric indexes to access elements.
- Exercises demonstrate creating multidimensional arrays and outputting array data to HTML tables.
This document discusses PHP functions and arrays. It covers basic syntax for defining functions, returning values from functions, and variable scope. It also covers array basics like indexing and printing arrays, as well as operations like sorting, searching, and iterating over arrays. Functions for stacks, queues and sets using arrays are also demonstrated. The document is a comprehensive reference for working with functions and arrays in PHP.
This document summarizes Python basics including its features, popularity in different fields and companies, data types, control flow, containers like lists and dictionaries, NumPy for numerical computing, and classes. Python is an interpreted, general-purpose language with rich library support. It is commonly used in computer science, data analysis, biology, and academic communities. Major companies like Google, Dropbox, and Instagram use Python.
This document summarizes Python basics including its features, popularity in different fields and companies, data types, control flow, containers like lists and dictionaries, NumPy for numerical computing, and classes. Python is an interpreted, general-purpose language with rich library support. It is commonly used in computer science, data analysis, biology, and academic communities. Major companies like Google, Dropbox, and Instagram use Python.
This document provides an overview of PHP (Hypertext Preprocessor), a popular server-side scripting language used for web development. It discusses key PHP concepts like server-side scripting, inclusion of files, syntax, variables, arrays, operators, functions, branching, looping, forms, MySQL integration, sessions, and cookies. The document is intended to help beginners get started with PHP.
The document discusses Perl 6 types and type checking. It shows examples of declaring scalar, array and hash variables with implicit and explicit types like Any, Int and Str. It then demonstrates type checking failures when assigning values of the wrong type. It also covers defining custom types through subtypes and multi dispatch to handle different types.
This document provides an overview of PHP and MySQL. It discusses key PHP elements like variables, arrays, conditional statements, and loops. It also covers PHP statements, naming variables, outputting values, performing calculations, working with arrays, conditional logic, and loops. The document then discusses connecting to and querying MySQL databases, and how to insert, update, delete data. It also covers building forms, getting form input, and basic file input/output in PHP.
This document provides an overview of PHP arrays, including:
- Arrays allow storing multiple elements that are accessed via numeric indexes. Elements can be of any type.
- Arrays can be iterated over using foreach loops or traditional for/while loops.
- Arrays have built-in functions for sorting, searching, merging, reversing, and more.
- Multidimensional arrays allow storing other arrays as elements.
- Associative arrays use named keys instead of numeric indexes to access elements.
- Exercises demonstrate creating multidimensional arrays and outputting array data to HTML tables.
This document discusses PHP functions and arrays. It covers basic syntax for defining functions, returning values from functions, and variable scope. It also covers array basics like indexing and printing arrays, as well as operations like sorting, searching, and iterating over arrays. Functions for stacks, queues and sets using arrays are also demonstrated. The document is a comprehensive reference for working with functions and arrays in PHP.
This document summarizes a presentation on Perl subroutines and closures. The presentation covers subroutine basics like defining and calling subs, passing arguments, and return values. It also discusses closures, including using static variables with anonymous subs to cache repeated function calls and enclosing lexical variables. Examples are provided for recursion, checking call context, and creating anonymous subs.
The document discusses improving the Dev Assistant project, an AI assistant tool, by reducing its use of PERL code and making it more accessible to non-expert Perl programmers. It encourages readers to contribute by forking the project's Github repository, making code changes, and submitting pull requests to help the project team modernize the codebase and provide a better first impression of the Perl language.
Implementing Glacier's Tree Hash using recursive, functional programming in Perl5. With Keyword::Declare we get clean syntax for tail-call elimination. Result is a simple, fast, functional solution.
The document discusses different types of arrays in PHP, including numeric index arrays, associative arrays, and multidimensional arrays. Numeric index arrays use integers to identify array elements, associative arrays use named keys, and multidimensional arrays contain arrays within other arrays. Examples are provided for each type of array to demonstrate their syntax and usage.
PHP is a server-side scripting language that is embedded into HTML files. The goal is to generate client-side code like HTML, CSS, and JavaScript. PHP files are executed on the web server and must be saved in a subdirectory that is accessible to the server, like /var/www. PHP allows variables, operators, conditional statements, loops, functions, and arrays. Sessions and cookies can be used to store and retrieve information across multiple requests.
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
This document provides information about arrays in PHP. It discusses numeric arrays, associative arrays, and multidimensional arrays. It explains how to create, iterate through, modify, and handle arrays in PHP. Various functions are described, including count(), print_r(), foreach(), array_slice(), and array_merge(). Multidimensional arrays are given as examples to demonstrate nested arrays and how to access elements within them using loops. Methods for splitting and merging arrays are also covered.
The document describes the initialization of a graphical user interface (GUI) for a harmonicograph application using the Wx::Perl toolkit. It loads localization text, remembered favorites, and default parameter ranges. It then creates widgets like sliders, buttons and a drawing board and arranges them in a tabbed layout within a main frame window. The frame is populated with the widgets and initialized parameter values before being displayed.
I will show how to create an interpreter for a simple programming language using Perl 6 grammars.
This talk is not an introduction to Perl 6 regexes and grammars, so we'll use them straight on, but I will add comments so that you can understand what's going on even if you never tried Perl 6 grammars.
There will not be enough time to write the whole compiler, of course, but I will show how you can do that at home.
The document discusses various PHP array functions including:
- Array functions like array_combine(), array_count_values(), array_diff() for comparing and merging arrays.
- Sorting arrays with asort(), arsort(), ksort(), krsort().
- Other functions like array_search(), array_sum(), array_rand() for searching, summing and random values.
- Modifying arrays with array_push(), array_pop(), array_shift() for adding/removing elements.
The document provides examples of using each array function in PHP code snippets.
This is the third set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This document discusses how Vim can improve productivity for Perl coding. It provides examples of using Vim motions and modes like Normal mode, Insert mode, and Visual mode to efficiently edit code. It also covers Vim features like syntax highlighting, custom syntax files, key mappings, and text objects that are useful for Perl. The document advocates that Vim is a powerful editor rather than an IDE and highlights how it can save significant time compared to less efficient editing methods.
This document discusses agile database access with CakePHP 3. It covers types of object-relational mappers (ORMs), setting up associations between tables, performing simple and complex queries, formatting and debugging queries, modifying JSON output, using value objects, and more advanced topics like custom serialization and associations between databases. The goal is to provide an ORM that is quick, flexible, and easy to work with for both simple and complex database needs.
This document discusses functional programming concepts in PHP 7 including lambda functions, closures, higher-order functions, currying, partial application, point-free style, and immutability. Examples are provided to demonstrate how these concepts can be applied to writing validation logic in a functional way using functions like pipe(), ifElse(), anyPass(), and has(). The talk encourages adopting a functional programming style for PHP code to write more reusable and composable functions.
PHP strings allow storing and manipulating text data. A string is a series of characters that can contain any number of characters limited only by available memory. Strings can be written using single quotes, double quotes, or heredoc syntax. Special characters in strings must be escaped using a backslash. PHP provides many built-in functions for working with strings like concatenation, comparison, searching, replacing, extracting, splitting, joining, formatting and more. Regular expressions provide powerful pattern matching capabilities for strings and PHP has functions like preg_match() for searching strings using regex patterns.
This document provides details on connecting to a Cassandra instance in EC2 cloud using Putty and performing various operations like listing keyspaces, working in a keyspace, describing and creating tables, inserting and retrieving records, deleting records, truncating tables, dropping tables and keyspaces, and using indexes. It also includes examples of creating a sample Facebook project with a UserProfiles table and updating records.
This document discusses various SQL commands used in SQL Plus including creating a table, altering table columns, inserting records, retrieving data using queries, joining tables, and aggregating data using group by and having clauses. It provides examples of creating a PERSONS table, modifying columns, inserting sample data, querying for highest, lowest, and average salaries, demonstrating inner joins between tables, and using group by with aggregate functions to retrieve statistics grouped by customer.
This document discusses various topics related to manual testing such as:
1. What is software testing and why testers are needed to do thorough testing.
2. How testing helps companies ensure requirements are implemented and collect metrics for future projects.
3. The different phases of the software development life cycle including requirements gathering, design, coding, testing, and release.
4. Types of requirements documents and their contents.
5. Testing methodologies like black box and white box testing.
6. How to write test cases and the characteristics of good test cases.
This document summarizes a presentation on Perl subroutines and closures. The presentation covers subroutine basics like defining and calling subs, passing arguments, and return values. It also discusses closures, including using static variables with anonymous subs to cache repeated function calls and enclosing lexical variables. Examples are provided for recursion, checking call context, and creating anonymous subs.
The document discusses improving the Dev Assistant project, an AI assistant tool, by reducing its use of PERL code and making it more accessible to non-expert Perl programmers. It encourages readers to contribute by forking the project's Github repository, making code changes, and submitting pull requests to help the project team modernize the codebase and provide a better first impression of the Perl language.
Implementing Glacier's Tree Hash using recursive, functional programming in Perl5. With Keyword::Declare we get clean syntax for tail-call elimination. Result is a simple, fast, functional solution.
The document discusses different types of arrays in PHP, including numeric index arrays, associative arrays, and multidimensional arrays. Numeric index arrays use integers to identify array elements, associative arrays use named keys, and multidimensional arrays contain arrays within other arrays. Examples are provided for each type of array to demonstrate their syntax and usage.
PHP is a server-side scripting language that is embedded into HTML files. The goal is to generate client-side code like HTML, CSS, and JavaScript. PHP files are executed on the web server and must be saved in a subdirectory that is accessible to the server, like /var/www. PHP allows variables, operators, conditional statements, loops, functions, and arrays. Sessions and cookies can be used to store and retrieve information across multiple requests.
Perl, a cross-platform, open-source computer programming language used widely in the commercial and private computing sectors. Perl is a favourite among Web developers for its flexible, continually evolving text-processing and problem-solving capabilities.
This document provides information about arrays in PHP. It discusses numeric arrays, associative arrays, and multidimensional arrays. It explains how to create, iterate through, modify, and handle arrays in PHP. Various functions are described, including count(), print_r(), foreach(), array_slice(), and array_merge(). Multidimensional arrays are given as examples to demonstrate nested arrays and how to access elements within them using loops. Methods for splitting and merging arrays are also covered.
The document describes the initialization of a graphical user interface (GUI) for a harmonicograph application using the Wx::Perl toolkit. It loads localization text, remembered favorites, and default parameter ranges. It then creates widgets like sliders, buttons and a drawing board and arranges them in a tabbed layout within a main frame window. The frame is populated with the widgets and initialized parameter values before being displayed.
I will show how to create an interpreter for a simple programming language using Perl 6 grammars.
This talk is not an introduction to Perl 6 regexes and grammars, so we'll use them straight on, but I will add comments so that you can understand what's going on even if you never tried Perl 6 grammars.
There will not be enough time to write the whole compiler, of course, but I will show how you can do that at home.
The document discusses various PHP array functions including:
- Array functions like array_combine(), array_count_values(), array_diff() for comparing and merging arrays.
- Sorting arrays with asort(), arsort(), ksort(), krsort().
- Other functions like array_search(), array_sum(), array_rand() for searching, summing and random values.
- Modifying arrays with array_push(), array_pop(), array_shift() for adding/removing elements.
The document provides examples of using each array function in PHP code snippets.
This is the third set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This is the seventh set of slightly updated slides from a Perl programming course that I held some years ago.
I want to share it with everyone looking for intransitive Perl-knowledge.
A table of content for all presentations can be found at i-can.eu.
The source code for the examples and the presentations in ODP format are on https://github.com/kberov/PerlProgrammingCourse
This document discusses how Vim can improve productivity for Perl coding. It provides examples of using Vim motions and modes like Normal mode, Insert mode, and Visual mode to efficiently edit code. It also covers Vim features like syntax highlighting, custom syntax files, key mappings, and text objects that are useful for Perl. The document advocates that Vim is a powerful editor rather than an IDE and highlights how it can save significant time compared to less efficient editing methods.
This document discusses agile database access with CakePHP 3. It covers types of object-relational mappers (ORMs), setting up associations between tables, performing simple and complex queries, formatting and debugging queries, modifying JSON output, using value objects, and more advanced topics like custom serialization and associations between databases. The goal is to provide an ORM that is quick, flexible, and easy to work with for both simple and complex database needs.
This document discusses functional programming concepts in PHP 7 including lambda functions, closures, higher-order functions, currying, partial application, point-free style, and immutability. Examples are provided to demonstrate how these concepts can be applied to writing validation logic in a functional way using functions like pipe(), ifElse(), anyPass(), and has(). The talk encourages adopting a functional programming style for PHP code to write more reusable and composable functions.
PHP strings allow storing and manipulating text data. A string is a series of characters that can contain any number of characters limited only by available memory. Strings can be written using single quotes, double quotes, or heredoc syntax. Special characters in strings must be escaped using a backslash. PHP provides many built-in functions for working with strings like concatenation, comparison, searching, replacing, extracting, splitting, joining, formatting and more. Regular expressions provide powerful pattern matching capabilities for strings and PHP has functions like preg_match() for searching strings using regex patterns.
This document provides details on connecting to a Cassandra instance in EC2 cloud using Putty and performing various operations like listing keyspaces, working in a keyspace, describing and creating tables, inserting and retrieving records, deleting records, truncating tables, dropping tables and keyspaces, and using indexes. It also includes examples of creating a sample Facebook project with a UserProfiles table and updating records.
This document discusses various SQL commands used in SQL Plus including creating a table, altering table columns, inserting records, retrieving data using queries, joining tables, and aggregating data using group by and having clauses. It provides examples of creating a PERSONS table, modifying columns, inserting sample data, querying for highest, lowest, and average salaries, demonstrating inner joins between tables, and using group by with aggregate functions to retrieve statistics grouped by customer.
This document discusses various topics related to manual testing such as:
1. What is software testing and why testers are needed to do thorough testing.
2. How testing helps companies ensure requirements are implemented and collect metrics for future projects.
3. The different phases of the software development life cycle including requirements gathering, design, coding, testing, and release.
4. Types of requirements documents and their contents.
5. Testing methodologies like black box and white box testing.
6. How to write test cases and the characteristics of good test cases.
Accenture Case Study Solution by Amit BhardwajAmit Bhardwaj
This document provides a QA plan and test strategy for testing the Centralized Global System (CGS) being developed by XYZ Company. It outlines the scope of testing, including features and types of testing that are in and out of scope. It describes the test design, strategy, and objectives. It also covers guidelines for test case prioritization, review, and tracking results. The testing process includes unit, integration, functional, regression and other types of testing. Roles and responsibilities are defined along with the bug tracking process.
The document provides requirements for a new accounts payable check printing system. Key requirements include usability features, user authentication and permissions, data entry fields for payment and greeting information, check printing format and fields, and generation of daily and weekly reports. The system must be compatible with the company's browser standard and interface with the existing general ledger application. Stakeholders who provided requirements include accounts payable clerks, supervisors, accountants, and IT staff.
The document discusses software development methodologies and user stories. It compares the waterfall and scrum/sprint approaches, noting that scrum is better suited when requirements are unclear or evolving. Scrum delivers working software incrementally while waterfall waits until the full product is complete. A user story should be broken down so it can be estimated and include details on who requested it and the priority level.
The document contains 11 Java programming assignments involving arrays and strings:
1. Sorting an integer array using bubble sort
2. Printing only odd numbers from an integer array
3. Moving all even numbers to the beginning of an integer array
4. Finding unique numbers and occurrences of duplicates in an array
5. Checking if an integer array matches the Fibonacci series
6. Checking if an integer array is a palindrome
7. Finding unique words in a string
8. Reversing a string
9. Reversing each word in a string separately
10. Reversing the lines when writing a file
11. Creating a Java program with APIs for database SELECT and UPDATE operations
Fitnesse is a software collaboration tool used for acceptance testing to ensure a system meets stakeholder requirements. It allows automating user acceptance tests by representing test cases and fixture code as wiki pages. Fitnesse runs as a wiki web server from a jar file, providing a home page at localhost where test tables can be created linking Java, Python, or other code to validate functionality matches expectations.
This document provides an overview of a Java/J2EE training course that covers 8 weeks of material. Week 1 covers core Java topics like object-oriented programming concepts, the Java language fundamentals, and Java statements. Week 2 delves deeper into advanced Java features. Weeks 3 and 4 cover exception handling, multithreading, SQL, JDBC, and collections. Weeks 5-7 cover key J2EE specifications and frameworks like Servlets, JSP, EJB, Struts, Hibernate, Spring, and web services. Week 8 discusses application packaging and deployment. The document provides contact information for the training provider.
The document is an ER diagram for the Wells Fargo banking system created by Sunil Kumar on December 12, 2012. It describes the entities in the system including bank branches, accounts, loans, and customers. The diagram shows the relationships between these entities such as a one-to-many relationship between bank branches and accounts, and a many-to-many relationship between accounts and loans. The document also includes a revision history and table of contents.
The document provides an extensive checklist for testing the functionality, usability, and performance of an ecommerce website. It includes test cases for functionality, main pages, product categories, product search, shopping basket, checkout and payments, browser compatibility, mobile compatibility, performance, links, proofreading, product pricing, web standards, accessibility, cookies, SEO, and social media integration. The checklist covers testing registration, user profiles, adding products, checkout, orders, admin functions, backend to frontend integration, configurable products, promotions, filters, sorting, wishlists, adding to basket, delivery options, payments, refunds, browser compatibility, mobile devices, page load times, broken links, content errors, prices, HTML/CSS validation
How to pass a coding interview as an automation developer
Oct 17 2016
T.J. Maher has been a software tester for twenty years, but only recently became an automation developer. March 2015 he went from one job executing other people's automated testplans to writing his own.
When he found himself needing to start job searching over a year later due to a switch in management, he found major changes to the interview process. This presentation describes T.J. Maher's job hunt, those changes, and how he managed to find a new position ... Not just as an automation developer, but as a Software Engineer in Test.
This document provides examples of test cases for an e-commerce application. It includes test cases for searching for products with expected valid, invalid, and empty search terms. It also includes positive and negative test cases for logging into the application. Each test case lists the test case name, description, target URL, steps to execute, expected results, actual results, and pass/fail status.
This document provides an overview of the Perl programming language. It discusses scalars, arrays, hashes, references, subroutines, packages, warnings, strictness, password encryption, file handling, command line arguments, and process management in Perl. Specific topics covered include using @ and $ prefixes for arrays and scalars, accessing elements of arrays and hashes, defining and calling subroutines, using crypt() for password hashing, opening/writing/reading files, and using fork() to create child processes. Examples of code are provided to demonstrate many of these Perl concepts.
Perl is a general purpose programming language invented by Larry Wall in 1987. It can be used for web development, system scripting, and data processing. Key points:
- Perl can run on both UNIX and Windows systems, and code developed on one system can be portable to the other.
- Common uses of Perl include web development, like writing CGI scripts for websites, and processing large data sets in fields like finance, manufacturing, and genetics.
- Perl supports scalar and list data types. Scalar variables start with $ and can hold numbers or strings. Lists are collections of scalar data that can be stored in array variables prefixed with @.
- Perl includes control structures like if/else, for loops
The document discusses various techniques for extending and improving Perl, including both good and potentially evil techniques. It covers Perl modules that port Perl 6 features to Perl 5 like given/when switches and state variables. It also discusses techniques for runtime introspection and modification like PadWalker and source filters. The document advocates for continuing to extend Perl 5 with modern features to keep it relevant and powerful.
Perl6 is a powerful programming language that incorporates many programming paradigms including functional, object oriented, reactive, and event based programming. It aims to provide programmers with a toolbox of features to build applications in many different styles. The language includes features like junctions, promises, channels, supplies, sets, roles, and strong support for Unicode. It also allows calling external native libraries and has built-in support for rational numbers, sequences, and lazy evaluation. Perl6 code examples are provided to demonstrate various features like List utilities, junctions, promises, channels/supplies, roles, and native calls. Further reading resources are also referenced.
Perl6 is a powerful programming language that incorporates many programming paradigms including functional, object-oriented, and reactive programming. It has built-in support for concepts like promises to handle asynchronous code, channels for communicating between asynchronous processes, and sets/bags for storing unique values. The language also has features for rational numbers, lazy evaluation, roles for composition, and easy integration with native libraries. Perl6 aims to provide programmers a flexible toolbox to build applications in many different styles.
This document compares and contrasts the programming languages Perl and Haskell. It discusses their differences in terms of being dynamic vs static, imperative vs functional, and weakly vs strongly typed. It provides examples of how similar tasks like mapping, doubling values, and finding lengths can be accomplished in both languages. It also explores some of the challenges that arise from Perl's scalar/list context and Haskell's use of monads and strong static types. Overall, the document examines the different philosophies behind Perl and Haskell while also showing how influences have flowed between the communities over time.
Perl is a high-level scripting language useful for tasks like parsing and restructuring data files, CGI scripts, and more. It was created in 1987 by Larry Wall as a "glue" language to connect systems. Perl code is compiled at runtime. Key features include regular expressions, hashes for associative arrays, object-oriented capabilities, and extensive standard and third-party libraries. Perl uses C-like syntax and data types like scalars, lists, and hashes. It supports control structures like if/else, for loops, and subroutines for modular programming. Perl is well-suited for text manipulation and system administration tasks.
The document discusses Perl arrays, scalars, and constants. Some key points:
- Arrays are prefixed with @ and hold a list of scalars. They can be assigned using @var = (value1, value2).
- Scalars represent a single value and are used to hold individual elements of an array.
- Constants are values that don't change, like numbers or defined strings. They don't require $ or @ prefixes.
This document provides an overview of the Perl programming language. It discusses Perl's history and introduction, beginning with Perl scripts, data types like scalars, lists, arrays, and hashes. It also covers Perl operators, conditional statements, regular expressions, subroutines, and file handling. The document is intended as an introduction to Perl and provides examples of basic Perl syntax and functions.
This document provides an overview and schedule for a one-day introduction to Perl programming course. It covers what will be taught including creating and running Perl programs, variables, operators, functions, input/output, and more. The schedule includes breaks and lunch and notes resources available online for the slides.
This document provides an overview of the Perl programming language. It introduces key Perl concepts like data types, scalars, arrays, hashes, flow control, input/output, and operators. Perl allows variables to be of any type and handles automatic type conversion. It supports common data structures like arrays and associative arrays (hashes). Subroutines provide modularity and scoping rules determine variable visibility. Perl scripts can process command line arguments, files, and network connections.
The document provides tips for writing simple, readable code that is easy to maintain and adapt to changes over time. It emphasizes keeping code well-structured with small, single-purpose functions and classes, using good naming conventions, testing code, and designing for flexibility through techniques like dependency injection and interfaces. The document also encourages practicing code through katas and code reviews to improve coding skills.
This document provides an overview of the Perl programming language and includes examples of common Perl scripts and functions. It discusses getting started with Perl, printing, variables, arrays, loops, conditionals, regular expressions, file handling and subroutines. Code snippets are provided to demonstrate concepts like opening and reading files, splitting strings, calculating averages and more. The document serves as a tutorial for beginners to learn the basics of Perl programming.
This document provides an overview of the Perl programming language and includes examples of common Perl constructs. It discusses getting started with Perl, printing, variables, arrays, loops, conditionals, regular expressions, file handling and subroutines. Code snippets are provided to demonstrate various Perl features such as accessing array elements, for/while loops, pattern matching with regular expressions, splitting strings, and defining subroutines.
This document provides an overview and schedule for an introduction to Perl course. The key topics that will be covered include: what Perl is, creating and running Perl programs, Perl variables, operators and functions, conditional constructs, subroutines, regular expressions, finding and using modules. The schedule outlines breaks and lunch over the course of the day from 09:45 to 17:00. Resources for slides and further information are also listed.
The document summarizes a Perl Mongers course on data and operators in Perl. It covers basic data types like scalars, arrays, and hashes. It describes strings, numbers, and how to perform operations on them. It also discusses control structures like conditionals and loops for program flow. Finally, it mentions input/output functions like STDIN and STDOUT.
The document discusses various ways to extend and modify the Ruby parser. It covers:
1. Proposed syntax additions like {:key :-) "value"} and ++i which would require changes to the lexer and parser.
2. How the parser handles colons and symbols using token types like tCOLON2.
3. Examples of parsing constructs like method calls, assignments, and the def A#b syntax.
4. Details of how the lexer and parser are implemented in C using a parser generator and interaction between lexer states and token types.
Perl is an interpreted programming language used for text manipulation and generating reports from text files. It has powerful string handling and pattern matching capabilities. Perl programs can be written and run without a compiler on all platforms. Perl is useful for tasks like extracting information from files, transforming it, and generating reports. It allows writing simple programs to perform complex tasks. Perl variables do not have fixed types and can hold different data types. Perl supports scalar variables, arrays, and lists to organize data. Arrays allow storing multiple values in an indexed list.
Program 1 (Practicing an example of function using call by referenc.pdfezhilvizhiyan
Program 1: (Practicing an example of function using call by reference)
Write a program that reads a set of information related to students in C++ class and prints them
in a table format. The information is stored in a file called data.txt. Each row of the file contains
student number, grade for assignment 1, grade for assignment 2, grade for assignment 3, and
grade for assignment 4. Your main program should read each row, pass the grades for the three
assignments to a function called ProcessRow to calculate the average of the grades, minimum of
the four assignments, and the maximum of the four assignments. The results (average,
maximum, and minimum) should be returned to the main program and the main program prints
them on the screen in a table format. For example, if the file includes
126534 7 8 10 7
321345 5 6 4 9
324341 8 3 8 5
your program should print
Std-Id A1 A2 A3 A4 Min Max Average
----------------------------------------------------------------------------------
126534 7 8 10 7 7 10 8
321345 5 6 4 9 4 9 6
324341 8 3 8 5 3 8 6
You must use call by reference to do the above question.
_________________________________________________________________
Program 2: (Practicing an example of function using call by value)
Repeat the above question using call by value. This means you need to have three different
functions: one to calculate the average, another to calculate the minimum, and the third one to
calculate the maximum. This is how to call these functions:
Max = CalculateMax(A1,A2,A3, A4);
Min = CalculateMin(A1,A2,A3, A4);
Average = CalculateAvg(A1,A2,A3, A4);
_________________________________________________________________
Program 3:
Write a program with several functions that performs the following tasks. :
Create a function that reads the following 5 float numbers from the file data.txt into array Called
Arr1.
12.0 15.0 29.3 25.0 93.2
Copy array Arr1 into array Arr2 in reverse order
Print array Arr1.
Print array Arr2.
Find the number of elements in array Arr1 that are >= 80 and <=100.
Find the number of the elements in array Arr1 in which their contents are divisible by 5
Find the index of the elements in array Arr1 in which their contents are divisible by 3.
Find mean (average) in array Arr1.
Find the maximum number in array Arr1.
Ask the user to input a key. Then search for the key in array Arr1 and inform the user about the
existence (true / false) of the key in array
Your program should include several functions.
A function for filling up the information from file into an array (part a should call this function)
A function that does the copying of one array into another in reverse order. Arrays must have the
same size (part b should call this function)
Printing any array with any size (part c and d should call this function)
finding and returning the number of elements between 80 and 100 in any array with any size
(part e calls this function)
finding and returning the number of elements in an array that are divisible by 5 (par.
Similar to PERL for QA - Important Commands and applications (20)
This document provides test cases to test the functionality of the CTODS web application, API, and grid service in the LSD 1.2 compliance tier. It includes 4 sections: document control, functional test introduction, limitations/dependencies, and test cases. The test cases section includes steps to configure CTODS with UPT, log in as different users, and explore/search the CTODS data as both a privileged and non-privileged user. It also provides steps to run the API and grid unit tests against a deployed CTODS instance.
This document provides SQL syntax examples for common SQL statements including SELECT, INSERT, UPDATE, DELETE, JOIN, WHERE and more. It shows the basic structure and keywords used for each statement type as well as examples of how to use operators, aliases, aggregates and more. Key statements covered include SELECT, INSERT, UPDATE, DELETE, different JOIN types, WHERE conditions and clauses like GROUP BY, HAVING, ORDER BY and more.
The document provides requirements for a new accounts payable check printing system. Key requirements include usability features, user authentication and permissions, data entry for payment and greeting information, check printing, and generation of daily and weekly reports. The system must also allow review and editing of check details. Technical requirements specify system availability and compatibility with the company's browser standard.
The document outlines an automation testing syllabus covering software development lifecycles, the role of testers, types of testing, test techniques, test cases, test plans, bugs, Java concepts, production tools, load testing, test management tools, and real-world manual testing projects. Key topics include waterfall, agile, and scrum models; unit, integration, and regression testing; black box and white box techniques; test plans; bug tracking; Java fundamentals; and tools like JUnit, Selenium, JIRA, LoadRunner, and QTP. The syllabus aims to equip students with the skills needed for both manual and automation testing.
This document provides a list of common Unix commands along with a brief description of what each command does. It includes commands for navigating and viewing files, editing text, finding and manipulating text, compressing and archiving files, remote access, printing, and more. The summary at the end highlights some frequently used commands for listing users, viewing directories, viewing parts of files, managing processes, text editing, disk usage, searching text, and remote access.
This document provides summaries of common Linux commands for logging in and viewing system information, handling files and directories, managing processes, string manipulation, and connecting to servers. It describes commands like pwd, ls, head, tail, grep, kill, mkdir, rmdir, telnet and ftp along with their basic functions such as listing contents, editing files, searching files for strings, transferring files, and killing processes.
The HTTP methods can pose security risks if not properly configured. Attackers may use Cross Site Tracing (XST) via the TRACE method to steal user credentials. PUT, DELETE, and CONNECT methods could allow attackers to upload malicious files, delete files to deface sites, or use the server as a proxy. It is important to limit these methods to trusted users under safe conditions. The OPTIONS method provides information about available communication options, which can be used for testing. Testing arbitrary methods like "JEFF" and "CATS" could exploit vulnerabilities if the server allows them without limitations like GET. Testing the HEAD method without authentication can bypass login requirements if it returns a 200 response without requiring authentication.
This document outlines the content of a training course on software testing lifecycles. The targeted audience is new testers and those with experience in ad-hoc testing who want to learn formal processes. The course content includes defining software testing, the role of testers, testing in the SDLC, test planning, design, execution, the V-model, bug lifecycles, documentation, and checklists. It provides details on each topic through explanations, diagrams and examples of templates.
The document discusses Scrum, an agile framework for managing product development. It describes key Scrum roles like the Product Owner who prioritizes features and the Scrum Master who facilitates the process. User stories are collected in a product backlog to plan releases. The team estimates stories in story points or hours. Sprints are short, timed periods used to tackle parts of the backlog and make the product shippable. Daily stand-up meetings and sprint retrospectives help monitor progress visualized in burndown charts and velocity metrics.
The document discusses access modifiers in Java and their usage with variables, functions, and classes at different levels. It explains that access modifiers like private, protected, default, and public determine whether elements are visible from within the same class, package, subclass, or any class. Private is most restrictive while public is most accessible. It also covers other concepts like static methods, inheritance, polymorphism, abstract classes, interfaces and exception handling in Java.
Java handles two types of exceptions - unchecked exceptions and checked exceptions. Unchecked exceptions do not need to be handled by programmers, while checked exceptions must be handled. Checked exceptions are environment or server-related issues outside a programmer's control. There are three ways to handle checked exceptions: try-catch blocks, throwing exceptions with the throw keyword, or specifying exceptions with the throws keyword in method signatures. Finally blocks are used to ensure cleanup code executes after try or catch blocks complete.
- Web services allow for two-way communication between a service provider and consumer using XML and SOAP.
- Orbit and Travelocity publish their WSDL files to a UDDI registry, allowing consumers like Kayak.com to access their services.
- A SOAP request contains an envelope with a header and body, while a response contains a header, body, and potential fault message.
This document outlines the requirements for a new Accounts Payable check printing system. It includes sections on document reviews and approvals, business requirements overview, scope statement, glossary of terms, stakeholders, and stakeholder requirements. The stakeholder requirements specify needs around usability, user authentication, system availability, general system operation, data entry for payment and greeting information, check printing, and generating daily and weekly reports. Requirements address functionality for clerks, supervisors, accountants, and other roles.
Hw1 project charter electronic health record for university health care_sunil...Sunil Kumar Gunasekaran
This 3 sentence summary provides the key details about the project charter:
The project charter outlines an 8 phase plan to implement an Electronic Health Record system for a University Student Health Care center over multiple years. The goal is to digitize paper health records, allow for electronic access and sharing of records between departments, and standardize documentation. The project involves various stakeholders from the university and health center and will require coordinating resources and dependencies between departments.
Hw2 gap analysis linked_in mobile app_sunil kumar gunasekaran_12052012.docxSunil Kumar Gunasekaran
The document summarizes a gap analysis performed on the LinkedIn mobile app to identify improvements. The current app has issues like limited profile editing and a cluttered interface. The proposed "to-be" model splits the interface into four main sections for key features and always displays a search box. It also allows profile editing from the app. The analysis prioritizes changes such as improving the user interface, adding more servers to the backend platform to increase performance, and removing unused features. The changes were approved to fund the new version of the LinkedIn mobile app project.
How to Build a Module in Odoo 17 Using the Scaffold MethodCeline George
Odoo provides an option for creating a module by using a single line command. By using this command the user can make a whole structure of a module. It is very easy for a beginner to make a module. There is no need to make each file manually. This slide will show how to create a module using the scaffold method.
This slide is special for master students (MIBS & MIFB) in UUM. Also useful for readers who are interested in the topic of contemporary Islamic banking.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
How to Add Chatter in the odoo 17 ERP ModuleCeline George
In Odoo, the chatter is like a chat tool that helps you work together on records. You can leave notes and track things, making it easier to talk with your team and partners. Inside chatter, all communication history, activity, and changes will be displayed.
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
हिंदी वर्णमाला पीपीटी, hindi alphabet PPT presentation, hindi varnamala PPT, Hindi Varnamala pdf, हिंदी स्वर, हिंदी व्यंजन, sikhiye hindi varnmala, dr. mulla adam ali, hindi language and literature, hindi alphabet with drawing, hindi alphabet pdf, hindi varnamala for childrens, hindi language, hindi varnamala practice for kids, https://www.drmullaadamali.com
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
Executive Directors Chat Leveraging AI for Diversity, Equity, and InclusionTechSoup
Let’s explore the intersection of technology and equity in the final session of our DEI series. Discover how AI tools, like ChatGPT, can be used to support and enhance your nonprofit's DEI initiatives. Participants will gain insights into practical AI applications and get tips for leveraging technology to advance their DEI goals.
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
PERL for QA - Important Commands and applications
1. Learn PERL
PERL - Practical Extraction and Reporting Language
1.
Where do we use PERL: ........................................................................................................................ 2
2.
What are the key features of PERL: ...................................................................................................... 2
3.
SCALAR Data: ........................................................................................................................................ 2
4.
USER IO: ................................................................................................................................................ 5
5.
STRING OPERATIONS: ........................................................................................................................... 5
6.
CHOMP: ................................................................................................................................................. 6
7.
LOOPS and CONDITIONS: ...................................................................................................................... 6
8.
ARRAYS: ............................................................................................................................................... 11
9.
Usage of $_ ......................................................................................................................................... 13
10.
Sub Routines: .................................................................................................................................. 16
11.
PERL DB ........................................................................................................................................... 17
12.
PERL FILE HANDLING ....................................................................................................................... 18
13.
PERL REGULAR EXPRESSION ........................................................................................................... 20
14.
PERL HASH....................................................................................................................................... 20
Praveen Kasireddy
Page 1
2. Learn PERL
1. Where do we use PERL:
Quick and dirty programs (automating simple daily jobs)
System Administration
Web backend (CGI/Database access)
Configuration Management
QA
Biotechnology
Prototypes
2. What are the key features of PERL:
Text processing (pattern matching)
List processing
Database access
System language
To know if PERL is installed in your machine, you can try perl –v or perl –V
Sample PERL code: perl -e "print 1000" will print à1000
# is a comment.
perldoc provides documentation about any one command
3. SCALAR Data:
A single piece of data either a number or a string is called a 'scalar' in Perl.
PERL Takes care of data types on its own:
print 3+4;
#7
print 9-7;
#2
print 2*3;
#6
print 3/0;
# ERROR - Even Perl cannot divide by 0
Print 11 % 3; # 2 (modulus)
Praveen Kasireddy
Page 2
3. Learn PERL
print 2 ** 3; # 8 (power of)
print "another 'string'"; # another 'string'
print "escape" this"; # ERROR
print "escape" this"; # escape" this
STRING Operators:
print "a" . "b"; # ab - concatenation
print "e" x 3; # eee - repetition
print "perl " x 3; # perl perl perl
print "-" x 80; # ------- (80 times)
SCALAR Variable declaration:
To save the values for later use in your program you need variables.
Rules:
Start with letter or underscore
Contains letters, underscores and digits
Case sensitive
** Same scalar variable can store integers and strings:
$x = 3;
$y = $x + 2;
$z = "hello world";
$z = 8;
String TO Number Conversion:
$x = "3 apples";
$y = "5 banana";
Praveen Kasireddy
Page 3
4. Learn PERL
$total = $x + $y;
print $total; # 8
# Using a numerical operator forces the strings to be numbers
print "3a2" * 4; # 12
print "7683a2" * 1; # 7683
print "a2" * 4; # 0
print "010a2" + 4; # 14
print "3.1" + 0; # 3.1
print "3e+2x" + 0; # 300
Special Observation:
print "2" + 3; # 5 - (+) is a numerical operator
print "2" . 3; # 23 - (.) is a string operator
Variable Interpolation:
$c = 3;
$what = "apples";
$q = "$c $what";
print $q; # 3 apples
works in double quoted strings only
print '$c $what'; # $c $what
Variable name
$what = "banana";
$c = 3;
print "$c $what"; # 3 banana
Praveen Kasireddy
Page 4
5. Learn PERL
print "$c $whats"; # 3 (warning)
print "$c ${what}sn"; # this works well
$c = 3;
$what = 'apple';
print "$c $what sn";
print $c . " " . $what . " sn";
print $c, " ", $what , " sn";
# all will result in '3 apple s' followed by a newline
4. USER IO:
$line = <STDIN>; # To Accept User inputs
if ($line eq "") {
print "Blank line";
}
print $line;
5. STRING OPERATIONS:
substr returns a substring of a big string
$part = substr($big, $index_of_first, $length);
Examples:
$big = "This is a big string";
print substr($big, 5,2); # is
print substr($big, 14); # string (till the end)
Praveen Kasireddy
Page 5
6. Learn PERL
print substr($big, length($big)-2, 2); # ng (from the end of the string)
print substr($big, length($big)-2); # ng (from the end of the string)
print substr($big, -2); # ng (from the end of the string)
print substr($big, 5,2,"was"); # is (original 2 characters)
print $big;
# This was a big string
uc, lc, ucfirst, lcfirst turns character(s) to upper case or lower case
Examples:
$y = "aBcD";
$x = lc($y); # $x becomes abcd
$x = uc($y); # $x becomes ABCD
$x = lcfirst($y); # $x becomes aBcD
$x = ucfirst($y); # $x becomes ABcD
6. CHOMP:
Removes exactly one newline if there is one (or more) at the end of the string
$line = <STDIN>;
chomp($line);
if ($line eq "") {
print "Blank line";
}
7. LOOPS and CONDITIONS:
You have to use {} even if there is only one statement between them !
if ($some_result) { ... }
Praveen Kasireddy
Page 6
7. Learn PERL
if ($age > 3) { ... }
if ($age > 3) {
...
}
else {
...
}
if ($age < 0) {
...
}
elsif ($age < 20) {
...
}
else {
...
}
UNLESS:
Sometimes you want to leave off the if part, and just do something in the else.
o
unless can do this for you:
unless ($num > 0) {
print “I said greater than 0n”;
}
WHILE:
Praveen Kasireddy
Page 7
8. Learn PERL
while ($num<0) {
print “Not valid, try again!n”;
print “Enter a number greater than 0n”;
$num = <STDIN>;
}
DO-WHILE:
do {
print “Enter a number greater than 0n”;
$num = <STDIN>;
} while ($num <= 0);
<STDIN> returns the value undef when it reaches End-of-File.
o undef is FALSE
while ($line = <STDIN>) {
print $line;
}
OR, AND Operators:
print “Enter a number between 1 and 100n”;
$num=<STDIN>;
if ($num<1 || $num>100) {
print “Dummyn”;
} else {
print “Great job! you entered $numn”;
}
Praveen Kasireddy
Page 8
9. Learn PERL
for ($j=0;$j<10;$j++) {
print “$jn”;
}
for ($x=100;$x>0;$x=$x-10) {
print “$xn”;
}
ForEach:
foreach iterates over the elements in an array (a list). A scalar variable assumes the
value of each element in the list (iteratively):
foreach $x (2,4,6) {
print “x is $xn”;
}
“$_”
$total=0;
while (<STDIN>) {
chop;
print “you entered”;
print;
$total = $total + $_;
}
print “the total is $_n”;
Praveen Kasireddy
Page 9
10. Learn PERL
EXERCISE:
Exercise 1
Write a program that computes the area of a rectangular ($length * $width) and prints it. Use
two variables and hard code their values.
Exercise 2
Modify the previous program to prompt for the two values (on two separate lines)
Exercise 3
Script that gets two strings (on two separate lines) and prints the concatenated version.
Exercise 4
Modify the previous area-calculator program to print a warning if one of the values is negative
and make the area 0 sized.
Exercise 5
Basic calculator that gets 2 values and an operator (+,-,*,/) (on 3 separate lines) and prints out
the result.
Exercise 6
Implement the 4 parameter version of substr using the 3 parameter version. Use the
documentation to find out what is the 4 parameter version. That is, assume your substr
function is not capable to work with 4 paramters. Write some code that would do the same
job. (hint: read the documentation to find out what does substr do with 4 parameters)
Exercise 7
You get a mathematical expression of two numbers and an operator on a single line of input
(one or more spaces separate the operator from the numbers). Calculate the result of the
expression.
(Input an be "31 * 8" or "23 / 7" etc.)
Exercise 8
Write a perl program that reads in a number and prints that number 10 times.
Exercise 9
Praveen Kasireddy
Page 10
11. Learn PERL
Write a perl program that reads in a number and prints an ASCII square of that size. For
example, if the number is 4, the program prints:
8. ARRAYS:
While a scalar is single value a list is a bunch of single values. A scalar value can be stored in a
scalar variable. A list can be stored in a list variable. It is called and array.
List Literals, list ranges
A list is an ordered set of scalar values.
Examples of lists:
(1, 5.2, "apple")
(1,2,3,)
# 3 values
# 3 values
(1,2,3,4,5,6,7,8,9,10)
(1..10)
# same as (1,2,3,4,5,6,7,8,9,10)
('a'..'z')
# all the lowercase letters
("joe", "peter", "mario", "cohen") # is the same as quote word
qw(joe peter mario cohen)
($a, $b, $c) = (2, 3, 7); # nearly the same as $a=2; $b=3; $c=7;
($a, $b) = (8, 1, 5); # ignore 5
($a, $b, $c) = (3, 4); # $c will be undef
An array is a variable that can hold a list, that is a list of scalars.
To get to the individual elements of the array you use the name of the array and the index of
the element.
The index can be ANY integer value, including negative numbers.
$name[0] = "Joe";
$name[1] = "Peter";
Praveen Kasireddy
Page 11
12. Learn PERL
$name[3] = "Cohen";
print $name[1]; # Peter
print $name[2]; # undef
Array Assignment:
You can write the following, but it is a bit too much typing
($name[0], $name[1], $name[2], $name[3]) = qw(joe peter mario cohen);
Instead you can use @ to refer to the whole array:
@name = qw(joe peter mario cohen);
You can also mix the variables on the right side and if there are arrays on the right side the
whole thing becomes one flat array !
@name = ($myname, 'joe', @oldnames);
($a, @b) = (1, 2, 3, 4); # $a is 1; @b is (2, 3, 4)
($a, @b, @x) = (1, 2, 3, 4); # $a is 1; @b is (2, 3, 4) @x is empty: ()
@a = (1, 2);
@b = (3, 4);
@c = (@a, @b); # @c becomes (1, 2, 3, 4)
In Perl there are several ways to go over all the elements of a list or an array.
Probably the most frequently used one is foreach.
foreach SCALAR (LIST) BLOCK
Example:
# this will print the names of 3 fruits:
foreach $fruit (qw(apple banana peach)) {
print "$fruitn";
Praveen Kasireddy
Page 12
13. Learn PERL
}
# Instead of lists you can use it with arrays:
@fruits = qw(apple banana peach);
foreach $fruit (@fruits) {
print "$fruitn";
}
9. Usage of $_
There is this strange scalar variable called $_
In Perl several functions and operators use this variable as a default variable in case no variable
is explicitely used. foreach and print are such functions. So here we can see a shorter version of
the previous script:
@fruits = qw(apple banana peach);
foreach $fruit (@fruits) {
print $fruit;
}
foreach $_ (@fruits) {
print $_;
}
# but the real use of the variable is when it is not used explicitly:
foreach (@fruits) {
print ;
}
Print Arrays:
Praveen Kasireddy
Page 13
14. Learn PERL
@a = qw(x y z);
print "pre ", @a, " postn";
# pre xyz post
# $, holds empty string
print "pre @a postn";
POP& PUSH, SHIFT and UNSHIFT
There are several functions working on arrays:
pop and push implement a LIFO stack.
pop fetches the last element of the array returns that value and the array becomes one shorter
if the array was empty pop returns undef
SCALAR = pop ARRAY;
Example:
@array = ('a', 'b', 'c');
$lastelem = pop(@array); # $lastelem gets 'c'
@array becomes ('a', 'b')
push is the opposite of pop it adds element(s) to the end of the array It returns number of
elements after the push.
PUSH ARRAY, SCALAR, ... (more SCALARs);
Example:
@array = ('a', 'b');
push(@array, 'd'); # @array becomes ('a', 'b', 'd')
push(@array, 'e', 'f'); # @array becomes ('a', 'b', 'd', 'e', 'f')
shift and unshift are working on the beginning (left side) of the array.
shift fetches the first element of an array.
Praveen Kasireddy
Page 14
15. Learn PERL
It returns the fetched element and the whole array becomes one shorter and moved to the left.
Returns undef if the array was empty.
Example:
@array = ('a', 'b', 'c');
$f = shift @array; # $f gets 'a', @array becomes ('b', 'c')
unshift adds element(s) to the beginning of an array returns number of elements in the array
after the addition
Example:
@array = ('b', 'c');
unshift(@array, 'x', 'y') # @array becomes ('x', 'y', 'b', 'c')
Exercise 1
Implement pop,push,shift,unshift (only with @ $ and array index)
Example: pop is used like this:
$x = pop @a;
implementation:
$x = $a[$#a];
$#a = $#a - 1;
Exercise 2
Create a menu system where the user can select a fruit by giving the corresponding number (17) and you print the name of the fruit. (The list of the fruits is hard coded)
Exercise 3
Read in a few numbers, each one on a separate line till end-of-input and print out the min, max
and average. (End-of-input is ^D on linux and ^Z ENTER on windows.)
23
11
Praveen Kasireddy
Page 15
16. Learn PERL
198
3
-70
1001
Exercise 4
Read in a few lines (till end-of-input) and print them in reverse order.
Exercise 5
Write a program that generates the first n Fibonacci numbers. (Definition: f(n) = f(n-1)+f(n-2),
f(0)=f(1)=1) The user supplies the value of n.
Example:
INPUT : 6
OUTPUT: 1 1 2 3 5 8
10.
Sub Routines:
sub foo {
"Hi Dave";
}
Calling Sub routines:
In the old days, the name of a subroutine started with '&' (doesn't have to any more).
These are all valid calls of the subroutine:
&foo; foo(1,2,3,4);
&foo("Hello"); foo 11.75;
** You can use the my keyword to declare a variable as private to the subroutine:
my($a,$b);
Praveen Kasireddy
Page 16
17. Learn PERL
my($size) = 11;
my(@foo) = (1,3..11);
Sample Sub routine:
sub min {
my($a,$b) = @_;
if ($a < $b) {
$a;
} else {
$b;
}
}
11.
PERL DB
Sample 1:
use Win32::ODBC;
# Create a database object and make sure
# the database was found
$db = new Win32::ODBC("eiw");
if (! $db) {
print "Error - the eiw database could not be foundn");
...
}
Praveen Kasireddy
Page 17
18. Learn PERL
Sample 2
use DBI;
$db=DBI->connect("dbi:ODBC:Flight32");
$a=$db->prepare("Select * from orders");
$a->execute;
@row=$a->fetchrow_array;
print @row;
12.
PERL FILE HANDLING
PERL reads files using various syntaxes :
open a file for reading, and link it to a filehandle:
open IN, “C:EHD.txt";
And then read lines from the filehandle, exactly like you would from <STDIN>:
$line = <IN>;
foreach $line (<IN>) ...
And don’t forget to close it:
close IN;
A nice way to check that the open didn’t fail (e.g. if the file doesn’t exists):
open IN, "$file" or die "can't open file $file";
PERL can also write into files:
open a file for writing, and link it to a filehandle:
open OUT, ">EHD.analysis";
(If a file by that name already exists it will be overwriten!)
Or, you can add lines at the end of an existing file (append):
open OUT, ">>EHD.analysis";
Print to a file:
print OUT "The mutation is in exon $exonNumbern";
Praveen Kasireddy
Page 18
19. Learn PERL
PERL understands various representations of folders paths :
open IN, '<D:EyalPERLp53.fasta';
n
n
Always use a full path name, it is safer and clearer to read
Remember to use in double qoutes
open IN, "<D:EyalPERL$name.fasta";
n
You can also use / (usually…)
open IN, "<D:/Eyal/PERL/$name.fasta";
PERL also can work with foldersand files inside them:
Perl allows easy access to the files in a directory by “globbing”:
foreach $fileName (<D:/scripts/*.pl>) {
open IN, $fileName
or die "can't open file $fileName";
foreach $line (<IN>) {
do something...
}
}
More samples:
open OF, "<C:File1.txt";
foreach $l(<OF>)
{
print "$ln";
}
open WF, ">>C:File1.txt";
print WF "nThis is additional Line";
Praveen Kasireddy
Page 19
20. Learn PERL
13.
PERL REGULAR EXPRESSION
Perl’s greatest capability is its regular expressions. It uses “/<expression> /” for applying regular
expression.
Sample:
print (" please enter your emailIDn");
$_=<STDIN>;
if (/[0-9].*@.*/)
{
print "It is a correct mail format";
}
else
{
print "it is a wrong mail format";
}
#Q> Write a text file with 10 mail ids (Valid and Invalid).
#Write a perl scrip which reads the file and copy all valid #emails to a new file.
14.
PERL HASH
What is a hash and why to use one?
Unordered group of key/value pairs where
key is a unique string and
value is any scalar
Also called Associative Array Like an array but the 'index' is string instead of number.
Examples of use, some kind of mapping:
phone book (name => phone number)
worker list (ID number => name)
DNS resolution (hostname => IP address)
UNIX admin (username => UID)
Praveen Kasireddy
Page 20
21. Learn PERL
Windows (Netbios name of computer => Name of person using it)
CGI: (fieldname => field value)
Sample1:
Accessing Individual Hash Elements
$phone{"Yossi Cohen"} = "03-672234";
# We create a hash called %phone and give value
to
print $phone{"Yossi Cohen"};
# one of its elements. then we can use that
element
$count_votes{"Bush"}++;
# in another hash we use the value as a number
$name = "Bush";
# We can use variables in place of the key
$count_votes{$name}--;
# The variable springs to existence.
# The original value is undef.
# before accessing a pair you should check if
if (exists $phone{"George"}) {
# the key exists at all
if (defined $phone{"George"}) {
# the value has been defined
print $phone{"George"};
}
}
# if you had enough from George
delete $phone{"George"};
# delete him from your phone book:
Sample 2
The whole hash
# The whole hash is called %phone
%phone = ("Yossi", 123, "Joe", 456, "Mary", 678);
%phone = (
# Maybe that is more readable like this
"Yossi", 123,
"Joe", 456,
"Mary", 678);
%phone = (
# or even better with the big arrow
"Yossi" => 123,
"Joe" => 456,
"Mary" => 678);
# If we get an array like this from somewhere, we can turn it to a hash but beware of the
change of meaning !
@array = ("Yossi", 123, "Joe", 456, "Mary", 678);
%phone = @array;
Praveen Kasireddy
Page 21