RE: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compar

RE: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compar

am 27.02.2007 10:08:28 von Reddy.Beri-Veera-ext

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.

Thanks and Regards
Reddy
-----Original Message-----
From: Nathan Haigh [mailto:n.haigh@sheffield.ac.uk]
Sent: 27 February 2007 09:52
To: n.haigh@sheffield.ac.uk
Cc: Beri Veera-ext, Reddy; ActivePerl
Subject: Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compar e
two files and update t o second fil e

-- snip --
>
> OK, so you only want the item and revision bits from the input file and
> you only want unique one's at that? If this is all you want to do, you
> have no need to read what's in the output file. The script below should
> do what you want. Simply execute with the input file as the 1st argument
> to the script and you can redirect STDOUT to a file.
>
> e.g.
> perl this_script.pl input.txt > output.txt
>
> I have sorted the items alphabetically, if you need the items in the
> order they were encountered in the input file, this will need to be
> changed slightly.
>
> Let me know if this works as you want.
>
> Nathan
>
> -- 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 () {
> # 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,$d ataset) =
> 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 end --
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>

Ouch - sorry for the line wrap!! Hopefully, you can figure it out!

Nathan
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compar

am 27.02.2007 10:11:28 von n.haigh

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 () {
# 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,$d ataset) =
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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compar

am 27.02.2007 10:12:23 von n.haigh

This is a multi-part message in MIME format.
--------------080409000602050601050204
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

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.
>>
>>


Hmm, still seems to be wrapping! Find the file attached this time!

Nathan

--------------080409000602050601050204
Content-Type: application/x-perl;
name="merge.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="merge.pl"

#!/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 () {
# 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,$d ataset) = 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"; }


--------------080409000602050601050204
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--------------080409000602050601050204--

RE: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: [RMX:#] Re: How to compare

am 27.02.2007 11:01:48 von Brian Raven

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 () {
> # 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,$d ataset) =3D
> split /;/;

If you only need those 2 fields, this is shorter (i.e. less likely to
wrap):

my ($id, $revision) =3D (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"} =3D 1;
> }

The if/eles statement is unnecessary. Use auto-vivification, e.g.

$item_rev{"$item_id;$item_revision"} =3D 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

==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================

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 immediat=
ely 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 Lon=
don 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 750=
09 Paris France.

L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.

Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs