Can the cgi start_html () method have multiple script attributes?

I think this question is pretty clear, but I use perl to create a webpage. Starts with using:

$cgi->start_html(-title=>'myPage',-style=>{-src=>'style.css'}, -script=>{-type=>'JAVASCRIPT', -src=>'custom.js'}, ); 

List item

But what if I want to have several scripts in the header? Or multiple CSS style sheets?

 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script> <script type="text/javascript" src="custom.js"></script> <link rel="stylesheet" href="css/basic.css" type="text/css" /> <link rel="stylesheet" href="css/style.css" type="text/css" /> 
+6
source share
2 answers

Use an anonymous array:

 $cgi->start_html( -title=>'myPage', -style=>[{-src=>'style.css'},{-src=>'basic.css'}], -script=>[{-type=>'JAVASCRIPT', -src=>'custom.js'},{-type=>'JAVASCRIPT', -src=>'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js'}], ); 
+4
source

Of course. When you think there are more than one , think of an array . When you think you are passing arrays as arguments , think array ref .

 use warnings; use strict; use CGI qw(:standard); print start_html(-title => "myPage", -style => [ {-src=>"style.css"}, {-src=>"basic.css"}, ], -script => [ {-type=>"text/javascript", -src=>"custom.js"}, {-type=>"text/javascript", -src=>"ohai.js"}, ], ); __END__ …snip… <title>myPage</title> <link rel="stylesheet" type="text/css" href="style.css" /> <link rel="stylesheet" type="text/css" href="basic.css" /> <script src="custom.js" type="text/javascript"></script> <script src="ohai.js" type="text/javascript"></script> …snip… 
+2
source

Source: https://habr.com/ru/post/895089/


All Articles