Alternative lookaheads in substitution, is it possible?

2007-01-20 Thread Michael Alipio
Hi,

Suppose I want to match all white spaces if it is followed by \w+= or not 
followed by date or time
:

$_ =~ s(/\s+(?=\w+=)/ || /\s+(?!(date|time)))/*/g;

Doesn't seem to do what I want.

Given a string:

Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15 msg=User admin login


I want it to produce something like:
Jan*19*11:37:21*firewall date=2007-01-19 time=11:42:15*msg=User admin 
login*log=3






 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

Re: Alternative lookaheads in substitution, is it possible? (SOLVED!!!)

2007-01-20 Thread Michael Alipio
Cool

I got this from approximately 71% perldoc perlre:

 print 5: got $1\n if $x =~ /^(\D*)(?=\d)(?!123)/;

so I don't need || between multiple look ahead assertions...

Sometimes, it's more rewarding to solve you're problem on your own.
You just have to RTFM.. :-)

More power to this helpful commmunity!!


- Original Message 
From: Michael Alipio [EMAIL PROTECTED]
To: begginers perl.org beginners@perl.org
Sent: Saturday, January 20, 2007 7:21:17 PM
Subject: Alternative lookaheads in substitution, is it possible?

Hi,

Suppose I want to match all white spaces if it is followed by \w+= or not 
followed by date or time
:

$_ =~ s(/\s+(?=\w+=)/ || /\s+(?!(date|time)))/*/g;

Doesn't seem to do what I want.

Given a string:

Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15 msg=User admin login


I want it to produce something like:
Jan*19*11:37:21*firewall date=2007-01-19 time=11:42:15*msg=User admin 
login*log=3






 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/






 

The fish are biting. 
Get more visitors on your site using Yahoo! Search Marketing.
http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php

Re: Alternative lookaheads in substitution, is it possible? (SOLVED!!!)

2007-01-20 Thread Mumia W.

On 01/20/2007 06:46 AM, Michael Alipio wrote:

Cool

I got this from approximately 71% perldoc perlre:

 print 5: got $1\n if $x =~ /^(\D*)(?=\d)(?!123)/;

so I don't need || between multiple look ahead assertions...

Sometimes, it's more rewarding to solve you're problem on your own.
You just have to RTFM.. :-)

More power to this helpful commmunity!!




Well if you like that, you're going to love this:

use strict;
use warnings;

my $string = 'Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15 
devname=TESTfirewall device_id=FGT-602905503304 log_id=0104032006
type=event subtype=admin pri=information vd=root user=admin 
ui=GUI(192.168.1.1) action=login status=success reason=none

msg=User admin login successfully from GUI(192.168.1.1)';

my %hash = $string =~ /(\w+)=([^]+|\S+)/g;
s/^()(.+)\1$/$2/ for (values %hash);

local $\ = \n;
print log_id = $hash{log_id};
print msg = $hash{msg};
print ui = $hash{ui};



:-)





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




Re: maximum file size for while(FILE) loop? - maybe HASH problem?

2007-01-20 Thread Tom Phoenix

On 1/19/07, Bertrand Baesjou [EMAIL PROTECTED] wrote:


While running my script it seems to use around a gigabyte of memory
(there is 1GB of RAM and 1GB of swap in the system), might this be the
problem?


If you're running low on memory, unless you're working on an
inherintly large problem, your algorithm is probably wasting some
memory.


foreach $line (INFILE) {
$somestorage{$linecounter}=$value;
$linecounter++;
}


Well, that builds a big hash for nothing. Unless you're trying to waste memory?


print $linecounter;


You should probably put a newline at the end of your output.


system(pwd) == 0 or die system failed: $?;



5198365system failed: 0 at ./sample1.pl line 22.


You're trying to run the command pwd, which seems to have failed.
The value of $? is zero though, which would normally indicate success.
Perhaps it's zero because the command couldn't be executed at all?
(Maybe low memory?) Does the pwd command normally work from
system()? (You're not comparing this pwd to the shell built-in, are
you?)

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Alternative lookaheads in substitution, is it possible? (SOLVED!!!)

2007-01-20 Thread I . B .

one more to remove spaces selectively:

