This is weird: Pop works but shift doesn't

2005-04-05 Thread Harold Castro
Hi,
 I'm parsing a log file that contains this format:

1112677214 31388202 181264589
1112677214 8843 59460 8843 59460
1112676919 10728 59045 10728 59045
1112676900 10617 59006 10728 59045
1112676600 8693 58389 9531 59661




These logs are in unix timestamp format:
I'm trying to convert the first column into scalar
localtime.


Here's my code:

our @temp;
open FILE, ./logfile.txt or die $!;
while (FILE){
   foreach my $time(split/\s+/, $_){
 push @temp, $time;
   }
print shift @temp, \n;
}


... And the output:

1112677214
31388202
181264589
1112677214
8843
59460
8843
59460
1112676919
10728
59045
10728
59045
1112676900
10617
59006
10728
59045
1112676600
8693
58389
9531
59661

This is wiered, it didn't print the very first element
of @temp.

But if I were to change shift into pop:

our @temp;
open FILE, ./logfile.txt or die $!;
while (FILE){
   foreach my $time(split/\s+/, $_){
 push @temp, $time;
   }
print pop @temp, \n;
}


The output will be:

181264589
59460
59045
59045
59661

It seems to be working fine with pop. 

Any idea?

Thank you very much.
















__ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: This is weird: Pop works but shift doesn't

2005-04-05 Thread Thomas Bätzler
Harold Castro [EMAIL PROTECTED] wrote:
  I'm parsing a log file that contains this format:
 
 1112677214 31388202 181264589
 1112677214 8843 59460 8843 59460
 1112676919 10728 59045 10728 59045
 1112676900 10617 59006 10728 59045
 1112676600 8693 58389 9531 59661
 
 These logs are in unix timestamp format:
 I'm trying to convert the first column into scalar localtime.

Why not do it the simple way:

while( FILE ){
  s/^(\d+)/scalar localtime( $1 )/e;
  print;
}

or even simpler on the command line:

perl -pne 's/^(\d+)/scalar localtime( $1 )/e'

HTH,
Thomas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: This is weird: Pop works but shift doesn't

2005-04-05 Thread John W. Krahn
Harold Castro wrote:
Hi,
Hello,
 I'm parsing a log file that contains this format:
1112677214 31388202 181264589
1112677214 8843 59460 8843 59460
1112676919 10728 59045 10728 59045
1112676900 10617 59006 10728 59045
1112676600 8693 58389 9531 59661
These logs are in unix timestamp format:
I'm trying to convert the first column into scalar
localtime.
Here's my code:
our @temp;
Why use our(), do you really need a package variable?
open FILE, ./logfile.txt or die $!;
while (FILE){
   foreach my $time(split/\s+/, $_){
 push @temp, $time;
   }
No need for a loop there:
push @temp, split;

print shift @temp, \n;
}
... And the output:
1112677214
31388202
181264589
1112677214
8843
59460
8843
59460
1112676919
10728
59045
10728
59045
1112676900
10617
59006
10728
59045
1112676600
8693
58389
9531
59661
This is wiered, it didn't print the very first element
of @temp.
Probably because you are push()ing everything onto @temp so that the array 
grows for each iteration of the loop.  When you read the first line of the 
file you push (1112677214, 31388202, 181264589) onto @temp and then shift 
1112677214 off.  On the second line you push (1112677214, 8843, 59460, 8843, 
59460) onto @temp so it now contains (31388202, 181264589, 1112677214, 8843, 
59460, 8843, 59460) and then you shift 31388202 off.

If you only want the first column then use a list slice:
while ( FILE ) {
my $time = ( split )[ 0 ];
print $time\n;
}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: This is weird: Pop works but shift doesn't

2005-04-05 Thread N. Ganesh Babu
Dear All,
I have to convert these lines into individual part of name information 
with a single regular expression.

Input:
B. E. Conway,
J. O. M. Bockris
B. Conway
Output:
fnameB./fnamemnameE./mnamesurnameConway/surname
fnameJ./fnamemnameO./mname mnameM./mname 
surnameBockris/surname
fnameB./fname surnameConway/surname

Can anybody help me in getting the single regular expression.
Thanks for the help.
Regards,
Ganesh

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Newbie Regular expression question

