Solved

How do i make my cgi write multiple outputs for one value?

Posted on 1997-11-16
6
238 Views
Last Modified: 2013-12-25
I am using a script i have found, call Real Audio Jukebox.
Except i want it to write as many urls as requested .
Example :
They type http://<address>/shadow/cgi-bin/rajb.cgi?action=play&serverpath=130.207.150.33/music/&<the part iam having problems with>file=never.ra,want.ra.
they should get a file called rajb.ram
with this output:
pnm://130.207.150.33/music/never.ra
pnm://130.207.150.33/music/want.ra

But they get,
pnm://130.207.150.33/music/never.ra,want.ra

How do i make it give me the first output example ?
Here's The Script :

#!/usr/local/bin/perl
#############################################################################
# RealAudio JukeBox              Version 1.0                                #
# Written by Sebastian Boschert  scripts@sb.nethosting.com                  #
# Copyright (C) 1997 SB-Soft     http://www.SB-SOFT.ml.org                  #
#############################################################################
# Variables #
$path = "";

# Added 'serverpath' variable to play_ra . #
# Trying to make a random link to any file #

#############################################################################
# DO NOT EDIT ANYTHING BELOW THIS LINE !!! ##################################
#############################################################################

&check_input;
&play_ra;

sub check_input {
   if ($ENV{'REQUEST_METHOD'} eq 'GET') {
      # Split the name-value pairs
      @pairs = split(/&/, $ENV{'QUERY_STRING'});
   }
   elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
      # Get the input
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 
      # Split the name-value pairs
      @pairs = split(/&/, $buffer);
   }
   else {
      die "Query String is not POST or GET";
   }

   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
 
      $name =~ tr/+/ /;
      $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $value =~ s/<!--(.|\n)*-->//g;

      if ($FORM{$name} && ($value)) {
          $FORM{$name} = "$FORM{$name}, $value";
      }
      elsif ($value) {
          $FORM{$name} = $value;
      }
   }

if ($FORM{'action'} eq 'play') {  
  if ($FORM{'file'} ne '') {
     &play_ra;
     exit;
    }
}
elsif ($FORM{'file'} eq '') {
     $error = "NO FILE WAS GIVEN !!!";
     &error_html;
     }
else {
     goto_index;
     }
}

sub goto_index {
  print "Content-type: text/html";
  print "Location:http://r70h200.res.gatech.edu/shadow/music/";
  exit;
}
   

sub error_html {
  print "Content-type: text/html\n\n";
  print "<HTML><HEAD><TITLE>ERROR !!!</TITLE></HEAD>\n";
  print "<BODY>\n";
  print "<meta http-equiv=\"REFRESH\" content=\"0; URL=http://128.61.70.200/shadow/music/\">";
  print "<h1>ERROR !!!</h1>\n";
  print "<hr><p>The following error occured:<br>\n";
  print "<b><font size=\"+1\">$error</font></b>\n";
  print "<p><hr><p>Script \&copy 1997 <a 'mailto:shadow\@full-moon.com'>Shadow</a><p>\n";
  print "</BODY></HTML>\n";
  exit;
}

sub play_ra {
  print "Content-type: audio/x-pn-realaudio\n\n\n";
# This is where the problem is #
foreach ($FORM{'file'}) {
  print "pnm://$FORM{'serverpath'}$FORM{'file'}\n";
}
  exit;
}

#EOF

The end .
0
Comment
Question by:shadow010397
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 200 total points
ID: 1831249
$FORM{'file'} is a comma-separated list of the files you want, so you need to split it into a list. Change the lines

foreach ($FORM{'file'}) {
 print "pnm://$FORM{'serverpath'}$FORM{'file'}\n";
}
to
foreach (split(/,/, $FORM{'file'})) {
 print "pnm://$FORM{'serverpath'}$_\n";
}

This should do the trick... please leave a comment if you have more problems, and good luck!
0
 

Author Comment

by:shadow010397
ID: 1831250
why the $_ ? What does _ stand for ?
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831251
$_ is the default variable perl uses when you don't tell it to use a different one - since you didn't specifiy a variable on the foreach it uses $_.

The following is equivalent to what I posted, just using the variable $file instead of $_:

foreach $file (split(/,/, $FORM{'file'})) {
 print "pnm://$FORM{'serverpath'}$file\n";
}
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 84

Expert Comment

by:ozo
ID: 1831252
perldoc perlvar
                 $ARG

                 $_      The default  input  and  pattern-searching  space.
                         The following pairs are equivalent:
                             while (<>) {...}    # equivalent in only while!
                             while (defined($_ = <>)) {...}

                             /^Subject:/
                             $_ =~ /^Subject:/

                             tr/a-z/A-Z/
                             $_ =~ tr/a-z/A-Z/

                             chop
                             chop($_)

                         Here are the places where Perl will assume $_ even
                         if you don't use it:

                            Various unary  functions,  including  functions
                            like  ord()  and int(), as well as the all file
                            tests (-f, -d) except for -t, which defaults to
                            STDIN.

                            Various   list   functions   like  print()  and
                            unlink().

                            The pattern matching operations m//, s///,  and
                            tr/// when used without an =~ operator.

                            The default iterator variable in a foreach loop
                            if no other variable is supplied.

                            The implicit iterator variable  in  the  grep()
                            and map() functions.

                            The default place to put an input record when a
                            <FH> operation's result is tested by itself  as
                            the  sole criterion of a while test.  Note that
                            outside of a while test, this will not  happen.
                            (Mnemonic:  underline  is understood in certain
                            operations.)

0
 

Author Comment

by:shadow010397
ID: 1831253
It worked . Thanks for explaning $_. One last thing though, where
is a good online resource for CGI programming in perl and c .
0
 
LVL 6

Expert Comment

by:alamo
ID: 1831254
http://www.perl.com/ is the best starting place I've found for perl resources, some say http://www.cgi-resources.com/ is good though I haven't really had a chance to explore it.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Scripting vs. Programming languages 25 179
Using a variable to name output in powershell script 2 40
Need a good Angular tutorial 5 84
OS Selection Menu 1 47
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question