How to store an array in session in Perl [closed] - perl

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am using Mojolicious Perl framework in my application. I want to store an array in session, but is not successful.
my #returnResult;
$returnResult['fn'] = $decoded->{'fn'};
$returnResult['ln'] = $decoded->{'ln'};
$self->session(returnResult => #returnResult);
Please help.

See hashes in Modern Perl and perldata.
my %return_result;
$returnResult{fn} = $decoded->{fn};
$returnResult{ln} = $decoded->{ln};
or
my %return_result = (
fn => $decoded->{fn},
ln => $decoded->{ln},
);
or simply
# http://perldoc.perl.org/perl5200delta.html#New-slice-syntax
my %return_result = %$decoded{qw(fn ln)};
You do not get automatic references like in other languages. Use the \ operator.
$self->session(returnResult => \%return_result);

Related

After creating tab bars and widgets the emulator gives such an error when opening the app [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I could not transfer my code to the site as I wrote it, but I placed your photo Please can you help me?
You are getting the error because you are trying to pass an uninitialized String to a Text-Widget (Naber). A Text-Widget can not handle uninitialized Strings which have the value null.
Therefore try initializing the String 'Naber' directly like:
String Naber = 'Some text';
This should work.

Accessing values - Swift [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
You are given a dictionary crypt of type [String:String] which has values for all lowercase letters. The crypt dictionary represents a way to encode a message. For example, if crypt["h"] = "#" and crypt["i"] = "!" the encoded version of the message "hi" will be "#!".
The thing is that i have to Write code that would take any string containing only lower case letters and spaces and encode it using the crypt dictionary. I have successfully failed trying to write the code so i ended up just using a single print statement
//print(crypt["h"]!,crypt["i"]!).
If you have any idea you would like to share, please do so.
Thank you
Does this do what you're looking for:
let message = "hi"
let encryptedMessage = message.map { crypt[String($0)]! }.joined()
If you're unfamiliar with it, mapping a string iterates through each character, doing something to it, and returning that string. $0 refers to the first parameter (in this case #1 of 1, but 0-indexed).
As Dopapp suggests, map is the most elegant solution. If you want to see the steps broken out a bit, you can do it the long way.
var message = "hi"
var crytpedMessage = ""
for char in message {
let newChar = crypt[String(char)]
cryptedMessage.append(newChar)
}

Remove common values from multidimension array perl [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want remove common element from array. For example:
array1 =
[
{'id'=>78597,'data'=>'great'}
];
array2=
[
{'id'=>78345,'data'=>'first'},{'id'=>78597,'data'=>'great'},
{'id'=>78355,'data'=>'second'}
]
Now key Id '78597' is common in both array
Now i to want remove that element from array2 based on the key 'id'. The examples I referred where all single dimension.
You can build %seen hash lookup and filter #$array2,
my %seen;
#seen{ map $_->{id}, #$array1 } = ();
#$array2 = grep { !exists $seen{$_->{id}} } #$array2;

web2py form with DB check [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm using web2py forms, but I need to set up a limit for 20 users registration. How can I do it?
PS: Edit to make easy to understand
Thanks in advance.
Best regards!
Assuming you wish to limit registration to a maximum of 20 users and you are using the standard /default/user function from the scaffolding application:
In the default.py controller:
def user():
if request.args(0) == 'register' and db.auth_user.count() >= 20:
form = None
else:
form = auth()
return dict(form=form)
In the default/user.html view:
{{if form is None:}}
<p>Sorry, no more registrations allowed.</p>
{{else:}}
{{=form}}
{{pass}}

How do you generate links for paginator in Perl? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Each link has the same url as the current requested uri except that the page parameter may differ.
How do you generate such links in Perl?
You do not seem to know the basics. Go read an introductory book or two about Web programming.
Construct a URI object.
use URI qw();
In CGI, piece it together from the enviroment. (Stackers, is there a better way/convenience method I've overlooked?)
my $current = 'http://example.com/?search=foobar';
my $u = URI->new($current);
In PSGI, use the uri method.
use Plack::Request qw();
…
my $req = Plack::Request->new($env);
my $u = $req->uri;
Higher-level frameworks should provide their own accessors. In Catalyst:
my $u = $c->request->uri;
Mutate the query string to include the paging parameter.
use URI::QueryParam qw();
$u->query_param(page => 13);
$u->as_string; # returns http://example.com/?search=foobar&page=13
The query_param DTRT and overwrites the parameter even if it's already set.
$u->query_param(page => 42);
$u->as_string; # returns http://example.com/?search=foobar&page=42