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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving .txt file as param name

Status
Not open for further replies.

ETbyrne

Programmer
Dec 27, 2006
59
US
I am working on a script and I'm having trouble saving the info as the param $name.txt (for instance: $name = 'robs site.txt') . Instead of saving as let's say 'robs site.txt' it saves as $name.txt . How can I fix this?

Below is my script.

Note: The script below also writes <a href='$name.txt'>$name</a><br> to links.txt, but that works fine.

Code:
#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;
$CGI::POST_MAX = 1024 * 10; # max 10K posts
$CGI::DISABLE_UPLOADS = 1; # no uploads
my $name = param('name') or error('You have to enter a name');
my $comments = param('comments') or error('You have to enter some comments');
#($name,$comments) = escapeHTML($name,$comments);

open(FH,'>>./mywebs/ETbyrne/test/portal/$name.txt') or die "$!";
print FH "<b>Name:</b> $name<br><b>Comments:</b> $comments</a><br>\n";
close (FH);

open(FH,'>>./mywebs/ETbyrne/test/portal/links.txt') or die "$!";
print FH "<a href='$name.txt'>$name</a><br>\n";
close (FH);

print "Location: [URL unfurl="true"]http://www.mywebsfree.com/ETbyrne/test/portal/index_page.shtml\n\n";[/URL]

sub error{
my $error = shift;
print header,start_html,h1($error),end_html;
exit;
}

_______________________________________

You don't know me.
 
Code:
open(FH,[COLOR=red]'[/color]>>./mywebs/ETbyrne/test/portal/$name.txt[COLOR=red]'[/color]) or die "$!";

Change those single quotes to double quotes and it should work.

Double quotes interpolate variables (e.g. $name will be replaced with the actual value of $name), whereas single quotes take everything literally (where $name literally is "$name" and not the value of a variable)

-------------
Cuvou.com | The NEW Kirsle.net
 
Oh right. I shouldn't have forgot that. *slaps forhead*

Thanks for the re' Kirsle! ^_^

_______________________________________

You don't know me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top