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
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 


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

Reply via email to