Changing row color with subroutine

2002-11-22 Thread Poster
Hi, I am having a little trouble with a sub that is using the modulus
operator.

It is called here-within a while loop:
while (my $row = $sth-fetchrow_hashref()) {
count++;
color_rows( $count )
--some other stuff
td bgcolor=$bgcolortable cell value/td
-some other stuff
}
--here is the sub
sub color_rows
{
my $num = @_;
my $bgcolor;

If ( $num % 2 == 0 ) {
$bgcolor=#bde6de;
} else {
$bgcolor=white;
}
return $bgcolor;
}#end sub

I expect that when the value that is passed in $count is even it will
set the row color green, otherwise it will set it to white. What it is
actually doing is setting the value white every time. 

Thanks.

Ramon Hildreth
---
[ www.subudusa.org ] [ www.subudseattle.org ]
[ www.ramonred.com ]




Re: Changing row color with subroutine

2002-11-22 Thread zentara
On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote:

Hi, I am having a little trouble with a sub that is using the modulus
operator.

Yeah, it fooled me too for a bit :-)
The problem is the way you pass the value to the
sub, @_ always is 1, the count of elements in @_.
Change @_ to @_[0]  or better yet $_[0]


It is called here-within a while loop:
while (my $row = $sth-fetchrow_hashref()) {
   count++;
   color_rows( $count )
   --some other stuff
   td bgcolor=$bgcolortable cell value/td
   -some other stuff
}
--here is the sub
sub color_rows
{
my $num = @_;

my $num = $_[0];

my $bgcolor;

If ( $num % 2 == 0 ) {
   $bgcolor=#bde6de;
} else {
   $bgcolor=white;
}
return $bgcolor;
}#end sub

I expect that when the value that is passed in $count is even it will
set the row color green, otherwise it will set it to white. What it is
actually doing is setting the value white every time. 

Thanks.

Ramon Hildreth
---
[ www.subudusa.org ] [ www.subudseattle.org ]
[ www.ramonred.com ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




arrays lists

2002-11-22 Thread Al Hospers
hi

I know I am missing a lot in my knowledge, but I'm trying to figure
something out  seemingly am in a hole...

the task is as follows:

1) query a mysql database for as many records as match a criteria
(I can do this OK)

2) put the resulting records, how ever many there are, into a list or an
array

3) count the number of records I have retrived
(I can do this OK)

4) choose a random record number
(I can do this)

5) get the record corresponding to the random record number from the array

6) get a particular field from the stored record

I am using DBI to get the data from the database. here is what I have so
far:

sub getRandomRecord{
  my $cgi = shift;
  my $dbh = shift;
  my $month = shift;
  my $day = shift;

  my $searchResult;
  my $returnValue;

   #prepare and execute SQL statement
$sqlstatement = SELECT * FROM $TABLE WHERE month like $month and day
like $day;
$sth = executeSQLStatement($sqlstatement, $dbh);

   $counter = 0;

   # put the records returned in an array/list  count how many
while ($searchResult = $sth-fetchrow_array() )
{
# get the 4th field from the record in the array  put it in the list
my @list = ($searchResult[3]);
 ++$counter;
   }

# pass the counter to the random integer routine  get a value back
my $randomNumber = getRandomNumber($counter);

$returnValue = @list[$randomNumber];

   # clean up the DBI
   $sth-finish();

   return $returnValue
   }




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




multiple selection

2002-11-22 Thread Mike(mickako)Blezien
Hello all,

having a problem with processing multiple selection from a scrolling list... 
first time working with tha scrolling list. Here is the test script I'm working 
with:
#!/usr/local/bin/perl
use CGI qw(:standard);

$action = param('action');

print header();
print start_html();
 if (!$action) {
print start_html();
print qq~
form method=POST action=/mailer/cgi/list.pl
input type=hidden name=action value=doit
font face=arial size=2BSelect List:/BP
~;
print scrolling_list(-name='list',
 -value=['List_1','List_2','List_3'],
 -default=['List_1'],
 -multiple=1);
print qq~
input type=submit value=Submit/form
~;
print end_html();
  } else {
  @lists = split(/ /,param('list'));
print qq|Total: @lists|;
  }

exit();

Now I thought that the @list array would store all the selected values from the 
list... but it doesn't, just one, even if all the items have been selected from 
the list... what am I missing here ??

thanks
--
MikemickaloBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://www.thunder-rain.com
Tel:  1(985)902-8484
MSN: [EMAIL PROTECTED]
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Changing row color with subroutine - a shortcut...

2002-11-22 Thread Peter Kappus
Another neat trick I use to get subroutine arguments is the old shift
function without an argument.

Since, @_ is the default array in a subroutine you can just say

my $firstParm = shift; #shift off the first arg from @_


Therefore, 

print add(30,50);

sub addTwo{
my $firstNum = shift;
my $secondNum = shift;
return $firstNum + $secondNum;
}

will print 80.  neato eh?

another fun trick if you have, say, 3 arguments is to say

my ($name, $size, $color) = @_;

this will map the first three args in your args array two the variables
$name, $size, and $color.

I hope this is useful...

-PK

-Original Message-
From: zentara [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 6:33 AM
To: [EMAIL PROTECTED]
Subject: Re: Changing row color with subroutine


On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote:

Hi, I am having a little trouble with a sub that is using the modulus
operator.

Yeah, it fooled me too for a bit :-)
The problem is the way you pass the value to the
sub, @_ always is 1, the count of elements in @_.
Change @_ to @_[0]  or better yet $_[0]

--here is the sub
sub color_rows
{
my $num = @_;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: arrays lists

2002-11-22 Thread Octavian Rasnita
First I need to tell you that I am not a MySQL specialist and my opinion
might be wrong butI think that:

1. You'll better use where day=$day and where month=$month because it works
faster than using the like operator.

2. I think MySQL has a function for returning random numbers, so you better
use that function instead.
It will return a single row that match a criteria from the database and not
a lot of records that need to be processed by Perl after that.
You might check MySQL documentation for finding out this function.

What you want, I think that it can be made with a single SQL line and you
will need to get the data from a single row using Perl.

Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message -
From: Al Hospers [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 11:03 PM
Subject: arrays  lists


hi

I know I am missing a lot in my knowledge, but I'm trying to figure
something out  seemingly am in a hole...

the task is as follows:

1) query a mysql database for as many records as match a criteria
(I can do this OK)

2) put the resulting records, how ever many there are, into a list or an
array

3) count the number of records I have retrived
(I can do this OK)

4) choose a random record number
(I can do this)

5) get the record corresponding to the random record number from the array

6) get a particular field from the stored record

I am using DBI to get the data from the database. here is what I have so
far:

sub getRandomRecord{
  my $cgi = shift;
  my $dbh = shift;
  my $month = shift;
  my $day = shift;

  my $searchResult;
  my $returnValue;

   #prepare and execute SQL statement
$sqlstatement = SELECT * FROM $TABLE WHERE month like $month and day
like $day;
$sth = executeSQLStatement($sqlstatement, $dbh);

   $counter = 0;

   # put the records returned in an array/list  count how many
while ($searchResult = $sth-fetchrow_array() )
{
# get the 4th field from the record in the array  put it in the list
my @list = ($searchResult[3]);
 ++$counter;
   }

# pass the counter to the random integer routine  get a value back
my $randomNumber = getRandomNumber($counter);

$returnValue = @list[$randomNumber];

   # clean up the DBI
   $sth-finish();

   return $returnValue
   }




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Changing row color with subroutine - a shortcut...

2002-11-22 Thread dirk van der Giesen
I rememeber sometimes doing something like this when
using CGI.pm and DBI.pm


push(@rows,td({-colspan='6',-bgcolor='#FF'},[$th]));

#blank row

$th = 'nbsp;';

push(@rows,td({-colspan='6',-bgcolor='#FF'},[$th]));

