How to make javascript from perl code

How to make javascript from perl code

Page 1 of 1

2 Replies - 829 Views - Last Post: 17 April 2009 - 08:30 PM

#1 winracer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 141
  • Joined: 02-March 09

How to make javascript from perl code

Posted 16 April 2009 - 06:31 AM

here is my perl code from forum post http://www.dreaminco...wtopic99231.htm

#start for todays date
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime (time);

my $day = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
		   "Friday", "Saturday")[$wday];

$year = 1900 + $year;
my $month = ++$mon < 10 ? '0'.$mon : $mon;
my $date = $mday < 10 ? '0'.$mday : $mday;
# Format the date any way you want, ie. $date/$month/$year or
# $year/$date/$month

#$todaysdate = "$month/$date/$year"; # might use later
# end of todays date code


# to open data file
my $location_of_hits_file = "$path/my.data";

#my @categories; define else where

# Your placement of {braces} is too inconsistent for me to
# identify your preferred style, so I just went with mine.
if (-e "$location_of_hits_file") {
  # Don't forget to check for and report errors!
  open (HITS_FILE, "$location_of_hits_file")
	or die "Unable to open $location_of_hits_file: $!\n";

while (<HITS_FILE>) {
	
	my $line = $_;
	chomp $line;
	# More efficient to just run the regex once before splitting
	$line =~ s/~nl~/<br>/g;
	my @hitsfields = split /\|/, $line;
		
	  
#for my $i (0..$#hitsfields) {#to get all files
# 0 is for ad number @adnumber1
	#3 is for $month/$date/$year
	#21 is for @categories

		for my $i (0, 3, 21, 24){
	  $hitsfields[$i] =~ s/~p~/\|/g;
	 
	}


# for ad number later used for ad rotating push @adnumber1, $hitsfields[0];
 
 	push @adnumber1, $hitsfields[0];
	push @adnumber2, $hitsfields[24];


# if the date posted is = to todays date then pull the ads and put in array categories 

# if the date posted is = to todays date then pull the ads and put in array
	# categories
	if ($hitsfields[3] eq "$month/$date/$year") {
	  
   push @categories, $hitsfields[21];

 }
 

}
	
  
  close HITS_FILE;

} else {
  # @categories is an array, so don't set it to a scalar value
  
  @categories = ();
  
 } 
  

my $rand_index = rand @adnumber1;
my $file_name = $adnumber1[$rand_index];
my $file_name1 = $adnumber2[$rand_index];

my $up = "$upload_path/$file_name";

my $image_file;
for my $ext ('gif', 'jpg') {
  if (-e "$up.$ext") {
	$image_file = "$file_name.$ext";
   

 last;
  }

}


$image_file = 'nophoto.jpg' unless $image_file;
print qq~ <br><font face="MS SANS SERIF" size="4" color="#000080"><b>$file_name1<br></b></font><a href="$path/index.pl?$file_name&query=retrieval"><img src="/$image_file" width="175" height="200" border="0" alt="Feature Ad $file_name">~;



my $graphic_html;
# for the ones that have been put in the array @categories test with $category
# and then display $graphic_html
# $graphic_html;

for my $i (0..$#categories) {
  
$graphic_html = $new_graphic_html if $categories[$i] eq $category;
}
print qq~ $graphic_html ~;







and what i am trying to do is convert it to javascript doing the about the same thing as the perl script.


here is what i have so far.


<script language="Javascript">
<!--

function random_feature_ad(){
  var adimage=new Array()
  //specify random images below. You can have as many as you wish
  adimage[1]="http://myurl.com/upload/$adnumber1[0].gif"
  adimage[2]="http://myurl.com/upload/$adnumber1[1].gif"
  adimage[3]="http://myurl.com/upload/$adnumber1[2].gif"

  //specify your corresponding links below to the images above
  var adlink=new Array()
  adlink[1]="http://myurl.com/index.pl?$adnumber1[0]&query=retrieval"
  adlink[2]="http://myurl.com/index.pl?$adnumber1[1]&query=retrieval"
  adlink[3]="http://myurl.com/index.pl?$adnumber1[2]&query=retrieval"

  var ry=Math.floor(Math.random()*adimage.length)

  if (ry==0)
	 ry=1
	 document.write('<a href='+'"'+adlink[ry]+'"'+'><img src="'+adimage[ry]+'"width="225" height="125" border="0" alt="Feature Ad " </a>')
}

  random_feature_ad()
//-->
</script>






I am reading up on javascript now on how to open a file

This post has been edited by winracer: 16 April 2009 - 07:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to make javascript from perl code

#2 winracer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 141
  • Joined: 02-March 09

Re: How to make javascript from perl code

Posted 17 April 2009 - 02:35 PM

How do you open a file in javascript?
Was This Post Helpful? 0
  • +
  • -

#3 winracer  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 141
  • Joined: 02-March 09

Re: How to make javascript from perl code

Posted 17 April 2009 - 08:30 PM

never mind I got my script to work in all perl code. thanks for any help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1