Click to See Complete Forum and Search --> : input two variables and print alpha *numeric


jwisneski2003
09-03-2005, 06:19 AM
hello all,

i have been fooling around with perl for just a little while, i know a litle vb and and thats about my experience with writting code. i would like a simple program that prompts for a users name and then a numer and then prints that name out (on the screen) X times thanks john

Nedals
09-03-2005, 10:38 AM
...prompts for a users name and then a number..
Got that bit.

...prints that name out (on the screen) X times
Do you mean if I enter 'John' and 10, it will print 'John' 10 times (one below the other)?

Why do you want to use Perl for this?
It could be done easily using Javascript.

CyCo
09-03-2005, 12:33 PM
Why do you want to use Perl for this?
It could be done easily using Javascript.Ditto, Nedals.

But, jwisneski2003, below is a simple example of using Perl to do what you described above.

#!/usr/bin/perl

use strict;
use CGI ':standard';
use warnings FATAL => 'all';
use CGI::Carp 'fatalsToBrowser';

print results();

sub create_form {
my $item = shift;

start_form, textfield($item), hidden('username',param('username')),
submit('action',$item), end_form;
}

sub results {
my @stuff;
my $action = param('action');

unless ($action) {
@stuff = create_form('username');
}
elsif ($action eq 'username') {
@stuff = create_form('number');
}
elsif ($action eq 'number') {
@stuff = map {param('username'),br} 1..param('number');
}

header, start_html('Perl CGI Example'), @stuff, end_html;
}