2005-04-05 Thread N. Ganesh Babu
Dear All,
I have to convert these lines into individual part of name information 
with a single regular expression.

Input:
B. E. Conway,
J. O. M. Bockris
B. Conway
Output:
fnameB./fnamemnameE./mnamesurnameConway/surname
fnameJ./fnamemnameO./mname mnameM./mname 
surnameBockris/surname
fnameB./fname surnameConway/surname

Can anybody help me in getting the single regular expression.
Thanks for the help.
Regards,
Ganesh

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Newbie Regular expression question

2005-04-05 Thread John W. Krahn
N. Ganesh Babu wrote:
Dear All,
Hello,
I have to convert these lines into individual part of name information 
with a single regular expression.

Input:
B. E. Conway,
J. O. M. Bockris
B. Conway
Output:
fnameB./fnamemnameE./mnamesurnameConway/surname
fnameJ./fnamemnameO./mname mnameM./mname 
surnameBockris/surname
fnameB./fname surnameConway/surname

Can anybody help me in getting the single regular expression.

$ perl -le'
my @names = ( B. E. Conway, J. O. M. Bockris, B. Conway );
for my $name ( @names ) {
  print $name;
  $name =~ 
s!^(\S+)\s+((?:\S+\s+)*)(\S+)$!fname$1/fname@{[mapmname$_/mname,split 
,$2]}surname$3/surname!;
  print $name;
  }
'
B. E. Conway
fnameB./fnamemnameE./mnamesurnameConway/surname
J. O. M. Bockris
fnameJ./fnamemnameO./mname mnameM./mnamesurnameBockris/surname
B. Conway
fnameB./fnamesurnameConway/surname


John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Installing Downloaded Modules from CPAN

2005-04-05 Thread Joel Divekar
Hi All

I am using Activestate Perl Ver 5.8.4 under Windows 2k
and due to firewall I am not able to install packages
using ppm / ppm3. I have checked following doc but no
luck. Please advice. I am sorry if this point was
discussed earlier.

http://www.cpan.org/modules/INSTALL.html

Regards

Joel
Mumbai, India
9821421965

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




datetime comparisons

2005-04-05 Thread John
hello all

i am wondering a there is a module that do comparisons
between two different datetime stamps

for example

2/4/2005:15:20:20 and 4/4/2005:12:09:23

which date is bigger (namely earliest)





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




initialize arrays

2005-04-05 Thread DBSMITH
Are these two statements the same?

my (@array, @array1) = ( );

my @array = my @array1 = ( );



Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: datetime comparisons

2005-04-05 Thread Moon, John
Subject: datetime comparisons

hello all

i am wondering a there is a module that do comparisons
between two different datetime stamps

for example

2/4/2005:15:20:20 and 4/4/2005:12:09:23

which date is bigger (namely earliest)



You may wish to look at Time::Local. This will convert the strings to
seconds then they can be compared...

Hope this gives you some ideas...

jwm



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: initialize arrays

2005-04-05 Thread John Doe
Am Dienstag, 5. April 2005 15.32 schrieb [EMAIL PROTECTED]:
 Are these two statements the same?

 my (@array, @array1) = ( );

 my @array = my @array1 = ( );

let's try:

$ perl

use strict; use warnings;

my (@array, @array1) = ( );
my @brray = my @brray1 = ();
print @array ? 1 : 0,\n;
print @array1 ? 1 : 0,\n;
print @brray ? 1 : 0,\n;
print @brray1 ? 1 : 0,\n;

# this prints: 

0
0
0
0

joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: datetime comparisons

2005-04-05 Thread Peter Rabbitson
On Tue, Apr 05, 2005 at 04:12:31PM +0300, John wrote:
 hello all
 
 i am wondering a there is a module that do comparisons
 between two different datetime stamps
 
 for example
 
 2/4/2005:15:20:20 and 4/4/2005:12:09:23
 
 which date is bigger (namely earliest)
 

I was down this road some time ago myself - definitely DateTime by Dave
Rolsky. While it is not the most compact and not the fastest solution it has
it all. Saved me way too many time from reinventing the wheel. On the other
hand if your application is rather small and is guaranteed to stay small
(which is usually not the case) you might look into other possibilities like
simple numerical acrobatics with Time::Local (e.g. converting everything to
epoch seconds and working from there). 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: 1 at end of script

