Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl script is almost working... help 1

Status
Not open for further replies.

TulsaJeff

Programmer
Jan 29, 2001
870
US
I am using the following script trying to print my "1message" variable which is actually a dynamic textbox in flash to a .txt file by the name of 1message.txt.

It prints to the .txt file fine and works great, however it only sends the name of my variable from Flash and does not print the content of the variable.

Here is the code I am using... please don't laugh... I know nothing yet but am trying to learn. To me just getting it to not give me any error messages is an accomplishment;-)

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

open(F,'>../1message.txt');
print F "1message=$1message";
close(F);

let me know what to do to make it read my variables content rather than the name of the variable. BTW... I am using a "post" action on a getURL for anyone who knows Flash. Regards,
TulsaJeff

cd_tektips.gif
 
Your problem is probably the fact that $1 is a variable name in perl, so perl is seeing $1 followed by the text "message" with the string. That's probably why variable names in perl are supposed to start with an alphabetic character or an underscore ONLY. Try changing the variable (and field) name to $message1 and I'll bet it will work. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Well, I was sincerely hopeful and I do appreciate the help...however...it still is not working. Any more ideas?

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

open(F,'>../1message.txt');
print F "1message=$message";
close(F);

As you can see I decided to change it to "message in the perl script as well as the field name in Flash. Regards,
TulsaJeff

cd_tektips.gif
 
You still have to have some way to get the value from the flash form into your program, it doesn't happen automatically. Check out the CGI library module for doing this. Check the CGI library documentation, the FAQs in this forum, or do a search on "use CGI". Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Ok...I have it pulling my message from flash into the 1message.txt file... that is good, however it is not wrapping the text within the .txt file.. it is one long continuous line of text. Does that hurt anything? How would I make it wrap if I needed to even if only for aesthetic reasons?

Here is my code at this point:

Code:
#!/usr/local/bin/perl

print "Content-type:text/html\n\n";

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}

foreach $key (keys(%FORM)) {
    print &quot;$key = $FORM{$key}<br>&quot;;
}

open(F,'>../1message.txt');
foreach $key (keys(%FORM)) {
    print F &quot;$key = $FORM{$key}&quot;;
}
close(F);

As always... thanks for all the help! Regards,
TulsaJeff

cd_tektips.gif
 
If you're using a textarea on the form for the data you can include the attribute wrap=&quot;hard&quot; in the textarea tag to make the returns in the textarea get passed to the program. I don't recommend this however. It's probably better to leave the text one long string in the file, and wrap it the way you want it to look when you output it again, by letting in wrap within a table cell or whatever.
If you plan on putting multiple entries within a single .txt file you definitely don't want the wrapping in the file, since a line-end character is usually the end-of-record character in a .txt file. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top