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
> 

#
# BSH Export Server Job File
# created with stylesheet version 1.0.2
#
BSH Export Server Job File
version=1.0.2

PLMEJob
item_id=PLMEJOB0000000002
item_uid=SNEZFD6aR6qTPD
workflow_uid=

PLMEJob Master
master_form_uid=SNHZFD6aR6qTPD
plme_m_job_d_01=
plme_m_job_d_02=
plme_m_job_d_03=
plme_m_job_i_01=0
plme_m_job_i_02=0
plme_m_job_i_03=0
plme_m_job_l_01=
plme_m_job_l_02=
plme_m_job_s_01=
plme_m_job_s_02=
plme_m_job_s_03=
plme_m_job_s_04=BSH Export
plme_m_job_s_05=
plme_m_job_s_06=
plme_m_job_s_07=
plme_m_job_s_08=
plme_m_job_s_09=
plme_m_job_s_10=
plme_m_job_s_11=To Convert
plme_m_job_s_12=
plme_m_job_s_13=

PLMEJob Revision
item_revision_id=A
item_revision_uid=SRLZFD6aR6qTPD

Referenced Item Revisions
Item;012863;A;IMAN_specification;UGPART;012863_dr01;qaf;dwg_sht1.qaf
Item;012863;A;IMAN_specification;UGPART;012863_dr01;qaf;qafmetadata.qaf
Item;012863;A;IMAN_specification;UGPART;012863_dr01;prt;012863_dr01.prt
Item;012863;A;IMAN_specification;UGMASTER;012863-a;qaf;images_preview.qaf
Item;012863;A;IMAN_specification;UGMASTER;012863-a;qaf;qafmetadata.qaf
Item;012863;A;IMAN_specification;UGMASTER;012863-a;prt;012863_a.prt
Item;012864;A;IMAN_specification;UGMASTER;012864-a;qaf;images_preview.qaf
Item;012864;A;IMAN_specification;UGMASTER;012864-a;qaf;qafmetadata.qaf
Item;012864;A;IMAN_specification;UGMASTER;012864-a;prt;012864_a.prt
Item;012864;A;IMAN_specification;UGPART;012864_dr01;qaf;dwg_sht1.qaf
Item;012864;A;IMAN_specification;UGPART;012864_dr01;qaf;qafmetadata.qaf
Item;012864;A;IMAN_specification;UGPART;012864_dr01;prt;012864_dr01.prt
Item;012864;A;IMAN_specification;PDFDrawing;012864,A;pdf;2tier.pdf
Item;012864;A;IMAN_specification;PDFDrawing;012864,A
Item;012862;A;IMAN_specification;UGMASTER;012862-a;qaf;images_preview.qaf
Item;012862;A;IMAN_specification;UGMASTER;012862-a;qaf;qafmetadata.qaf
Item;012862;A;IMAN_specification;UGMASTER;012862-a;prt;012862_a.prt
Item;012862;A;IMAN_specification;UGPART;012862_dr01;qaf;dwg_sht1.qaf
Item;012862;A;IMAN_specification;UGPART;012862_dr01;qaf;qafmetadata.qaf
Item;012862;A;IMAN_specification;UGPART;012862_dr01;prt;012862_dr01.prt

PLMEJob Referenced Datasets
IMAN_reference;Text;PLMEJOB0000000002;txt;22.txt
IMAN_reference;PDFDrawing;pdfatt;pdf;workflow_process.pdf
IMAN_reference;PDFDrawing;pdfatt

PLMEJob Revision Referenced Datasets

Attachment: cr_ass_array.pl
Description: cr_ass_array.pl

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to