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

AS news1 at dsl.pipex.com
Thu Nov 6 21:54:04 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
> I have tried various ways of entering it using [perl]code[/perl] but
> 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
> 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
if you don't need the scratch variable to be saved to the user's
That's assuming you're using 4.9.x, of course.

Thanks, that works well, I am using 4.8.7.

If I now squirt the ship_address out to a label printer will this
formatted postcode get printed? I looked in the database and the
postcode still retains the old format.

I can't try it yet as I am waiting for the printer to arrive.



More information about the interchange-users mailing list