John, thanks for the succinct suggestion on the set in place edit
extension.....I'll humbly accept additional "yo here's how to simplify this
deal" examples. ;^)
I could still be doing a number of things wrong, I can launch the script ,
but it 'hangs', & my prompt doesn't return. I'm not getting an error, simply
an empty file in /data/dir/newlogs/ named *.new. Confused whether the error
is occurring on read/write or open. I think it's on writing? Tried
changing:
18 open ( NEWLOG, ">$newlogdir/$log.new" ) || die "Can't
create: $!\n";
Can't create: No such file or directory
while:
18 open ( NEWLOG, ">$newlogdir/*.new" ) || die "Can't
create: $!\n";
seems to be writing an empty file?
The script as it stands at present:
1 #!/usr/bin/perl -w
2 use strict;
3 # try5.plx
4 # open filehandle to read all .log files present in /dir
5 # open filehandle to write matched lines to .new in /dir/newlogs
6 # match lines
7 ############################
8 my $logdir = '/data/dir
9 my $newlogdir = '/data/dir/newlogs';
10 # set in place edit extension
11 $^I = "$newlogdir/*.new";
12
13 chdir ( $logdir );
14 # slurp all .logs into an array for looping
15 my @rawlogs = glob( "$logdir/*.log" );
16 foreach my $log ( @rawlogs ) {
17 open ( LOG, $log ) || die "Can't open file: $!\n";
18 open ( NEWLOG, ">$newlogdir/*.new" ) || die "Can't
create: $!\n";
19 while ( <> ) {
20 # match lines that start with '#', contain
'CommunityID=399',
21 # or contain '/developersupport/testfiles', or
'/remotegadgets/marks'
22
23 if (
m/^#|CommunityID\=399|\/developersupport\/testfiles|\/remotegadgets\/marks\/
gadget/ ) {
24 print NEWLOG;
25 }
26 }
27 }
28 close LOG;
29 close NEWLOG;
> -----Original Message-----
> To apply this to your original program you could do something like this:
>
>
> #!/usr/bin/perl -w
> use strict;
>
> my $newdir = '/something';
> $^I = "$newdir/*.new";
>
> while ( <> ) {
> if (
> m!^#|CommunityID=399|/developersupport/testfiles|/remotegadgets/marks/gadg
> et!
> ) {
> print;
> }
> }
>
> __END__
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]