Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1997-11-16
6
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
alamo earned 800 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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

618 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