push(@rows,td({-bgcolor='#FFCC99'},['',b('Verwijderen:'),b('Naam:'),b('Voornaam:'),b('Vertegenwoordiger:*'),b('Bekijk
CV:')]));
while (@data = $cursor-fetchrow) {
$count++;
if ($count % 2 == 0){
$bgcolor = #FFCC99;
}else{
$bgcolor = #FF;
}

etc..

and then i the end i printed the table

$innertable = table({-border='0',-width='100%',
-cellspacing='1', -cellpadding='2',
-bgcolor='#FF'},Tr(\@rows));


I always founded this a very nice feature of CGI.pm.

The only thing i never found out is how you could
manipulate tables in this same kind of way ? 


Thanks,

Dirk



--- Peter Kappus [EMAIL PROTECTED] wrote:
 Another neat trick I use to get subroutine arguments
 is the old shift
 function without an argument.
 
 Since, @_ is the default array in a subroutine you
 can just say
 
 my $firstParm = shift; #shift off the first arg from
 @_
 
 
 Therefore, 
 
 print add(30,50);
 
 sub addTwo{
   my $firstNum = shift;
   my $secondNum = shift;
   return $firstNum + $secondNum;
 }
 
 will print 80.  neato eh?
 
 another fun trick if you have, say, 3 arguments is
 to say
 
 my ($name, $size, $color) = @_;
 
 this will map the first three args in your args
 array two the variables
 $name, $size, and $color.
 
 I hope this is useful...
 
 -PK
 
 -Original Message-
 From: zentara [mailto:[EMAIL PROTECTED]]
 Sent: Friday, November 22, 2002 6:33 AM
 To: [EMAIL PROTECTED]
 Subject: Re: Changing row color with subroutine
 
 
 On Fri, 22 Nov 2002 03:28:39 -0800,
 [EMAIL PROTECTED] (Poster) wrote:
 
 Hi, I am having a little trouble with a sub that is
 using the modulus
 operator.
 
 Yeah, it fooled me too for a bit :-)
 The problem is the way you pass the value to the
 sub, @_ always is 1, the count of elements in @_.
 Change @_ to @_[0]  or better yet $_[0]
 
 --here is the sub
 sub color_rows
 {
 my $num = @_;
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
 


__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space

2002-11-22 Thread John W. Krahn
Mariusz K wrote:
 
 Hi,

Hello,

 One part of my script ads several strings into one:
 $text = $part1.$part2.$part3.(...etc)
 
 However, if the part3 through part10 were empty I get that many white spaces
 at the end of $text. I thought the best thing would be just to remove the
 spaces at the end, but how? (maybe search and remove pattern?)

Why not use an array instead of ten separate scalars?  If the variable
is really empty it wouldn't print out as a space.

$ perl -e'
( $part1, $part2, $part3, $part4, $part5 ) = ( one, two, , undef,
five );
$text = $part1.$part2.$part3.$part4.$part5;
print $text\n;
'
onetwofive


How to remove whitespace at the end (or beginning) of a string is a
Frequently Asked Question.

perldoc -q How do I strip blank space from the beginning/end of a
string




John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: eval and alarm timeout for slow process (XML post)

2002-11-22 Thread NYIMI Jose (BMB)
 -Original Message-
 From: jeff loetel [mailto:[EMAIL PROTECTED]] 
 Sent: Friday, November 22, 2002 9:01 AM
 To: Perl beginners
 Subject: eval and alarm timeout for slow process (XML post)
 
 
 Does this look correct below. I know that I should test but 
 due to the environment that this program lives it is 
 difficult track down problems. It is a trigger off of a db. 
 Can anyone take a few seconds to provide feedback. Is there a 
 betterway? The problem that I am trying to solve here is a 
 slow connection or a server down. I am using LWP and set the 
 timeout feature but it never really seemed to catch the situation. 
 
 Any feedback is welcome.
 
 eval {
   local $SIG{ALRM} = sub { die timeout\n };
   alarm (60);   # 60 sec. timeout
 
   # XML POST stuff here   
 }
 
 alarm (0);

Try putting alarm(0) inside the eval block.

 if ($@ =~ /timeout/) {
 print STDERR $date_time XML POST timed out\n\n;
 exit;
 }

See code below from Oreilly Perl Cookbook.

 
 Jeff
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

This comes from Oreilly Perl Cookbook :

Problem
You want to make sure an operation doesn't take more than a certain amount of time. 
For instance, you're running filesystem backups and want to abort if it takes longer 
than an hour. Or, you want to schedule an event for the next hour.

Solution
To interrupt a long-running operation, set a SIGALRM handler to call die. Set an alarm 
with alarm, then eval your code:

$SIG{ALRM} = sub { die timeout };

eval{
alarm(3600);
# long-time operations here
alarm(0);
};
if($@){
if($@=~/timeout/){
# timed out; do what you will here
}else{
alarm(0);   # clear the still-pending alarm
die;# propagate unexpected exception
} 
}

José.


 DISCLAIMER 

This e-mail and any attachment thereto may contain information which is confidential 
and/or protected by intellectual property rights and are intended for the sole use of 
the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or 
partial reproduction, communication or distribution in any form) by other persons than 
the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by 
telephone or by e-mail and delete the material from any computer.

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at 
http://www.proximus.be or refer to any Proximus agent.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




random string

2002-11-22 Thread rpayal
Hi,
I am not at all familar to perl. I want to write a small perl script
which will print a random string of atleast 8 characters. This string I
intend to use as password for my application.
I don't know perl at all. perl is in /usr/local/bin/perl
The script when invovked like should print,

#perl randon_string.pl
AQs1QsaL

etc.
Can please someone help in this?
Thanks a lot and bye.
With regards.

-Payal
-- 
---
Contact :-  Linux Success Stories : -
payal at hotpop dot com   www.geocities.com/rpayal99
---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: random string

2002-11-22 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
 
 Hi,

Hello,

 I am not at all familar to perl. I want to write a small perl script
 which will print a random string of atleast 8 characters. This string I
 intend to use as password for my application.
 I don't know perl at all. perl is in /usr/local/bin/perl
 The script when invovked like should print,
 
 #perl randon_string.pl
 AQs1QsaL
 
 etc.
 Can please someone help in this?


# character set to choose from as per your example
my @chars = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
# pick eight random characters from the array
my $string = join '', map $chars[ rand @chars ], 1 .. 8;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Modulus operator, unexpected results

2002-11-22 Thread Poster
Hi, I am having a little trouble with a sub that is using the modulus
operator.

It is called here-within a while loop:
while (my $row = $sth-fetchrow_hashref()) {
count++;
color_rows( $count )
--some other stuff
td bgcolor=$bgcolortable cell value/td
-some other stuff
}
--here is the sub
sub color_rows
{
my $num = @_;
my $bgcolor;

If ( $num % 2 == 0 ) {
$bgcolor=#bde6de;
} else {
$bgcolor=white;
}
return $bgcolor;
}#end sub

I expect that when the value that is passed in $count is even it will
set the row color green, otherwise it will set it to white. What it is
actually doing is setting the value white every time. 

Thanks.

Ramon Hildreth

 
---
[ www.subudusa.org ] [ www.subudseattle.org ]
[ www.ramonred.com ]




Re: Modulus operator, unexpected results

2002-11-22 Thread Sudarshan Raghavan
On Fri, 22 Nov 2002, Poster wrote:

 Hi, I am having a little trouble with a sub that is using the modulus
 operator.
 
 It is called here-within a while loop:
 while (my $row = $sth-fetchrow_hashref()) {
   count++;
   color_rows( $count )
   --some other stuff
   td bgcolor=$bgcolortable cell value/td
   -some other stuff
 }
 --here is the sub
 sub color_rows
 {
 my $num = @_;

This statement assigns the number of elements in @_(no of arguments passed 
into the sub) into $num. In your case $num will always contain 1.

This should be 
my $num = $_[0];
or
my $num = shift;


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




book for perl ???

2002-11-22 Thread Sunil Sonnad
Hi all,
 Which book would make the gr8 reference for PERL ???
  
S.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: book for perl ???

2002-11-22 Thread Jerry M . Howell II
O'Riely puts out a book most of my perl friends call the cammel book.
Probably becuse of the cammel on the front cover, that would be my
recomendation


On Fri, 22 Nov 2002 17:23:41 +0530
Sunil Sonnad [EMAIL PROTECTED] wrote:

 Hi all,
   Which book would make the gr8 reference for PERL ???

  S.
 
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 


-- 
Jerry M. Howell II

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Fwd: Re: Declare $main::scalar in begin with 'use strict'

2002-11-22 Thread Paul Johnson

Dr. Poo said:

 This worked perfectly. Why the hell havn't i ever seen INIT before?

You haven't read perl5005delta?  INIT is still fairly new - CHECK is even
newer.  Their initial purpose was to help the compiler.

perldoc perlmod for the gory details.

 One more thing though. In my code, i *HAD* BEGIN and END preceded by the
 sub keyword...Would that have any ill effect to the program?

None whatsoever.

 had this --
   sub BEGIN

 In your code you have something like this (the {}'s are different)
   INIT

 So i then decided, hmm... i guess i don't need them on any of the
 pre-processor directive. And now i have this,

   BEGIN

 Any reason why to do one over the other?

Personal preference.  The desire for brevity.  Lack of disk space.  Dodgy
s on your keyboard.  Don't like too much SHOUTING.  ;-)

The Csub is optional and most people tend to leave it out.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: book for perl ???

2002-11-22 Thread papapep
Sunil Sonnad wrote:

Hi all,
 Which book would make the gr8 reference for PERL ???
  S.


1.- Programming Perl

2.- Learning Perl

Personally I prefer the second.

Take a look at amazon, for example.

Josep Sànchez
 [papapep]





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




outlook

2002-11-22 Thread Javeed SAR
Hi All,

I am working on win2000( outlook), i have a question,depending on the
message contents i need to do some further processing , is it possible to
automatically copy the contents of  the mail( i.e  body contents) to your
local drive or is it possible to take it in an array in PERL.


Regards 
j



Re: Modulus operator, unexpected results

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, Poster said:

Hi, I am having a little trouble with a sub that is using the modulus
operator.

No, your function is written incorrectly, and you don't use it correctly.

while (my $row = $sth-fetchrow_hashref()) {
   count++;
   color_rows( $count )
   --some other stuff
   td bgcolor=$bgcolortable cell value/td
   -some other stuff
}

sub color_rows {
my $num = @_;

First mistake is that line.  That assigns the NUMBER of elements in @_ to
$num.  Use one of the following methods:

  my $num = shift;
  # or
  my ($num) = @_;

my $bgcolor;

Your while loop can't see this variable.

if ( $num % 2 == 0 ) {
   $bgcolor=#bde6de;
} else {
   $bgcolor=white;
}
return $bgcolor;
}#end sub

If you're returning a value, USE it:

  while (...) {
my $bg = color_rows($count++);
print qq{td bgcolor=$bg.../td};
  }

There's no need for a function, though.

  while (...) {
my $bg = $count++ % 2 ? #bde6de : #ff;
# ...
  }

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: book for perl ???

2002-11-22 Thread Melanie Rouette
That would be Perl In a Nutshell. I also recommend it.

Jerry M. Howell II wrote:


O'Riely puts out a book most of my perl friends call the cammel book.
Probably becuse of the cammel on the front cover, that would be my
recomendation


On Fri, 22 Nov 2002 17:23:41 +0530
Sunil Sonnad [EMAIL PROTECTED] wrote:

 

Hi all,
 Which book would make the gr8 reference for PERL ???
  
S.





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



   



 





RE: Can perl read a word doc

2002-11-22 Thread Kipp, James
found this in a google seach, hth..
http://www.suite101.com/article.cfm/7977/89607

 -Original Message-
 From: Johnstone, Colin [mailto:[EMAIL PROTECTED]]
 Sent: Friday, November 22, 2002 12:26 AM
 To: '[EMAIL PROTECTED]'
 Subject: Can perl read a word doc
 
 
 Gidday all,
 
 Can I use Perl to open a word document ?
 
 Our press releases come to us as word docs, we cut and paste 
 the text into our cms(Interwoven Teamsite), and then publish 
 on the web.
 
 Im wondering if I can write some perl code so we can just 
 upload the document and perl will do the rest.
 
 Thank You
 Colin Johnstone 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




localtime

2002-11-22 Thread jonathan . musto
Hi all,
 
Does anyone know how to get the last six months into an array?
 
ive got: 
my $month = (split ' ', uc localtime)[1];
to get the current month and now i want to get the previous 5 months, is
there any way to perform arithmetic on the month value!??
 
Any help would be much appreciated, cheers.
 
Jonathan Musto

 

BT Ignite Solutions
Telephone - 0113 237 3277
Fax - 0113 244 1413
E-mail -  mailto:[EMAIL PROTECTED] [EMAIL PROTECTED]
http://www.technet.bt.com/sit/public http://www.technet.bt.com/sit/public 


British Telecommunications plc 
Registered office: 81 Newgate Street London EC1A 7AJ 
Registered in England no. 180 
This electronic message contains information from British Telecommunications
plc which may be privileged or  confidential. The information is intended to
be for the use of the individual(s) or entity named above. If you  are not
the intended recipient be aware that any disclosure, copying, distribution
or use of the contents of  this information is prohibited. If you have
received this electronic message in error, please notify us by  telephone or
email (to the numbers or address above) immediately.




 



How to find list of variables and sub routines loaded, dynamically.

2002-11-22 Thread sharan
Hello,

Is there any special variable which contains list of variable and sub
routines in current scope.  I would like to know dynamically if any and
release them, if i don't need them.
(similary to %INC, which contains list of loaded modules with their path).

Thanks
Sharan Hiremath



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to find list of variables and sub routines loaded, dynamically.

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, sharan said:

Is there any special variable which contains list of variable and sub
routines in current scope.  I would like to know dynamically if any and
release them, if i don't need them.

You can look through the %main:: hash to see the variables that exist in
the main:: package.  You don't need to release them, though.  You should
use properly scoped lexicals instead of globals.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: localtime

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, [EMAIL PROTECTED] said:

Does anyone know how to get the last six months into an array?

  my @mon = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );

my $month = (split ' ', uc localtime)[1];
to get the current month and now i want to get the previous 5 months, is
there any way to perform arithmetic on the month value!??

Don't get the month NAME.  Get the month NUMBER:

  my $mon = (localtime)[4];
  my @last_six_months = @mon[($mon-5) .. $mon];

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Starter of a script

2002-11-22 Thread Chris Browning
On Thursday 21 November 2002 03:21 am, cedric gross wrote:
 Hello every body,

 How to know what task have run a perl script ?
 I mean is possible to get within the code which process Id have start the
 script.

If you're running Linux or Unix, perl holds your environment variables in a 
hash; %ENV. Your process id number is $ENV{PID}. 

HTH,

Chris Browning
[EMAIL PROTECTED]

Hah!! -- James Brown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Starter of a script

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, Chris Browning said:

On Thursday 21 November 2002 03:21 am, cedric gross wrote:
 Hello every body,

 How to know what task have run a perl script ?
 I mean is possible to get within the code which process Id have start the
 script.

If you're running Linux or Unix, perl holds your environment variables in a
hash; %ENV. Your process id number is $ENV{PID}.

You can just use the $$ variable too.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: localtime

2002-11-22 Thread John W. Krahn
Jonathan Musto wrote:
 
 Hi all,

Hello,

 Does anyone know how to get the last six months into an array?
 
 ive got:
 my $month = (split ' ', uc localtime)[1];
 to get the current month and now i want to get the previous 5 months, is
 there any way to perform arithmetic on the month value!??

$ perl -le'
@mons = ( qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/ ) x 2;
$mon = (localtime)[4] + 12;
print @mons[$mon - 5 .. $mon]
'
Jun Jul Aug Sep Oct Nov



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




file not found : stat problem

2002-11-22 Thread Ben Crane
Hi list,

I've got a silly problem that for some reason I can't
work out..the following program goes through a txt
file that contain folder structures, e.g. j:\temp\ex\
I want the program too loop through the array, and
give me all the files within those directories and
their size...but sometimes it works, but most of the
time it just says:
can't stat etc and file not found...but I have used an
example of c:\temp (which does exist) and has files in
it...occasionally it works but mostly it doesn't...

Any reasons for why stat wouldn't work?
#!/perl/bin -w
use File::Find;
open (DLIST, c:/temp/dirlistforbatchcopy(pl).txt) ||
die opening log file: $!;
open (DEST, c:/temp/DirList.txt) || die opening
log file: $!;
@DLISTCONTENTS=DLIST;
sub getlist 
{
{
  print DEST $File::Find::name;
  print DEST (stat($File::Find::name))[7];
  print DEST \n;
}
}
foreach $dirvalue ( @DLISTCONTENTS ) 
{
  find(\getlist, $dirvalue);
}
close(DEST);
close(DLIST);

thanx
Ben

__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: localtime

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, John W. Krahn said:

@mons = ( qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/ ) x 2;
$mon = (localtime)[4] + 12;
print @mons[$mon - 5 .. $mon]

Why the double array?  (-5 .. 0) works just as well as (6 .. 11).

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to find list of variables and sub routines loaded, dynamically.

2002-11-22 Thread Peter Scott
In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Jeff 'Japhy' Pinyan) writes:
On Nov 22, sharan said:

Is there any special variable which contains list of variable and sub
routines in current scope.  I would like to know dynamically if any and
release them, if i don't need them.

You can look through the %main:: hash to see the variables that exist in
the main:: package.  You don't need to release them, though.  You should
use properly scoped lexicals instead of globals.

And those lexicals aren't visible in %main::.  You need the PadWalker module
from CPAN to list them.

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Starter of a script

2002-11-22 Thread Paul Johnson

Jeff japhy Pinyan said:
 On Nov 22, Chris Browning said:

On Thursday 21 November 2002 03:21 am, cedric gross wrote:
 Hello every body,

 How to know what task have run a perl script ?
 I mean is possible to get within the code which process Id have start
 the script.

If you're running Linux or Unix, perl holds your environment variables
 in a hash; %ENV. Your process id number is $ENV{PID}.

 You can just use the $$ variable too.

Good answers to the wrong quiestion ;-)

I think the requirement is to find the process id of the parent process. 
$ENV{PPID} might give you that (it does on Solaris 8 which doesn't have
$PID) or you might be able to find out by calling Cgetppid.

  perl -V:d_getppid

will tell you whether your perl supports this call.

  perldoc -f getppid

for what it's worth ;-)

[ Didn't someone already answer this?  Oh for a decent threaded webmail
thingy. ]

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




modification of stat problem

2002-11-22 Thread Ben Crane
Hi,

Sorry, I forgot to add this:

using file::find::name...what happens with folders
that have a space in them, e.g. f:\special
information\?

Is there a special way of dealing with that?

Ben

__
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




perl dbi

2002-11-22 Thread Christopher Burger
Hello,

I using the perl dbi and mysql and I was wondering if their was a load
command with this.  

The following statement works with php
  LOAD DATA LOCAL INFILE '$file_location' INTO TABLE $table FIELDS
TERMINATED BY ','

However I can not get the same command to work in perl.

Any answers would be appreciated.

Chris Burger



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space

2002-11-22 Thread Mariusz
Thank you for your response. I went to perldoc on the net and couldn't find
any examples or more info on -q space

Mariusz


- Original Message -
From: Sudarshan Raghavan [EMAIL PROTECTED]
To: Perl beginners [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 1:29 AM
Subject: Re: removing white space


 On Fri, 22 Nov 2002, Mariusz K wrote:

  Hi,
 
  One part of my script ads several strings into one:
  $text = $part1.$part2.$part3.(...etc)
 
  However, if the part3 through part10 were empty I get that many white
spaces
  at the end of $text. I thought the best thing would be just to remove
the
  spaces at the end, but how? (maybe search and remove pattern?)

 perldoc -q space


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space

2002-11-22 Thread Mariusz
Thanks for replying.
My text data comes from text fields so I read them through param and then in
one instance I combine them into one string. Therefore, I don't need to
remove all white spaces - only the ones at the end.

I tried to lookup the perldoc -q on the net but couldn't find anything?
(www.perldoc.com right?)

Mariusz


- Original Message -
From: John W. Krahn [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 2:50 AM
Subject: Re: removing white space


 Mariusz K wrote:
 
  Hi,

 Hello,

  One part of my script ads several strings into one:
  $text = $part1.$part2.$part3.(...etc)
 
  However, if the part3 through part10 were empty I get that many white
spaces
  at the end of $text. I thought the best thing would be just to remove
the
  spaces at the end, but how? (maybe search and remove pattern?)

 Why not use an array instead of ten separate scalars?  If the variable
 is really empty it wouldn't print out as a space.

 $ perl -e'
 ( $part1, $part2, $part3, $part4, $part5 ) = ( one, two, , undef,
 five );
 $text = $part1.$part2.$part3.$part4.$part5;
 print $text\n;
 '
 onetwofive


 How to remove whitespace at the end (or beginning) of a string is a
 Frequently Asked Question.

 perldoc -q How do I strip blank space from the beginning/end of a
 string




 John
 --
 use Perl;
 program
 fulfillment

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Last Wednesday of Month

2002-11-22 Thread Johnson, Shaunn

Howdy:

Can someone clue me in as to how I 
can get the last Wednesday (or whatever) 
of the month?

I have an example of what *might* work, but
I'm not sure how I can use it if, say, there 
are five  Wednesdays in the Month.  

[snip from code]
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Calc qw(:all);

my $month=(localtime())[4]+1;
my $year=(localtime())[5];
my $new_year=$year + 1900;

my @last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,4);
print @last_wednesday, \n\n;

[/snip code]

In the definition of @last_wednesday, if I change ($new_year, $month, 3, 4)
to ($new_year, $month, 3, 5), it could return nothing.  I'm not sure
how to test that.

Suggestions?

Thanks!

-X



RE: Last Wednesday of Month

2002-11-22 Thread Wagner, David --- Senior Programmer Analyst --- WGO
I took at the doc and it states that it comes back empty if not
valid.  So you could do something like:

@last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,5);   # start
w/ 5th wed of month
if (scalar(@last_wednesday)) { # if a value, then 5th wed exists
 }else {
  @last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,4);  # try
4th Wed
 }
   print @last_wednesday, \n\n;

Wags ;)
-Original Message-
From: Johnson, Shaunn [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 09:06
To: [EMAIL PROTECTED]
Subject: Last Wednesday of Month



Howdy:

Can someone clue me in as to how I 
can get the last Wednesday (or whatever) 
of the month?

I have an example of what *might* work, but
I'm not sure how I can use it if, say, there 
are five  Wednesdays in the Month.  

[snip from code]
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Calc qw(:all);

my $month=(localtime())[4]+1;
my $year=(localtime())[5];
my $new_year=$year + 1900;

my @last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,4);
print @last_wednesday, \n\n;

[/snip code]

In the definition of @last_wednesday, if I change ($new_year, $month, 3, 4)
to ($new_year, $month, 3, 5), it could return nothing.  I'm not sure
how to test that.

Suggestions?

Thanks!

-X


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Last Wednesday of Month

2002-11-22 Thread Johnson, Shaunn
--Looks great!

--Thanks!

-X

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 12:40 PM
To: Johnson, Shaunn; [EMAIL PROTECTED]
Subject: RE: Last Wednesday of Month


I took at the doc and it states that it comes back empty if not
valid.  So you could do something like:

@last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,5);   # start
w/ 5th wed of month
if (scalar(@last_wednesday)) { # if a value, then 5th wed exists
 }else {
  @last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,4);  # try
