> On Aug 18, 2017, at 6:05 AM, Harry Putnam <rea...@newsguy.com> wrote: > > jimsgib...@gmail.com (Jim Gibson) writes: >>> > > A second attempt trying to use your last example as inspiration > follows: > > -------8< snip -------------8< snip -------------- > > use strict; > use warnings; > use Text::Wrap; > > my $rgx = qr/@{[shift]}/; > > $Text::Wrap::columns = 68; > > > while ( my $line = <> ) { > if (/$rgx/) { > print "\n"; > print wrap(",", $line); > } > } > > -------8< snip -------------8< snip -------------- > > Output from same `logs' file: > > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 1. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 2. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 3. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 4. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 5. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 6. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 7. > Use of uninitialized value $_ in pattern match (m//) at > /vcs/d0/home/reader/scripts/perl/logwrp line 48, <> line 8.
There is an error in what I posted (sorry). The input is read into the $line variable, but your regular expression is implicitly testing the default variable $_. The loop should be: while ( my $line = <> ) { if ( $line =~ /$rgx/ ) { print "\n"; print wrap(",", $line); } } I don’t know what Text::Wrap is complaining about. It helps if you are able to include a text string in your posted source code that demonstrates the problem. Use the built-in DATA file handle to include data within your program source. Check out ‘perldoc perldata’ and search for “__DATA__”. This is the pattern: ... while ( my $line = <DATA> ) { if ( $line =~ /$rgx/ ) { print "\n"; print wrap(",", $line); } } ... __DATA__ This is data to be read using the <DATA> operation. Jim Gibson jgib...@snowlands.org -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/