Hello all,
I'm in the process of writing a script that will search a file for a specific pattern and write the results to a new file. I have been able to partially accomplish this but I'm not completely satisfied with the results. The specifics are as follows:
Details
If the following pattern matches print to a new file.
Pattern = Any amount of alpha charatcters (upper or lower case) followed by five digits followed a specfic grouping "(x)" [without the quotes].
My Code
#!/usr/bin/perl -w
use strict;
my $file = "InputFile.txt";
my $disabled =~ /^[a-zA-Z]\w\d{5}(?:\(x\))/m;
open(FH, "<$file") || die ("Cannot open file for read: $!");
open(OF, ">>disabled.txt") || die ("Cannot open file for write: $!");
select OF;
$|=1;
while (<FH>) {
if ($disabled) {
print "$_", "\n";
}
}
close(OF);
close(FH);
The results of this script either print the entire contents of file being read or returns the error:
use of unitialized value in patter match (m//) at ./file.pl line 7. # this is what I am getting today
Work Around
My work around is to replace the contents of the while loop and it works just fine. This however only print out the enabled users.
#!/usr/bin/perl -w
use strict;
my $file = "./SPList";
open(FH, "<$file") || die ("Cannot open $file for read: $!");
open(OF, ">>./enabled.txt") || die ("Cannot open file for write: $!");
select OF;
$|=1;
while (<FH>) {
unless (/\(x\)/msg) {
print "$_";
}
}
close(FH);
I have tried breaking out the regular expression with white space to make it more readable like so:
my $disabled = /
^( #start capture; must be at beginning of line
[a-zA-Z]?+ #capture at least one or more alpha chars
\d{5} #followed by 5 digits
(?: #start a group
\(x\) #group contains (x)
) #end group
) #end capture
/xm;
But this still gives me the "unitialized value" error message. Any input is greatly appreciated.
=+=+=+=+=+=+=+=+=+=
Shawn Kelley
Network|Systems Admin
Deloitte & Touche, LLP
[EMAIL PROTECTED]
Great spirits have always encountered violent opposition from mediocre minds.
-- Albert Einstein (1879-1955)
This message (including any attachments) contains confidential information intended for a specific individual and purpose, and is protected by law. If you are not the intended recipient, you should delete this message. Any disclosure, copying, or distribution of this message, or the taking of any action based on it, is strictly prohibited.