On Wed, 16 Feb 2005 15:14:47 -0500, AstroDrabb <[EMAIL PROTECTED]> wrote: > > The main part of the code is: > > my $newline = $cmdopts{'msdos'} ? "\r\n" : "\n"; > local($/) = $newline x 2; # Blank line terminates records > > while (<>) { > my @flds = split $newline; > # Don't add it if parse fails > my $u = LDIF::User->new([EMAIL PROTECTED]) or next; > > my $node = $DRI->add({ > org => $u->org, > concept => $u->concept, > division => $u->division, > region => $u->region, > id => $u->id, > } > ); > my $uid = $u->uid or next; # Parse of user record failed > $u->node($node); # Remember the user's home node > $node->add_user($uid); # ...and the users at each node > $Users->{$uid} = $u; # ...and all userids with their data > } > ...
> sub new { > my $class = shift; > my $flds = shift; > > use constant FLDS => qw/uid first last email tz > org concept division region id access/; > my %self = ( > tz => '', # timezone > org => 'DRI', > manager_level => '', # Sometimes this isn't in the data... > ); > > foreach (@$flds) { > my ($k,$val) = split ':', $_, 2; > > # the below line we get an error on > my $key = $usermap{$k} or next; > # the above line we get an error on > > $val =~ s/^\s+//; # Strip leading ws > $self{$key} = $val; > } > ... > > The error we get is: > Use of uninitialized value in hash element at > /usr/local/webevent/wecore/bin/importer.pl line 941, <> chunk 6715. > > There is one LDIF record that we think throws the error since this > person never shows up in the application. The LDIF record is: > > dn: CN=Sharon XXXXXXXX,OU=users,OU=RSC,DC=darden,DC=com > changetype: add > company: RL1 > division: 06 > mail: [EMAIL PROTECTED] > givenName: Sharon > physicalDeliveryOfficeName: 0943 > sAMAccountName: RMKSLD1 > sn: XXXXXXXX > Darden-Job-Code: 6121 > Darden-Region: 01 > Darden-Security-Code: 89999 > Darden-Business-Unit: RLUSA > Darden-Company-Number: 1000 > Darden-Manager-Level: Y > > Compared to all our other records, there is nothing wrong with this one. > > Can anyone give any help fixing this problem? > > Thanks, > > James Drabb James, If this is a proprietary program, you might want to look at your liscence. They may not appreciate you publishing bits of the code in a public forum. Changing the code may also violate the terms. In that case, you shuold probably be talking to thier tech support people, not this list. I'll assume, though, that you've already checked into the legal bits. Give us a little bit more to go on, here. Is Sharon in fact chunk 6715? that shouldn't be too difficult to figure out, assuming the records are processed in order. Are the records stored in a single file, or is <> grabbing several files from the command line? Without any further information, several of possibilities jump to mind, both related to the record separator: 1) At some point you have more than one blank line in the file. Since $/ = $newline x2, $newline > 3 will produce a blank record in the output for every multiple of two blank lines. 2) Sharon X may have no blank line after her record, causing her to get lumped in with the record after, where map will overwrite record with the next. Is she by any chance the last record in a file? If she is, and the file has only one trailing newline, she's probably being combined with the first record in the next file. __EOF__ != \n\n. This may or may not be related to the error above. In fact, it probably isn't. Whatever the case in the data is, you're getting the error because new() isn't finding anything in chunk 6715 that it can split and assign to the hash. Therefore $usermap{$k} doesn't exist, and it throws an error when you try to assign it to $key. The programmer took a shortcut here, and doesn't test that the value actually exists before it gets assigned. The single line my $key = $usermap{$k} or next; Is doing the work of next unless exists $usermap{$k} ; my $key = $usermap{$k} ; This may or may not be considered a 'feature'. On the one hand, it's a shortcut. On the other hand, you probably want the error. Otherwise You wouldn't know there was an anomoly in your data, and you probably want to know that. To get the best of both worlds, try this: unless (exists $usermap{$k}) { print STDERR "Record $. seems to have been typed by drunk monkeys\n" ; next; } my $key = $usermap{$k} ; HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>