Страница 1 из 1

перебор хэш массова в объекте

Добавлено: 2008-12-27 8:33:08
ProFTP

Код: Выделить всё

my %p = $query->Vars;
в %p пепедается массив fDomains из html, он есть, если посмотреть через Data::Dumper

Код: Выделить всё

dumper ($self->{p}->{fDomains});

Код: Выделить всё

'fDomains' => '2sdfsdf3sdf.org.ua?3dfgsdfdg.org.ua'
данный код не работает:

Код: Выделить всё

foreach $item (@{$self->{p}->{fDomains}}) { 
             print $item;
             exit;
}

найти как сделать не смог
надо что-то добавить?

Re: перебор хэш массова в объекте

Добавлено: 2008-12-27 13:29:12
ProFTP

Код: Выделить всё

@foo = split("\0",$params->{'foo'});

Re: перебор хэш массова в объекте

Добавлено: 2008-12-27 13:57:06
zg
гм... null-символ вроде не является признаком конца строки с тех пор как появился объект String

Re: перебор хэш массова в объекте

Добавлено: 2008-12-27 14:13:44
ProFTP
этоот метод vars для безопасноти, типо, и если много данных передаються, чтобы одной строкой записать в хэш
FETCHING THE PARAMETER LIST AS A HASH:

$params = $q->Vars;
print $params->{'address'};
@foo = split("\0",$params->{'foo'});
%params = $q->Vars;

use CGI ':cgi-lib';
$params = Vars;

Many people want to fetch the entire parameter list as a hash in which the keys are the names of the CGI parameters, and the values are the parameters' values. The Vars() method does this. Called in a scalar context, it returns the parameter list as a tied hash reference. Changing a key changes the value of the parameter in the underlying CGI parameter list. Called in a list context, it returns the parameter list as an ordinary hash. This allows you to read the contents of the parameter list, but not to change it.

When using this, the thing you must watch out for are multivalued CGI parameters. Because a hash cannot distinguish between scalar and list context, multivalued parameters will be returned as a packed string, separated by the "\0" (null) character. You must split this packed string in order to get at the individual values. This is the convention introduced long ago by Steve Brenner in his cgi-lib.pl module for Perl version 4.

If you wish to use Vars() as a function, import the :cgi-lib set of function calls (also see the section on CGI-LIB compatibility).