File: uvar.pl

package info (click to toggle)
libvariable-magic-perl 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 4,256; ansic: 633; makefile: 8
file content (27 lines) | stat: -rwxr-xr-x 647 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env perl

use strict;
use warnings;

use lib qw<blib/arch blib/lib>;
use Variable::Magic qw<wizard cast dispell>;

my $wiz = wizard
 fetch  => sub { print STDERR "$_[0] FETCH KEY $_[2]\n" },
 store  => sub { print STDERR "$_[0] STORE KEY $_[2]\n" },
 'exists' => sub { print STDERR "$_[0] EXISTS KEY $_[2]\n" },
 'delete' => sub { print STDERR "$_[0] DELETE KEY $_[2]\n" };

my %h = (foo => 1, bar => 2);
cast %h, $wiz;

print STDERR "foo was $h{foo}\n";
$h{foo} = 3;
print STDERR "now foo is $h{foo}\n";

print STDERR "foo exists!\n" if exists $h{foo};

my $d = delete $h{foo};
print STDERR "foo deleted, got $d\n";

dispell %h, $wiz;