in reply to Strings with undefined variables?
#! /usr/bin/perl use warnings; use strict; use String::Interpolate; my $template = 'String::Interpolate'->new; $template->('http://something.com/api_stuff/$GUID'); make_call( '1234' ); sub make_call { my $GUID = shift; $template->{GUID} = $GUID; POST("$template"); } use Test::More; sub POST { is shift, 'http://something.com/api_stuff/1234', 'intepolates'; } done_testing();
The same using Template:
#! /usr/bin/perl use warnings; use strict; use Template; my $template = 'http://something.com/api_stuff/[%GUID%]'; make_call( '1234' ); sub make_call { my $GUID = shift; my $template_object = 'Template'->new; $template_object->process(\$template, {GUID => $GUID}, \ my $outpu +t); POST($output); } use Test::More; sub POST { is shift, 'http://something.com/api_stuff/1234', 'intepolates'; } done_testing();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Strings with undefined variables?
by 23skiddoo (Beadle) on Jan 04, 2019 at 13:00 UTC |