I have a variable containing about 200 characters of text, named
$text.
I would like to run the shell command "fmt" against this text, and
print out the output.
I have tried various combinations of the system and exec functions,
but so far, I have been frustrated.
Can anyone post a code snippet of the syntax I should use?
TMTOWTDI - the idiomatic Perl way or the way you you wanted to do it.
The way you wanted to do it requires you to save the output from the
script (in this case $text) to a file, then use fmt. fmt works better
if it has a real file to deal with.
Idiomatic Perl has several flavors to chose from. The one you may be
looking for uses formats (to make $text look uniform and make sure the
text is only so many collums wide, etc.)
For example:
==untested==
#!/usr/bin/perl -w
use strict;
my $text = 'The quick brown fox jumped over the lazy Perl
programmerXXXXX';
$text .= 'The quick brown fox jumped over the lazy Perl
programmerXXXXX';
$text .= 'The quick brown fox jumped over the lazy Perl
programmerXXXXX';
$text .= 'The quick brown fox jumped over the lazy Perl
programmerXXXXX';
format STDOUT=
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$text
..
write;
exit;
==end==
Notice there are no newlines anywhere in $text. I take it that's why
you wanted to use fmt.
perldoc perlform
for more information.
HTH