From c8c0808657417bc40150bb5f98994a98f4def1fd Mon Sep 17 00:00:00 2001 From: Korjavin Ivan Date: Thu, 22 Aug 2013 08:11:07 +0600 Subject: More tutorial links --- perl.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'perl.html.markdown') diff --git a/perl.html.markdown b/perl.html.markdown index 024bd851..f03e7244 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -114,5 +114,7 @@ perlfaq contains questions and answers related to many common tasks, and often p #### Further Reading -[Learn at www.perl.com](http://www.perl.org/learn.html) - and perldoc perlintro + - [perl-tutorial](http://perl-tutorial.org/) + - [Learn at www.perl.com](http://www.perl.org/learn.html) + - [perldoc](http://perldoc.perl.org/) + - and perl built-in : `perldoc perlintro` -- cgit v1.2.3 From 9a36a51ccc1cb7d64baac17a067be71a7923afdd Mon Sep 17 00:00:00 2001 From: Korjavin Ivan Date: Thu, 22 Aug 2013 08:16:54 +0600 Subject: Few words about subs and file i/o --- perl.html.markdown | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'perl.html.markdown') diff --git a/perl.html.markdown b/perl.html.markdown index f03e7244..18339dde 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -104,6 +104,35 @@ $a =~ s/foo/bar/; # replaces foo with bar in $a $a =~ s/foo/bar/g; # replaces ALL INSTANCES of foo with bar in $a +#### Files and I/O + +# You can open a file for input or output using the "open()" function. + +open(my $in, "<", "input.txt") or die "Can't open input.txt: $!"; +open(my $out, ">", "output.txt") or die "Can't open output.txt: $!"; +open(my $log, ">>", "my.log") or die "Can't open my.log: $!"; + +# You can read from an open filehandle using the "<>" operator. In scalar context it reads a single line from +# the filehandle, and in list context it reads the whole file in, assigning each line to an element of the list: + +my $line = <$in>; +my @lines = <$in>; + +#### Writing subroutines + +# Writing subroutines is easy: + +sub logger { + my $logmessage = shift; + open my $logfile, ">>", "my.log" or die "Could not open my.log: $!"; + print $logfile $logmessage; +} + +# Now we can use the subroutine just as any other built-in function: + +logger("We have a logger subroutine!"); + + ``` #### Using Perl modules -- cgit v1.2.3 From 2c7fa291a34eb88380e9cf8c8e35a49e70114251 Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Fri, 4 Oct 2013 12:44:13 +0300 Subject: [Perl] Remove some redundant spaces --- perl.html.markdown | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'perl.html.markdown') diff --git a/perl.html.markdown b/perl.html.markdown index 18339dde..b04b76cd 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -131,13 +131,11 @@ sub logger { # Now we can use the subroutine just as any other built-in function: logger("We have a logger subroutine!"); - - ``` #### Using Perl modules -Perl modules provide a range of features to help you avoid reinventing the wheel, and can be downloaded from CPAN ( http://www.cpan.org/ ). A number of popular modules are included with the Perl distribution itself. +Perl modules provide a range of features to help you avoid reinventing the wheel, and can be downloaded from CPAN (http://www.cpan.org/). A number of popular modules are included with the Perl distribution itself. perlfaq contains questions and answers related to many common tasks, and often provides suggestions for good CPAN modules to use. -- cgit v1.2.3 From fba9728e46d46ab8d9c8b2ae02778d6bd1213837 Mon Sep 17 00:00:00 2001 From: Christos Kontas Date: Fri, 4 Oct 2013 12:46:28 +0300 Subject: [perl] Fix list with links at "Further Reading" --- perl.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'perl.html.markdown') diff --git a/perl.html.markdown b/perl.html.markdown index b04b76cd..ad9155e4 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -141,7 +141,7 @@ perlfaq contains questions and answers related to many common tasks, and often p #### Further Reading - - [perl-tutorial](http://perl-tutorial.org/) - - [Learn at www.perl.com](http://www.perl.org/learn.html) - - [perldoc](http://perldoc.perl.org/) - - and perl built-in : `perldoc perlintro` + - [perl-tutorial](http://perl-tutorial.org/) + - [Learn at www.perl.com](http://www.perl.org/learn.html) + - [perldoc](http://perldoc.perl.org/) + - and perl built-in : `perldoc perlintro` -- cgit v1.2.3