It can be done as follows :-
my $date = "2009-27-02";
$date =~ s/(\d{4})-(\d{2})-(\d{2})/$2\/$3\/$1/;
say $date;
O/p
27/02/2009
It can be done as follows :-
my $date = "2009-27-02";
$date =~ s/(\d{4})-(\d{2})-(\d{2})/$2\/$3\/$1/;
say $date;
O/p
27/02/2009
It can be done as follows:-
SELECT * FROM table_name ORDER BY FIELD(filed_name,
"value_y"
,"value_x") DESC
We may see that we don’t get proper output in IE when we try to use
document.getElementById('my_id').innerHTML="mm";
This mainly happens in the case we try to implement innerHTML
into the select
tag. The way I recommend to overcome this situation is to use jquery. We can write the content in jquery as follows:
$('#
my_id
').html("<option value='mm'>mm</option>
");
I had tested it and saw that it’s working.
We can write multidimensional array in Perl as follows :
my @array1 = (1, 2, 3, 'four');
my $reference1 = \@array1;
my @array2 = ('one', 'two', 'three', 4);
my $reference2 = \@array2;
my @array = (\@array1, \@array2);
print $array[1]->[0];
The output will be as follows :
one
The rand()
function is used to generate random numbers. By default it generates a number between 0 and 1, however you can pass it a maximum and it will generate numbers between 0 and that number.
To generate a random decimal number between 0 and 1, use rand()
without any parameters.
#!/usr/bin/perl use strict; use warnings; my $random_number = rand(); print $random_number . "\n";
This will give you a random number, like:
0.521563085335405
Quite often you don’t want a number between 0 and 1, but you want a bigger range of numbers. If you pass rand()
a maximum, it will return a decimal number between 0 and that number. Our example below generates a random number between 0 and 100.
#!/usr/bin/perl use strict; use warnings; my $range = 100; my $random_number = rand($range); print $random_number . "\n";
The program will produce something like:
34.0500569277541
To generate a random integer, convert the output from rand to an integer, as follows:
#!/usr/bin/perl use strict; use warnings; my $range = 100; my $random_number = int(rand($range)); print $random_number . "\n";
This program gives you an integer from 0 to 99 inclusive:
68
To generate a random number between, for example, 100 and 150, simply work out the range and add the minimum value to your random number.
#!/usr/bin/perl use strict; use warnings; my $range = 50; my $minimum = 100; my $random_number = int(rand($range)) + $minimum; print $random_number . "\n";
This program gives you:
129
You must be logged in to post a comment.