Mega Code Archive
Search
.Net
ASP .Net
ASP .Net Tutorial
C#
C# Book
C# by API
C# Tutorial
VB.Net
VB.Net by API
VB.Net Tutorial
Visual C++ .Net
VisualBasic Script
Java
Java
Java Book
Java by API
Java Tutorial
Script
Flash ActionScript
Flex
JavaScript DHTML
JavaScript Reference
JavaScript Tutorial
Database
MSSQL
MSSQL Tutorial
MySQL
MySQL Tutorial
Oracle PLSQL
Oracle PLSQL Tutorial
PostgreSQL
Languages
Android
C
C Tutorial
C++
C++ Tutorial
Delphi
Perl
PHP
Python
Python Tutorial
Ruby
Silverlight
Office
MSOfficeExcel 2007 Tutorial
MSOfficePowerPoint 2007 Tutorial
MSOfficeWord 2007 Tutorial
Data
XML
XML Tutorial
Perl
Language Basics 431 codes
Home
Perl
Language Basics
1 ! $v1 $v2
2 #!usrbinperl -w tells the perl command to turn on extra warnings with the -w option
3 $ is END_OF_OUTPUT
4 $ is the separator
5 $! is the error number
6 $! stores the error message
7 $# is the default format
8 $(dollar), is the separator
9 $^ is the format header
10 $^O stores the name of the operating system
11 $^S
12 $^W
13 $^X
14 $_ for print function
15 $_ stores the user input
16 $~ is the format
17 $data is a scalar variable, while @data is an array
18 $SIG{__DIE__}
19 $SIG{__WARN__} = IGNORE
20 $SIG{__WARN__} = sub {die Warning
21 %, the remainder, or modulo operator
22 %INC values
23 &&, , and !
24 @_ has runtime scope
25 @a1 = $v1 1 10
26 = returns 0, -1 , or 1
27 A case-conversion program
28 A more expanded version for showing how to use the $_
29 A package is a separate name space for variables to reside in
30 A program that changes the value of $
31 A program that sorts input lines in reverse order
32 A program that uses AUTOLOAD
33 A program that uses the $ (dollar and quotation) variable
34 A program that uses the $ variable
35 A program that uses the $(dollar and slash) variable
36 A program that uses the $(dollar), variable
37 A program that uses the -0 option
38 A program that uses the -l option
39 A program that uses the pre-increment operation
40 A scalar is a variable that holds a single value, a single string, or a number
41 A scalar variable can reference a string value or a numeric value
42 A simple Perl program that reads and writes a line of input
43 A simple Perl program with comments
44 A simple program that assigns to $_ using STDIN
45 A simple version of the cat command using $_
46 Add 3 to $var; same as $var=$var+3
47 Adding 10 to an undefined variable
48 Adding a number and a string
49 After incrementing
50 After pre-decrement
51 After pre-increment
52 Aliases and Values
53 Alternative names for Perl system variables
54 An example of exponentiation
55 An example of the -a option
56 Any line starting with a number sign (#) indicates a comment
57 ARGV and the Null Filehandle
58 ARGV in Perl represents the command-line arguments
59 Arithmetic Operators in action
60 Assign a number to a single variable
61 Assign elements in @_ to scalar
62 Assign new value to string variable
63 Assign new value to the integer scalar variable
64 Assign string array to @ARGV by using qw
65 Assign text to a single variable
66 Assign value to @_
67 Assign value to a variable without declaration
68 Assign value to four variables
69 Assigning Input to an Array
70 Assignment Operators
71 Assignment Statements
72 Auto local variable
73 Autoincrement and Autodecrement Operators and Assignment
74 Basic arithmetic operators
75 Basic Math Compound Assignment Statements
76 Basic Numeric Operations
77 Begin and End block
78 Bitwise And Operators in action
79 Bitwise exclusive or Operators in action
80 Bitwise Logical Operators
81 Bitwise operator
82 Bitwise Or Operators in action
83 Block main
84 Block variable scope
85 Blocks
86 Boolean and
87 Boolean Combination Operators
88 Boolean operator
89 Build the ARGV array with qw function
90 Built-in Perl Arithmetic Functions
91 Built-in variables
92 Call-by-Reference and the @_ Array
93 Capturing fatal errors
94 Catching the sigINT signal
95 Check a specific bit
96 Cmp with or
97 Code the $_ specifically
98 Commenting Your Code
99 Comments are plain text that allow you to insert documentation in your Perl script
100 Compare integer value
101 Compare string value
102 Compare the first four decimal places
103 Compare value entered with number with underscore
104 Comparing Numbers for Equality
105 Comparing Numbers for Inequality
106 Comparison Operators listing
107 Complex Assignment
108 Compound assignment operator with scalar variable
109 Compound Assignment Operators
110 Compound Boolean operator Or
111 Compound operator
112 Concatenate two scalar variables with double quotes
113 Conditional debug
114 Conditional Operator
115 Conditional Operators and print statement
116 Constant scalar
117 Contents of the symbol table for the main package
118 Convert to scalar
119 Creates a global variable $myvar and prints out the global instance of the variable and the package-specific variable
120 Creating a Scalar
121 Curly Braces
122 Debug flag
123 Declare scalar variable to store the integer value
124 Declare three variables in one statement
125 Default package is main
126 Define variables with the same name in different package
127 Demonstrates the difference between pre- and postincrement
128 Do while with diamond operator
129 Dont use == when you should use eq!
130 Downloading and Installing Modules using Perl -MCPAM
131 Downloading and Installing Windows Modules using ppm
132 Edit files using the -i option
133 Ending modifiers
134 Eq, ne, lt, gt operators
135 Equality Operators and Numeric Values
136 Equality Operators and String Values
137 Error message is stored in $!
138 Examples of assignment operators
139 Executing the Script
140 Extracts information from the $] variable
141 File-searching program using $ARGV
142 Float power
143 Foreach (@_)
144 Foreach loop and $_
145 Format text output with HTML tags
146 Forward Reference
147 Get Computer Name key in the %ENV
148 Get local time from $^T
149 Get reference to a scalar
150 Get the documentation of the built-in function
151 Get the Power
152 Getting Input in Perl Scripts
153 Getting information on modules
154 Guess My Number
155 If $_contains needle, the string is printed
156 If not equal
157 If terminator is in backquotes, will execute OS commands
158 If the strings are not quoted, the filehandle STDOUT must be specified, or
159 If there are no quotes, then Perl has to decide whether the value is a string or a numeric value
160 If variable defined
161 In Perl, an assignment itself can serve as an lvalue
162 Increment and Decrement Operations
163 Increment and Decrement Operators
164 Initializing scalars and printing their values
165 Insert comments
166 Integer signal
167 Integer-comparison operators
168 Is the same as STDIN
169 Left shift
170 Lexical variables
171 Libraries and Modules
172 Lines Remaining on the Page
173 List all command line argument
174 Local builtin var
175 Local element
176 Local to Block
177 Local variables
178 Locate all numbers less than 6
179 Logical Operators (Short-Circuit Operators)
180 Logical operators are defined
181 Logical Word Operators
182 Loop block
183 Manipuate @_ and return @_
184 Mannually change the $1 variable
185 Map using a block
186 Match
187 Merge scalar variable into the string for output
188 Minus power
189 Mix the string the integer calculation in a print statement
190 Modifying a Variable
191 Module
192 Modulus operator
193 Naming Scalar Variables
194 No strict refs
195 Not equals operator
196 Numeric Literals
197 Numeric operators
198 Operating and Assigning at Once
199 Operator
200 Operator associativity
201 Operator precedence
202 Operators demo
203 Or die $!
204 Or die $^E
205 Out value scope
206 Output the result of division with string
207 Output the result of multiply with string
208 Output two values in one print statement
209 Package declarations and subroutine
210 Passing Arguments at the Command Line
211 Passing scalar variable to a subroutine by reference using $_
212 Perl 5 Built-In Variables
213 Perl can take its input from a file and send its output to a file using standard IO redirection
214 Perl Flow Control Commands
215 Perl Flow Control in Brief
216 Perl offers many types of operators
217 Perl Statements
218 Perl statements end with a semicolon (;)
219 Perl supports integers (decimal, octal, hexadecimal), floating point numbers, scientific notation, Booleans, and null
220 Perl variables
221 Perls modules reside in the directories named in the @INC array, or subdirectories
222 Perls operators for numeric comparisons
223 Perls special arrays
224 Perls special variables
225 Place a # in the middle of a line, and Everything from the # to the end of the line is a comment
226 Post-increment operation
227 Postmatch $
228 Power with
229 Precedence and Associativity
230 Precedence with word operators and short-circuit operators
231 Pre-increment string value
232 Prematch
233 Print $]; (Perl version number)
234 Print $_ = 0 $_
235 Print $_ 10 $_
236 Print $INC{English pm}
237 Print 1, 2, 3, 4, sort 9, 8, 7, 6, 5
238 Print 16 % 3
239 Print 2048 3
240 Print 24 15
241 Print all command line argument
242 Print -e STDIN;#Does STDIN exist
243 Print function prints a string or a list of comma-separated words to the Perl filehandle STDOUT
244 Print Hello!n
245 Print Hello, $ENV{USER}!n
246 Print only care about the first parenthesis
247 Print out all pm library location
248 Print out here document
249 Print sqrt 4
250 Print -t STDIN;#Is it tied to a terminal
251 Print the default variables ($_) value
252 Print -z STDIN;#Does it have zero size
253 Printf Flag Modifiers
254 Printf function prints a formatted string
255 Printing Numeric Literals
256 Printing Output
257 Printing String Literals
258 Prints a welcome statement with escape character
259 Prints a welcome statement with several escape characters
260 Prints out each element of @ARGV separately
261 Program to illustrate the use of scalar variables
262 Put all into a parenthesis for print statement
263 Put code in a block
264 Quick Sum
265 Read a line of input from the keyboard
266 Read a single character from the keyboard
267 Read and set environment variables
268 Read input from keyboard
269 Read lines from supplied filenames
270 Read name from console
271 Read three lines of text from standard input
272 Read user input
273 Read user input and use if statement to check it
274 Reading from STDIN
275 Redirect STDIN to error log
276 Reference element in @_
277 Reference variable by package name
278 Relational Operators and Numeric Values
279 Relational Operators and String Values
280 Relational Operators demo
281 Remainder and power
282 Require another perl file
283 Requires the package created above and calls the subroutine declared within it
284 Resetting array base
285 Resulting Values of Bitwise Operators
286 Retrieving the Entire Pattern
287 Saving in the $& special scalar
288 Scalar alias
289 Scalar value interpolation
290 Scalar variables hold a single number or string and are preceded by a dollar sign ($)
291 Scalar, array, and hash output
292 Scalars (Denoted by $)
293 Scope and block
294 Scope change
295 Scope of Variables
296 Set the $ and chomp
297 Shift
298 Short-circuit operators
299 Simple calculation with scalar variable
300 Special Hashes
301 Special Literals
302 Special Variables
303 Splitting up $_
304 Splitting up $_ and creating an unnamed list
305 Square $var
306 Standard input
307 Statements, Whitespace, and Linebreaks
308 Stick with one variable and modify its value
309 String- and numeric-comparison operators
310 String comparison operator
311 Subtract 1 from $var
312 Surrounding FINIS with single quotes
313 Switches between packages
314 Syntac of using a module
315 Syntax for the print Function
316 System variables that control how write sends output to a file
317 Test of open and die with $!
318 The $_ Scalar Variable
319 The %SIG hash sets signal handlers for signals
320 The @ field
321 The @ISA Array and Calling Methods
322 The and Operator
323 The Argument Vector @ARGV
324 The ARGV Array
325 The assignment operators
326 The autoincrement operator
327 The backslash operator means adddress of
328 The Bit-Manipulation Operators
329 The -c Switch checks the Perl syntax without actually executing the Perl commands
330 The code executes a line of code you type as long as that line doesnt start with a #
331 The diagnostics Pragma
332 The -e switch executes Perl statements at the command line instead of from a script
333 The environment associative array
334 The filehandle STDOUT must be specified if strings are not quoted
335 The following functions and operators work with the $_ variable by default
336 The HTML tags are embedded in the here document to avoid using multiple print statements
337 The list separator is a comma
338 The list separator is the empty string
339 The -n Switch
340 The numeric comparison operator evaluates its operands
341 The Pattern-Matching Operator and $_
342 The print command prints out the text you provide it
343 The shift operator returns an undefined value if the array has no more elements
344 The startup line tells the shell where Perl is located
345 The strict Pragma
346 The strict Pragma and Words
347 The Substitution Operator and $_
348 The -w option passed to the perl command generates a warning about the code itself
349 The warnings Pragma and the -w Switch
350 This code should be stored in the file Mymodule pm
351 Three-way-comparison becomes cmp
352 Time - $^T
353 To force perl to perform an operation of lower precedence first, use brackets
354 To list all pm files by using the @INC array
355 To quit the ppm command
356 To set a variable, use the = operator
357 Undef $
358 Undef a variable
359 Use constant PI
360 Use eq to compare strings
361 Use parentheses wherever possible to force precedence
362 Use strict
363 Use strict and subroutine
364 Use strict Pragma
365 Use strict refs
366 Use strict subs
367 Use strict vars
368 Use strict with package
369 Use while loop to display all entries in ENV
370 Uses the same name inside and outside a foreach statement
371 Using $, to set the separator for print command
372 Using $_ (dollar underscore)
373 Using $_ as the array index
374 Using $_ variable with while statement
375 Using %SIG to define our own signal handlers
376 Using (bar) operator
377 Using @_ directly
378 Using ^ operator
379 Using __LINE__ to output line number
380 Using a Module from the Standard Perl Library in a Script)
381 Using a Perl 5 Module from the Standard Perl Library
382 Using and ( ) operator with if statement
383 Using Assignment Operators on Scalar Variables
384 Using auto-increment operator for a string
385 Using auto-increment operator for a string with digits
386 Using bare blocks to form a multiple-selection structure
387 Using boolean operator (and ) to connect the comparison operator
388 Using comma in a print statement
389 Using defined
390 Using defined keyword in if statement
391 Using diamond operator with while statement
392 Using diamond sign to read from keyboard
393 Using e modifier to evaluate
394 Using -e option to execute the perl statement
395 Using eof and together
396 Using eq in statement
397 Using ne in if statement
398 Using operator
399 Using Perl Built-in Functions
400 Using Perl to Create Your Own Module
401 Using scalar reference
402 Using shift to process the command-line arguments
403 Using the $ variable
404 Using the $;(dollar and semicolon) variable
405 Using the @_ to reference the parameter
406 Using the Default Variable $_
407 Using the diamond operator with @ARGV
408 Using the if statement to check the command line parameters
409 Using the -n option
410 Using the package keyword to change the package context
411 Using the print Function
412 Using the special Perl variable $! in the message passed to die
413 Using the strict Pragma
414 Using tr to convert all file names passed in to uppercase
415 Using two statements with -e option
416 Using undef to represent an unusual condition
417 Using variable with -e option
418 Variables and Arrays
419 Verify an installation using ppm
420 Verify the total number of the command line parameter
421 While block
422 Working with $_ usually makes programming much easier, but more confusing to the uninitiated
423 X 4 says that the text within the here document will be printed four times
424 You can combine operators such as +, -, and with the assignment operator
425 You can omit the STDIN altogether
426 You can pass a list of items to print, where you separate the list items with commas
427 You display the current line of execution in a Perl script by referring to it with the __LINE__ token
428 You display the name of the current file with the __FILE__ token
429 You display the name of the current Perl package with __PACKAGE__
430 You have to tell Perl which packages you intend to use, with the use command
431 Your package