[Catalyst] Re: retrieving multiple values from forms

Сергей Мартынов sergey at martynov.info
Thu Dec 20 18:06:23 GMT 2007


> > > i dare say that's not what i'd suggested.  i wrote:
> > >
> > > my @titles = ref $c->request->params->{title}
> > >    ? @{ $c->request->params->{title} } : ($c->request->params->{title} || '');
> > >
> > > the @{ ... } bit  was not extraneous.
> > >
> > > (on the other hand, if there's a more idiomatic way of doing this i'd
> > > love to hear about it.)
> >
> > I use perlish way to get rid of excessive method calls and make the
> > statement a bit more compact:
> >
> > my @list = map { ref $_ ? @$_ : ($_ || '') } $c->request->params->{title}
>
> That'll break if the submitted value is zero "0"

Well, okay, I just copied from the code above :) I usually write
simply map { ref $_ ? @$_ : $_ } - passing undef values as they are.
The other nice practice is

my @list = map { ref $_ ? @$_ : defined $_ ? $_ : () }
$c->request->params->{title}

which gives us an expected empty list when no value was passed.



More information about the Catalyst mailing list