Re: Searching hash if a given value exists

2007-01-19 Thread Igor Sutton
Yes there is a faster way. Use the reverse function: my %hash = (dog = 'house', pig = 'barn', bird= 'cage'); my %rhash = reverse %hash; if ($rhash{house}) { print Found house.\n; } That's a really good looking idiom, but I see it is less efficient than the foreach

Re: Capturing stdout and stderr without redirection

2007-01-19 Thread Peter Scott
On Thu, 18 Jan 2007 20:28:42 -0600, David Moreno Garza wrote: On Thu, 2007-01-18 at 07:11 -0800, Peter Scott wrote: my $output = `myperlscript.pl 21`; send_email($output) if $output; Isn't send_email($output) in this situation still going to happen? I mean, even of there is not output on

Re: Searching hash if a given value exists

2007-01-19 Thread Igor Sutton
[...] New benchmarks about the subject: foreach_hash_keys: 4 wallclock secs ( 4.40 usr + 0.00 sys = 4.40 CPU) @ 227272.73/s (n=100) foreach_hash_values: 4 wallclock secs ( 3.46 usr + 0.01 sys = 3.47 CPU) @ 288184.44/s (n=100) reverse_hash: 6 wallclock secs ( 6.85 usr + 0.01 sys

Pattern Matching

2007-01-19 Thread Dharshana Eswaran
Hi All, I have a string as shown below: $string = {[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00} This is stored as a string in a variable. I need to pull out only the numbers and store them in a array. Like: @array =

Re: Pattern Matching

2007-01-19 Thread Igor Sutton
Hi Dharshana, 2007/1/19, Dharshana Eswaran [EMAIL PROTECTED]: Hi All, I have a string as shown below: $string = {[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00} This is stored as a string in a variable. I need to pull

Re: Pattern Matching

2007-01-19 Thread Igor Sutton
I have an update: my @data = $string =~ m/0x(\d{2})/g; my @data = $string =~ m/0x(\S{2}),?/g; Now I think it is right :) -- Igor Sutton Lopes [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

substitute all spaces in a sentence except spaces in the first three words

2007-01-19 Thread Michael Alipio
Hi, Suppose I have: my $sentence = 'the quick brown fox jumps over the lazy dog. Now I want it to become: 'the quick brown:fox:jumps:over:the lazy dog. That is, to replace the spaces between brown-fox, fox-jumps, jumps-over, over-the, with :. Should I split the sentence and put each in an

choosing which to join in a given string.

2007-01-19 Thread Michael Alipio
Hi, my $string = This is a sentence; Now, I want to join is and a by a dash. Any idea how do i do that? using regexp may not be want I want because the real string contains many words, so I have to join several words without using too much regexp substitutions. Thanks.

exec and pipe

2007-01-19 Thread Andreas Brillisauer - Hetzner Online AG
Hello, I'm just writing a script that gets an email from stdin. This mail should be passed to procmail via ssh. If calling ssh or procmail fails, the mail should be saved locally. First I tried to solve this with system or open. But I cannot pipe the mail to ssh when using system. open can

Re: exec and pipe

2007-01-19 Thread Igor Sutton
Hi Andreas, 2007/1/19, Andreas Brillisauer - Hetzner Online AG [EMAIL PROTECTED]: Hello, I'm just writing a script that gets an email from stdin. This mail should be passed to procmail via ssh. If calling ssh or procmail fails, the mail should be saved locally. First I tried to solve this

Cannot modify read-only value in while loop?

2007-01-19 Thread Richard Jones
Help. I've just stumbled upon a new one to me: my $ref = [ 1..3 ]; push @$ref, 4; print Dumper $ref as expected gives: $VAR1 = [ 1, 2, 3, 4 ]; But in a DBI context: while ( my $ref = $sth-fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with

maximum file size for while(FILE) loop?

2007-01-19 Thread Bertrand Baesjou
Hi, I am trying to read data from a file, I do this by using the while (FILE){ $line} construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fine (perl -wc - syntax OK). I was thinking that maybe it was running to the

Re: Passing hash into sub routines (should i use reference?)

2007-01-19 Thread Richard Jones
Michael Alipio wrote: Hi, Suppose I have this code: #/usr/local/bin/perl use warnings; use strict; use subs 'verify'; my %where=( Gary = Dallas, Lucy = Exeter, Ian = Reading, Samantha = Oregon ); # Then i open a logfile open FH, '', $logfile or die Can't open $logfile!: $!; # Now, for

Re: maximum file size for while(FILE) loop?

2007-01-19 Thread Ken Foskey
On Fri, 2007-01-19 at 13:16 +0100, Bertrand Baesjou wrote: Hi, I am trying to read data from a file, I do this by using the while (FILE){ $line} construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fine (perl -wc -

Re: choosing which to join in a given string.

2007-01-19 Thread Ken Foskey
On Fri, 2007-01-19 at 02:08 -0800, Michael Alipio wrote: Hi, my $string = This is a sentence; Now, I want to join is and a by a dash. Any idea how do i do that? using regexp may not be want I want because the real string contains many words, so I have to join several words without

Re: substitute all spaces in a sentence except spaces in the first three words

2007-01-19 Thread Rob Dixon
Michael Alipio wrote: Suppose I have: my $sentence = 'the quick brown fox jumps over the lazy dog. Now I want it to become: 'the quick brown:fox:jumps:over:the lazy dog. That is, to replace the spaces between brown-fox, fox-jumps, jumps-over, over-the, with :. Should I split the sentence

Re: choosing which to join in a given string.

2007-01-19 Thread Rob Dixon
Michael Alipio wrote: my $string = This is a sentence; Now, I want to join is and a by a dash. Any idea how do i do that? using regexp may not be want I want because the real string contains many words, so I have to join several words without using too much regexp substitutions. This is

Re: maximum file size for while(FILE) loop?

2007-01-19 Thread Rob Dixon
Bertrand Baesjou wrote: Hi, I am trying to read data from a file, I do this by using the while (FILE){ $line} construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fine (perl -wc - syntax OK). How does your script

Re: Pattern Matching

2007-01-19 Thread Rob Dixon
Igor Sutton wrote: I have an update: my @data = $string =~ m/0x(\d{2})/g; my @data = $string =~ m/0x(\S{2}),?/g; Now I think it is right :) my @data = $string =~ m/=0x(..)/g; :) Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Pattern Matching

2007-01-19 Thread John W. Krahn
Dharshana Eswaran wrote: Hi All, Hello, I have a string as shown below: $string = {[0]=0x53,[1]=0x65,[2]=0x63,[3]=0x75,[4]=0x72,[5]=0x69,[6]=0x74,[7]=0x79,[8]=0x43,[9]=0x6F,[10]=0x64,[11]=0x65,[12]=0x00} This is stored as a string in a variable. I need to pull out only the numbers

Re: substitute all spaces in a sentence except spaces in the first three words

2007-01-19 Thread John W. Krahn
Michael Alipio wrote: Hi, Hello, Suppose I have: my $sentence = 'the quick brown fox jumps over the lazy dog. Now I want it to become: 'the quick brown:fox:jumps:over:the lazy dog. One way to do it: $ perl -le' my $sentence = the quick brown fox jumps over the lazy dog.; $sentence

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

2007-01-19 Thread Bertrand Baesjou
Ken Foskey wrote: On Fri, 2007-01-19 at 13:16 +0100, Bertrand Baesjou wrote: Hi, I am trying to read data from a file, I do this by using the while (FILE){ $line} construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all

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

2007-01-19 Thread Paul Johnson
On Fri, Jan 19, 2007 at 03:17:19PM +0100, Bertrand Baesjou wrote: foreach $line (INFILE) { See, this isn't a while loop, as you have in the subject. That is the cause of your problems. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For

Re: memory issues?

2007-01-19 Thread Bertrand Baesjou
Paul Johnson wrote: On Fri, Jan 19, 2007 at 03:17:19PM +0100, Bertrand Baesjou wrote: foreach $line (INFILE) { See, this isn't a while loop, as you have in the subject. That is the cause of your problems. Damn, not very awake today I think. I also left an old subject line in

Re: memory issues?

2007-01-19 Thread Octavian Rasnita
From: Bertrand Baesjou [EMAIL PROTECTED] Paul Johnson wrote: On Fri, Jan 19, 2007 at 03:17:19PM +0100, Bertrand Baesjou wrote: foreach $line (INFILE) { See, this isn't a while loop, as you have in the subject. That is the cause of your problems. Damn, not very awake today I

Re: memory issues?

2007-01-19 Thread Bertrand Baesjou
Octavian Rasnita wrote: From: Bertrand Baesjou [EMAIL PROTECTED] Paul Johnson wrote: On Fri, Jan 19, 2007 at 03:17:19PM +0100, Bertrand Baesjou wrote: foreach $line (INFILE) { See, this isn't a while loop, as you have in the subject. That is the cause of your problems. Damn,

Re: Searching hash if a given value exists

2007-01-19 Thread Dr.Ruud
Igor Sutton schreef: [attribution repaired] Mumia W: Yes there is a faster way. Use the reverse function: my %hash = (dog = 'house', pig = 'barn', bird= 'cage'); my %rhash = reverse %hash; if ($rhash{house}) { print Found house.\n; } That's a really good

Re: simple perl script on Windows

2007-01-19 Thread Dr.Ruud
David Moreno Garza schreef: open FILE, 'H:\My Music\folderlist.txt'; open DEST, ' H:\My Music\artists.txt'; foreach my $line(readline FILE) { chomp; print DEST $1.\n if $line =~ /DIR\s*(.*)$/; } close FILE; close DEST; Wouldn't it be great if, especially on this list, such

Re: memory issues?

2007-01-19 Thread Xavier Noria
On Jan 19, 2007, at 5:53 PM, Bertrand Baesjou wrote: Thank you very much, this is indeed the solution. The explanation is that when you process lines this way foreach my $line (FH) { ... } the readline operator is evaluated in list context and, thus, the file is slurped into a single

Re: Cannot modify read-only value in while loop?

2007-01-19 Thread Xavier Noria
On Jan 19, 2007, at 12:55 PM, Richard Jones wrote: while ( my $ref = $sth-fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with 'Modification of read-only value attempted at .. line xx' I can't see the difference here between the two $ref arrayrefs, but Perl

Re: maximum file size for while(FILE) loop?

2007-01-19 Thread David Moreno Garza
On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: ++$lines; What's exactly the difference between: ++$lines; and $lines++; ? David. -- 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?

2007-01-19 Thread Ken Foskey
On Fri, 2007-01-19 at 16:21 -0600, David Moreno Garza wrote: On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: ++$lines; What's exactly the difference between: ++$lines; and $lines++; ? Nothing in this context. It does make a difference if you are 'using' the value see

Re: maximum file size for while(FILE) loop?

2007-01-19 Thread John W. Krahn
David Moreno Garza wrote: On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: ++$lines; What's exactly the difference between: ++$lines; and $lines++; ? In void context they are both the same because perl optimizes $lines++ to ++$lines. John -- Perl isn't a toolbox, but a

Re: Cannot modify read-only value in while loop?

2007-01-19 Thread Richard Jones
Xavier Noria wrote: On Jan 19, 2007, at 12:55 PM, Richard Jones wrote: while ( my $ref = $sth-fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with 'Modification of read-only value attempted at .. line xx' Yes, that reference has a flag READONLY turned on, this

Re: Searching hash if a given value exists

2007-01-19 Thread Michael Alipio
Hi, - Original Message From: Igor Sutton [EMAIL PROTECTED] To: Mumia W. [EMAIL PROTECTED] Cc: Beginners List beginners@perl.org Sent: Friday, January 19, 2007 4:42:09 PM Subject: Re: Searching hash if a given value exists [...] New benchmarks about the subject:

Re: Searching hash if a given value exists

2007-01-19 Thread Rob Dixon
Michael Alipio wrote: Hi, - Original Message From: Igor Sutton [EMAIL PROTECTED] To: Mumia W. [EMAIL PROTECTED] Cc: Beginners List beginners@perl.org Sent: Friday, January 19, 2007 4:42:09 PM Subject: Re: Searching hash if a given value exists [...] New benchmarks about the

Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread Michael Alipio
Hi, Suppose I have: 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 ty pe=event subtype=admin pri=information vd=root user=admin ui=GUI(192.168.1.1) action=login status=success reason=none msg =User admin

Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread I . B .
you can use lookaheads: my @matched = split /\s+(?=\w+=)/,$string; cheers, ~i On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote: Hi, Suppose I have: 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 ty

Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread Michael Alipio
- Original Message From: I.B. [EMAIL PROTECTED] To: begginers perl.org beginners@perl.org Sent: Saturday, January 20, 2007 1:02:39 PM Subject: Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern) you can use lookaheads: my @matched =

character classes vs regexp alternatives (using ( ) or [ ]

2007-01-19 Thread Michael Alipio
Hi, I'm a bit confused here: I have a regexp: ($date) = $log =~ /date=(\S+?)[\s+|,]/; so if I have: date=2007-01-12 blah blah or date=2007-01-12,blah,blah I was able to retrieve 2007-01-12 However, just recently after reading my notes on perl, I read that I should use parenthesis on

Re: character classes vs regexp alternatives (using ( ) or [ ]

2007-01-19 Thread I . B .
[,|\s+] - means one of the following characters: , or | or \s or + (,|\s+) - means , or \s+ , but yeas alternation will match $2 in : ~ /date=(\S+?)(\s+|,)/; On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote: Hi, I'm a bit confused here: I have a regexp: ($date) = $log =~

Re: Selective splits... (treat this pattern as a delimiter only if it is followed by this pattern)

2007-01-19 Thread I . B .
substitute \s with * to make split easier sounds like a very bad idea. didn't see people doing that in perl. problem is solved, why do you add extra complexity? On 1/19/07, Michael Alipio [EMAIL PROTECTED] wrote: - Original Message From: I.B. [EMAIL PROTECTED] To: begginers perl.org