in reply to missing outputs

Without an example of the output you expect and lacking a clear description of what you are trying to achieve it's rather hard to know what you want. However the following may give you something to think about:

use strict; use warnings; use 5.010; my $date = 'Wed Mar 10 10:10:48 IST 2010'; my @parts = split /[ :]/, $date; my $valueStr = <<VALS; Fri_Jan_29_14:30:22_v09.11-e024_1 Wed_Jan_27_14:30:11_v09.11-e022_1 Mon_Mar_08_14:30:04_v09.11-s008_1 Thu_Jan_28_14:30:13_v09.11-e023_1 Tue_Nov_24_15:54:18_v09.11-e005_1 Tue_Mar_01_14:30:08_v09.10-p002_1 Tue_Nov_24_17:31:07_v09.10-p001_1 Wed_Nov_25_10:27:43_v09.11-e002_1 Wed_Mar_25_10:27:43_v08.11-e002_1 VALS my @values = split /[\s\n]+/, $valueStr; for my $value (@values) { next if $value !~ /_$parts[1]_/; given ($value) { when (/(v09.11-[a-z]\d{3})/) {print "$1\n"; continue}; when (/(v09.10-[a-z]\d{3})/) {print "$1\n"; continue}; when (/(v08.\d{2}-[a-z]\d{3})/) {print "$1\n"; continue}; } }

Prints:

v09.11-s008 v09.10-p002 v08.11-e002

I've trimmed and edited the data somewhat to better suit what I guess you might be trying to do and reduce the size and noise in the sample.


True laziness is hard work

Replies are listed 'Best First'.
Re^2: missing outputs
by blackgoat (Acolyte) on Mar 11, 2010 at 07:43 UTC
    how can these outputs be displayed in a html page?
      use strict; use warnings; use 5.010; use CGI qw(); my $date = 'Wed Mar 10 10:10:48 IST 2010'; my @parts = split /[ :]/, $date; my $valueStr = <<VALS; Fri_Jan_29_14:30:22_v09.11-e024_1 Wed_Jan_27_14:30:11_v09.11-e022_1 Mon_Mar_08_14:30:04_v09.11-s008_1 Thu_Jan_28_14:30:13_v09.11-e023_1 Tue_Nov_24_15:54:18_v09.11-e005_1 Tue_Mar_01_14:30:08_v09.10-p002_1 Tue_Nov_24_17:31:07_v09.10-p001_1 Wed_Nov_25_10:27:43_v09.11-e002_1 Wed_Mar_25_10:27:43_v08.11-e002_1 VALS my @values = split /[\s\n]+/, $valueStr; my $cgi = CGI->new (); print $cgi->header (); print $cgi->start_html (); for my $value (@values) { next if $value !~ /_$parts[1]_/; given ($value) { when (/(v09.11-[a-z]\d{3})/) {print $cgi->p ($1); continue} +; when (/(v09.10-[a-z]\d{3})/) {print $cgi->p ($1); continue} +; when (/(v08.\d{2}-[a-z]\d{3})/) {print $cgi->p ($1); continue} +; } } print $cgi->end_html ();

      Prints:

      Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <p>v09.11-s008</p><p>v09.10-p002</p><p>v08.11-e002</p> </body> </html>

      True laziness is hard work
        Is it possible to incorporate a form within a form?? Usually forms are used to submit data to a perl script so it can do something useful with it. But i want data to be taken from the script and displayed as contents of the drop down list when the page loads. I simply cant figure out how to do that!
        What I'm really trying to do is to make a dynamic dropdown list. Since the values ($ver1, $ver2, $ver3) depend somewhat on the date(in my actual script), they will vary from time to time and the dropdown list must get updated by directly refering to their current values. Can any one pls help??

        This is my html page:

        #!/usr/bin/perl -W use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI; print "Content-type: text/html\n\n"; print <<ENDHTML; <html> <head> <title>Title</title> <script language='Javascript'> function validate_required(field,alerttxt) { with (field) { if (value==null || value==\"\") { alert(alerttxt); return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(rundir,\"Runpath must be filled +out!\")==false) { rundir.focus(); return false;} } } } </script> </head> <body ><form name='form1' action='XXXXXX' method='POST' onsubmit=\"ret +urn validate_form( this)\"> <div align=\"center\"> <table cellpadding=\"10\"> <tr> <td> <font color='CC3300'><b>Enter rundir path</b>: +</font> </td> <td> <input type=text name=rundir size=50 onChange= +\"valid_data(this.name)\"> </td> </tr> <tr> <td> <font color='CC3300'><b>Select Version</b>:</f +ont> </td> <td> <form name=options action=\"XXXXX\" method='GE +T'> <select name=version Version> <option selected value=\"$ver1 +\">$ver1</option> <option value=\"$ver2\">$ver2< +/option> <option value=\"$ver3\">$ver3< +/option> </select> </form> </td> </tr> < +tr> <td></td> <td> <input type=\"submit\" value=\"Submit\" /> </td> <tr> <td></td> <td> <form name=user_log action=\"XXXXX\" method=P +OST> <input type=submit name=submit value=\ +"User Log\"> </form> </td> </tr> </table> </div> </body> </html> ENDHTML

        And this is my perl script that gives me my options:

        #!/usr/bin/perl -W use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI; #------------------------------------------------------------ #Get date #------------------------------------------------------------ my $dt = `date`; my (@dtar) = split /[ :]/, $dt; #------------------------------------------------------------ #Get data #------------------------------------------------------------ $FILEPATH = "/PATH"; $valar = `ls $FILEPATH`; #------------------------------------------------------------ #Get 3 versions #------------------------------------------------------------ @valar1 = split(/[\s+\n]/, $valar); foreach (@valar1) { if ($_ =~ /$dtar[1]/) { my ($ver1) = $_ =~ m/(v09.11-[a-z]\d{3})/; print "$ver1\n"; last; } } foreach (@valar1) { if (my ($ver2) = $_ =~ m/(v09.10-[a-z]\d{3})/) { print "$ver2\n"; last; } } foreach (@valar1) { if (my ($ver3) = $_ =~ m/(v08.\d{2}-[a-z]\d{3})/) { print "$ver3\n"; last; } }

        But the options in the list dont show!!

        I did it!! I just needed to pass the variables from one perl script to the other. I used require() and did it.

        But still thanks to you all for the suggestions!!

        BG

        But this is hardcoding... How can I create a dynamic html page that automatically refers to thses variables(ver1, ver2, ver3) ant display them?