Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing $variable from main script to subroutine...how?

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have one file, map.pl, that runs a script. it requires subs.pl, which i include.


the above url is what i use to initiate the program.

the code takes the name=value pairs and should use them in the script.

the map.pl calls a subroutine, which is written on subs.pl.

the codes are as follows...


_____________________________



# map.pl

#!/usr/local/bin/perl

use strict;
use CGI qw:)standard :html3);
require "subs.pl";

if ( param() ) {
my $mn = param("mn");
my $sn = param("sn");
my $url = param("url");

&eyc_html;


} else { yada, yada, yada....}

print end_html();

****


_____________________________



# subs.pl

****

sub eyc_html {


print <<EOP


<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;
&quot;
<HTML>

<HEAD>

<META HTTP-EQUIV=&quot;content-type&quot; CONTENT=&quot;text/html; charset=ISO-8859-1&quot;>

<script language=&quot;javascript&quot;>mn='$mn';sn='$sn';url='$url';</script>

</body>

</html>


EOP
}

1;

****


_____________________________


question....how do i get the value of the variables, ($mn, $sn, $url) into the subroutine? as you can see, the value of the info passed through perl becomes the new local page variables in javascript, (shown in bold letters). i tried, (as you see above)
and also tried to change the variables from 'my' to 'local', but no luck.

right now, as it rights the page from eyc_html, it just leaves the js variables blank.

(it shows this:

<script language=&quot;javascript&quot;>mn='';sn='';url='';</script>

no values passed.)

also, what's the difference between:

my $variable =
local $variable =
$variable =

i'm confused on this. -c

pss! i tried adding %60 to each value, like


and then took the '' marks out at subs.pl like

<script language=&quot;javascript&quot;>mn=$mn;sn=$sn;url=$url;</script>

figuring that since %60 is a ' mark anyway...that seems to work, but then it only reads the '' marks.

someone has to know what i am doing wrong. -c
 
I think this is what you mean.

Say you have a variable called $text and you wanted to pass it to a sub to perform a regex on it (just say for example), you could do something like this:

[tt]
my $text = &quot;texxxxxxxxt&quot;;

sub regex {
my $newtext = shift;
$newtext =~ s/\x//g;
return $newtext;
}

[/tt]

Then you could use the subroutine like so:

[tt]

my $text = &quot;texxxxxxxxxxt&quot;;
$text = regex($text);
[/tt]

I think that you will be able to apply that to your code.


Hope this helps.
-Vic vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top