[Ilugc] Perl basics

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Tue, 11 Dec 2012 13:08:09 +0530

Since the level of perl knowledge sucks I will start from the basics.

I had already done that long ago. But now the LUG river will have new fishes.

Okay it is really trivial to get the first perl code running:

$ cat f.pl
print "How are you?";

That is it.

Every line is terminated with semicolon and if and else and elsif all
require  parantheses like C.

But you cannot leave  it out for single lines as in C.

Java and perl and C++ all follow C style. perhaps not C++.

Anyway the way to read a file is very simple.  You can either directly
read with the diamond(<>) operator
 or use the Tie::File CPAN module.

$ cat fileread.pl

for(<>) {
    print;
}

That is it.

now run it with

$ perl fileread.pl /etc/passwd

To actually open a file for reading,

$ cat openfile.pl
open F, "/etc/passwd";

for(<F>) {
   print;
}

close F;

Now to write to a file, do this:

$ cat writefile.pl

open F, ">/tmp/test";
print F "how is this going?\n";
close F;

Try these first.

-Girish

Also refer to perldoc perldoc or perldoc perl

There are 1000s of tutorials in man pages.
$perldoc perlfaq5



-- 
Gayatri Hitech
http://gayatri-hitech.com

Other related posts:

  • » [Ilugc] Perl basics - Girish Venkatachalam