Beri Veera-ext, Reddy wrote:
> Hi 
> Thanks for your help. I had implemented in my code. I have one doubt in this
> You declared $item_rev but in foreach you used $item_with_rev.  
> I am getting a error "Missing $ on loop variable at
> C:\BSH\ExportModule\bsh_export.pl" at foreach.
>   

Just in case it's an issue with the line wrapping - I'll try again!
Here's the code - see if that works:

-- code start --
#!/usr/bin/perl -w

use strict;

my %item_rev;   # use this to keep track of what item and revisions are
encountered

open (INPUT, $ARGV[0]) or die "Couldn't open input file '$ARGV[0]': $!\n";
while (<INPUT>) {
        # skip all lines except those starting "CADItem"
        next unless /^CADItem/;

        # split the line into it's component fields
        my
($item_type,$item_id,$item_revision,$relation,$datsettype,$dataset) =
split /;/;

        if (exists $item_rev{"$item_id;$item_revision"} ) {
          # we already found the 1st occurence of this item and revision
        } else {
          # this must be the first occurence
          $item_rev{"$item_id;$item_revision"} = 1;
        }
}
close INPUT;

# %item_rev now contains a unique list of items with revisions
foreach my $item_with_rev (sort keys%item_rev) { print STDOUT
"$item_with_rev\n"; }
-- code stop --
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to