RE: Query in Perl Programming

2009-01-28 Thread S, Rajini (STSD)

Thanks Gunnar for the suggestions. 

In which version of perl is Parse module available. 

We have perl version 5.8.0 and parse module is not available. 

Rajini 


 

-Original Message-
From: Gunnar Hjalmarsson [mailto:nore...@gunnar.cc] 
Sent: Tuesday, January 27, 2009 7:42 PM
To: beginners@perl.org
Subject: Re: Query in Perl Programming 

S, Rajini (STSD) wrote:
 Hi,
 
 I am new to Perl Programming and have a query in perl. 
 
 In perl is there any system defined functions to find out the 
 Differences in dates.
 
 Eg : 
 
 Date 1 - 26-Jan-2009
 Date 2 - 14-Jan-2009
 
 So the difference between two dates is 12 days. 
 
 Is there a way to achieve this with any system defined functions In 
 Perl 

It depends on what you mean by system defined functions. As 
others have told you, there are many CPAN modules that deal 
with date and time related tasks. Your particular problem can 
be easily solved using only a module that is included in the 
standard Perl distribution.

 use Date::Parse;

 my $time1 = str2time '26-Jan-2009';
 my $time2 = str2time '14-Jan-2009';

 print 'Difference: ',
   sprintf( '%.0f', ($time1-$time2)/86400 ),  days\n;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For 
additional commands, e-mail: beginners-h...@perl.org 
http://learn.perl.org/



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Query in Perl Programming

2009-01-28 Thread Rob Dixon
S, Rajini (STSD) wrote:
 From: Gunnar Hjalmarsson [mailto:nore...@gunnar.cc] 
 S, Rajini (STSD) wrote:

 I am new to Perl Programming and have a query in perl. 

 In perl is there any system defined functions to find out the 
 Differences in dates.

 Eg : 

 Date 1 - 26-Jan-2009
 Date 2 - 14-Jan-2009

 So the difference between two dates is 12 days. 

 Is there a way to achieve this with any system defined functions In 
 Perl 

 It depends on what you mean by system defined functions. As 
 others have told you, there are many CPAN modules that deal 
 with date and time related tasks. Your particular problem can 
 be easily solved using only a module that is included in the 
 standard Perl distribution.

 use Date::Parse;

 my $time1 = str2time '26-Jan-2009';
 my $time2 = str2time '14-Jan-2009';

 print 'Difference: ',
   sprintf( '%.0f', ($time1-$time2)/86400 ),  days\n;


 Thanks Gunnar for the suggestions. 
 
 In which version of perl is Parse module available. 
 
 We have perl version 5.8.0 and parse module is not available. 

(Please bottom-post your responses to this group. Thank you.)

As far as I know Gunnar is mistaken and Date::Parse is not a standard module in
any version of Perl. However Time::Local is, and you may be interested in the
solution below that uses it. If your dates aren't guaranteed to be well-formed
then you may want to do some checking on them before you call the epoch_days
function.

HTH,

Rob


use strict;
use warnings;

use Time::Local;

my $days1 = epoch_days('26-Jan-2009');
my $days2 = epoch_days('14-Jan-2009');

print Difference: @{[$days1 - $days2]} days\n;

BEGIN {

  my %month_num = do {
my $n = 1;
map(($_, $n++), qw/jan feb mar apr may jun jul aug sep oct nov dec/);
  };

  sub epoch_days {

my @dmy = split /-/, shift;
$dmy[1] = $month_num{lc $dmy[1]} || 0;

return timelocal(0, 0, 0, @dmy) / (24 * 60 * 60);
  }
}

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: removing an arbitrary element from array

2009-01-28 Thread Sharan Basappa
On Sun, Dec 7, 2008 at 2:01 AM, Rob Dixon rob.di...@gmx.com wrote:
 Sharan Basappa wrote:

 I was wondering if there is a quick way to remove an arbitrary element
 from an array.
 I have an array which stores _ delimited strings a_b_c_1). The last
 string stores the rank of the string.
 I have to remove a string from array that has the lowest number.

 e.g. a_b_c_1, a_b_c_2. In this case, a_b_c_2 should be removed. The
 strings are not arranged in any
 specific order in the array.

 I'm hoping you've made a mistake, because if I understand you correctly then 
 out
 of ('a_b_c_1', 'a_b_c_2') the first should be removed because 1 is less than 
 two.

 If I'm right then the program below should be useful.

 HTH,

 Rob



 use strict;
 use warnings;

 my @data = qw/
  a_b_c_99
  a_b_c_6
  a_b_c_1
  a_b_c_2
  a_b_c_22
 /;

 my ($idx, $min_seq);
 foreach (0 .. $#data) {
  my ($seq) = $data[$_] =~ /(\d+)$/;
  next if defined $idx and $seq  $min_seq;
  ($idx, $min_seq) = ($_, $seq);
 }

 splice @data, $idx, 1;


