Loginskip to content

October 29th, 2006

use strict $message = “Hello World”; print “$messagen”;

Consider a program with one extraneous character: use strict; my $x = 1; my $y = 2; $x == $y; print “$x,$yn”; Run the program and Perl prints: 1,2. No errors or warnings are given; this is expected, since each program statement is valid Perl. Now consider a program that differs from the previous one by one character: use strict; my $x = 1; my $y = 2; $x = $y; print “$x,$yn”; When run, Perl prints: 2,2. Output from the second program shows the value of $xset to the value of $y, whereas the first performs no such operation. What did the first program do? In line 4, $x=$y was intended, but $x==$y was coded. The former is an assignment to modify $x, the latter a Boolean test that modifies neither $xnor $y a particularly nasty problem as both commands are correct Perl syntax, and both execute without a complaint, with or without use strict. All this is very elementary, of course, until you wonder “What if I use -w?” Run our first program with -w and Perl returns: Useless use of numeric eq in a void context. File ‘typo1.pl’; Line 4. This reveals yet another reason to use -w in every program: with it, Perl can warn us that while our mistake resulted in syntactically valid Perl, it was odd Perl. It can’t raise a red flag stating “An extra = on line 4!” but it can point out that we’ve executed an essentially useless operation. 8.1.4 Alteration Let’s examine another single typo program: use strict; $message = “Hello World’; print “$messagen”; exit; On running, Perl returns the following: Scalar found where operator expected at typo.pl line 3, at end of line (Might be a runaway multi-line “” string starting on
Note: If you are looking for good and high quality web space to host and run your java application check Vision java hosting services

Comments are closed.