Category: perl

Perl: ternary operator

Perl self-tutoring: the tutor mentions the ternary operator. Let’s imagine the variable $v0 is not defined, and therefore false from Perl’s point of view. $v0 ? print ‘defined’ : print ‘not defined’ will output not defined. a?b:c is known as

Perl: map

Tutoring Perl: the tutor gives an example of Perl’s fantastic map function. Suppose you have the array (1,2,3,4), but you want to musically enhance it to (and a 1, and a 2,….) @arr=map {‘and a ‘.$_} (1,2,3,4); yields @arr =

Perl: greedy vs lazy match

Perl tutoring: the tutor compares a greedy match with its corresponding lazy one. argument greedy lazy e2ee9a /e\w*\d/ /e\w*?\d/ match e2ee9 e2 Source: roberts perl tutorial McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.

Computer science: regular expressions w/ Perl

Perl tutoring: the tutor comments about square brackets in Perl regex. Perl regex match string /[beat24]/ string containing any of b,e,a,t,2,or 4. /beat24/ string containing the exact sequence beat24 Source: McGrath, Mike. Perl in easy steps. Southam: Computer Step, 2004.

Computer science: Perl regex: grouping with parentheses

Self-tutoring about computer science: the tutor mentions using parentheses in Perl regular expressions to form groups. A useful feature of regular expressions is the optional use of parentheses. There are numerous reasons to use them, but one is to report

Perl: use feature ‘say’;

More self-tutoring about Perl: the tutor mentions another way to enable ‘say’ in Perl. In my post from Aug 15 I mention the Perl feature say and that, to enable it, a user might key use v5.10; below the she-bang

Using say in Perl

Tutoring computer science, new language ideas will always be noticed. The tutor mentions the Perl construct say. use v5.10; #Apparently you need this to use say. $var1=”Hey there:)”; say $var1; #same effect as print “$var1\n”; I’ve never known of say,