Hi Rob,

I have a question on this. I realized that I also need to save the
element that I am removing from
the array. Would this code work (should remove the element and save it
in the variable)
$removed_element = splice @data, $idx, 1

Regards

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: removing an arbitrary element from array

2009-01-28 Thread Rob Dixon
Sharan Basappa wrote:
 On Sun, Dec 7, 2008 at 2:01 AM, Rob Dixon rob.di...@gmx.com wrote:

 I'm hoping you've made a mistake, because if I understand you correctly then 
 out
 of ('a_b_c_1', 'a_b_c_2') the first should be removed because 1 is less than 
 two.

 If I'm right then the program below should be useful.



 use strict;
 use warnings;

 my @data = qw/
  a_b_c_99
  a_b_c_6
  a_b_c_1
  a_b_c_2
  a_b_c_22
 /;

 my ($idx, $min_seq);
 foreach (0 .. $#data) {
  my ($seq) = $data[$_] =~ /(\d+)$/;
  next if defined $idx and $seq  $min_seq;
  ($idx, $min_seq) = ($_, $seq);
 }

 splice @data, $idx, 1;

 
 I have a question on this. I realized that I also need to save the element
 that I am removing from the array. Would this code work (should remove the
 element and save it in the variable)

 $removed_element = splice @data, $idx, 1

Exactly right. Yes.

Rob

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: removing an arbitrary element from array

2009-01-28 Thread Sharan Basappa
Thank you ...

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Query in Perl Programming

2009-01-28 Thread Gunnar Hjalmarsson

Rob Dixon wrote:

S, Rajini (STSD) wrote:
From: Gunnar Hjalmarsson [mailto:nore...@gunnar.cc] 
Your particular problem can 
be easily solved using only a module that is included in the 
standard Perl distribution.


use Date::Parse;

my $time1 = str2time '26-Jan-2009';
my $time2 = str2time '14-Jan-2009';

print 'Difference: ',
  sprintf( '%.0f', ($time1-$time2)/86400 ),  days\n;

Thanks Gunnar for the suggestions. 

In which version of perl is Parse module available. 

We have perl version 5.8.0 and parse module is not available. 


(Please bottom-post your responses to this group. Thank you.)

As far as I know Gunnar is mistaken and Date::Parse is not a standard module in
any version of Perl.


Obviously I am; Sorry about that. (It happened to be included in both 
the distributions I am currently working with.)


Still easy to install, of course. ;-)

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Help with modules and objects

2009-01-28 Thread Bill
On Jan 26, 1:36 pm, wpflu...@yahoo.com (Bill) wrote:
 I'm not a beginner with perl but all of my previous stuff has been
 simple and I've never really used modules, until now.  I'm working on
 a program that has to receive a mime encoded email and pull info out
 of it.  I'm using Email::Simple and Email:MIME and I can read the
 emails fine but I'm having problems accessing the 'parts' of the email
 without just dumping the entire message to a raw format in a variable
 and string searching it for what I want.  My problem is that I'm not
 sure how to 'use' the data objects returned by the module.  My example
 is that I  get a message in using NET::POP3 and make it into a string
 using join and then I pass the string into Email::MIME and make a new
 object?? out of it I can check the subject of the main message using 
 -header_pairs and then pulling the subject out of the list it makes

 but there is a seconday subject because the emails I'm working on will
 be returned emails meaning they failed in getting through somehow and
 I need to pull the original subject line to find out some info.  I
 tried using -parts on it but here is where I'm stuck as I don't
 understand how to handle what I get back.  The docs say that parts
 pass back, and I quote:

 This returns a list of Email::MIME objects reflecting the parts of
 the message.

 I'm just not sure how I go about pulling the info out of the three
 hash?? references??  I'm getting back.

 Can anyone point me in the right direction?

 Thanks

Well I kinda figured out this part on my own, just had to feed back
the object through Email::MIME and got what I needed.  I need help on
another email problem but I'll start a new post for that.

Bill


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What does MakeFile do?

2009-01-28 Thread Lewis Kirk
Which is obviously a real beginner question. I have googled around, but all 
the info I have found assumes you have access to the server.

