mrwebmaster
asked on
Format of cgi script
I have perl 5 using a cgi script that send me information from my text box on my web form. The text is intered in my html page as:
category= tree grass lumber etc.in one line.
I need formating in my perl script that when cgi emailes me using the send mail it will be formated as
category tree+grass+lumber
I need formatting code so sendmail will ad the + signes.
category= tree grass lumber etc.in one line.
I need formating in my perl script that when cgi emailes me using the send mail it will be formated as
category tree+grass+lumber
I need formatting code so sendmail will ad the + signes.
Wait, sorry, I did that wrong, the correct line is:
$catagory =~ s/ /+/g;
Stupid me :P
OKSD
$catagory =~ s/ /+/g;
Stupid me :P
OKSD
No, he did it wrong twice, the correct line is:
$category =~ s/\s+/\+/g;
$category =~ s/\s+/\+/g;
No, $catagory =~ s/ /+/g; should work.... what'd I do wrong?
OKSD
OKSD
No, $catagory =~ s/ /+/g; should work.... what'd I do wrong?
OKSD
OKSD
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What's the \s for?
OKSD
OKSD
Tintin: thanks for cutting and pasting my answer into your own. Good job.
OKSD: for starters you spelled category wrong, but also you have no space in your regex therefore it won't find a space (although I wonder if the site here might be what did that).
A \s is better, that picks up any white space, so it includes tabs and sequences of spaces, etc.
OKSD: for starters you spelled category wrong, but also you have no space in your regex therefore it won't find a space (although I wonder if the site here might be what did that).
A \s is better, that picks up any white space, so it includes tabs and sequences of spaces, etc.
OKSD's regex does have a space in it, although perhaps not obvious depending on what sort of font you view it in.
ASKER
After looking at what needs to be accomplished, I may have not made myself clear. This is of no fault of yours it is strictly mine. ( hope format turns out correct )
It has to do with URL encoding
My html file submits from 4 text boxes:
TLC
The Learning Channel
CTLC.com
Reality TV
etc
In my mail to area of my form NOW I have theselines:
Print Mail
" KEY4=$in{'key1'}\n",
" KEY5=$in{'key2'}\n",
" KEY6=$in{'key3'}\n",
" KEY6=$in{'key4'}\n",
etc
I am wanting the end format to be:
TLC%2CThe+Learning+Channel %2CTLC.com %2CReality +TV%2C
I need this in place of Key 1,2,3,4 as it is now. I am changing a cgi file, I am not a perl programmer. But I was reading about URL encoded, but I do not know how to use it.
Please Advise
It has to do with URL encoding
My html file submits from 4 text boxes:
TLC
The Learning Channel
CTLC.com
Reality TV
etc
In my mail to area of my form NOW I have theselines:
Print Mail
" KEY4=$in{'key1'}\n",
" KEY5=$in{'key2'}\n",
" KEY6=$in{'key3'}\n",
" KEY6=$in{'key4'}\n",
etc
I am wanting the end format to be:
TLC%2CThe+Learning+Channel
I need this in place of Key 1,2,3,4 as it is now. I am changing a cgi file, I am not a perl programmer. But I was reading about URL encoded, but I do not know how to use it.
Please Advise
First, replace the spaces with + as you wanted and as I have already told you... then join them, like this:
for(1..4) {
$in{key$_} =~ s/\s+/\+/;
}
print join("%2C", $in{key1}, $in{key2}, $in{key3}, $in{key4});
for(1..4) {
$in{key$_} =~ s/\s+/\+/;
}
print join("%2C", $in{key1}, $in{key2}, $in{key3}, $in{key4});
for(key1..key4) {
$in{$_} =~ s/\s+/+/g;
}
#or
for( values %n ){ s/\s/+/g; }
print join("%2C", @in{key1..key4});
$in{$_} =~ s/\s+/+/g;
}
#or
for( values %n ){ s/\s/+/g; }
print join("%2C", @in{key1..key4});
ASKER
I still cannot get it to work, I have paster the whole code. Can you help me ?( hope my cut and paste works OK The bottom 2 lines is where I need the TLC%2CThe+Learning+Channel %2CTLC.com %2CReality +TV%2C
sub write {
local ($prefix);
$time = time;
$file = $data_dir . 'testing.csv';
(-e "$file") ? ($prefix = '>>') : ($prefix = '>');
open(WRITE, "$prefix$file") || &error("Error opening
$file for writing");
print WRITE join(',', $time, $in{'PROFILE_NAME'},
$in{'MAIN_CATEGORY'},$in
{'PROFILE_NAME'},$in{'KEYW ORDS'},
$in{'key1'}, $in{'key2'}, $in{'key3'}, $in{'key4'},
$in{'key5'}, $in{'key6'}, $in{'key7'}, $in{'key8'}, $in{'key9'},
$in{'key10'}, $in{'key11'}, $in{'key12'}, $in{'key13'}, $in{'key14'},
$in{'key15'}, "1|$in{'key16'}", "1|$in{'key17'}", $in{'key18'},
close(WRITE);
chmod(0777, $file);
}
sub mail_admin {
open (MAIL, "|$mail_prog") || &error('Error opening mail connection');
print MAIL " PROFILE_NAME=$in{'PROFILE_ NAME'}\n",
" KEYWORDS=$in{'key1'},$in{' key2'},$in {'key3'},$ in{'key4'} )\n",
}
sub write {
local ($prefix);
$time = time;
$file = $data_dir . 'testing.csv';
(-e "$file") ? ($prefix = '>>') : ($prefix = '>');
open(WRITE, "$prefix$file") || &error("Error opening
$file for writing");
print WRITE join(',', $time, $in{'PROFILE_NAME'},
$in{'MAIN_CATEGORY'},$in
{'PROFILE_NAME'},$in{'KEYW
$in{'key1'}, $in{'key2'}, $in{'key3'}, $in{'key4'},
$in{'key5'}, $in{'key6'}, $in{'key7'}, $in{'key8'}, $in{'key9'},
$in{'key10'}, $in{'key11'}, $in{'key12'}, $in{'key13'}, $in{'key14'},
$in{'key15'}, "1|$in{'key16'}", "1|$in{'key17'}", $in{'key18'},
close(WRITE);
chmod(0777, $file);
}
sub mail_admin {
open (MAIL, "|$mail_prog") || &error('Error opening mail connection');
print MAIL " PROFILE_NAME=$in{'PROFILE_
" KEYWORDS=$in{'key1'},$in{'
}
ASKER
Got it:
It was by default at:$val =~ s/\,//g;
I have changed it to:$val =~ s/\s+/+/g;
Works great
Thanks
It was by default at:$val =~ s/\,//g;
I have changed it to:$val =~ s/\s+/+/g;
Works great
Thanks
ASKER
OOps, forgot to grade it
On an unrelated point, where you have:
(-e "$file") ? ($prefix = '>>') : ($prefix = '>');
open(WRITE, "$prefix$file") || &error("Error opening
$file for writing");
you can just do
open WRITE, ">>$file" or &error("Error open $file for writing $!");
(-e "$file") ? ($prefix = '>>') : ($prefix = '>');
open(WRITE, "$prefix$file") || &error("Error opening
$file for writing");
you can just do
open WRITE, ">>$file" or &error("Error open $file for writing $!");
$catagory =~ / /+/;
That changes all spaces into +'s
Replace $catagory with whatever variable your information is storred in.
OKSD