Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Perl variables embedded in CSS in a CSS file not resolving correctly when the file is linked in

by Corion (Pope)
on Oct 05, 2018 at 14:02 UTC ( #1223577=note: print w/replies, xml ) Need Help??


in reply to Perl variables embedded in CSS in a CSS file not resolving correctly when the file is linked in

What you want is to use one of the many templating systems. See Template for a selection of those.

If you're hell-bent on rolling your own, just to keep the precious Perl variables, my suggestion is to declare them explicitly in a hash and to replace them with a tiny loop:

my %template_variables = ( 'navytext' => $navytext, # ... ); my $css = <<'CSS'; #tabmenu { color: #$navytext; } CSS sub fill_template { my( $str, $vars ) = @_; $str =~ s!\$(\w+)!$template{ $1 } || '$' . $1!ge; $str }; print fill_template( $css , \%template_variables );
  • Comment on Re: Perl variables embedded in CSS in a CSS file not resolving correctly when the file is linked in
  • Download Code

Replies are listed 'Best First'.
Re^2: Perl variables embedded in CSS in a CSS file not resolving correctly when the file is linked in
by craigt (Acolyte) on Oct 05, 2018 at 14:54 UTC

    Thanks for the suggestion Corion.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1223577]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2020-02-24 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (104 votes). Check out past polls.

    Notices?