Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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

Replies are listed 'Best First'.
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?
[choroba]: LanX I miss working in a bank sometimes...
[Corion]: Discipulus: Ooof. Especially yearly things are things I like to automate instead of trying to remember how I did things last year...
[Corion]: And the second rule that I've learned is, that there is no one-off job, so writing a program for it pays off almost immediately. The third rule is to give all my programs numbers and have them reproduce that number in the name of their output files. :)
[Discipulus]: the true part is that also specification change between years.. but well our job is cheap but dont abuse of us.. ;=)
[LanX]: Choroba: do you miss chaos with ties? apply at the US government.. ;)
[ambrus]: Corion: those are good rules.
[ambrus]: Discipulus: oh sure. the input data has different filenames every time I get them.

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2017-03-29 12:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (350 votes). Check out past polls.