Good evening,

I am trying to finish up a script that simply reads 2 files, matches a value unique in each file, and then writes output to a fixed format based on attributes from each file.

Here is the code, and please bear with me. I know that I have major syntax problems, but I think I ended up moving code accidentally when editing.

How do I get this to sort and print properly? I think I am on the right track but I am now getting confused.

#!/usr/bin/perl # # #Creation date: 10/4/2004 # This script will perform four major operations # 1) Read an LDIF extract from Active Directory, # objectClass=Users. Copy DN and samACCOUNTNAME into a hash. # $key is dn and $value is samACCOUNTNAME # 2) Read a CSV extract from a legacy AS400 Database into @hris. # 3) Compare hash and @hris and match the samACCOUNTNAME # value and and value [0] from @hris. On match and write record co +ntaing DN, # samACCOUNTNAME from @mlf1 and Division and Location from # @hris. # 4) Write record to file an LDIF record using the DN, samACCOUNTNAME, + # division,and personalTitle attributes. use warnings; use strict; open (my $FILE, 'c:/test/ldif.ldf') || die "can't open 'ldif.ldf': $!" +; # open LDIF file for reading open (my $OUTPUT_FILE, '>mlfexport.txt') || die "can't open 'mlfexport +.txt': $!"; #open output file open (my $FILE1, 'c:/test/hris.csv') || die "can't open 'hris.csv': $! +"; #open csv file for reading local $/ = "\n\n"; # Set an empty newline as line separator my %lookup; #hash for $File my($key, $value); my $dn = $key; # want to assign the dn as the key in the hash table my $samACCOUNTNAME = $value; #want to assign samACCOUNTNAME to value #next block will hash $file for 2 values while (<$FILE>) { my ($dn)= /^dn: (.*)$/m; my ($samACCOUNTNAME)= /^sAMAccountName: (.*)$/m;{ $lookup {$dn} = {$samACCOUNTNAME} # verify syntax, is $looku +p defined right, and is this matching dn and samACCOUNTNAME if defined $samACCOUNTNAME and $dn ; # only if both are found } } # I think I am making this too complicated. Do I need all these varia +ble declarations? my @hris = ($FILE1); #associate csv file to array my @ldif = (%lookup); #associate table to array my $uid = ((@hris)[0]); #set usernamme which also equals samACCOUNTNAM +E my $div = ((@hris)[1]); #set division value for printing my $loc = ((@hris)[2]); #set personalTitle value for printing # The next block should look for the samACCOUNTNAME in $value and matc +h it to array position 0 in hris. while (<$FILE1>) { foreach my $value (keys %lookup){ if $hris [1] eq $lookup($value) # what I want to do here is val +idate a match on $value and array [0] and print the entry to the outp +ut file } &print_entry($dn, $uid, $div, $loc); } #this block prints the output sub print_entry { local($dn, $uid, $div, $loc) = @_; #print out LDIF file print $OUTPUT_FILE "dn:$ldif[2]","\n"; print $OUTPUT_FILE "changetype:=modify","\n"; print $OUTPUT_FILE "sAMAccountName:=$uid","\n"; print $OUTPUT_FILE "division:=$hris[1]","\n"; print $OUTPUT_FILE "personalTitle:=$hris[2]","\n"; print $OUTPUT_FILE "\n"; } close($OUTPUT_FILE) || die "can't close mlfexport.txt: $!"; close($FILE1) || die "can't close 'hris.csv': $!"; close($FILE) || die "can't close 'ldif.ldf': $!"; exit; # successful exit

Here is error messaging I get when I run it

C:\test>perl mlfimport.pl syntax error at mlfimport.pl line 55, near "if $hris " Global symbol "$lookup" requires explicit package name at mlfimport.pl + line 55. Execution of mlfimport.pl aborted due to compilation errors.

And here is what output I am getting when I have gotten this running with warnings

dn:CN=Patel\, Rupal,OU=Users,OU=BartorRd,OU=Corporate,DC=oakleaf,DC=ca changetype:=modify sAMAccountName:=HASH(0x224e0c) division:= personalTitle:=
Any help would be greatly appreciated.

In reply to Syntax and variable problems by contrite_newbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.