[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Possible to Create files?
On Thursday 01 August 2002 05:55, you wrote:
> > I understand that Perl uses the Safe mode when it comes to
> > writing files. I would like to know whether it's possible for me
> > to create my own tmp/text files from the IC programs. If really
> > can not, what about using "export" to export out the relevant
> > values from the database into a flat file? Can both be done at
> > all? If so, would greatly appreciate any guidance/pointers!
>
> Have a look at the [log] tag:
>
> http://www.icdevgroup.org/cgi-bin/ic/docfly.html?mv_arg=ictags04%2e
>43
>
> This will allow you to write lines out to a file. Other than this,
> you may find writing a global usertag, which will bypass safe, will
> better serve your needs.
Thanks for your suggestion! :) However, I find that using the "log"
tag will append the results to the file. I need to re-create the
file instead (ie, not append). In perl, what we usually will do is
to use ">file", however, when I tried this (refer to code below), it
doesn't work --only the last line remains in the file, those lines
above it are lost. How can I achieve that?
This is what I tried:
[tmp my_mailinglist]
[query st=db sql="select * from userdb WHERE newsletter = 'yes'"
list=1]
[sql-data userdb email][/query]
[/tmp]
[scratch my_mailinglist]
[log file=">mailinglist" interpolate=1 hide=1][scratch
my_mailinglist][/log]
Do I really need to use global usertag? I tried to do that using
[perl] for testing first (so I do not need to restart IC whenever I
make mistakes in catalog.cfg). But my following code (taken from the
archives) didn't work either:
[perl tables="userdb"]
my $return = "";
my $sql = "select * from userdb WHERE newsletter = 'yes'";
my ($results,$colname_hashref,$colname_arrayref) = $Tag->query({
wantarray => 1,sql => $sql, } );
my @results = @{$results};
foreach my $ref (@results) {
my @tmp = @{$ref}; #dereference each arrayref
foreach my $test (@tmp) { #@temp now holds actual
(dereferenced) results
$return .= "$test\n";
}
}
return "return";
[/perl]
Any ideas?