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 (Patriarch)
on Oct 05, 2018 at 14:02 UTC ( [id://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 );

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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1223577]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-03-28 17:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found