Home > Archive > PERL Miscellaneous > November 2005 > save to file problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
save to file problem
|
|
|
| Hi all
I have a script to save the user input into text file
$q=new CGI;
open (somet,">> saveall.txt" );
$name=$q->param("name"); # king -> user input
$comment=$q->param("comment"); # go to school-> user input
$dd="300/20/500/30:200 4";
print somet "$dd::$name::$comment\n";
when save to the file saveall.txt as the followong only
300/20/500/30:200 4::go to school
I dont know why the name part doesnt exist there after the 4::
it should save this
300/20/500/30:200 4::king::go to school
the code above work if I using only one " : "
print somet "$dd:$name:$comment\n"
I using Perl 5.8.4
| |
| usenet@DavidFilmer.com 2005-11-24, 3:58 am |
| phal wrote:
> print somet "$dd::$name::$comment\n";
> snip
> I dont know why the name part doesnt exist there after the 4::
> snip
> the code above work if I using only one " : "
Right. The "::" tells Perl you are specifying a package identifier (all
variables are in a package; for example, you could print main::$dd
which is the same as $dd in this case).
You can escape one of the colons like this:
print "$dd:\:$name:\:$comment\n";
and it won't trick Perl into thinking you are using a package
identifier.
| |
| usenet@DavidFilmer.com 2005-11-24, 3:58 am |
| use...@DavidFilmer.com wrote:
> You can escape one of the colons like this:
> print "$dd:\:$name:\:$comment\n";
Or something like:
print join '::', $dd, $name, $comment
Or (my preference):
printf "%s::%s::%s\n", $dd, $name, $comment;
| |
| John Bokma 2005-11-24, 3:58 am |
| usenet@DavidFilmer.com wrote:
> use...@DavidFilmer.com wrote:
>
> Or something like:
>
> print join '::', $dd, $name, $comment
>
> Or (my preference):
>
> printf "%s::%s::%s\n", $dd, $name, $comment;
print "${dd}::${name}::${comment}\n";
:-D.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)
| |
| Dr.Ruud 2005-11-24, 7:57 am |
| John Bokma:
> usenet@DavidFilmer.com:
[color=darkred]
>
> print "${dd}::${name}::${comment}\n";
{ local ($OFS, $ORS) = ('::', "\n");
print $dd, $name, $comment;
}
> :-D.
blegh
--
Affijn, Ruud
"Gewoon is een tijger."
| |
| Tad McClellan 2005-11-24, 7:57 am |
| usenet@DavidFilmer.com <usenet@DavidFilmer.com> wrote:
>The "::" tells Perl you are specifying a package identifier (all
> variables are in a package;
Not all variables are in a package.
(I'm sure David knows this, but that isn't what he said. :-)
Perl has 2 different and separate variable systems, lexical variables
and package variables.
All package variables (our, local) are in a package.
Lexical variables (my) are never in a package.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
| |
| Ala Qumsieh 2005-11-24, 6:57 pm |
| Dr.Ruud wrote:
> { local ($OFS, $ORS) = ('::', "\n");
> print $dd, $name, $comment;
> }
That requires a 'use English;'.
--Ala
| |
| usenet@DavidFilmer.com 2005-11-25, 3:57 am |
| Tad McClellan wrote:
> Not all variables are in a package.
> (I'm sure David knows this, but that isn't what he said. :-)
Oops. I meant to point out that all the variables in the OP's program
were in a package (namely, main).
Thanks for the catch. I hate to be imprecise.
|
|
|
|
|