Original Message
Subject: Re: Building/defining variables from an value in string
Date: Wed, 23 Apr 2008 04:46:21 -0400
From: Uri Guttman <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Newsgroups: perl.beginners
References: <[EMAIL PROTECTED]>
<[EMAIL PROTE
Aruna Goke wrote:
print keys %h; print "---"; say values %h;
say keys %h, '---', values %h;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/
Li, Jialin wrote:
use strict;
my $string = 'field1,int,10#field2,string,abc';
my @values = split /#/,$string;
my @vars;
no strict 'refs';
for (@values) {
my @tmp = split /,/;
push @vars, $tmp[0];
${$tmp[0]} = $tmp[2];
}
for (@vars) {
print $_, ": ", ${$_},
use strict;
my $string = 'field1,int,10#field2,string,abc';
my @values = split /#/,$string;
my @vars;
no strict 'refs';
for (@values) {
my @tmp = split /,/;
push @vars, $tmp[0];
${$tmp[0]} = $tmp[2];
}
for (@vars) {
print $_, ": ", ${$_}, "\n";
}
__END__
Hi: I have a string with a number of variable name, type and value pairs. I
want to split the field and build my variables. Below is an example
$string = "field1,int,10#field2,string,abc";
@values = split(/#/,$string);
I want to get two variables from the string, equivalent to the below statemen