Reading values in perl

Hi whats the easiest way to read data from a feed file?

sample data in a file called data.txt:


name = varun
ip = '23.43.123.2'
address = "asd, blah blah blah ..... @#!$%$#%"

i want to use this data in a perl script.
I thought of initially reading it line by line n then cutting fields out but that didn't seem to work well with the single quotes and all....

Something like this:

$ cat data.pl
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %conf = map {
    chomp;
    my @a = split / = /;
    $a[1] =~ s/['"]//g;
    $a[0] => $a[1];
} <DATA>;
print Data::Dumper->Dump( [ \%conf ], [qw/conf/] );

__DATA__
name = varun
ip = '23.43.123.2'
address = "asd, blah blah blah ..... @#!$%$#%"

$ perl data.pl
$conf = {
          'ip' => '23.43.123.2',
          'name' => 'varun',
          'address' => 'asd, blah blah blah ..... @#!$%$#%'
        };

thanks man...
in the same situation,
supposing the data was present in a file called data.txt
how would i pull out the data then???

By using open to, y'know, "open" the file and reading from the resulting file handle.

isn't there any way to read the entire file in one shot rather than record wise.... it's a little confusing... could u plzzzzzzzzzzzzzzz show me an example... thanx.... :smiley:

Let me ask you a question: if you don't know how to use the open function, how are you going to make anyone believe you thought up the map?

And please use proper English instead of that script-kiddy "plz" and "thanx".

first up....
im not trying to convince anyone that i thought up the map....
all im trying to do is understand and learn how this works..

I have used the open function before like this:

if (open(INFILE, $locationoffile)) {
	@fh = <INFILE>;
	close(INFILE);
} #[else.. whatever....]

after opening it up like this, i count the number of lines in the array and then run two loops to pick out one line(record) at a time....
ALL I WANTED to know was if there was another way to use the data dumper which would help me pick up data in a better way

Sorry, just making sure you're not a student trying to cheat.

Data::Dumper isn't doing the magic in my code, it just dumps a data structure (hence the name). The magic is happening in the map "loop", and it's acting on a whole file handle (it's basically a glorified foreach, but more powerful).

Huh? Is it just me, or does this seem unnecessarily complicated?