Solved

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

Posted on 1997-11-16
6
233 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

776 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