My sites are shared hosting accounts located at Earthlink, Verio, GoDaddy, 
etc. I have used a number of scripts which I can use just by ftp uploading 
text files and changing permissions. Now I have a script (a module actually) I 
would like to use which arrives as a package that needs to be installed with a 
MakeFile.PL

First, how can I install this module?


Well, I just copied the .pm files up to folders on the remote server and 
changed permissions. Before I had the folder organization wrong. In the calling 
file I used use lib '.'; to get the dependencies.

So my question still stands: What does MakeFile do that just copying the .pm 
files doesn't?

Thanks for your help.
-- 
Lewis Kirk
www.dmzgraphics.com
803-787-3450

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: What does MakeFile do?

2009-01-28 Thread Owen
Which is obviously a real beginner question. I have googled around,
 but all the info I have found assumes you have access to the server.

My sites are shared hosting accounts located at Earthlink, Verio,
 GoDaddy, etc. I have used a number of scripts which I can use just
by ftp uploading text files and changing permissions. Now I have a
script (a module actually) I would like to use which arrives as a
package that needs to be installed with a MakeFile.PL

First, how can I install this module?


 Well, I just copied the .pm files up to folders on the remote server
and changed permissions. Before I had the folder organization wrong.
In the calling file I used use lib '.'; to get the dependencies.

 So my question still stands: What does MakeFile do that just copying
the .pm files doesn't?



As I stated earlier, if the module is architecture dependent the make
builds against the architecture.


Also, you get the documentation with make, guess you cant do a
'perldoc module' with your installation. Of course, that may not
matter



Owen




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




perl stdout errors due to called script does not exist

2009-01-28 Thread inetquestion
for the example perl script below is there a way to avoid errors from
showing up in stdout if the shell script being called does not exist?
The shell script being called is not in the same directory as the perl
script, but is in the path.  Otherwise I would just do a check to see
if it exist before calling it. redirecting the output to /dev/null
doesn't seem to work.


#!/usr/bin/perl

`sm_timeline.sh $0 socket usage 2/dev/null`;
print hello\n;



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: perl stdout errors due to called script does not exist

2009-01-28 Thread Raymond Wan


Hi,

inetquestion wrote:

for the example perl script below is there a way to avoid errors from
showing up in stdout if the shell script being called does not exist?
The shell script being called is not in the same directory as the perl
script, but is in the path.  Otherwise I would just do a check to see
if it exist before calling it. redirecting the output to /dev/null
doesn't seem to work.

#!/usr/bin/perl

`sm_timeline.sh $0 socket usage 2/dev/null`;
print hello\n;



So, if you want to check to see if the file exists, then you just use the 
appropriate file test from here:

http://perldoc.perl.org/functions/-X.html

If you want to redirect stdout to /dev/null, then you will need:  1/dev/null.  
2 is stderr.  If you want both going to /dev/null, then:

1/dev/null 21

would send stderr to the same place you sent stdout.

Was this what you were looking for?

Ray



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




system(cd /home/tomer/temp) problem

2009-01-28 Thread tomer
after exectue the command system(cd /home/tomer/temp)
I dont see the terminal change the direcotry?
maybe the change is valid only in the script?
how can i control seeing terminal direcotry with perl script ?
Thanks
Tomer


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: system(cd /home/tomer/temp) problem

2009-01-28 Thread Raymond Wan


Hi Tomer,


tomer wrote:

after exectue the command system(cd /home/tomer/temp)
I dont see the terminal change the direcotry?
maybe the change is valid only in the script?
how can i control seeing terminal direcotry with perl script ?



