in reply to given/when one case prefixes another
This produces the following output:#!/usr/bin/perl use warnings; use strict; use v5.10; my @data = ('foo', 'bar', 'baz'); for my $element (@data) { given ($element) { when ('foo') { # Do foo things print("foo here\n"); # force common ending routine $_ = 'MAGIC_foobar'; continue; } when ('bar') { # Do bar things print("bar here\n"); # force common ending routine $_ = 'MAGIC_foobar'; continue; } when ('baz') { # Do baz things print("baz here\n"); } when ('MAGIC_foobar') { # Do common ending things here print("foobar ending here\n"); } } }
foo here foobar ending here bar here foobar ending here baz here
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: given/when one case prefixes another
by John M. Dlugosz (Monsignor) on Apr 26, 2011 at 08:41 UTC | |
by ww (Archbishop) on Apr 26, 2011 at 12:49 UTC |