jimsgib...@gmail.com (Jim Gibson) writes: > 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.
I am really sorry here. I'm not able to make sense of how this is done even though you've given some hefty clues. That section of perldoc perldata with `__DATA__' in it reads like some kind of riddle. I guess I'm not understanding it even a little. The second main paragraph mentioning `__DATA__' says: See SelfLoader for more description of __DATA__, and an example of its use. [...] So I tried my best to follow that too. Especially looking for an example of its use. I guess the example is supposed to be: SYNOPSIS package FOOBAR; use SelfLoader; ... (initializing code) __DATA__ sub {.... Seems like more riddles. Apparently this is too far above my pay grade. It reads like I should be able to do something like: print $FOOBAR::DATA Which I guess means `print $Text::Wrap::DATA' But of course, that does not work. ------- ------- ---=--- ------- ------- Your clues seem to indicate I should be able to do: while ( my $line = <DATA> ) { if ( $line =~ /$rgx/ ) { print "\n"; print wrap(",", $line); } } ## ... print __DATA__; ------- ------- ---=--- ------- ------- But that is not what is needed either. ------- ------- ---=--- ------- ------- Is the __DATA__ something more than the lines being read? I mean are we just talking about seeing the incoming lines? I did include the actual log lines at one point. So trying to simplify things I'm running the script against 3 log lines produced by sendmail. The 3 lines below are in a file named `mail-loglines'. Each is all on one line (hopefully this is the DATA you need to see): Aug 13 19:59:10 u0 postfix/smtp[7922]: 1993C180CB9: to=<hp...@fastmail.fm>, relay=smtp.fastmail.com[66.111.4.139]:587, delay=0.7, delays=0.15/0.08/0.35/0.11, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 7240B7F986) Aug 13 19:59:10 u0 postfix/cleanup[7920]: B5619180CBB: message-id=<20170813235910.B5619180CBB@u1> Aug 13 19:59:11 u0 spamd[831]: spamd: result: . 0 - DKIM_ADSP_NXDOMAIN,NO_RELAYS scantime=0.3,size=2008,user=reader,uid=1000,required_score=5.0,rhost=localhost,raddr=::1,rport=56648,mid=<20170813235910.B5619180CBB@u1>,autolearn=no autolearn_force=no ------- ------- ---=--- ------- ------- The script -- cat linewrp: [...] use strict; use warnings; use Text::Wrap; my $rgx = qr/@{[shift]}/; $Text::Wrap::columns = 68; while ( my $line = <> ) { if ( $line =~ /$rgx/ ) { print "\n"; print wrap(",", $line); } } ------- ------- ---=--- ------- ------- The output: linewrp 'Aug' ./mail-loglines Increasing $Text::Wrap::columns from 68 to 220 to accommodate length of subsequent tab at /vcs/2x/export/home/reader/scripts/perl/linewrp line 21. Increasing $Text::Wrap::columns from 220 to 252 to accommodate length of subsequent tab at /vcs/2x/export/home/reader/scripts/perl/linewrp line 21. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/