|
|
Up |
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Feb 18, 2008 18:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.11: How do I get a random number between X and Y?
To get a random number between two values, you can use the "rand()"
built-in to get a random number between 0 and 1. From there, you shift
that into the range that you want.
"rand($x)" returns a number such that "0 <= rand($x) < $x". Thus what
you want to have perl figure out is a random number in the range from 0
to the difference between your *X* and *Y*.
That is, to get a number between 10 and 15, inclusive, you want a random
number between 0 and 5 that you can then add to 10.
my $number = 10 + int rand( 15-10+1 ); # ( 10,11,12,13,14, or 15 )
Hence you derive the following simple function to abstract that. It
selects a random integer between the two given integers (inclusive), For
example: "random_int_between(50,120)".
|
| Show full article (2.17Kb) |
|
| |
no comments
|
|
  |
Author: TelemachTelemach
Date: Feb 18, 2008 12:13
I'm newbie in Perl but don't give up so easily. My question is : Is it
possible to achieve my goals browsing just a xls file ? I know it's
good to convert to some better format but I would be happy if that
step is not necessary.
I have big Excel file which has over 20 worksheets.
What I need is to search for $value1 within the whole spreadsheet and
if found to search for $value2 within a worksheet where $value1 was
found. I know that cells have multi line input like :
ABCaaa
CDEbbb
EFGccc
etc.
so if $value2 = "CDE" I need Perl to get only CDEbbb and put under
$result1
next I want to read the col/row number of search result for $value2
and check the cell on two colums right from this one and copy the
content to $result2, if cell is blank I need to check
every single one above until cell with content is found
|
| Show full article (1.01Kb) |
|
| |
8 Comments |
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Feb 18, 2008 12:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.22: How do I expand function calls in a string?
(contributed by brian d foy)
This is documented in perlref, and although it's not the easiest thing
to read, it does work. In each of these examples, we call the function
inside the braces used to dereference a reference. If we have more than
one return value, we can construct and dereference an anonymous array.
In this case, we call the function in list context.
print "The time values are @{ [localtime] }.\n";
|
| Show full article (2.74Kb) |
|
no comments
|
|
  |
Author: oprah.chopraoprah.chopra
Date: Feb 18, 2008 11:20
I am using the following subroutine to calculate the number of days
since 1/1/2000 . Is there any possible bug in it? I know I can use
Date::Manip but it will slow down my program which is around 100 kb
long.
use strict;
use warnings;
my $days = &calc_days;
print "The number of days since 1/1/2000 is $days\n";
###############
sub calc_days {
my ( $mday, $mon, $year ) = ( localtime(time) )[3,4,5];
if ($mday < 10) { $mday = "0$mday"; }
$year += 1900;
# assign the Beginning date values
my ($MTH,$TDD,$YRW) = (1,1,2000);
my @TM = (31,28,31,30,31,30,31,31,30,31,30,31);
my $total_days = 0;
while ($MTH <= ($mon + 1) && $YRW == $year || $MTH <= 12 && $YRW <
$year) {
|
| Show full article (1.36Kb) |
|
58 Comments |
|
  |
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Feb 18, 2008 06:03
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.5: How do I convert between numeric representations/bases/radixes?
As always with Perl there is more than one way to do it. Below are a few
examples of approaches to making common conversions between number
representations. This is intended to be representational rather than
exhaustive.
Some of the examples later in perlfaq4 use the "Bit::Vector" module from
CPAN. The reason you might choose "Bit::Vector" over the perl built in
functions is that it works with numbers of ANY size, that it is
optimized for speed on some operations, and for at least some
programmers the notation might be familiar.
How do I convert hexadecimal into decimal
Using perl's built in conversion of "0x" notation:
$dec = 0xDEADBEEF;
|
| Show full article (5.00Kb) |
|
no comments
|
|
  |
Author: nazratnazrat
Date: Feb 18, 2008 03:07
i'd like to know if there's a way to get back the original hex values
of a unicode character.
ex:
my $u = "\x{20A3}";
my $h = pack(....., $u) ? so that $h is now a string '20A3'. thanks.
|
| |
|
1 Comment |
|
  |
Author: Ilias LazaridisIlias Lazaridis
Date: Feb 18, 2008 02:57
[RESEND of answer to all initial groups]
On 16 Öåâ, 15:45, Steve Holden holdenweb.com> wrote:
> Ilias Lazaridis wrote:
> [...]> Of course I'll not stay with trac, I'll leave the sinking ship, I've
>> prepare long time ago to do so, step by step. An will migrate step by
>> step away from trac and python - toward an own implementation based
>> on...
>> perl and it's libraries.
> I'm sure you will find the Perl community much more welcoming and
> receptive to your ideas about how open source projects should be run.
The perl projects can decide themselfs if they like to adopt the most
essential things:
http://case.lazaridis.com/wiki/Project
I do not analyze languages and communities anymore, thus there is no
need for them to 'worry', e.g. that I attemp to transform them to an
high evolutive language system.
Ruby and Python were excellent for this (Ruby = weak puppets, Python =
egoism driven).
|
| Show full article (3.41Kb) |
|
no comments
|
|
  |
|
|
  |
|
|
  |
Author: PerlFAQ ServerPerlFAQ Server
Date: Feb 18, 2008 00:03
This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
3.30: What's MakeMaker?
(contributed by brian d foy)
The "ExtUtils::MakeMaker" module, better known simply as "MakeMaker",
turns a Perl script, typically called "Makefile.PL", into a Makefile.
The unix tool "make" uses this file to manage dependencies and actions
to process and install a Perl distribution.
--------------------------------------------------------------------
|
| Show full article (1.30Kb) |
|
no comments
|
|
|
|
|