[email protected] (Jim Gibson) writes:
>> On Aug 13, 2017, at 6:02 PM, Harry Putnam <[email protected]> wrote:
>>
>> My aim:
>>
[...]
>> my @text;
>>
>> while (<>) {
>> if (/$rgx/) {
>> print "\n";
>> print wrap(",", @text);
>> }
>> }
>>
>> It wasn't at all clear from perldoc Text::Wrap how @text is supposed
>> to be populated.
>
> @text is a list of scalar strings passed to the wrap subroutine. You
> can pass a single string also. Try this loop instead:
Argh, yes I see
> while (<>) {
> if (/$rgx/) {
> print "\n";
> print wrap(",", $_);
> }
> }
>
> It is usually better to use explicit variables:
>
> while ( my $line = <> ) {
> if (/$rgx/) {
> print "\n";
> print wrap(",", $line);
> }
> }
Thanks for clearing that up, and the good practices tip.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/