system might not be what you want.  What it does is that it creates a new process in 
which to run your command (see http://perldoc.perl.org/functions/system.html); so that is 
one reason why you can't see the change.

If you want to change the directory, use perl's built-in function chdir:

http://perldoc.perl.org/functions/chdir.html

I think that is what you are looking for.

Ray


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




very basic questions

2009-01-28 Thread b chen
i am completely new to perl, can you explain to me the following line of
code in red.

how does this line of code grab a time value and assign it to $ time,

how does assigment happend in this conditiona statement.



while ()
{
 chop;
 # Grab the time
 next unless ($time) = /(\d+:\d+:\d+\,\d+)/;


Re: very basic questions

2009-01-28 Thread Owen
 i am completely new to perl, can you explain to me the following line
 of
 code in red.

 how does this line of code grab a time value and assign it to $ time,

 how does assigment happend in this conditiona statement.



 while ()
 {
  chop;
  # Grab the time
  next unless ($time) = /(\d+:\d+:\d+\,\d+)/;




I don't see any line in red :-(


I presume time is written in a format such as :MM:DD,HH ( eg
2009:01:29,15 )

/(\d+:\d+:\d+\,\d+)/ is therefore the regular expression that looks
for digits separated by colons and finally a comma

\d+: is any number of digits followed by a :

/(\d+:\d+:\d+\,\d+)/ will match 2009:01:29,15 but not 2009:01:29:15

Once a match is made, an assignment is made, otherwise  $time would be
undefined or the value of the last match



Owen


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: very basic questions

2009-01-28 Thread John W. Krahn

b chen wrote:

i am completely new to perl, can you explain to me the following line of
code in red.


There is no red here, there is only black and white.



how does this line of code grab a time value and assign it to $ time,

how does assigment happend in this conditiona statement.



while ()
{
 chop;


Better to use chomp instead of chop.



 # Grab the time
 next unless ($time) = /(\d+:\d+:\d+\,\d+)/;


The capturing parentheses in the regular expression return their 
contents in list context and the parentheses around the variable $time 
define a list context with a single lvalue.




John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




how to copy elements into the next array

2009-01-28 Thread itshardtogetone
Hi,
How do I copy the first 10 elements of @a into @b?

The method that I use is long :-
my @a = 1..20;
my @b = ();

my $ctr = 0;
foreach (@a){
 if ($ctr  10){
 push @b,$_;
 }
 $ctr ++;
}






Thanks.



回复:how to copy elements into the next array

2009-01-28 Thread yantao
try this,

@b[0..9] = @a[0..9];


- 原邮件 -
从: itshardtogetone itshardtoget...@hotmail.com
日期: 星期四, 一月 29日, 2009 下午2:39
主题: how to copy elements into the next array

 Hi,
 How do I copy the first 10 elements of @a into @b?
 
 The method that I use is long :-
 my @a = 1..20;
 my @b = ();
 
 my $ctr = 0;
 foreach (@a){
 if ($ctr  10){
 push @b,$_;
 }
 $ctr ++;
 }
 
 
 
 
 
 
 Thanks.
 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: how to copy elements into the next array

2009-01-28 Thread John W. Krahn

itshardtogetone wrote:

Hi,


Hello,


How do I copy the first 10 elements of @a into @b?


my @b = @a[ 0 .. 9 ];


John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Is there a way to un-install modules?

2009-01-28 Thread sanket vaidya
 
Hi,

There is no tool available to uninstall modules. However what you can do
manually is this.

I use Active Perl 5.10 on Windows.

1. Open the .packlist file in Perl/lib directory in any text editor. This
contains the path of all modules installed on your system (along with some
other entries as well).
2. Search module u want to remove in that file. (You will get the exact path
of all files related to the module).
3. Take the backup of all those files.
4. Navigate to the paths  remove files manually.
5. Check whether perl is working fine or not.
6. Remove the entry from .packlist

You can do the same with file equivalent to '.packlist' on 'LINUX' or
'UNIX'.

Hope this helps.

Thanks
Sanket Vaidya

-Original Message-
From: Randal L. Schwartz [mailto:mer...@stonehenge.com] 
Sent: Sunday, January 25, 2009 9:56 AM
To: beginners@perl.org
Subject: Re: Is there a way to un-install modules?

 Bruce == Bruce Ferrell bferr...@baywinds.org writes:

Bruce I know this is going to sound odd, but I've installed some 
Bruce modules using the CPAN module and I now want to uninstall them or 
Bruce put them into a state where they are no longer detected.  Is there a
way to do this?

The key thing to remember is that CPAN and CPANPLUS are installers, not
packagers.  As such, they do not ensure that a file that they are installing
belongs exclusively to the thing being installed.  Thus, if you blindly
remove everything that had been installed during a particular run, you could
end up with a broken system.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional
commands, e-mail: beginners-h...@perl.org http://learn.perl.org/


_ 

This e-mail message may contain proprietary, confidential or legally privileged 
information for the sole use of the person or entity to whom this message was 
originally addressed. Any review, e-transmission dissemination or other use of 
or taking of any action in reliance upon this information by persons or 
entities other than the intended recipient is prohibited. If you have received 
this e-mail in error kindly delete this e-mail from your records. If it appears 
that this mail has been forwarded to you without proper authority, please 
notify us immediately at netad...@patni.com and delete this mail.
_

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/