format, stdout, with 'swrite' no hot ^

W

woof

Monkey'd right out of perlform, I 'print' a format string to
to a variable with swrite like so:


$FO_UP = ' @<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<<<<<<<<';
$name = 'John Doe';
$note = 'this is a very long note some would say for a 25ish space';
$psec .= swrite(<<"END", $name, $note);

sub
swrite {
my $format = shift;
$^A = "";
formline($format, @_);
return $^A;
}

Isn't the second format string "^<<<<<<<<" supposed to produce
multiline output?


I expect something like this:

John Doe this is a very long
note some would say
for .....

I get this:

John Doe this is a very long

Am I right or wrong? Should I expect the first or second output?

Thanks
 
B

Bob Walton

woof said:
Monkey'd right out of perlform, I 'print' a format string to
to a variable with swrite like so:


$FO_UP = ' @<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<<<<<<<<';
$name = 'John Doe';
$note = 'this is a very long note some would say for a 25ish space';
$psec .= swrite(<<"END", $name, $note);

sub
swrite {
my $format = shift;
$^A = "";
formline($format, @_);
return $^A;
}

Isn't the second format string "^<<<<<<<<" supposed to produce
multiline output?


I expect something like this:

John Doe this is a very long
note some would say
for .....

I get this:

John Doe this is a very long

Am I right or wrong? Should I expect the first or second output?

Thanks

That doesn't compile as posted. *Please* copy/paste working code.

If you look at:

perldoc -f formline

you will see where it says "You may therefore need to use
multiple formlines to implement a single record format, just
like the format compiler.". Some more calls of formline might give you
what you want, although you may need to alter the format and supplied
variables for those subsequent calls.
 
W

woof

The below goes. A second call to formline gets the ^<<< but
John Doe shows up again. Appears as if I must to this by hand or
redirect stdio and just use write.


my $FO_UN = " @<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<<<<<<<<";

$name = 'John Doe';
$note = '11231231233 123123123123 123123123123 1231231231 123';
$psec .= swrite(<<"END", $name, $note);
$FO_UN
END

print qq/$psec\n/;
#---------------------------------------------------------------------------
sub
swrite {
my $format = shift;
$^A = "";
formline($format, @_);
formline($format, @_);
return $^A;
}
 
J

Joe Smith

The below goes. A second call to formline gets the ^<<< but
John Doe shows up again. Appears as if I must to this by hand or
redirect stdio and just use write.

sub swrite {
my $format = shift;
$^A = "";
formline($format, @_);
formline($format, @_);
return $^A;
}

You missed the part where Bob said to "alter the format and supplied
variables for those subsequent calls". This works:

unix> cat temp
my $FO_UN = " @<<<<<<<<<<<<< | ^<<<<<<<<<<<<<<<<<<<<<<<<<";

$name = 'John Doe';
$note = '123456789 abcdefghi ABCDEFGHI jklmnopqr JKLMNOPQR stu';
$psec .= swrite(<<"END", $name, $note);
$FO_UN
END

print qq/$psec\n/;
#---------------------------------------------------------------------------
sub swrite {
my($format,$arg1,$arg2) = @_;
$^A = "";
print "before: arg2='$arg2'\n";
formline($format, $arg1, $arg2);
print "after: arg2='$arg2'\n";
substr($format,1,14) = ' ' x 14; # Done with "@<<<<<<<<<<<<<" part
formline($format, $arg2) while $arg2 ne ""; # Do multi-line
return $^A;
}
unix> perl temp
before: arg2='123456789 abcdefghi ABCDEFGHI jklmnopqr JKLMNOPQR stu'
after: arg2='ABCDEFGHI jklmnopqr JKLMNOPQR stu'
John Doe | 123456789 abcdefghi
| ABCDEFGHI jklmnopqr
| JKLMNOPQR stu

unix>

You have to make your routine act "just like the format compiler".
-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,147
Messages
2,570,835
Members
47,382
Latest member
MichaleStr

Latest Threads

Top