Command Line Arguments

Slides:



Advertisements
Similar presentations
Week 5 Part I Kyle Dewey. Overview Exam will be back Thursday New office hour More on functions File I/O Project #2.
Advertisements

● Perl reference
Computer Programming for Biologists Class 9 Dec 4 th, 2014 Karsten Hokamp
Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
Perl I/O Learning Objectives: 1. To understand how to perform input from standard Input & how to process the input 2. To understand how to perform input.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Perl I/O Software Tools. Lecture 15 / Slide 2 Input from STDIN Reading from STDIN is easy, and we have done it many times. $a = ; In a scalar context,
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
How shell works Shell reads in input, parse & process it, the resulting string is taken to be argv[] and executed echo a  shell sees “ echo a ” echo gets.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
CSc 352 Shell Scripts Saumya Debray Dept. of Computer Science
Perl - Advanced More Advanced Perl  Functions  Control Structures  Filehandles  Process Management.
2 $ command Command Line Options ls –a –l hello hi Command Arguments.
Shell Scripting Todd Kelley CST8207 – Todd Kelley1.
GNU Compiler Collection (GCC) and GNU C compiler (gcc) tools used to compile programs in Linux.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
Introduction to Perl Part III By: Bridget Thomson McInnes 6 Feburary 2004.
Introduction to Unix – CS 21
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Iteration While / until/ for loop. While/ Do-while loops Iteration continues until condition is false: 3 important points to remember: 1.Initialise condition.
Memory Layout, File I/O Bryce Boe 2013/06/27 CS24, Summer 2013 C.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
Perl Scripting II Conditionals, Logical operators, Loops, and File handles Suzi Lewis Genome Informatics.
The Perl Debugger Issac Goldstand Mirimar Networks
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
1 Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Perl Subroutines User Input Perl on linux Forks and Pipes.
Week 6 - Friday.  What did we talk about last time?  Pointers  Passing values by reference.
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Lecture 7 Introduction to Shell Programming
Lecture 7 Introduction to Shell Scripts COP 3353 Introduction to UNIX.
Input from STDIN STDIN, standard input, comes from the keyboard.
CSC 352– Unix Programming, Spring 2016, Final Exam Guide
Chapter 6 CS 3370 – C++ Functions.
CSC 352– Unix Programming, Fall 2012
Part 1: Basic Commands/Utilities
Introduction to Python
Command Line Arguments
Command line arguments
Command Line Arguments
CSE 351 Section 1: HW 0 + Intro to C
Instructor: Ioannis A. Vetsikas
Sarah Diesburg Operating Systems CS 3430
Introduction to Python
User Defined Functions
Intro to UNIX System and Homework 1
LING 408/508: Computational Techniques for Linguists
Command Line Parameters
Perl Variables: Array Web Programming.
CS 240 – Lecture 18 Command-line Arguments, Typedef, Union, Bit Fields, Pointers to Functions.
Basic Input/Output Web Programming.
Lesson 2. Control structures File IO - reading and writing Subroutines
Perl I/O Learning Objectives:
Writing Functions.
A LESSON IN LOOPING What is a loop?
Lab 4: Introduction to Scripting
Module 6 Working with Files and Directories
CSC 352– Unix Programming, Fall, 2011
Quick Tutorial on MPICH for NIC-Cluster
Subroutines.
Review The Unix Shells Graham Glass and King Ables,
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Presentation transcript:

Command Line Arguments

Command Line Arguments Arguments provided to your program via the command line. Not read from user input in C/C++: argv[] contains program name and arguments argc contains number of arguments plus one in Perl: @ARGV contains list of arguments $0 contains program name

Examples: myscript.pl 15 4 hello perl_hw2.pl @ARGV  (15, 4, 'hello') scalar(@ARGV)  3 perl_hw2.pl @ARGV  ( ) $0  'perl_hw2.pl' scalar(@ARGV)  0

Notes These are true globals – no matter what package you're in, $0 always means $main::0, @ARGV always means @main::ARGV unless you've declared a lexical @ARGV don't do that. Depending on your system, $0 may contain just the script name, a relative path to the script, or an absolute path.

Some Magic The standard <> operator has some magic built into it When "empty", <> will open the first file specified on the command line, and begin reading it. Once it's exhausted, will open the next file, etc. If another call to <> occurs after all arguments are read, <> begins reading from STDIN While <> is processing command line arguments, $ARGV contains the name of the current argument. If any file can't be opened, a warning is issued, and processing continues with the next one.

Magic Example myscript.pl file1.txt sample while (<>){ chomp; print "$ARGV, line $. = $_\n"; } open file1.txt, print out all lines in that file open sample, print out all lines in that file loop terminates. At this point, @ARGV  () any future reads to <> will read from STDIN