[Courses] [Perl] Perl course part 3 (some corrections)

Jacinta Richardson jarich at perltraining.com.au
Sun Apr 13 15:59:36 EST 2003


On Sun, 13 Apr 2003, Alice Wood wrote:

A very good part of a Perl course, but in need of a minor correction or
two..

> LinuxChix Perl Course Part 3: User Input, chomp and chop.

> 2) Chomp
....
> "chomp" is also called the "safe chop"
> 
> chop will remove any single final character.
> chomp will remove only a new line character (i.e. the enter from
> the keyboard).

Chomp will remove any string specified in $/.  Hence if $/ were equal to
"this", then:

$/ = "this";
$fred = "let's say we have a string like this";
chomp $fred;
print $fred;

would print "let's say we have a string like ";  

The key is, that if $/ is set to "\n" as it is by default then calling
chomp on our string would ONLY remove the trailing newline, if it
existed.  If there is not trailing newline, then chomp will remove
nothing.  Chomp is not restricited to only removing a single character,
neither is $/ restricted to being set to a single character.

....

> 3) Exercises
> 
> a) Try adding the following line to your program, before my $line = <STDIN=
> >;
> 
> $/ ",";

This most certainly should be:
$/ = ",";

note the missing = character.




Hope they help.

	Jacinta

--
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson	    |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +613 9354 6001 	    |  
  _..`--'_..-_/  /--'_.' ,'           | contact at perltraining.com.au |
(il),-''  (li),'  ((!.-'              |   www.perltraining.com.au   |



More information about the Courses mailing list