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

Hi Monks, I am having problems using format command. Can anyone give me an example where their format command was within a function? It seems i always need the format in main ... . In addition, the values I saved do not show up at all.

Replies are listed 'Best First'.
Re: Problems with format command
by RazorbladeBidet (Friar) on Feb 24, 2005 at 19:18 UTC
    If you have a code snippet that would help.

    I have my format inside a subroutine and haven't had any problems.
    --------------
    It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
Re: Problems with format command
by Fletch (Bishop) on Feb 24, 2005 at 19:48 UTC

    With no code this is just a guess, but you're probably trying to reference lexical variables (i.e. stuff you've declared with my $zorch = ...) which won't work. Formats only can see package variables (globals).

    Update: I stand partially corrected. Shows how long it's been since I've really used write I guess. :)

      Sort of:

      Lexical variables (declared with "my") are not visible within a format unless the format is declared within the scope of the lexical variable. (They weren't visible at all before version 5.001.)


      From perlform
      --------------
      It's sad that a family can be torn apart by such a such a simple thing as a pack of wild dogs
Re: Problems with format command
by artist (Parson) on Feb 24, 2005 at 20:02 UTC
    From perldoc perlform
    use Carp; sub swrite { croak "usage: swrite PICTURE ARGS" unless @_; my $format = shift; $^A = ""; formline($format,@_); return $^A; } $string = swrite(<<'END', 1, 2, 3); Check me out @<<< @ @>>> END print $string;
Re: Problems with format command
by saberworks (Curate) on Feb 24, 2005 at 20:54 UTC
Re: Problems with format command
by hsinclai (Deacon) on Feb 24, 2005 at 21:02 UTC
    format() inside of sub shown here

A reply falls below the community's threshold of quality. You may see it by logging in.