2005-04-05 Thread Peter Scott
On Sun, 03 Apr 2005 14:45:55 -0500, Dave Kettmann wrote:
 Nevermind I *just* figured it out. It is the exit code. Oops :)

No it isn't.  It is the result of printing the return value of a
subroutine whose last expression evaluated is a print() statement.

 $action = param('action');
   if   ( $action eq 'login' )   { print checkpw(); }
   else { print login(); }
[snip]
 
 sub checkpw {
 
   print Check password here ...\n;
 }

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


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: 1 at end of script

2005-04-05 Thread Peter Scott
On Sun, 03 Apr 2005 14:45:55 -0500, Dave Kettmann wrote:
 Nevermind I *just* figured it out. It is the exit code. Oops :)

It just occurred to me that perhaps by 'exit code' you meant 'return value
of the subroutine' instead of what 'exit code' normally means, the exit
code of the script, in which case you got the right answer, just the wrong
name for it.  Your problem is not the result of anything calling exit().

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


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: initialize arrays

2005-04-05 Thread Charles K. Clarkson
[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

: Are these two statements the same?
: 
: my (@array, @array1) = ( );
: 
: my @array = my @array1 = ( );

According to Data::Dumper the results are the same.

print Dumper [EMAIL PROTECTED], [EMAIL PROTECTED];


But then this has the same result.

my( @array, @array1 );


Why are you trying to initialize perl arrays?


Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: initialize arrays

2005-04-05 Thread DBSMITH
I am just playing with variable assign.  I always initialize my arrays
first as I need them.
thanks,

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



   
 Charles K.   
 Clarkson 
 [EMAIL PROTECTED]  To 
 .net beginners@perl.org
cc 
 04/05/2005 10:17  
 AMSubject 
   RE: initialize arrays   
   
   
   
   
   
   




[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:

: Are these two statements the same?
:
: my (@array, @array1) = ( );
:
: my @array = my @array1 = ( );

According to Data::Dumper the results are the same.

print Dumper [EMAIL PROTECTED], [EMAIL PROTECTED];


But then this has the same result.

my( @array, @array1 );


Why are you trying to initialize perl arrays?


Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: initialize arrays

2005-04-05 Thread Larsen, Errin M HMMA/IT
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, April 05, 2005 9:24 AM
 To: Charles K. Clarkson
 Cc: beginners@perl.org
 Subject: RE: initialize arrays
 

SNIP

 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote:
 
 : Are these two statements the same?
 :
 : my (@array, @array1) = ( );
 :
 : my @array = my @array1 = ( );
 
 According to Data::Dumper the results are the same.
 
 print Dumper [EMAIL PROTECTED], [EMAIL PROTECTED];
 
 
 But then this has the same result.
 
 my( @array, @array1 );
 
 
 Why are you trying to initialize perl arrays?
 
 
 Charles K. Clarkson
 --
 Mobile Homes Specialist
 254 968-8328
 

Hi everyone,

  this one made me wonder.  Isn't there a way to get Perl to print out
exactly how it evaluates the statements that are written?  If so, we
could use that to see what Perl does with those two different
assignments above.

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: initialize arrays

2005-04-05 Thread JupiterHost.Net

[EMAIL PROTECTED] wrote:
I am just playing with variable assign.  I always initialize my arrays
first as I need them.
Then of your two examples this makes the most sense;
my(@array,@array1);
but if you are simply doing:
my( @array, @array1 );
@array = foo();
@array1 = bar();
then it'd be much better to just do
my @array = foo();
my @array1 = bar();
unless you have a good reason that you can explain to my() them before 
you assign data to them, maybe something like this:

sub foobarize_list_into_arrayref {
   my @array;
   for(@_) { push @array, foobarize_string($_); }
   return [EMAIL PROTECTED];
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



XML::XPath query

2005-04-05 Thread Manish Sapariya
Hi List,
I doing XML for the first path and got the things as
I wanted using XPath. However only one thing I cannot
figure out is how do I get Telephone number in a separate
list. What the module returning to me is concatenated list
of Telephone number and I have to add extra delimiter   (space)
in my case. I do split on space and then reconstruct list out
of it.
Is there a way that this module will return me the list instead
of single object in concatenated form.
Thanks and Regards,
Manish
Here is my code.
-
#!/usr/bin/perl -w
use strict;
use XML::XPath;
my $xml = qq(
Instructions
   Agent
   Contacts
   Contact
   TelephoneNumbers
   TelephoneNumber
Type=Mobile 77/TelephoneNumber
   TelephoneNumber
Type=Home 8/TelephoneNumber
   TelephoneNumber
Type=Work 9/TelephoneNumber
   /TelephoneNumbers
   /Contact
   /Contacts
   Address/
   TelephoneNumbers
   TelephoneNumber 111/TelephoneNumber
   TelephoneNumber 222/TelephoneNumber
   /TelephoneNumbers
   /Agent
/Instructions
);
my $doc = XML::XPath- new(xml=$xml);
my @agents = $doc- findnodes('//Agent');
foreach my $agent (@agents) {
   print $agent- findvalue('TelephoneNumbers/TelephoneNumber'), \n;
}
-
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Installing Downloaded Modules from CPAN

2005-04-05 Thread Felix Geerinckx
On 05/04/2005, Joel Divekar wrote:

 I am using Activestate Perl Ver 5.8.4 under Windows 2k
 and due to firewall I am not able to install packages
 using ppm / ppm3. 

Open your ActivePerl HTML documentation and locate PPM in the
ActivePerl Components section of the TOC.
Scroll down to the PPM, Proxies and Firewalls paragraph. It's
explained there:

NOTE: If none of the changes in this document work for you, you may

download individual packages from here [ActivePerl 801 and later]
or
here [ActivePerl 613 and later] or here [ActivePerl 522 and
earlier]
and install them according to the directions in the README file 
contained within the ZIP file. If you want, you can also keep a 
local repository, with several .ppd files in a permanent repository 
directory, and their .tar.gz files in an x86 directory beneath that.

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Net::SSH::Perl bind socket problem

2005-04-05 Thread gui
added debug in the params. Can't find any real clue on what to do 
though, here's what I got :

ubuntu: Reading configuration data /home/gui/.ssh/config
ubuntu: Reading configuration data /etc/ssh_config
ubuntu: Allocated local port 1023.
ubuntu: Connecting to 192.168.0.1, port 22.
ubuntu: Remote protocol version 2.0, remote software version OpenSSH_3.9p1
ubuntu: Net::SSH::Perl Version 1.27, protocol version 2.0.
ubuntu: No compat match: OpenSSH_3.9p1.
ubuntu: Connection established.
ubuntu: Sent key-exchange init (KEXINIT), wait response.
ubuntu: Algorithms, c-s: 3des-cbc hmac-sha1 none
ubuntu: Algorithms, s-c: 3des-cbc hmac-sha1 none
ubuntu: Entering Diffie-Hellman Group 1 key exchange.
ubuntu: Sent DH public key, waiting for reply.
ubuntu: Received host key, type 'ssh-dss'.
ubuntu: Host '192.168.0.1' is known and matches the host key.
ubuntu: Computing shared secret key.
ubuntu: Verifying server signature.
ubuntu: Waiting for NEWKEYS message.
ubuntu: Enabling incoming encryption/MAC/compression.
ubuntu: Send NEWKEYS, enable outgoing encryption/MAC/compression.
ubuntu: Sending request for user-authentication service.
ubuntu: Service accepted: ssh-userauth.
ubuntu: Trying empty user-authentication request.
ubuntu: Authentication methods that can continue: 
publickey,password,keyboard-interactive.
ubuntu: Next method to try is publickey.
ubuntu: Trying pubkey authentication with key file '/home/gui/.ssh/id_rsa'
ubuntu: Login completed, opening dummy shell channel.
ubuntu: channel 0: new [client-session]
ubuntu: Requesting channel_open for channel 0.
ubuntu: channel 0: open confirm rwindow 0 rmax 32768
ubuntu: Got channel open confirmation, requesting shell.
ubuntu: Requesting service shell on channel 0.
ubuntu: channel 1: new [client-session]
ubuntu: Requesting channel_open for channel 1.
ubuntu: Entering interactive session.
ubuntu: Sending command: wget -q http://www.google.com
ubuntu: Requesting service exec on channel 1.
ubuntu: channel 1: open confirm rwindow 0 rmax 32768
ubuntu: input_channel_request: rtype exit-status reply 0
ubuntu: channel 1: rcvd eof
ubuntu: channel 1: output open - drain
ubuntu: channel 1: rcvd close
ubuntu: channel 1: input open - closed
ubuntu: channel 1: close_read
ubuntu: channel 1: obuf empty
ubuntu: channel 1: output drain - closed
ubuntu: channel 1: close_write
ubuntu: channel 1: send close
ubuntu: channel 1: full closed
ubuntu: Reading configuration data /home/gui/.ssh/config
ubuntu: Reading configuration data /etc/ssh_config
Net::SSH: Can't bind socket to port 1023: Adresse déjà utilisée at 
./test_ssh.pl line 50

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re[2]: datetime comparisons

2005-04-05 Thread John

From: Peter Rabbitson [EMAIL PROTECTED]
To: beginners@perl.org
Date: Tuesday, April 5, 2005, 5:03:09 PM
Subject: datetime comparisons



  Tuesday, April 5, 2005, 5:03:09 PM, you wrote:

   On Tue, Apr 05, 2005 at 04:12:31PM +0300, John wrote:
 hello all
 
 i am wondering a there is a module that do comparisons
 between two different datetime stamps
 
 for example
 
 2/4/2005:15:20:20 and 4/4/2005:12:09:23
 
 which date is bigger (namely earliest)
 

 I was down this road some time ago myself - definitely DateTime by Dave
 Rolsky. While it is not the most compact and not the fastest solution it has
 it all. Saved me way too many time from reinventing the wheel. On the other
 hand if your application is rather small and is guaranteed to stay small
 (which is usually not the case) you might look into other possibilities like
 simple numerical acrobatics with Time::Local (e.g. converting everything to
 epoch seconds and working from there). 



DateTime helped and me.

The comparison is made easy with two datetime objects.

Thanks



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Regular expression $1,$2,$3 ... in array ?

2005-04-05 Thread Michael Gale
Hello,

I have the following input as an example:

$_ = DATA;
servicedescr:Disk Usage
output:DISK OK - free space: / 21994 MB (76%): /boot 80 MB
(81%): /dev/shm 1732 MB (100%): /var/lib/mysql 200680 MB (43%):
perfdata: /=7071MB;23251;26157;0;29064 /boot=18MB;78;88;0;98 
/dev/shm=0MB;1384;1557;0;1731 /var/lib/mysql=268606MB;375428;422357;0;469286
DATA


Now, if I run this following regular expression against it:
/output:.*DISK.*-.free.space:.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%
\):.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%\):/


So two questions, 

1. I can simplify the above regexp by using groups correct ?
 /output:.*DISK.*-.free.space:(.(\S+).*MB.\((\d+)%\):){1,}/

2. It breaks it up into parts, $1,$2,$3,$4,  etc. Can I save the
parts into an array ?

Thanks.

Michael.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: XML::XPath query

2005-04-05 Thread Jesper Krogh
I gmane.comp.lang.perl.beginners, skrev Manish Sapariya:
  my $doc = XML::XPath- new(xml=$xml);
 
  my @agents = $doc- findnodes('//Agent');
 
  foreach my $agent (@agents) {
  print $agent- findvalue('TelephoneNumbers/TelephoneNumber'), \n;
  }

This seems to work here:

foreach my $agent (@agents) {   
foreach($agent-findnodes('TelephoneNumbers/TelephoneNumber')){
print $_-string_value() . \n;
}
} 

Jesper

-- 
./Jesper Krogh, [EMAIL PROTECTED], Jabber ID: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: initialize arrays

2005-04-05 Thread Offer Kaye
On Apr 5, 2005 4:29 PM, Larsen, Errin M HMMA/IT wrote:
 
 Hi everyone,
 
   this one made me wonder.  Isn't there a way to get Perl to print out
 exactly how it evaluates the statements that are written?  

Sure - the B modules, such as B::Debug and B::Concise.

 If so, we
 could use that to see what Perl does with those two different
 assignments above.
 

Seeing is one thing; understanding - that's quite another thing ;-)

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regular expression $1,$2,$3 ... in array ?

2005-04-05 Thread Offer Kaye
On Apr 5, 2005 5:53 PM, Michael Gale wrote:
 
 So two questions,
 
 1. I can simplify the above regexp by using groups correct ?
  /output:.*DISK.*-.free.space:(.(\S+).*MB.\((\d+)%\):){1,}/
 

Yes, you can simplify by using groups, but there's something wrong
with both your REs, IMHO. What exactly are you trying to capture from
the data? Your RE looks too complex to me. I think you are trying to
get the path name and percentage number, right? Well, here's one way:
   /(\/\S*).+?\((\d+)/sg
Note the s modifier - your data is multiline, so I need the s
modifier to make . match a newline.

 2. It breaks it up into parts, $1,$2,$3,$4,  etc. Can I save the
 parts into an array ?

Simply assign the result of the match to an array:
my @arr = /(\/\S*).+?\((\d+)/sg;

-- 
Offer Kaye

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Perl Socket Client for C++ Server

2005-04-05 Thread news-funsi
Hi there,

i have written a socket c++ server, which listens for clients and
understands   some commands. 
here the structs of the server commands:


enum command { SET_PRIO, CLEAR, SEND_STRING, SET_CURSOR, SHOW_CURSOR };

struct string_packet_t
{
  char str[DATA_LENGTH];
};

struct int_packet_t
{
  int data;
};

 
struct cmd_packet_t
{
  command type; 
  union
  {
int_packet_t int_pkg;
string_packet_t str_pkg;
  };
};

a c++ client would now send following command over the socket to the the
server:

  cmd_packet_t command;
  command.type=SEND_STRING;
  strcpy(command.str_pkg.str, Hello World);
  write(fd, command, sizeof(command);

with c/c++ all is working fine. 

The problem is the perl client. after setting up the socket i tried:

print SOCKET sprintf(%u%d, 0, 2)
# 0 For the first command == SET_PRIO, 2 for the argument
but the server receives no useable data.
(12848 for the command value, instead of 0 and
 1 for the integer argument)

any idea?

thank,

Simon Funke

-- 
Sparen beginnt mit GMX DSL: http://www.gmx.net/de/go/dsl

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: datetime comparisons

2005-04-05 Thread John W. Krahn
John wrote:
hello all
Hello,
i am wondering a there is a module that do comparisons
between two different datetime stamps
for example
2/4/2005:15:20:20 and 4/4/2005:12:09:23
which date is bigger (namely earliest)
Probably the easiest way is to convert them to comparable strings:
my ( $date1, $date2 ) = ( '2/4/2005:15:20:20', '4/4/2005:12:09:23' );
# I assume the date is m/d/y:h:m:s?
my $cmp1 = sprintf '%04d%02d%02d%02d%02d%02d', ( $date1 =~ /\d+/g )[ 
2,0,1,3,4,5 ];
my $cmp2 = sprintf '%04d%02d%02d%02d%02d%02d', ( $date2 =~ /\d+/g )[ 
2,0,1,3,4,5 ];

if ( $cmp1 gt $cmp2 ) {
do_something();
}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: initialize arrays

2005-04-05 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
Are these two statements the same?
my (@array, @array1) = ( );
my @array = my @array1 = ( );
$ perl -le'
my $x = q/my (@array, @array1) = ( );/;
my $y = q/my @array = my @array1 = ( );/;
print These two are , $x eq $y ?  : NOT , the same.;
'
These two are NOT the same.
All kidding aside, the first statement assigns everything in the right hand 
list to the first array (or hash) on the left and every variable after that 
receives nothing, but since my() has the same affect as assigning an empty 
list to an array or a hash the result is the same.
The second statement assigns an empty list to an empty array and the result of 
that is assigned to another empty array.


John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Regular expression $1,$2,$3 ... in array ?

2005-04-05 Thread John W. Krahn
Michael Gale wrote:
Hello,
Hello,
I have the following input as an example:
$_ = DATA;
servicedescr:Disk Usage
output:DISK OK - free space: / 21994 MB (76%): /boot 80 MB
(81%): /dev/shm 1732 MB (100%): /var/lib/mysql 200680 MB (43%):
perfdata: /=7071MB;23251;26157;0;29064 /boot=18MB;78;88;0;98 
/dev/shm=0MB;1384;1557;0;1731 /var/lib/mysql=268606MB;375428;422357;0;469286
DATA
Now, if I run this following regular expression against it:
/output:.*DISK.*-.free.space:.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%
\):.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%\):.(\S+).*MB.\((\d+)%\):/
So two questions, 

1. I can simplify the above regexp by using groups correct ?
 /output:.*DISK.*-.free.space:(.(\S+).*MB.\((\d+)%\):){1,}/
2. It breaks it up into parts, $1,$2,$3,$4,  etc. Can I save the
parts into an array ?
To answer your second question first, yes:
$ perl -le'
$_ = q/ 123  abc  4567  defgh /;
my @x = /(\w+)\s+(\w+)\s+(\w+)\s+(\w+)/;
print map $_  , @x;
'
123  abc  4567  defgh
As to your first question, it will MATCH the same string but it will not 
CAPTURE the same strings, it will only capture the contents of existing 
parentheses:

$ perl -le'
$_ = q/ 123  abc  4567  defgh /;
my @x = /^\s*((\w+)\s+){1,}\s*$/;
print map $_  , @x;
'
defgh  defgh

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Wide character in print?

2005-04-05 Thread Johnstone, Colin
Gidday all,

What does this error mean please?

**
Colin Johnstone
Independent Interwoven Teamsite Analyst Programmer (Contractor)
eGovernment Delivery Team
Department of Employment and Training
Phone   (07) 3244 6268
Fax (07) 3244 6265
Email   Colin.Johnstone mailto:[EMAIL PROTECTED]
Web www.trainandemploy.qld.gov.au
http://www.trainandemploy.qld.gov.au/
Address 417 Main Street, Kangaroo Point 4169, QLD, Australia.
**



This E-Mail is intended only for the addressee. Its use is limited to that
intended by the author at the time and it is not to be distributed without the
author's consent. Unless otherwise stated, the State of Queensland accepts no
liability for the contents of this E-Mail except where subsequently confirmed in
writing. The opinions expressed in this E-Mail are those of the author and do
not necessarily represent the views of the State of Queensland. This E-Mail is
confidential and may be subject to a claim of legal privilege.

If you have received this E-Mail in error, please notify the author
and delete this message immediately.

!DEPTSTAMP1!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Wide character in print?

2005-04-05 Thread John W. Krahn
Johnstone, Colin wrote:
Gidday all,
Hello,
What does this error mean please?
??  I assume that you mean the Subject line?
perldoc perldiag
[snip]
 Wide character in %s
 (W utf8) Perl met a wide character (255) when it wasn't expecting
 one.  This warning is by default on for I/O (like print).  The
 easiest way to quiet this warning is simply to add the :utf8 layer
 to the output, e.g. binmode STDOUT, ':utf8'.  Another way to turn
 off the warning is to add no warnings 'utf8'; but that is often
 closer to cheating.  In general, you are supposed to explicitly mark
 the filehandle with an encoding, see open and binmode in perlfunc.
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Wide character in print?

2005-04-05 Thread Johnstone, Colin
Thanks John,

For the explanation

I have done some debugging myself since posting, the character in
question turned out to be a hyphen that one of our content producers had
cut and paste from a word doc into our cms.

Regards
Colin

-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 6 April 2005 12:17 PM
To: Perl Beginners
Subject: Re: Wide character in print?

Johnstone, Colin wrote:
 Gidday all,

Hello,

 What does this error mean please?

??  I assume that you mean the Subject line?


perldoc perldiag
[snip]
  Wide character in %s
  (W utf8) Perl met a wide character (255) when it wasn't
expecting
  one.  This warning is by default on for I/O (like print).  The
  easiest way to quiet this warning is simply to add the :utf8
layer
  to the output, e.g. binmode STDOUT, ':utf8'.  Another way to
turn
  off the warning is to add no warnings 'utf8'; but that is
often
  closer to cheating.  In general, you are supposed to
explicitly mark
  the filehandle with an encoding, see open and binmode in
perlfunc.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



This E-Mail is intended only for the addressee. Its use is limited to that
intended by the author at the time and it is not to be distributed without the
author's consent. Unless otherwise stated, the State of Queensland accepts no
liability for the contents of this E-Mail except where subsequently confirmed in
writing. The opinions expressed in this E-Mail are those of the author and do
not necessarily represent the views of the State of Queensland. This E-Mail is
confidential and may be subject to a claim of legal privilege.

If you have received this E-Mail in error, please notify the author
and delete this message immediately.

!DEPTSTAMP1!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response