(Apparently the:
syntax is from a dialect of BASIC.print "Foo...\n" if $verbose;
The good thing about these similarities is that it encourages coders with some familiarity.
The bad thing is that they might not realise that compared with the 'strand' of coding they are familiar with from before, the 'braid' which is perl often has better ways to do a given task.
e.g. a C coder starting at perl might loop through an array like this:
instead of:my @array = ( "foo", "bar", "baz" ); my $i; my $array_size = scalar( @array ); for( $i = 0; $i < $array_size; $i++ ) { ...do something with $array[$i]...including assigning to it }
whereas a shell scripter would be more likely to have used the latter construct in the first place. And vice versa for other things.my @array = ( "foo", "bar", "baz" ); foreach my $value ( @array ) { ...do something with $value...including assigning to it }
Lastly, top tip for every perl coder is *ALWAYS* use the '-w' switch. It basically stops you shooting yourself in the foot in many ways. (You can include it on the first line of your script:
and thanks to the magic of perl, this will work on windows as well as Unix.#!/usr/bin/perl -w ...your script here...
Even more lastly, and especially if you are coming from C, consider always putting:
at the top of each script. If you don't perl won't warn you if you don't declare variables (and do other marginal stuff). If you don't declare variables, they are global by default. If that doesn't scare you, then well, happy debugging.use strict;
And honestly, definitely lastly, try looking into CPAN (and/or the PPM modules if you use ActiveState perl on Win32). One of the key reasons to use perl is the useful amount of library code which is there to interface to practically everything and its toaster's pet dog.
Good luck and have fun
In reply to RE: My life as a monk, day 1.
by jbert
in thread My life as a monk, day 1.
by Bowie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |