swapy345 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on how to redirect to other file using system command or anything not by file handler
  • Download Code

Replies are listed 'Best First'.
Re: how to redirect to other file using system command or anything not by file handler
by tospo (Hermit) on Apr 14, 2010 at 16:13 UTC

    You should definitely use code tags

    I'm not sure what you mean with "other file" but it looks like your problem might be that the contents of your file gets overwritten. That's because you open the same file with ">" (overwrite) throughout the while loop, or at least you were before commenting out those lines. Do it like this instead:

    my $a="/var/lib/processed/parkings-stats2/dailystat_$curtime"; print $a; open (FH, '>', $a) or die "could not open"; while(my $row=$sth->fetchrow_hashref) { my $eunq= $row->{eunq}; my $eclk=$row->{eclk}; my $domain_id=$row->{domain_id}; my $ts = $row->{ts}; my $id = $row->{id}; my $ervn = $row->{ervn}; my $account_id=$row->{account_id}; print "$eunq==$domain_id\n"; print FH "$account_id"; print "$eunq\t$eclk\t$domain_id\t$ts\t$id\t$ervn\t$account_id\n"; } close FH;

    Does that solve your problem?

Re: how to redirect to other file using system command or anything not by file handler
by choroba (Cardinal) on Apr 14, 2010 at 13:18 UTC
Re: how to redirect to other file using system command or anything not by file handler
by rowdog (Curate) on Apr 14, 2010 at 20:18 UTC
    i want above output in other file without using file handler ..i think it is system command or anythink else help appreciated.

    Usually, it is a bad idea to involve the shell. You have to fork the shell and execute the command which will open, write, and close the file. As a bonus, the shell will interpret your data on the way to the file so you will need to escape the data properly or open a big can of worms that includes a gaping security hole.

    It is much faster and less error prone to open, write, and close a file handle yourself (as tospo has demonstrated). If you really want the shell to process your output, you'll want to use backticks, system or open a pipe to execute a shell command like echo.

Re: how to redirect to other file using system command or anything not by file handler
by AR (Friar) on Apr 14, 2010 at 16:12 UTC
    Why don't you want to use a file handle? It seems to me to be the most straight forward way to do it.