Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: perl javascript help passing varable

by thunders (Priest)
on Oct 15, 2009 at 03:38 UTC ( #801271=note: print w/ replies, xml ) Need Help??


in reply to perl javascript help passing varable

I don't really understand the question. Is perl generating the page the javascript is on? In that case the number variable should be filled in as long as you put the content you are generating in a double quoted string(and assuming you assign a value to $number before you try to use it). But you show the javascript as a separate block. If you do something like the following, your $number should be replaced successfully.

$number = 7; print << "END_OF_HTML"; <html> <head> <script type="text/javascript"> /* ... a bunch of JS .. */ messages[0] = new Array('upload/$number.gif','$number.gif',"#FFFFFF"); messages[1] = new Array('upload/$number.jpg','$number.jpg',"#DDECFF"); messages[2] = new Array('/upload/test.gif','Test description','black', +'white'); /* ... a bunch of JS .. */ </script> </head> <!-- HTML body stuff --> </html> END_OF_HTML


Comment on Re: perl javascript help passing varable
Download Code
Re^2: perl javascript help passing varable
by winracer (Initiate) on Oct 15, 2009 at 13:36 UTC
    thanks I have found out that the $number varable is a array in my perl script and on the page I am useing it on it has a while loop in it. the javascript part is in the head and I have it working that it picks up the 1st $number varable so I am thing that i need to pass the $number array to the javascript array. How do you pass arrays
    Winracer Jack of all trades master of none http://www.helpmewithperl.com “Only a life lived for others is a life worth while” Albert Einstein “The golden rule for every business man is this: 'Put yourself in your customer’s place'” Orison Swett Marden “No person was ever honored for what he received; honor has been the reward for what he gave” Calvin Coolidge

      If it was an array it'd be called @number. However $number may be an array reference. If it is an array reference you can dereference it inside of a double quoted string, as in the example below.

      $number = [1,2,3]; @number = (4,5,6); print "$number @$number @number";

      prints something like this:

      ARRAY(0x814cc20) 1 2 3 4 5 6

      Perl's default behavior is to separate an arrays elements with spaces in double quoted context. If you instead wanted to separate with commas you could do something like this:

      my $comma_sep_number = join(",",@$number); print "My Array Contains: $comma_sep_number";

      prints:

      My Array Contains: 1,2,3

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (17)
As of 2014-09-23 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (228 votes), past polls