Software Sue

Link to Simply Sue
Link to Sustainability Sue
location: software/scripting/perl functions Skip navigation : Home  

Perl Functions


Perl has a variety of functions that can be called by your program. They are called by function name, and can accept a list of parameters (preferably enclosed in parentheses). Examples of built-in functions are:

Chomp

When Perl reads a line of input, it includes the newline at the end. Chomp() removes all such newline characters at the end of a string. If there are none, it does nothing.

#!/usr/bin/perl  
@mylist = ;  # read the input into my list
chomp(@mylist);  # remove any trailing newlines
print(@mylist);  # print the list

Chop

Chop() removes the last character of a string. If the string has been input, this will probably be a newline at the end that is removed.

chop(@sources);  # remove the last line