comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
February 2008
motuwethfrsasuw
    123 5
45678910 6
11121314151617 7
18192021222324 8
2526272829   9
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  FAQ 4.11 How do I get a random number between X and Y?         


Author: PerlFAQ 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
  Searching within XLS files - is it good approach ?         


Author: Telemach
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
  FAQ 4.22 How do I expand function calls in a string?         


Author: PerlFAQ 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
  Number of days since 1/1/2000         


Author: oprah.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
  LWP::UserAgent::request: Simple response: Not Found         


Author: Phil Powell
Date: Feb 18, 2008 08:09

I am using WWW::Mechanize to scrape from https://blah.foo.www.domain.com/main/index.html,
which is a secured site that can only be obtained via Netegrity
Siteminder-based authentication via https://blah.foo.www.domain.com/registration/login.html

So this is what normally happens if you go manually:

1) you type in https://blah.foo.www.domain.com/main/index.html
2) You are not detected to be logged in so you're automatically
redirected to https://blah.foo.www.domain.com/registration/login.html
3) You fill out an online form with your username and password
4) You submit, which takes you to https://blah.foo.www.domain.com/login/login.fcc
(Siteminder) which will check out your entry for authentication
5) You are successfully logged in, so on you to go
https://blah.foo.www.domain.com/main/index.html

I have a Perl script that should perform all steps 1 - 5, however it
breaks at 5, never getting to the intended URL due to receiving a 404
Object Not Found error, furthermore, in my LWP Debug statements I get
"LWP::UserAgent::request: Simple response: Not Found".

Here is how I'm trying to do it using Perl:

#!/strawberry/perl/bin/perl
Show full article (11.52Kb)
no comments
  FAQ 4.5 How do I convert between numeric representations/bases/radixes?         


Author: PerlFAQ 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
  unicode <-> hex         


Author: nazrat
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
  Re: TRAC - Trac, Project Leads, Python, and Mr. Noah Kantrowitz (sanitizer)         


Author: Ilias 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
  Parsing multi-line text         


Author: keith
Date: Feb 18, 2008 02:42

Hi all,

I have a data file structured something like this:
Show full article (0.89Kb)
7 Comments
  FAQ 3.30 What's MakeMaker?         


Author: PerlFAQ 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