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
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
[...]
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
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 =
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
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/
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
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.
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
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
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
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
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
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 -
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
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
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
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
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]
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
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
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
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
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
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
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,
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
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
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
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
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/
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
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
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
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:
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
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
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
- 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 =
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
[,|\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 =~
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
42 matches
Mail list logo