Please don't update your node without indicating that you have done so! The code and output is appreciated, but wasn't part of the original node.
Consider the following:
#!/usr/bin/perl use strict; use warnings; use Data::Dump; my $filename = "./DATA.txt"; open my $outFile, '>', $filename or die "Can't create $filename: $!"; print $outFile <<'FILE_DATA'; name = "varun" ip='9.12.23.222' #including the irregular spaces FILE_DATA close $outFile; open my $inFile, '<', $filename or die "Can't open $filename: $!"; my %data; while (<$inFile>) { chomp; my ($id, $value) = split /\s*=\s*/; $data{$id} = $value; } print Data::Dump::dump (\%data);
Prints:
{ ip => "'9.12.23.222' #including the irregular spaces", name => "\"varun\"", }
which creates a temporary file as part of the sample code (so the while thing is self contained), reads the file and builds a hash containing name/value pairs (this may not do it for you if there are multiple lines in your file using the same name), then dumps the resulting data structure as you might do when you haven't figured out how to use the debugger and want to see what you got.
In reply to Re: Accessing data present in a text file with references...
by GrandFather
in thread Accessing data present in a text file with references...
by VGR
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |