The script I am using is this
#!"\xampplite\perl\bin\perl.exe"
use CGI qw/:standard/;
use overload;
$| = 1;
$q = new CGI;
print $q->header();
local $/=undef;
open FILE, "users.list" or die "Couldn't open file: $!";
binmode FILE;
$string = <FILE>;
close FILE;
$_ = $string;
chomp($_);
#Removes some of the formatting
s/Cof....Members//g;
s/To:\s//g;
s/Bc:.*\s//g;
#Checks if the expression will replace anything
if(m/ {1}\w.+\w\b.\w.+\w {1}/g){print "Hello";}
#Finds all names and replaces them with ___
s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
open (OUT,">>usersFinal.list") || die;
print OUT $_;
close OUT;
The line I am having problems with is
s/ {1}\w.+\w\b.\w.+\w {1}/___/g;
The line is supposed to find all the names and remove them. It does
that, but replaces all the names with one instance of ___ instead of
___ for each name on the list. I can not break the names up by
looking for \n or \r. I am not sure why, but I think that they got
stripped
Eventually I want to add to the end of the name some other
information, but for now I just need to find the expression that finds
the names.
Below is an example of the starting information.
Cof2001Members
To: LastName1, FirstName1
To: LastName2, FirstName2
To: LastName3, FirstName3
To: LastName4, FirstName4
Bc: Zzip
Here is the way I want to eventually make the information look
Cof2001Members
Smith, Bob, smit001,
Jones, John, jone001,
Green, Jane, gree001,
Henry, Chris, henr001,
Either the expression to match the names and/or the code to add to the
end of names the needed information would be wonderful. Thanks
everyone.
> So, I am working on a program to take a list of First and Last names
> exported from Novell Groupwise and making the list become Last, First,
> firstfourlettersofLastName, password ||
>
> The script I am using is this
>
> #!"\xampplite\perl\bin\perl.exe"
> use CGI qw/:standard/;
> use overload;
You should have here:
use strict;
use warnings;
You seem to be making it hard on yourself by trying to process the file
in one go. You are also discarding the 'To: ' string that marks the
relevant lines. Why don't you process the file line by line? Something
like this:
#!/usr/local/bin/perl
use strict;
use warnings;
while(<DATA>) {
if( m{ To: \s+ (\w+) , \s+ (\w+) }x ) {
my( $last, $first ) = ($1, $2);
my $pwd = lc(substr($last,0,4)) . '001';
print "$last, $first, $pwd\n";
}
}
__DATA__
Cof2001Members
To: Smith, Bob
To: Jones, John
To: Green, Jane
To: Henry, Chris
Bc: Zzip
--
Jim Gibson
Do not.
Hope this helps,
Ilya
I am using the code
$userList = "usersFinal.list";
open(userList) or die("Could not open the user list.");
foreach $line (<userList>) {
chomp($line); # remove the newline from $line.
print "${line}<br />";
# do line-by-line processing.
}
Using a foreach loop instead of a while loop means that the entire file
is read into memory and $line is aliased to each line read one-by-one.
A while loop will only read and process one line at a time, so is more
efficient in its use of memory:
while( my $line = <userList> ) {
chomp($line);
#do line-by-line processing
}
--
Jim Gibson