Skip to Content
Perl 6 Deep Dive
book

Perl 6 Deep Dive

by Andrew Shitov
September 2017
Beginner
402 pages
9h 52m
English
Packt Publishing
Content preview from Perl 6 Deep Dive

The temp operator

The temp operator temporary replaces a variable with a new value.

Consider the following example:

my $var = 1;f(); # 1{    f(); # 1    temp $var = 2;    f(); # 2}f(); # 1sub f() {    say $var;}

The f subroutine prints the value of the global variable $var. Initially, the value of the variable is 1. Thus, the first call of f prints 1.

 Then, we have a block of code between a pair of curly braces. The second call of f is using the save value of $var as before. Then, the value of it is temporarily set to 2. So, the third call of f prints 2.

After exiting from the code block, the scope of the temporary value ends and the original value of $var is restored. So, the fourth call of f prints 1 again. The temp keyword is different from the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Learning Perl 6

Learning Perl 6

brian d foy
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 9781787282049Supplemental Content