Nathan Haigh <> wrote: > 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: >
I have a few comments on your code. > -- code start -- > #!/usr/bin/perl -w It is generally better to 'use warnings;' > > 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 you only need those 2 fields, this is shorter (i.e. less likely to wrap): my ($id, $revision) = (split /;/)[1,2]; > > 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; > } The if/eles statement is unnecessary. Use auto-vivification, e.g. $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 > ActivePerl@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ========================================= Atos Euronext Market Solutions Disclaimer ========================================= The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of Atos Euronext Market Solutions. Atos Euronext Market Solutions Limited - Registered in England & Wales with registration no. 3962327. Registered office address at 25 Bank Street London E14 5NQ United Kingdom. Atos Euronext Market Solutions SAS - Registered in France with registration no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 75009 Paris France. L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bien vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de votre systeme. Le contenu de ce message electronique ne represente pas necessairement la position ou le point de vue d'Atos Euronext Market Solutions. Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée au Royaume Uni sous le numéro 3962327, dont le siège social se situe 25 Bank Street E14 5NQ Londres Royaume Uni. Atos Euronext Market Solutions SAS, société par actions simplifiée, enregistré au registre dui commerce et des sociétés sous le numéro 425 100 294 RCS Paris et dont le siège social se situe 6/8 Boulevard Haussmann 75009 Paris France. ========================================= _______________________________________________ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs