So far we’ve seen how Perl’s basic data structures work and also how to put them all together. Now it’s time to see what built-in functions and techniques Perl provides us to work with scalars, arrays, and hashes.
General functions
print [FILE HANDLE] list of data
Used to print data. If not passed a FILE HANDLE, it will print directly to STDOUT. Interpolation rules apply. Some interesting details about print are:
print @array; # prints all elements of @array with
# no spaces between them
print "@array"; # prints the elements WITH spaces between them
print $var1, $var2, @array; # prints values with no spaces between them
print FH "some data"; # prints the string "some data" inside file represented by FH (see open below).
# Note the lack of comma between the FH and the data to be printed.
open (FILE HANDLE, mode, filename) or open (FILE HANDLE, “modefilename”)
Opens a file or pipe for reading/writing/appending. Normally filehandles tend to be constants in uppercase, but it’s good practice to use variables to hold your filehandles. That way you can pass them between functions without occupying the main namespace. There are 2 styles of open – old style with 2 parameters and new style with 3.