$string =~ s/(\s+)(?:(?!date=|time=)(?=\w+=))/*/g;

cheers,
~i


On 1/20/07, Mumia W. [EMAIL PROTECTED] wrote:

On 01/20/2007 06:46 AM, Michael Alipio wrote:
 Cool

 I got this from approximately 71% perldoc perlre:

  print 5: got $1\n if $x =~ /^(\D*)(?=\d)(?!123)/;

 so I don't need || between multiple look ahead assertions...

 Sometimes, it's more rewarding to solve you're problem on your own.
 You just have to RTFM.. :-)

 More power to this helpful commmunity!!



Well if you like that, you're going to love this:

use strict;
use warnings;

my $string = 'Jan 19 11:37:21 firewall date=2007-01-19 time=11:42:15
devname=TESTfirewall device_id=FGT-602905503304 log_id=0104032006
type=event subtype=admin pri=information vd=root user=admin
ui=GUI(192.168.1.1) action=login status=success reason=none
msg=User admin login successfully from GUI(192.168.1.1)';

my %hash = $string =~ /(\w+)=([^]+|\S+)/g;
s/^()(.+)\1$/$2/ for (values %hash);

local $\ = \n;
print log_id = $hash{log_id};
print msg = $hash{msg};
print ui = $hash{ui};



:-)





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





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




putting ; as a replacement in the substitution.

2007-01-20 Thread Michael Alipio
Hi,

#I have this string:

my $string = 'vd=root,status=';

#Now, I want to transform it into:

'vd=root;status='

#That is replace the comma(,) between root and status with semicolon (;);


$string =~ s/vd=\w+(,)/;/;
print $string,\n;

#And it prints:

;status=

Can you tell me why it has ate up vd= as well?
And how to get around with it..


Thanks!







 

Get your own web address.  
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL

Re: putting ; as a replacement in the substitution.

2007-01-20 Thread Bill Jones

On 1/20/07, Michael Alipio [EMAIL PROTECTED] wrote:

my $string = 'vd=root,status=';
'vd=root;status='


$string =~ s[\,][\;]g;
--
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/
http://pgp.mit.edu:11371/pks/lookup?op=vindexsearch=0x2A46CF06fingerprint=on

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




Date and time

2007-01-20 Thread M. Lewis


Given the following code, if I were to want $day, $month, $hour, $minute 
 $sec to have a leading zero (ie 01 for Jan rather than 1), is my only 
option to use printf? Or is there a better way.


What I'm searching for here is the *correct* method to get $day, $month, 
etc for uses like naming backup files (databackup-2007-01-21.tar.gz).


Thanks,
Mike


#!/usr/bin/perl

use strict;
use warnings;

my($sec, $min, $hour, $day, $month, $year)=(localtime)[0 .. 5];

print day=$day\n;
print month=.($month+1).\n;
print year=.($year+1900).\n\n;
print hour=$hour\n;
print minute=$min\n;
print second=$sec\n\n;


--

 If I had it all to do over again, I'd spell creat with an e.  - 
Kernighan

  02:10:01 up 7 days, 12:47,  0 users,  load average: 0.49, 0.24, 0.15

 Linux Registered User #241685  http://counter.li.org

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




Re: putting ; as a replacement in the substitution.

2007-01-20 Thread Michael Alipio


- Original Message 
From: Bill Jones [EMAIL PROTECTED]
To: begginers perl.org beginners@perl.org
Sent: Sunday, January 21, 2007 1:03:33 PM
Subject: Re: putting ; as a replacement in the substitution.

On 1/20/07, Michael Alipio [EMAIL PROTECTED] wrote:
  my $string = 'vd=root,status=';
 ' vd=root;status='

 $string =~ s[\,][\;]g;

Oops, I only want to match the comma, right after vd=\w+..

My string might be:

'devid=234FB,vd=root,status=ok,logid=1235'

I tried replacing my delimiters with [ ] but still it eats up vd=\w+



-- 
WC (Bill) Jones -- http://youve-reached-the.endoftheinternet.org/
http://pgp.mit.edu:11371/pks/lookup?op=vindexsearch=0x2A46CF06fingerprint=on

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









 

We won't tell. Get more on shows you hate to love 
(and love to hate): Yahoo! TV's Guilty Pleasures list.
http://tv.yahoo.com/collections/265