[ic] Formatting an IC Tag Variable with Perl - How??

Kevin Walsh kevin at cursor.biz
Thu Nov 6 21:10:40 EST 2003

AS [news1 at dsl.pipex.com] wrote:
> I want to format an IC Tag variable with a line (or two) of Perl.
> I want to use this perl line:-
> s/(...$)/ ${1}/g;
> to format the [loop-data transactions zip] which should add a space 3
> characters from the end. 
> Below is the current code from order_view page for the shipping address,
> I have tried various ways of entering it using [perl]code[/perl] but it
> always just prints the perl line on the screen.
> I really want to apply this format to the variable rather than just
> displaying it in this format, will this work? If not how can I re-format
> it? 
> [set ship_address]
> [loop-data transactions fname] [loop-data transactions lname]<br>
> [loop-data transactions address1]<br>
> [if-loop-data transactions address2]
> [loop-data transactions address2]<br>
> [/if-loop-data]
> [loop-data transactions city]<br>
> [loop-data transactions state]<br>
> [loop-data transactions zip]<br>
> <br>
> [/set]
If you want to use non-looping tags, such as [perl] then you will want
to use [seti], instead of [set], to force interpolation.  If you don't
force interpolation then the tags will be printed as-is, as you have

The following should work within a [set] tag, as it only makes use of
looping tags.  It'll also be more efficient than calling the [perl]

        my $zip = q{[loop-data transactions zip]};
        $zip =~ s/\s+//g;         # remove existing whitespace
        $zip =~ s/(...)$/ $1/;    # add a space three chars from the end

Also, consider using [tmpn] instead of [set] (or [tmp] instead of [seti])
if you don't need the scratch variable to be saved to the user's session.
That's assuming you're using 4.9.x, of course.

   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin at cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/

More information about the interchange-users mailing list