Nilay Puri wrote: > > Can any one walk me thru this piece of code :: > > while(<STDIN>) > { > chomp ; > $isbn =(split(/^_/, $_))[0] ; --- not able to understand what is > being accessed (......)[0] > unless ($KEYS{$isbn} ) ---- isbn is a scalar variable, how keys > wok on it ? > { > print "$_\n" ; > $KEYS{$isbn} =1 ; > } > }
Hi Nilay. >From your question, I guess the code isn't your own? I've put some whitespace in so that it's a bit more visible, like this: while (<STDIN>) { chomp; $isbn = (split(/^_/, $_))[0]; # --- not able to understand what is being accessed (......)[0] unless ( $KEYS{$isbn} ) { # ---- isbn is a scalar variable, how keys wok on it ? print "$_\n"; $KEYS{$isbn} = 1; } } First of all, the line $isbn = (split(/^_/, $_))[0]; is almost certainly not what was meant. It will put into $isdn either a null string (if the first character of the record is an underscore) or else a copy of the entire record. I can't guess what the interntion was. As for the line that accesses the %KEYS hash, you're probably best off reading perldoc perldata about how strings can be used to index hashes. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>