4th Wed
 }
   print @last_wednesday, \n\n;

Wags ;)
-Original Message-
From: Johnson, Shaunn [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 09:06
To: [EMAIL PROTECTED]
Subject: Last Wednesday of Month



Howdy:

Can someone clue me in as to how I 
can get the last Wednesday (or whatever) 
of the month?

I have an example of what *might* work, but
I'm not sure how I can use it if, say, there 
are five  Wednesdays in the Month.  

[snip from code]
#!/usr/bin/perl -w
use strict;
use warnings;
use Date::Calc qw(:all);

my $month=(localtime())[4]+1;
my $year=(localtime())[5];
my $new_year=$year + 1900;

my @last_wednesday = Nth_Weekday_of_Month_Year($new_year,$month,3,4);
print @last_wednesday, \n\n;

[/snip code]

In the definition of @last_wednesday, if I change ($new_year, $month, 3, 4)
to ($new_year, $month, 3, 5), it could return nothing.  I'm not sure
how to test that.

Suggestions?

Thanks!

-X


**
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.




RE: Last Wednesday of Month

2002-11-22 Thread Satya_Devarakonda

Hi,

In one of my scripts  I am trying to grep lines from a list that doesn't
have the word HOLD

@temp_str = grep ( {$_ ne /HOLD/}, @temp_str);

Can anybody help me on this.

Satya Devarakonda
IS - EDI
Tufts Health Plan
Tel: 617-923-5587 X 3413
Fax: 617-923-





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




avoid grepping a string

2002-11-22 Thread Satya_Devarakonda
Hi,

In one of my scripts  I am trying to grep lines from a list that doesn't
have the word HOLD

@temp_str = grep ( {$_ ne /HOLD/}, @temp_str);

Can anybody help me on this.

Satya Devarakonda
IS - EDI
Tufts Health Plan
Tel: 617-923-5587 X 3413
Fax: 617-923-






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: avoid grepping a string

2002-11-22 Thread Tanton Gibbs
I think you want
@temp_str = grep { $_ !~ /HOLD/ }, @temp_str;

or

@temp_str = grep { !/HOLD/ }, @temp_str;

- Original Message - 
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 1:02 PM
Subject: avoid grepping a string


 Hi,
 
 In one of my scripts  I am trying to grep lines from a list that doesn't
 have the word HOLD
 
 @temp_str = grep ( {$_ ne /HOLD/}, @temp_str);
 
 Can anybody help me on this.
 
 Satya Devarakonda
 IS - EDI
 Tufts Health Plan
 Tel: 617-923-5587 X 3413
 Fax: 617-923-
 
 
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: avoid grepping a string

2002-11-22 Thread Jeff 'japhy' Pinyan
On Nov 22, Tanton Gibbs said:

@temp_str = grep { $_ !~ /HOLD/ }, @temp_str;
@temp_str = grep { !/HOLD/ }, @temp_str;

No comma after the block.

  grep BLOCK LIST

or

  grep EXPR, LIST

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Perl MySQL (SELECT)

2002-11-22 Thread Mariusz
A while ago I asked for help on the following:

 I would like to be able to select records from the a table where record_id
 and $record_id from my @record_ids matches. I know I could go through a
loop
 and send a SELECT query for each element in the array but is there a
better
 way? How can I accomplish the same but only sending one query?

One of the responses was the following solution:

@record_ids = param ('record_ids');

my $sql = qq{SELECT ad_id, text, life FROM $table WHERE ad_id in(' .
join(',',@record_ids) . ')};

then execute the $sql only once


However that doesn't find any records, any obvious mistakes in my sql
statement that you can notice?


thanks a lot,
M


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Perl MySQL (SELECT)

2002-11-22 Thread wiggins


On Fri, 22 Nov 2002 11:56:44 -0600, Mariusz [EMAIL PROTECTED] wrote:

 A while ago I asked for help on the following:
 
  I would like to be able to select records from the a table where record_id
  and $record_id from my @record_ids matches. I know I could go through a
 loop
  and send a SELECT query for each element in the array but is there a
 better
  way? How can I accomplish the same but only sending one query?
 
 One of the responses was the following solution:
 
 @record_ids = param ('record_ids');
 
 my $sql = qq{SELECT ad_id, text, life FROM $table WHERE ad_id in(' .
 join(',',@record_ids) . ')};
 
 then execute the $sql only once
 
 
 However that doesn't find any records, any obvious mistakes in my sql
 statement that you can notice?
 
 
 thanks a lot,
 M
 

In your original post you said where record_id but in your select statement you have 
ad_id in should this be record_id in??

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread david
Tom Allison wrote:

 How do I export a Constant from a module?
 
 Test.pm:
 
 package Test;
 
 @EXPORT_OK = qw(__what__);
 use constant FOO = 123;
 

name the following Test.pm:

#!/usr/bin/perl -w
use strict;

package Test;

use Exporter;
our @EXPORT_OK = qw(HI);

use constant HI = 'Hi I am a constant in Test.pm';

1;

__END__

name the following test.pl:

#!/usr/bin/perl -w
use strict;

use Test qw(HI);

print TEST::HI,\n;

__END__

prints:

Hi I am a constant in Test.pm

that's what you want right?

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
Will print HI; not work...you would think you wouldn't have to qualify it if
you import it into your namespace?
- Original Message -
From: david [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 3:32 PM
Subject: Re: exporting Constants


 Tom Allison wrote:

  How do I export a Constant from a module?
 
  Test.pm:
 
  package Test;
 
  @EXPORT_OK = qw(__what__);
  use constant FOO = 123;
 

 name the following Test.pm:

 #!/usr/bin/perl -w
 use strict;

 package Test;

 use Exporter;
 our @EXPORT_OK = qw(HI);

 use constant HI = 'Hi I am a constant in Test.pm';

 1;

 __END__

 name the following test.pl:

 #!/usr/bin/perl -w
 use strict;

 use Test qw(HI);

 print TEST::HI,\n;

 __END__

 prints:

 Hi I am a constant in Test.pm

 that's what you want right?

 david

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Hi all, question about caracter detection

2002-11-22 Thread Miguel Angelo
Hi All, 

thankx for the help (Sudarshan Raghavan and Beau E.
Cox), i have found a generic solution

here is the sample script...
#

#!/usr/bin/perl -wT

##
# modules
##
use strict ;


##
# Global Variables
##


#
# will recive a string are check agains a list of
allowed values
# Will return : 0 if only allowed chars were found
#   1 if at least one invalid char is
found 
sub check_string { 

unless ( $_[0] =~ m/[^a-zA-Z0-9]/ ) {

return 0;
}

return 1; 
}

##
# Main
##
my $STRING = askdnj\nasj;

print \n(0 is ok, 1 means invalid chars) : ;
print check_string($STRING);
print \n;


###


Stay well all
Miguel Angelo





 

 --- Sudarshan Raghavan [EMAIL PROTECTED] wrote:
 On Mon, 18 Nov 2002, Beau E. Cox wrote:
 
  Hi -
  
  This will 'strip' all but a-zA-Z0-9:
  
  #!/usr/bin/perl
  
  use strict;
  use warnings;
  
  my $STRING = kjsh234Sd\nki;
  
  $STRING =~ s/[^a-zA-Z0-9]//sg;
  
  print $STRING\n;
  
  the ~ makes the character class negative, 
 
 I guess you meant ^, not ~
 
  the s makes
  the regex examine new lines, and g means global.
 
 You need an /s when you want . to match newlines
 (which it
 normally doesn't). In this case since you are not
 using a
 .., /s is not needed.
 
 $STRING =~ s/[^a-zA-Z0-9]//g;
 The above will work just fine
 
 You can also use tr/// for this
 $STRING =~ tr/a-zA-Z0-9//cd;
 
 If the OP just wants to check not replace either of
 these should
 do
 unless ($STRING =~ m/[^a-zA-Z0-9]/) {
# Valid STRING
 }
 
 or 
 
 unless ($STRING =~ tr/a-zA-Z0-9//c) {
# Valid STRING
 }
 
 
 
 
 -- 
 To unsubscribe, e-mail:
 [EMAIL PROTECTED]
 For additional commands, e-mail:
 [EMAIL PROTECTED]
  

=
*
* Miguel Angelo *
* E-mail: [EMAIL PROTECTED] *
* Domain: http://migas.mine.nu  *
*

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Hi all, question about caracter detection

2002-11-22 Thread Tanton Gibbs
You could also use

return $_[0] !~ m/[^a-zA-Z0-9]/;

or

return $_[0] =~ m/^[a-zA-Z0-9]+\Z/;

the last one is clearer to me because you eliminate all of the negatives.
- Original Message - 
From: Miguel Angelo [EMAIL PROTECTED]
To: Perl beginners [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 3:34 PM
Subject: RE: Hi all, question about caracter detection


 Hi All, 
 
 thankx for the help (Sudarshan Raghavan and Beau E.
 Cox), i have found a generic solution
 
 here is the sample script...
 #
 
 #!/usr/bin/perl -wT
 
 ##
 # modules
 ##
 use strict ;
 
 
 ##
 # Global Variables
 ##
 
 
 #
 # will recive a string are check agains a list of
 allowed values
 # Will return : 0 if only allowed chars were found
 #   1 if at least one invalid char is
 found 
 sub check_string { 
 
 unless ( $_[0] =~ m/[^a-zA-Z0-9]/ ) {
 
 return 0;
 }
 
   return 1; 
 }
 
 ##
 # Main
 ##
 my $STRING = askdnj\nasj;
 
 print \n(0 is ok, 1 means invalid chars) : ;
 print check_string($STRING);
 print \n;
 
 
 ###
 
 
 Stay well all
 Miguel Angelo
 
 
 
 
 
  
 
  --- Sudarshan Raghavan [EMAIL PROTECTED] wrote:
  On Mon, 18 Nov 2002, Beau E. Cox wrote:
  
   Hi -
   
   This will 'strip' all but a-zA-Z0-9:
   
   #!/usr/bin/perl
   
   use strict;
   use warnings;
   
   my $STRING = kjsh234Sd\nki;
   
   $STRING =~ s/[^a-zA-Z0-9]//sg;
   
   print $STRING\n;
   
   the ~ makes the character class negative, 
  
  I guess you meant ^, not ~
  
   the s makes
   the regex examine new lines, and g means global.
  
  You need an /s when you want . to match newlines
  (which it
  normally doesn't). In this case since you are not
  using a
  .., /s is not needed.
  
  $STRING =~ s/[^a-zA-Z0-9]//g;
  The above will work just fine
  
  You can also use tr/// for this
  $STRING =~ tr/a-zA-Z0-9//cd;
  
  If the OP just wants to check not replace either of
  these should
  do
  unless ($STRING =~ m/[^a-zA-Z0-9]/) {
 # Valid STRING
  }
  
  or 
  
  unless ($STRING =~ tr/a-zA-Z0-9//c) {
 # Valid STRING
  }
  
  
  
  
  -- 
  To unsubscribe, e-mail:
  [EMAIL PROTECTED]
  For additional commands, e-mail:
  [EMAIL PROTECTED]
   
 
 =
 *
 * Miguel Angelo *
 * E-mail: [EMAIL PROTECTED] *
 * Domain: http://migas.mine.nu  *
 *
 
 __
 Do You Yahoo!?
 Everything you'll ever need on one web page
 from News and Sport to Email and Music Charts
 http://uk.my.yahoo.com
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




howto: array index inside a foreach loop

2002-11-22 Thread Ken Lehman
Say I have a foreach loop that I used to modify elements when they match a
pattern that I am searching for, but there is one special case where I get a
match and I need the index for that element. Can I get that index or do I
have to go with a for() loop. If this can be done how would I use it?
Thanks in advance
Ken


# something along these lines
foreach $temp_string (@array_of_strings)
{
 if ($temp_string =~  /^CRASH/)
 {
   $array_of_strings[$this_is_what_I_need - 1] = LOOK OUT!;
 }


}



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space

2002-11-22 Thread david
Mariusz wrote:

 Thank you for your response. I went to perldoc on the net and couldn't
 find any examples or more info on -q space
 
 Mariusz
 
 

on your machine, try the following in the command line:

perldoc -q space

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: howto: array index inside a foreach loop

2002-11-22 Thread Tanton Gibbs
You need to use a for loop for this.
- Original Message -
From: Ken Lehman [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 3:42 PM
Subject: howto: array index inside a foreach loop


 Say I have a foreach loop that I used to modify elements when they match a
 pattern that I am searching for, but there is one special case where I get
a
 match and I need the index for that element. Can I get that index or do I
 have to go with a for() loop. If this can be done how would I use it?
 Thanks in advance
 Ken


 # something along these lines
 foreach $temp_string (@array_of_strings)
 {
  if ($temp_string =~  /^CRASH/)
  {
$array_of_strings[$this_is_what_I_need - 1] = LOOK OUT!;
  }


 }

 --
--
 
 The views and opinions expressed in this email message are the sender's
 own, and do not necessarily represent the views and opinions of Summit
 Systems Inc.


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: random string

2002-11-22 Thread david
[EMAIL PROTECTED] wrote:

 Hi,
 Thanks for the mails all.
 But I haven't got a sentence or even a word.
 Please, I am looking for a *script* which will print a random string.
 Please someone take trouble of putting the info. in a file so that I can
 cut-paste it.
 As, I said I know *nothing* of perl, nothing at all so all those
 my @chars = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 );
 etc. are pretty useless to me, unless they are in a script form.
 

why would you want to use Perl in the first place? no other alternatives?
your problem is straight forward and if you are not familiar with Perl, you 
might want to go with another language. i don't think it will be that hard 
right? c/c++? java? shell script?

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread david
Tanton Gibbs wrote:

 Will print HI; not work...you would think you wouldn't have to qualify it
 if you import it into your namespace?

the statement: 

print HI;

won't work. it's:

print Test::HI,\n;

that i have in the code. Otherwise, Perl thinks that you want to print $_ to 
the HI file handle.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
Ah, then what about
print HI, \n;

the comma should disambiguate from a filehandle, right?
- Original Message -
From: david [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 4:02 PM
Subject: Re: exporting Constants


 Tanton Gibbs wrote:

  Will print HI; not work...you would think you wouldn't have to qualify
it
  if you import it into your namespace?

 the statement:

 print HI;

 won't work. it's:

 print Test::HI,\n;

 that i have in the code. Otherwise, Perl thinks that you want to print $_
to
 the HI file handle.

 david

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread david
Tanton Gibbs wrote:

 Ah, then what about
 print HI, \n;
 

no. sorry! :-(

in that case, Perl probably thinks that you want to call the function HI and 
than print whatever that function return to STDOUT.

no such HI function so Perl will panic! :-)

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
Huh?  I thought constants were implemented as functions?  In other words, HI
and HI() should both refer to the same entity.
- Original Message -
From: david [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 4:06 PM
Subject: Re: exporting Constants


 Tanton Gibbs wrote:

  Ah, then what about
  print HI, \n;
 

 no. sorry! :-(

 in that case, Perl probably thinks that you want to call the function HI
and
 than print whatever that function return to STDOUT.

 no such HI function so Perl will panic! :-)

 david

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: howto: array index inside a foreach loop

2002-11-22 Thread david
Ken Lehman wrote:

 Say I have a foreach loop that I used to modify elements when they match a
 pattern that I am searching for, but there is one special case where I get
 a match and I need the index for that element. Can I get that index or do
 I have to go with a for() loop. If this can be done how would I use it?
 Thanks in advance
 Ken
 
 
 # something along these lines
 foreach $temp_string (@array_of_strings)
 {
  if ($temp_string =~  /^CRASH/)
  {
$array_of_strings[$this_is_what_I_need - 1] = LOOK OUT!;
  }
 
 
 }
 

sorry i might be missing your point but why not just:

#!/usr/bin/perl -w
use strict;

my @array_of_strings = qw(CRASH Windoes use linux);

s/^CRASH/LOOK OUT!/ for(@array_of_strings);

print join(\n,@array_of_strings),\n;

__END__

prints:

LOOK OUT!
windoes
use
linux

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread david
Tanton Gibbs wrote:

 Huh?  I thought constants were implemented as functions?  In other words,
 HI and HI() should both refer to the same entity.

true. but not in the your current namespace.

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: upgrading PPM

2002-11-22 Thread Clinton
Afraid of breaking something.
Clinton
http://www.mediamas.com.au/salesmine/default.htm
- Original Message - 
From: Timothy Johnson [EMAIL PROTECTED]
To: 'Clinton ' [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 6:42 PM
Subject: RE: upgrading PPM


 
 Why not just upgrade to ActivePerl 5.6.1 build 633?
 
 -Original Message-
 From: Clinton
 To: [EMAIL PROTECTED]
 Sent: 11/21/02 7:52 PM
 Subject: upgrading PPM
 
 On Win running 5.6.0 build 623- How do I upgrade my version of PPM 2.12
 to
 3.01
 Help appreciated
 Regards
 Clinton
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: howto: array index inside a foreach loop

2002-11-22 Thread Ken Lehman
yeah sorry, my problem is not quite as simple as the example. I just put
that in to try and illustrate my point. I'm not trying to do a straight
replace, I need to replace an element only if I find a certain string
somewhere else.

-Original Message-
From: david [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 4:12 PM
To: [EMAIL PROTECTED]
Subject: Re: howto: array index inside a foreach loop


Ken Lehman wrote:

 Say I have a foreach loop that I used to modify elements when they match a
 pattern that I am searching for, but there is one special case where I get
 a match and I need the index for that element. Can I get that index or do
 I have to go with a for() loop. If this can be done how would I use it?
 Thanks in advance
 Ken
 
 
 # something along these lines
 foreach $temp_string (@array_of_strings)
 {
  if ($temp_string =~  /^CRASH/)
  {
$array_of_strings[$this_is_what_I_need - 1] = LOOK OUT!;
  }
 
 
 }
 

sorry i might be missing your point but why not just:

#!/usr/bin/perl -w
use strict;

my @array_of_strings = qw(CRASH Windoes use linux);

s/^CRASH/LOOK OUT!/ for(@array_of_strings);

print join(\n,@array_of_strings),\n;

__END__

prints:

LOOK OUT!
windoes
use
linux

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
Sure it is, because you imported it from Test...I tried the following
example and it worked fine

#In file THGTest.pm

package THGTest;
use Exporter;

our @ISA=qw(Exporter);
our @EXPORT_OK=qw(HI);

use constant HI = 'Hi, I am a constant.'

#in file test.pl
use THGTest qw(HI);

print HI, \n;

Two notes:
1.) In your original example, you didn't have the @ISA, which IIRC, is
necessary
2.) You should never create a Test.pm because perl already comes with
Test.pm

Tanton
- Original Message -
From: david [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 4:13 PM
Subject: Re: exporting Constants


 Tanton Gibbs wrote:

  Huh?  I thought constants were implemented as functions?  In other
words,
  HI and HI() should both refer to the same entity.

 true. but not in the your current namespace.

 david

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
oops, left off a ; and a 1;

corrections below.
- Original Message - 
From: Tanton Gibbs [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 4:44 PM
Subject: Re: exporting Constants


 Sure it is, because you imported it from Test...I tried the following
 example and it worked fine
 
 #In file THGTest.pm
 
 package THGTest;
 use Exporter;
 
 our @ISA=qw(Exporter);
 our @EXPORT_OK=qw(HI);
 
 use constant HI = 'Hi, I am a constant.'
should be 
use constant HI = 'Hi, I am a constant.';

1;
 
 #in file test.pl
 use THGTest qw(HI);
 
 print HI, \n;
 
 Two notes:
 1.) In your original example, you didn't have the @ISA, which IIRC, is
 necessary
 2.) You should never create a Test.pm because perl already comes with
 Test.pm
 
 Tanton
 - Original Message -
 From: david [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, November 22, 2002 4:13 PM
 Subject: Re: exporting Constants
 
 
  Tanton Gibbs wrote:
 
   Huh?  I thought constants were implemented as functions?  In other
 words,
   HI and HI() should both refer to the same entity.
 
  true. but not in the your current namespace.
 
  david
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: removing white space

2002-11-22 Thread John W. Krahn
Mariusz wrote:
 
 From: John W. Krahn [EMAIL PROTECTED]
 
  How to remove whitespace at the end (or beginning) of a string is a
  Frequently Asked Question.
 
  perldoc -q How do I strip blank space from the beginning/end of a
  string
 
 Thanks for replying.
 My text data comes from text fields so I read them through param and then in
 one instance I combine them into one string. Therefore, I don't need to
 remove all white spaces - only the ones at the end.
 
 I tried to lookup the perldoc -q on the net but couldn't find anything?
 (www.perldoc.com right?)

perldoc is a program that is installed on your computer when you
install Perl.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread david
Tanton Gibbs wrote:

 Sure it is, because you imported it from Test...I tried the following

No, you can call (or use the constant) it without full qualifying it doens't 
mean the function or the constant is in your namespace. as you said below, 
Perl has way of finding it from the Exporter interface. the function or 
constant still belongs to the package it's defined. when you import 
something, it only makes it available for you to use in your script. you 
don't need to fully qualify it because you said you are an 
Exporter(@ISA=qw(Exporter)). I don't use Exporter so I fully qualify it.

how about a little experiment?

#!/usr/bin/perl -w
use strict;

use THGTest qw(HI); #-- See I learn not to use Test :-) Thanks!

print $_: $::{$_}\n for(keys %::);

#--
#-- Now do this:
#--
print $_: $THGTest::{$_}\n for(keys %THGTest::);

__END__

for the first for(...):
see if you can find HI anywhere. You won't find it because it's not there! 
You still can use it but it doesn't belong to you.

for the second for(...):
you will see something like:
HI: *Model::HI

btw, @ISA=qw(Exporter) is not strictly neccessary but pretty much everyone 
agree it's a good thing to do for the reason mentioned above...

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: exporting Constants

2002-11-22 Thread Tanton Gibbs
Ah, I see the difference now.

I didn't realize that you could still do the export without being an
exporter.  With that distinction I understand.  HI is actually put into the
namespace if you are an exporter...if you are not, then HI remains in the
THGTest namespace.  Thanks for all you help in clarifying the issue.

Tanton
- Original Message -
From: david [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 5:12 PM
Subject: Re: exporting Constants


 Tanton Gibbs wrote:

  Sure it is, because you imported it from Test...I tried the following

 No, you can call (or use the constant) it without full qualifying it
doens't
 mean the function or the constant is in your namespace. as you said below,
 Perl has way of finding it from the Exporter interface. the function or
 constant still belongs to the package it's defined. when you import
 something, it only makes it available for you to use in your script. you
 don't need to fully qualify it because you said you are an
 Exporter(@ISA=qw(Exporter)). I don't use Exporter so I fully qualify it.

 how about a little experiment?

 #!/usr/bin/perl -w
 use strict;

 use THGTest qw(HI); #-- See I learn not to use Test :-) Thanks!

 print $_: $::{$_}\n for(keys %::);

 #--
 #-- Now do this:
 #--
 print $_: $THGTest::{$_}\n for(keys %THGTest::);

 __END__

 for the first for(...):
 see if you can find HI anywhere. You won't find it because it's not there!
 You still can use it but it doesn't belong to you.

 for the second for(...):
 you will see something like:
 HI: *Model::HI

 btw, @ISA=qw(Exporter) is not strictly neccessary but pretty much everyone
 agree it's a good thing to do for the reason mentioned above...

 david

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: removing white space

2002-11-22 Thread Mark Anderson
I tried to lookup the perldoc -q on the net but couldn't find anything?
(www.perldoc.com right?)

perldoc is software that generally is installed with perl.

perldoc.com has the same information, but doesn't have a way to use the
flags that the software version has.

The -q flag to perldoc searches the FAQs, so from www.perldoc.com, select
the FAQ index.  Using your browser to search for the string space on that
page leads to How do I strip blank space from the beginning/end of a
string? within perlfaq4.  If you click on the perlfaq4 link, and again
search on space, you get a link to that question, clicking on which gives
you
http://www.perldoc.com/perl5.8.0/pod/perlfaq4.html#How-do-I-strip-blank-spa
ce-from-the-beginning-end-of-a-string-
which I won't copy to hear because everyone should be able to find it now on
their own if they want to read it.

/\/\ark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




How to tally money datatype?

2002-11-22 Thread chris
I am retrieving rows with a money datatype from a database. These are
written to a file with 2 decimal places. I also keep a running total.
My problem is the total does not equal to the sum of details.

I have tried using 
$amount = sprintf('%.2f', $amount);
$total += $amount;

# do this after all tallying, just before writing to file
$total = sprintf('%.2f', $total);

How do I tally money with perl?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Last Wednesday of Month

2002-11-22 Thread Randal L. Schwartz
 Shaunn == Shaunn Johnson [EMAIL PROTECTED] writes:

Shaunn Can someone clue me in as to how I 
Shaunn can get the last Wednesday (or whatever) 
Shaunn of the month?

use Date::Manip;
print UnixDate(ParseDateString(last wed of oct 2002), %m/%d/%Y\n);

= 10/30/2002\n

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: random string

2002-11-22 Thread rpayal
Hi,
 why would you want to use Perl in the first place? no other alternatives?
Maybe, But I am not a coder at all.
 your problem is straight forward and if you are not familiar with Perl, you 
 might want to go with another language. i don't think it will be that hard 
 right? c/c++? java? shell script?
hehehehee, if I knew that then i would have made it myself. I know a bit
of shell scripting, but I never knew that one can generate random string
in shell.
Can you help me do it in perl?
My requirement is very very simple. To write a program which will
generate *just* a random string of say 8 characters. Characters allowed
will be - [a-z] [A-Z] [0-9]. Can it be done?
Thanks and bye.
-Payal

-- 
---
Contact :-  Linux Success Stories : -
payal at hotpop dot com   www.geocities.com/rpayal99
---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: extra characters return plus 0 in script

2002-11-22 Thread mike
On Fri, 2002-11-22 at 05:44, John W. Krahn wrote:
 Mike wrote:
  
  I'm getting confused - I have the following script
  
  open(DESK,gtkdoclist) or die cant open;
  @desk1=DESK;
  foreach $desk1 (@desk1){
  chomp $desk1;
  print $desk1\n;
  $gtkdoc1=system(grep -h gtk_doc_min_version= $desk1);
  chomp $desk1;
  print $gtkdoc1;
  

Solved the immediate problem but now from this script

#!/usr/bin/perl -w
open(DESK,gtkdoclist) or die cant open;
@desk1=DESK;
foreach $desk1 (@desk1){
print $desk1;
$desk3=$desk1;
$gtkdoc1=`grep gtk_doc_min_version= $desk1`;
chop $gtkdoc1;
chomp $gtkdoc1;
chomp $gtkdoc1;
print $gtkdoc1\n;
@gtkdoc2=split /=/, $gtkdoc1;
print $gtkdoc2[1]\n;
$gtkdoc3=$gtkdoc2[1];
$mult='10';
$gtkdoc4=$gtkdoc3 * $mult;# this is the error
print $gtkdoc3
$gtkdoc5=$gtkdoc1;


gives the following error

atk/configure.in
gtk_doc_min_version=0.6
0.6
Filehandle main::0.6 never opened at ./gtkdocchk line 17, DESK line
41.

as you can see (0.6) my var for calculation seems in scope but
calculation is not taking place
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: random string

2002-11-22 Thread Tanton Gibbs
You should look at the rand function

perldoc -f rand

also,

perldoc perlop

and look for the . operator and .= operator as well as the .. range
operator.

If that doesn't work, try asking your professor for help.

Tanton
- Original Message -
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 9:32 PM
Subject: Re: random string


 Hi,
  why would you want to use Perl in the first place? no other
alternatives?
 Maybe, But I am not a coder at all.
  your problem is straight forward and if you are not familiar with Perl,
you
  might want to go with another language. i don't think it will be that
hard
  right? c/c++? java? shell script?
 hehehehee, if I knew that then i would have made it myself. I know a bit
 of shell scripting, but I never knew that one can generate random string
 in shell.
 Can you help me do it in perl?
 My requirement is very very simple. To write a program which will
 generate *just* a random string of say 8 characters. Characters allowed
 will be - [a-z] [A-Z] [0-9]. Can it be done?
 Thanks and bye.
 -Payal

 --
 ---
 Contact :- Linux Success Stories : -
 payal at hotpop dot com www.geocities.com/rpayal99
 ---


 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: extra characters return plus 0 in script

2002-11-22 Thread John W. Krahn
Mike wrote:
 
 On Fri, 2002-11-22 at 05:44, John W. Krahn wrote:
  Mike wrote:
  
   I'm getting confused - I have the following script
  
   open(DESK,gtkdoclist) or die cant open;
   @desk1=DESK;
   foreach $desk1 (@desk1){
   chomp $desk1;
   print $desk1\n;
   $gtkdoc1=system(grep -h gtk_doc_min_version= $desk1);
   chomp $desk1;
   print $gtkdoc1;

Did you try the code that I posted here in my last reply?


 Solved the immediate problem but now from this script
 
 #!/usr/bin/perl -w
 open(DESK,gtkdoclist) or die cant open;
 ^^
You should include the actual file name and the $! variable in the error
message.


 @desk1=DESK;
 foreach $desk1 (@desk1){
 print $desk1;
^  ^
The quotation marks are not required as the print function will convert
everything it prints to a string.


 $desk3=$desk1;
 $gtkdoc1=`grep gtk_doc_min_version= $desk1`;

Do you understand what the backticks do in a scalar context?


 chop $gtkdoc1;
 chomp $gtkdoc1;
 chomp $gtkdoc1;

Do you understand what chop() and chomp() do?


 print $gtkdoc1\n;
 @gtkdoc2=split /=/, $gtkdoc1;
 print $gtkdoc2[1]\n;
 $gtkdoc3=$gtkdoc2[1];
 $mult='10';
 $gtkdoc4=$gtkdoc3 * $mult;# this is the error
 print $gtkdoc3
^
The actual error is here.  Something is missing.


 $gtkdoc5=$gtkdoc1;
 
 gives the following error
 
 atk/configure.in
 gtk_doc_min_version=0.6
 0.6
 Filehandle main::0.6 never opened at ./gtkdocchk line 17, DESK line
 41.
 
 as you can see (0.6) my var for calculation seems in scope but
 calculation is not taking place

That is because the result of the multiplication is stored in a
different variable then the one you are printing.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: How to tally money datatype?

2002-11-22 Thread John W. Krahn
Chris wrote:
 
 I am retrieving rows with a money datatype from a database. These are
 written to a file with 2 decimal places. I also keep a running total.
 My problem is the total does not equal to the sum of details.
 
 I have tried using
 $amount = sprintf('%.2f', $amount);
 $total += $amount;
 
 # do this after all tallying, just before writing to file
 $total = sprintf('%.2f', $total);
 
 How do I tally money with perl?

Assuming that you are tallying dollars like $12,345.67, convert to cents
(an integer) by removing all punctuation and convert back to dollars to
print the final total.

$ perl -le'
@dollars = qw/ $12,345.67 $11,555.99 $9,765.35 $432 $876.4 /;
for ( @dollars ) {
# add zeros for proper format
$_ .= .00 unless tr/.//;
$_ .= 0   unless /\.\d\d$/;
# remove non-digits
tr/0-9//cd;
$total += $_;
}
($total2 = $total) =~ s/(\d\d)$/.$1/;
printf %.2f\n, $total / 100;
print $total2;
'
34975.41
34975.41



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: extra characters return plus 0 in script

2002-11-22 Thread mike
On Sat, 2002-11-23 at 04:50, John W. Krahn wrote:
 Mike wrote:
  
  On Fri, 2002-11-22 at 05:44, John W. Krahn wrote:
   Mike wrote:
   
I'm getting confused - I have the following script
   
open(DESK,gtkdoclist) or die cant open;
@desk1=DESK;
foreach $desk1 (@desk1){
chomp $desk1;
print $desk1\n;
$gtkdoc1=system(grep -h gtk_doc_min_version= $desk1);
chomp $desk1;
print $gtkdoc1;
 
 Did you try the code that I posted here in my last reply?

I modified my code to use backticks, when the code worked up to that
point - thanks.

 
  Solved the immediate problem but now from this script
  
  #!/usr/bin/perl -w
  open(DESK,gtkdoclist) or die cant open;
  ^^
 You should include the actual file name and the $! variable in the error
 message.
 

I know I should (and would if the file handle was not being opened -
noting after this would work if it wasn't)

  @desk1=DESK;
  foreach $desk1 (@desk1){
  print $desk1;
 ^  ^
 The quotation marks are not required as the print function will convert
 everything it prints to a string.
 
 
  $desk3=$desk1;
  $gtkdoc1=`grep gtk_doc_min_version= $desk1`;
 
 Do you understand what the backticks do in a scalar context?
 

I think so - ie: feeding the result back to perl ($gtkdoc1 above)

  chop $gtkdoc1;
  chomp $gtkdoc1;
  chomp $gtkdoc1;
 
 Do you understand what chop() and chomp() do?
 

yep - just making sure

  print $gtkdoc1\n;
  @gtkdoc2=split /=/, $gtkdoc1;
  print $gtkdoc2[1]\n;
  $gtkdoc3=$gtkdoc2[1];
  $mult='10';
  $gtkdoc4=$gtkdoc3 * $mult;# this is the error
  print $gtkdoc3
 ^
 The actual error is here.  Something is missing.
 
 
  $gtkdoc5=$gtkdoc1;
  
  gives the following error
  
  atk/configure.in
  gtk_doc_min_version=0.6
  0.6
  Filehandle main::0.6 never opened at ./gtkdocchk line 17, DESK line
  41.
  
  as you can see (0.6) my var for calculation seems in scope but
  calculation is not taking place
 
 That is because the result of the multiplication is stored in a
 different variable then the one you are printing.
 

sorry about the typo in the last print. I am still trying to work out
where the error is coming from.

more errors follow to show more of what seems to be happening

glib/configure.in
gtk_doc_min_version=0.6
0.6
Filehandle main::6 never opened at ./gtkdocchk line 17, DESK line 41.
glib/configure
gtk_doc_min_version=0.6
0.6
Filehandle main::6 never opened at ./gtkdocchk line 17, DESK line 41.
gnome-panel/configure.in
gtk_doc_min_version=0.9
0.9
Filehandle main::9 never opened at ./gtkdocchk line 17, DESK line 41

The Filehandle main error seems to be referencing the first digit to the
right of the decimal point

As I understand it up to my problem is

I split $gtkdoc1 - OK
I print $gtkdoc2[1] - OK
I assign this to $gtkdoc3 -Ok
I print this to be sure (0.6 or 0.9 or 0.7 etc) -Ok

then I try to assign to gtkdoc4 a multiplication of $gtkdoc3 * $mult,
which is where it goes toes up

 
 John
 -- 
 use Perl;
 program
 fulfillment
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]