Re: how to store data in file with out using print
by ikegami (Patriarch) on Apr 25, 2009 at 15:00 UTC
|
You have an XY Problem. Tell us why you think print isn't suitable, and we'll help you solve your actual problem.
| [reply] [d/l] |
Re: how to store data in file with out using print
by holli (Abbot) on Apr 25, 2009 at 11:56 UTC
|
| [reply] [d/l] |
Re: how to store data in file with out using print
by Corion (Patriarch) on Apr 25, 2009 at 11:58 UTC
|
Why do you want to avoid print? Maybe you want to use write, which is just print combined with a format?
| [reply] |
Re: how to store data in file with out using print
by merlyn (Sage) on Apr 25, 2009 at 14:04 UTC
|
I'm guessing you want persistence without a lot of hassle. Take a look at DBM::Deep, which can store nearly arbitrary data into a single flat file, and uses no C code so you can easily drop it onto a stupid ISP that doesn't let you install modules.
-- Randal L. Schwartz, Perl hacker
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
| [reply] |
Re: how to store data in file with out using print
by JavaFan (Canon) on Apr 25, 2009 at 12:20 UTC
|
system "echo '$a' > file.txt";
| [reply] [d/l] |
Re: how to store data in file with out using print
by almut (Canon) on Apr 25, 2009 at 12:21 UTC
|
my $val = 10;
open my $fh, ">", "text.out" or die $!;
syswrite $fh, $val;
| [reply] [d/l] |
Re: how to store data in file with out using print
by shmem (Chancellor) on Apr 25, 2009 at 12:59 UTC
|
Use an editor. Open file, type "10", save, close ;-)
Or use Sys::Mmap:
use Sys::Mmap;
{
new Sys::Mmap my $foo, 2, "bar" or die $!;
$foo = 10;
}
open my $fh, '<', 'bar' or die $!;
my $foo = <$fh>;
print "read: '$foo'\n";
__END__
read: '10'
| [reply] [d/l] |
Re: how to store data in file with out using print
by cdarke (Prior) on Apr 25, 2009 at 13:21 UTC
|
You could use printf instead, but that is probably less efficient, or use write with a format. But why? Or you could write the code to use the native operating system API in XS, but why would you want to? | [reply] |
Re: how to store data in file with out using print
by Marshall (Canon) on Apr 25, 2009 at 14:36 UTC
|
The simple answer is: NO!
There is NO way to save a value to a file without writing to that file! "print" is a way to write to a file. There are other ways, but they all call print or something that print calls.I am just guessing that you want to save and access parm values in a simple database, for example a ".ini" file. I would suggest that you look at this module: Config::INI.
| [reply] |
Re: how to store data in file with out using print
by targetsmart (Curate) on Apr 25, 2009 at 14:29 UTC
|
$filename = <absolute path of the file>;
`echo "$a" > $filename`
if double quotes surrounded by $a is missed, then if $a contains ;(semi colon) then the echo won't write into the file, the echo command just end with that semi colon, so double quotes around $a is must
for example the below won't write into a file
$a = "this is testing;";
`echo $a > $filename`
it just creates a 0 byte file, because that semi colon just ends that echo command, and the redirection operator would have already created that file with 0 byte size
I spent some time on this issue so I am sharing this here
i am speaking in the context of *nix systems.
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
| [reply] [d/l] [select] |