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

Hi, I am a beginner in Perl. I am trying to use format function for my program. It was printing correctly, but after I added the "use strict;", this is the code.
sub PRINT{ my $k, my $z, my $x, my $c; format head= user | processes | cpu-seconds | memory (k) --------+-----------+---------------+------------ . format result= @<<<<<<<|@>>>>>>>> |@>>>>>>>>>>>> |@>>>>>>>>>>> $k, $z, $x, $c . $- = "result"; foreach $k(@keys){ $z = $sum2->{$k}->{'process'}; $x = $sum2->{$k}->{'time'}; $c = $sum2->{$k}->{'mem'}; #$- = "result"; write(); } }#end of sub PRINT
and I am getting an error like this.
Undefined format "STDOUT" called at pigs line 64.
can somebody help me?

Replies are listed 'Best First'.
Re: using format with "use strict;"
by Paladin (Vicar) on Feb 02, 2003 at 00:33 UTC
    In your line $- = "result"; you probably mean to use $~ (that's a dollar sign followed by the tilde character).

    From perldoc perlvar:

    $~ The name of the current report format for the currently selected output channel. Default is the name of the filehandle.
    Since you haven't used select to change the current filehandle, it defaults to STDOUT.
      thx^^
Re: using format with "use strict;"
by artist (Parson) on Feb 02, 2003 at 01:07 UTC
Re: using format with "use strict;"
by Flame (Deacon) on Feb 02, 2003 at 02:22 UTC
    On a side note, you don't need to keep declaring "my" on that first line. The following is typically preferred:
    my($k,$z,$x,$c);

    Good Luck!



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      thx ^^ shorter one!!