in reply to Accessing data present in a text file with references...
So you could have declared the variables "$data", "@svr_raw" by preceding them with the "my" keyword, that would've given you hints that @svr_raw has been declared as an array but then you used a hash ref.
The module Data::Dumper is used to stringify data structures, (i.e it represents the strings that a data structure - when appropriately referenced- would show), hence you can look at the dumped structure and make judgments on how it can best be accessed. I would stress that it is very handy to learn advanced data structures in Perl,
Are some of the resources for you...
"Oh and yea does it make a difference in accessing the data from this text file if i use single quotes and double quotes? "double quotes and single quotes contexts come into light if you are accessing variables, since interpolation is affected by the way a variable is enclosed, double quotes allow variable interpolation and single quotes do not..
Run this code, which does work similar to what you intend$name = "varun monk"; print "$name\n"; print '$name\n';
use strict; use warnings; my $data={}; #declare an anonymous hash while(<DATA>){ chomp; my ($key, $val)=split /\s*=\s*/; $data->{$key}=$val; } print "name=>", $data->{name},"\n"; print "ip=>", $data->{ip},"\n"; ##View the data structure## use Data::Dumper; print Dumper($data); __DATA__ name = "varun" ip = "9.12.23.222";
|
|---|