?
Solved

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

Posted on 1997-11-16
6
Medium Priority
?
250 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

777 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