Your program works fine, you made a mistake in the final print.
Here is a more "perlish" version
$file = 'c:/temp/export/CONVERSION/test.txt'; # You can use / instead of \, it
works fine even under Windows
open TEST, "$file" || die "Cant open file $file";
while(<TEST>)
{
chomp;
if (/PLMEJob Master/../^$/)
{
chomp;
next if /PLMEJob Master/ || /^$/;
my @a = split /=/;
$info{$a[0]} = $a[1];
}
}
close(TEST);
print "$_ => $info{$_}\n" foreach sort keys %info;
Big mistake :
foreach(%info)
{
print "$_ => $info{$_}\n"
}
An associative array is an array indeed !
So when you print foreach %info, you print each key and each value. Of course
it wont find any value for $info{value}
> -----Message d'origine-----
> De : [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] De la
> part de Beri-Veera-ext, Reddy (n.a.)
> Envoyé : mardi 10 juillet 2007 10:54
> À : Nathan S. Haigh
> Cc : ActivePerl
> Objet : RE: [RMX:#] Re: How to add to Associative Array
>
> Hi all,
> I wrote a sample program with your guide lines but the associative
> array has double entries. Please the attachment for my program and
> test.txt file. Please tell me what I did the wrong.
>
>
> Thanks && Regards
> Karunakar Reddy B.V.
>
> -----Original Message-----
> From: Nathan S. Haigh [mailto:[EMAIL PROTECTED]
> Sent: 10 July 2007 10:10
> To: Beri-Veera-ext, Reddy (n.a.)
> Cc: Bill Luebkert; ActivePerl
> Subject: RE: [RMX:#] Re: How to add to Associative Array
>
> If you want to read the lines in from a file, you need to open a
> filehandle:
> open(IN, $path_to_my_file) or die "Couldn't open file: $!\n";
>
> then use the IN filehandle in the while loop, such as::
> foreach (<IN>) {
> # stuff to do with each line
> # ...
> }
>
> The close the filehandle with:
> close IN;
>
> Hope this helps
> Nath
>
>
> Quoting "Beri-Veera-ext, Reddy (n.a.)"
> <[EMAIL PROTECTED]>:
>
> > Hi,
> > Thanks for your quick info. How I will get
> > my @lines = ( # phoney test data simulating file data
> > "red,danger\n",
> > "blue,going smooth\n",
> > "yellow, pending\n",
> > "Green, accept\n",
> > );
> > How I will convert test.txt to @line.
> > Please explain this.
> >
> >
> > Thanks && Regards
> > Karunakar Reddy B.V.
> >
> >
> > -----Original Message-----
> > From: Bill Luebkert [mailto:[EMAIL PROTECTED]
> > Sent: 10 July 2007 09:48
> > To: Beri-Veera-ext, Reddy (n.a.)
> > Cc: ActivePerl
> > Subject: [RMX:#] Re: How to add to Associative Array
> >
> > Beri-Veera-ext, Reddy (n.a.) wrote:
> > > Hello,
> > > I want to add to Associative Array dynamically (means=> I don't
> > exact
> > > size of Associative Array).
> > >
> > > Ex: In test.txt I have the fallowing data.
> > > red,danger
> > > blue,going smooth
> > > yellow, pending
> > > Green, accept.
> > > ....etc
> > >
> > > I have to add these values to Associative Array
> > > like
> > > %info= (red =>danger
> > > blue =>going smooth
> > > yellow => pending
> > > Green=>accept.
> > > ...etc)
> > >
> > > For these I have read the test.txt line by line and add to %info.
> > Please
> > > guide me how to do this....
> >
> > use strict;
> > use warnings;
> >
> > my @lines = ( # phoney test data simulating file data
> > "red,danger\n",
> > "blue,going smooth\n",
> > "yellow, pending\n",
> > "Green, accept\n",
> > );
> >
> > my %info = ();
> > foreach (@lines) { # would normally be: while (<IN>) { # reading
> > from file
> > chomp;
> > my @a = split /\s*,\s*/;
> > $info{$a[0]} = $a[1];
> > }
> > print "$_ => $info{$_}\n" foreach keys %info;
> >
> > __END__
> > _______________________________________________
> > ActivePerl mailing list
> > [email protected]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
>
>
>
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs