[28364] in Perl-Users-Digest
Perl-Users Digest, Issue: 9728 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 14:06:08 2006
Date: Fri, 15 Sep 2006 11:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 15 Sep 2006 Volume: 10 Number: 9728
Today's topics:
arrays and hashes <skimba@dambo.di>
Re: arrays and hashes <mritty@gmail.com>
Re: arrays and hashes <David.Squire@no.spam.from.here.au>
Re: arrays and hashes <skimba@dambo.di>
Re: arrays and hashes <abigail@abigail.be>
Re: arrays and hashes <mritty@gmail.com>
Re: Check IP range for DNSBL listing <hjp-usenet2@hjp.at>
Column extraction in perl <vkrish7@gmail.com>
Re: Column extraction in perl <nobull67@gmail.com>
Re: Column extraction in perl <tzz@lifelogs.com>
If...else and exit; <mattjones@hotmail.co.uk>
Re: If...else and exit; <daveandniki@ntlworld.com>
Re: If...else and exit; <nobull67@gmail.com>
Re: If...else and exit; <nobull67@gmail.com>
Re: If...else and exit; <nobull67@gmail.com>
Re: If...else and exit; <nobull67@gmail.com>
Modification of a read-only value attempted - why? <pcunix@gmail.com>
Re: Modification of a read-only value attempted - why? <nobull67@gmail.com>
Re: Modification of a read-only value attempted - why? anno4000@radom.zrz.tu-berlin.de
Re: perl on windows - possible bug? <rvtol+news@isolution.nl>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Sep 2006 16:50:05 +0300
From: Oobi Van Doobi <skimba@dambo.di>
Subject: arrays and hashes
Message-Id: <MLxOg.12510$SW5.3277@reader1.news.jippii.net>
Could someone please brief me a little on arrays and hashes.
For example:
What is the difference with () and {}?
also:
do I need to enclose each element in an array with []?
I am trying to construct an array of hashes. All is good but iterating over
the array there is only one element*S*...and iterating over the element
gives me the hash array*S*. ...
this is what i have
my @ary=
[
{
},
...
{
},
];
Thank you,
any advice much appreciated
------------------------------
Date: 15 Sep 2006 06:33:59 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: arrays and hashes
Message-Id: <1158327239.314260.169030@d34g2000cwd.googlegroups.com>
Oobi Van Doobi wrote:
> Could someone please brief me a little on arrays and hashes.
You should REALLY REALLY read a decent tutorial on Perl for these sorts
of questions. I recommend starting in this case with
http://perldoc.perl.org/perldata.html
> For example:
> What is the difference with () and {}?
Parentheses are (usually) used to construct a list, which is used to
populate an array or a hash:
my @array = (1, 2, 3, 4);
my %hash = (one => 1, two => 2, three => 3);
Curly-braces have a variety of functions in Perl. They are used to
access a specific value of a hash by enclosing a key:
$hash{four} = 4;
They are used to create an anonymous hash reference:
my $hash_ref = { one => 1, two => 2, three => 3 } ;
The are also used to create blocks and subroutines, as well as delimit
a variable name inside a double-quoted string. There are other uses as
well, but I don't think they apply to your question.
> also:
> do I need to enclose each element in an array with []?
No. Brackets, like braces, have multiple functions. They are used to
access a specific element from an array, by enclosing an index:
$array[2] = 20;
They are also used to create an anonymous array reference:
my $array_ref = [ 1, 2, 3, 4];
> I am trying to construct an array of hashes.
You need to read a decent tutorial or two about this too.
http://perldoc.perl.org/perlreftut.html
http://perldoc.perl.org/perllol.html
http://perldoc.perl.org/perldsc.html
http://perldoc.perl.org/perlref.html
> All is good but iterating over
> the array there is only one element*S*...and iterating over the element
> gives me the hash array*S*. ...
> this is what i have
> my @ary=
> [
> {
> },
> ...
> {
> },
> ];
This creates an array that contains exactly one element. That one
element is a reference to an anonymous array. That anonymous array
contains multiple references to anonymous hashes.
Changing the outer [ ] to ( ) will be a good start, but you really need
to read those Perldocs to understand multi-level structures in Perl.
Paul Lalli
------------------------------
Date: Fri, 15 Sep 2006 14:48:15 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: arrays and hashes
Message-Id: <eeeauv$jr1$1@gemini.csx.cam.ac.uk>
Oobi Van Doobi wrote:
> Could someone please brief me a little on arrays and hashes.
Perl is your friend. It comes with documentation included so that people
don't have to type this stuff again and again on Usenet. See:
perldoc perldata
perldoc perldsc
If you would prefer to read these online, they are available at
http://www.perl.com/pub/q/documentation
> For example:
> What is the difference with ()
allows you to construct a list
and {}?
allows you to construct a reference to an anonymous hash.
> also:
> do I need to enclose each element in an array with []?
No.
> I am trying to construct an array of hashes.
There is a whole section on this topic in perldoc perldsc
Here is an example:
----
#!/usr/bin/perl
use strict;
use warnings;
my @array_of_hashes = ( # start defining a list, the contents of the array
{ # start the first element of the list, which is an anonymous hashref
'cat' => 'mammal',
'frog' => 'amphibian',
'snake' => 'reptile',
},
{ # start another list element
'cup' => 'crockery',
'knife' => 'cutlery',
},
);
foreach my $array_element (@array_of_hashes) {
print "###################################\n";
foreach my $key ( keys %{$array_element} ) { # notice we dereference
the element
print "$key: $$array_element{$key}\n";
}
}
----
Output:
###################################
cat: mammal
snake: reptile
frog: amphibian
###################################
knife: cutlery
cup: crockery
DS
------------------------------
Date: Fri, 15 Sep 2006 18:27:51 +0300
From: Oobi Van Doobi <skimba@dambo.di>
Subject: Re: arrays and hashes
Message-Id: <obzOg.12561$B17.4222@reader1.news.jippii.net>
Paul Lalli wrote:
> Oobi Van Doobi wrote:
>> Could someone please brief me a little on arrays and hashes.
>
> You should REALLY REALLY read a decent tutorial on Perl for these sorts
> of questions. I recommend starting in this case with
> http://perldoc.perl.org/perldata.html
>
>> For example:
>> What is the difference with () and {}?
>
> Parentheses are (usually) used to construct a list, which is used to
> populate an array or a hash:
>
> my @array = (1, 2, 3, 4);
> my %hash = (one => 1, two => 2, three => 3);
>
> Curly-braces have a variety of functions in Perl. They are used to
> access a specific value of a hash by enclosing a key:
> $hash{four} = 4;
> They are used to create an anonymous hash reference:
> my $hash_ref = { one => 1, two => 2, three => 3 } ;
>
> The are also used to create blocks and subroutines, as well as delimit
> a variable name inside a double-quoted string. There are other uses as
> well, but I don't think they apply to your question.
>
>> also:
>> do I need to enclose each element in an array with []?
>
> No. Brackets, like braces, have multiple functions. They are used to
> access a specific element from an array, by enclosing an index:
>
> $array[2] = 20;
>
> They are also used to create an anonymous array reference:
> my $array_ref = [ 1, 2, 3, 4];
>
>> I am trying to construct an array of hashes.
>
> You need to read a decent tutorial or two about this too.
> http://perldoc.perl.org/perlreftut.html
> http://perldoc.perl.org/perllol.html
> http://perldoc.perl.org/perldsc.html
> http://perldoc.perl.org/perlref.html
>
>> All is good but iterating over
>> the array there is only one element*S*...and iterating over the element
>> gives me the hash array*S*. ...
>> this is what i have
>> my @ary=
>> [
>> {
>> },
>> ...
>> {
>> },
>> ];
>
> This creates an array that contains exactly one element. That one
> element is a reference to an anonymous array. That anonymous array
> contains multiple references to anonymous hashes.
>
> Changing the outer [ ] to ( ) will be a good start, but you really need
> to read those Perldocs to understand multi-level structures in Perl.
>
> Paul Lalli
oh, !!thank's!!
------------------------------
Date: 15 Sep 2006 16:41:46 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: arrays and hashes
Message-Id: <slrnegllua.r0.abigail@alexandra.abigail.be>
David Squire (David.Squire@no.spam.from.here.au) wrote on MMMMDCCLXIII
September MCMXCIII in <URL:news:eeeauv$jr1$1@gemini.csx.cam.ac.uk>:
;;
;; > What is the difference with ()
;;
;; allows you to construct a list
Eh, not really. Context makes lists - the only place where () is significant
in creating a list is on the left hand side of the x.
() are mostly used for precedence and syntax constructs.
Abigail
--
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
|perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
|perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
|perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;
------------------------------
Date: 15 Sep 2006 10:38:12 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: arrays and hashes
Message-Id: <1158341891.914510.326800@i42g2000cwa.googlegroups.com>
Abigail wrote:
> David Squire (David.Squire@no.spam.from.here.au) wrote on MMMMDCCLXIII
> September MCMXCIII in <URL:news:eeeauv$jr1$1@gemini.csx.cam.ac.uk>:
> ;;
> ;; > What is the difference with ()
> ;;
> ;; allows you to construct a list
>
> Eh, not really. Context makes lists - the only place where () is significant
> in creating a list is on the left hand side of the x.
Hrm. How does that jive with things such as:
my $x = @foo;
vs
my ($x) = @foo;
The way I understand it, in the first, @foo is evaluated in scalar
context, because we're assigning to a scalar value, and so $x gets the
size of @foo. In the second, @foo is evaluated in list context,
because we're assigning to a list, and so $x gets the first value of
@foo. So didn't the parentheses change "$x" from "a scalar value" to
"a list containing a single scalar value"?
Paul Lalli
------------------------------
Date: Fri, 15 Sep 2006 18:00:05 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Check IP range for DNSBL listing
Message-Id: <slrnegljg5.sah.hjp-usenet2@yoyo.hjp.at>
On 2006-09-15 07:12, RR <scubacuda@gmail.com> wrote:
> I'm looking for a Perl script that will easily check ranges of IP
> addresses that make it into DNSBLs, such as sbl-xbl.spamhaus.org and
> bl.spamcop.net
>
> I found RBLcheck and ARBLcheck
>
> http://freshmeat.net/projects/rblcheck.pl/
> http://www.unixwiz.net/tools/arblcheck.html
>
> But unfortunately those don't allow me to put in ranges of IPs
Then change them to take a range of IP addresses and query each address
in the range. If you run into problems, feel free to ask questions. But
keep in mind that this is a discussion group for programmers, so while
you will almost certainly receive helpful (though not always polite)
comments on any code you have written, you probably won't get much help
if you are looking for ready-made solutions.
One other thing to consider: Some RBLs may consider it abuse if you
frequently check a large number of IP addresses. Some offer to send you
a notification if they list one of your addresses. Check the web sites
of the RBLs first!
hp
--
_ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR | > ist?
| | | hjp@hjp.at | Was sonst wäre der Sinn des Erfindens?
__/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
------------------------------
Date: 15 Sep 2006 09:31:25 -0700
From: "vkrish7@gmail.com" <vkrish7@gmail.com>
Subject: Column extraction in perl
Message-Id: <1158337885.085929.221870@d34g2000cwd.googlegroups.com>
Hello all,
I am very new to PERL and need some help here to get this going...
I have about 100 text files and each text file looks something like
this:-
V_or_I Lo_BIT
5330 1
5380 5
5390 6
5400 9
5410 11
5420 15
Now i need to grab only the first column starting with (5330, skip
"V_or_I" line) go till the end of the file(Say till 5420) and write
this to another file(say dataappend.txt). Then open another text file(
out of 100 text files) do the same( ie. start from second line of the
file which will be in number format similar to 5330 and grab the first
column and append to dataappend.txt... Can any1 please show me how to
do this on perl?
Hoping for a reply!
Thanks,
Vijay
------------------------------
Date: 15 Sep 2006 10:14:03 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Column extraction in perl
Message-Id: <1158340443.288938.269550@e3g2000cwe.googlegroups.com>
vkrish7@gmail.com wrote:
> I am very new to PERL and need some help here to get this going...
It's Perl not PERL - see FAQ.
>
> I have about 100 text files and each text file looks something like
> this:-
>
> V_or_I Lo_BIT
> 5330 1
> 5380 5
> 5390 6
> 5400 9
> 5410 11
> 5420 15
>
> Now i need to grab only the first column starting with (5330, skip
> "V_or_I" line) go till the end of the file(Say till 5420) and write
> this to another file(say dataappend.txt). Then open another text file(
> out of 100 text files) do the same( ie. start from second line of the
> file which will be in number format similar to 5330 and grab the first
> column and append to dataappend.txt... Can any1 please show me how to
> do this on perl?
>
> Hoping for a reply!
What bits are you having trouble with? Show us what you've wrtten so
far. People here will not be inclined to help you if there's no
evidence that you are making any effort yourself.
------------------------------
Date: Fri, 15 Sep 2006 13:53:14 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Column extraction in perl
Message-Id: <g69k645ow39.fsf@CN1374059D0130.kendall.corp.akamai.com>
On 15 Sep 2006, vkrish7@gmail.com wrote:
> I have about 100 text files and each text file looks something like
> this:-
>
> V_or_I Lo_BIT
> 5330 1
> 5380 5
> 5390 6
> 5400 9
> 5410 11
> 5420 15
>
> Now i need to grab only the first column starting with (5330, skip
> "V_or_I" line) go till the end of the file(Say till 5420) and write
> this to another file(say dataappend.txt). Then open another text file(
> out of 100 text files) do the same( ie. start from second line of the
> file which will be in number format similar to 5330 and grab the first
> column and append to dataappend.txt... Can any1 please show me how to
> do this on perl?
You may want to consider using the `cut' utility to do this. It was
designed for this sort of task.
With Perl it's pretty simple:
perl -ane 'print $F[0], "\n"' FILE1 FILE2 FILE3
perl -ane 'print $F[1], "\n"' FILE1 FILE2 FILE3
these two commands will print the first and second column,
respectively, of the file you give them. If you know you're not
interested in the header lines, remove them.
perl -ane 'print $F[0], "\n"' FILE.data | grep -v V_or_I
perl -ane 'print $F[1], "\n"' FILE.data | grep -v V_or_I
Type 'perldoc perlrun' to learn what the -a and -n switches do.
Ted
------------------------------
Date: 15 Sep 2006 08:35:33 -0700
From: "MattJ83" <mattjones@hotmail.co.uk>
Subject: If...else and exit;
Message-Id: <1158334533.786889.291520@i42g2000cwa.googlegroups.com>
Hi,
I've written some code which is almost complete but am having trouble
at the final hurdle.
My code looks for the string FASTSEARCH - if this line is not here - i
want the program to exit.
If there is an error message where the FASTSEARCH string should be -
return this value and carry on with the script. If there is no error OR
FASTSEARCH - the script should terminate.
The script seems to return the correct values when i ask it to print
them - but i am trying to put them into a database - and it isn't
working as the 'print on screen' is.
Any help would be appreciated.
Working code:
#!/usr/central/bin/perl
use strict;
use warnings;
my @filenames = </home/username/logs/*.log>;
foreach my $filename (@filenames)
{
open my $LOG, '<', $filename or die "can't open $filename: $!\n";
print "$filename\n";
my ($fast, $error, $inversions);
while(<$LOG>) {
if (/updates table/) {
/Rows in fast-search index updates table: (.*)/;
print "$1\n";
}
if (/deletions table/) {
/Rows in fast-search index deletions table: (.*)/;
print "$1\n";
}
if (/elapsed/) {
if ($fast or $error) {
/deltas: elapsed=(.*), cpu=(.*), user=(.*), sys=(.*), n=(.*)/;
print "$1\n";
last;
}
}
if (/FASTSEARCH/) {
$fast = $_;
}
if (/conflicting/) {
$error = $_;
print "Conflicting Lock Error Found\n";
}
}
while (<$LOG>) {
if (/inversions/) {
$inversions = $_;
}
}
if (!$fast) { <----------if /FASTSEARCH/ is not
found i want the program to exit.
exit; } elsif ($error) {next;} <----------if /conflicting/ is
found I want the script to keep running
if (!$inversions) {
exit; }
close($LOG);
}
Test data:
_________$LOG__________
string string
Rows in fast-search index updates table: 8
Rows in fast-search index deletions table: 6
string
string
string
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
string
FASTSEARCH <-------this may not be here - if not
exit....else if error
message is here
(/conflicting/) return error
message and go to next log
(carry on)
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
inversions
deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
------------------------------
Date: Fri, 15 Sep 2006 17:48:53 +0200
From: "Dave" <daveandniki@ntlworld.com>
Subject: Re: If...else and exit;
Message-Id: <450acb6f$0$5104$ba4acef3@news.orange.fr>
"MattJ83" <mattjones@hotmail.co.uk> wrote in message
news:1158334533.786889.291520@i42g2000cwa.googlegroups.com...
> Hi,
>
> I've written some code which is almost complete but am having trouble
> at the final hurdle.
>
> My code looks for the string FASTSEARCH - if this line is not here - i
> want the program to exit.
> If there is an error message where the FASTSEARCH string should be -
> return this value and carry on with the script. If there is no error OR
> FASTSEARCH - the script should terminate.
> The script seems to return the correct values when i ask it to print
> them - but i am trying to put them into a database - and it isn't
> working as the 'print on screen' is.
>
> Any help would be appreciated.
>
> Working code:
>
> #!/usr/central/bin/perl
> use strict;
> use warnings;
>
> my @filenames = </home/username/logs/*.log>;
> foreach my $filename (@filenames)
> {
> open my $LOG, '<', $filename or die "can't open $filename: $!\n";
> print "$filename\n";
>
> my ($fast, $error, $inversions);
> while(<$LOG>) {
>
> if (/updates table/) {
> /Rows in fast-search index updates table: (.*)/;
> print "$1\n";
>
> }
> if (/deletions table/) {
> /Rows in fast-search index deletions table: (.*)/;
> print "$1\n";
>
> }
> if (/elapsed/) {
> if ($fast or $error) {
> /deltas: elapsed=(.*), cpu=(.*), user=(.*), sys=(.*), n=(.*)/;
> print "$1\n";
>
> last;
> }
> }
> if (/FASTSEARCH/) {
> $fast = $_;
> }
> if (/conflicting/) {
> $error = $_;
> print "Conflicting Lock Error Found\n";
> }
> }
> while (<$LOG>) {
> if (/inversions/) {
> $inversions = $_;
> }
> }
>
> if (!$fast) { <----------if /FASTSEARCH/ is not
> found i want the program to exit.
> exit; } elsif ($error) {next;} <----------if /conflicting/ is
> found I want the script to keep running
> if (!$inversions) {
> exit; }
>
> close($LOG);
>
> }
>
> Test data:
>
> _________$LOG__________
>
> string string
> Rows in fast-search index updates table: 8
> Rows in fast-search index deletions table: 6
> string
> string
>
> string
> deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
> string
> FASTSEARCH <-------this may not be here - if not
> exit....else if error
> message is here
> (/conflicting/) return error
> message and go to next log
> (carry on)
> deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
> inversions
>
> deltas: elapsed=(0), cpu=(0), user=(0), sys=(0), n=(0)
>
The problem is in muddled thinking rather than the code. Reread your own
description.
------------------------------
Date: 15 Sep 2006 09:34:11 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: If...else and exit;
Message-Id: <1158338051.018948.44490@e3g2000cwe.googlegroups.com>
MattJ83 wrote:
> I've written some code which is almost complete...
..ly unreadable!
I've moved the whitespace about so that it's readble.
I've also changed the comment marker to # rather than <----------
I don't know what version you have of perl that treats <---------- as a
comment but I've never seen one.
Note: I've not tried to understand or fix your code (yet) I've just
cleaned up the formatting so anyone who was inclined to help you would
not have to do so.
Note that by reapeatedly posting code that so badly indented you are
rappidly exhasting your God-given (or is that Camel-given) quota of
good will.
use strict;
use warnings;
my @filenames = <*.log>;
foreach my $filename (@filenames) {
open my $LOG, '<', $filename or die "can't open $filename: $!\n";
print "$filename\n";
my ($fast, $error, $inversions);
while(<$LOG>) {
if (/updates table/) {
/Rows in fast-search index updates table: (.*)/;
print "$1\n";
}
if (/deletions table/) {
/Rows in fast-search index deletions table: (.*)/;
print "$1\n";
}
if (/elapsed/) {
if ($fast or $error) {
/deltas: elapsed=(.*), cpu=(.*), user=(.*), sys=(.*), n=(.*)/;
print "$1\n";
last;
}
}
if (/FASTSEARCH/) {
$fast = $_;
}
if (/conflicting/) {
$error = $_;
print "Conflicting Lock Error Found\n";
}
}
while (<$LOG>) {
if (/inversions/) {
$inversions = $_;
}
}
if (!$fast) {
# if /FASTSEARCH/ is no found i want the program to exit.
exit;
} elsif ($error) {
# if /conflicting/ is found I want the script to keep running
next;
}
if (!$inversions) {
exit;
}
close($LOG);
}
__END__
------------------------------
Date: 15 Sep 2006 09:43:35 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: If...else and exit;
Message-Id: <1158338615.577902.23470@i42g2000cwa.googlegroups.com>
MattJ83 wrote:
> The script seems to return the correct values when i ask it to print
> them - but i am trying to put them into a database - and it isn't
> working as the 'print on screen' is.
I suspect this is untrue.
> Any help would be appreciated.
I sugesst you produce a _minimal_ but _complete_ (cleanly indented)
example that you think should write to a database and confirm that is
fails as you expect.
Then comment out the database operations and replace them with print
statements. Do not make any other changes.
Confirm that this appears not to fail in the same way.
Then post the script and the data here _unaltered_. If you want
comments in your exemplar script then put comments in the script, do
_not_ insert syntatically invalid prose into the post.
------------------------------
Date: 15 Sep 2006 09:48:54 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: If...else and exit;
Message-Id: <1158338933.995991.24380@b28g2000cwb.googlegroups.com>
Brian McCauley wrote:
> Then comment out the database operations and replace them with print
> statements. Do not make any other changes.
By which I mean that the print() statements should print out exactly
what was to be written to the database in exactly the same place in the
code as it would have been written.
------------------------------
Date: 15 Sep 2006 09:52:27 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: If...else and exit;
Message-Id: <1158339147.290217.16650@h48g2000cwc.googlegroups.com>
Brian McCauley wrote:
> if (/updates table/) {
> /Rows in fast-search index updates table: (.*)/;
> print "$1\n";
> }
You should _never_ use $1 etc unless you know the match succeded.
You probaly wanted to say:
if (/Rows in fast-search index updates table: (.*)/) {
print "$1\n";
}
------------------------------
Date: 15 Sep 2006 09:37:09 -0700
From: "Tony Lawrence" <pcunix@gmail.com>
Subject: Modification of a read-only value attempted - why?
Message-Id: <1158338229.394350.314710@i42g2000cwa.googlegroups.com>
Can someone explain this to me?
(full text at http://aplawrence.com/Unix/perl_readonly.html ,
abbreviated version here)
Test code:
#!/usr/bin/perl -w
# no problem here
caroomba("first");
@dayval=qw(foo ba);
foreach $dayval (@dayval) {
# no problem here
caroomba($dayval);
}
foreach $dayval ("foo2","ba2") {
# no problem here either
caroomba($dayval);
}
foreach ("foo3","ba3") {
# doesn't like this
$dayval=$_;
caroomba($dayval);
}
sub caroomba {
my $p=shift;
print "Caroomba called $p\n";
open(I,"./t");
while (<I>) {
# stuff..
}
close I;
}
When run, that produces:
Caroomba called first
Caroomba called foo
Caroomba called ba
Caroomba called foo2
Caroomba called ba2
Caroomba called foo3 Modification of a read-only value attempted at
./t.pl line 23, <I> line 23.
Why?
Something to do with anonymous arrays, but I don't grok it.
------------------------------
Date: 15 Sep 2006 10:08:31 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: Modification of a read-only value attempted - why?
Message-Id: <1158340111.713442.282160@i3g2000cwc.googlegroups.com>
Tony Lawrence wrote:
> Can someone explain this to me?
>
> (full text at http://aplawrence.com/Unix/perl_readonly.html ,
> abbreviated version here)
>
> Test code:
[still rather long ]
I've abberviated your example to:
for ("foo3") {
while (<DATA>) {
}
}
__END__
The <> construct in a while() performs an implicit assignment to the
global variable $_ but does _not_ perform an implicit local($_) in the
way for() does.
The for() makes the global variable $_ an alias for the readonly value
"foo3".
> Something to do with anonymous arrays, but I don't grok it.
No, nothing to do with arrays.
The obvious, but _wrong_ solution is to insert local($_) before the
while(<...>). This will work 99.99% of the time but that last time in
10000 $_ will be aliased to an element of a tied agregate (HASH or
ARRAY) and then local($_) will do evil things.
The correct fix is either to local(*_) or to avoid the implicit
assignment feature completely.
Note that an unfortunate side effect of local(*_) is that is localizes
@_ etc too. You can get arround this with the rather peverse looking
code...
local(*_) = do{ \my $underscore };
------------------------------
Date: 15 Sep 2006 17:13:55 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Modification of a read-only value attempted - why?
Message-Id: <4n05ajF85avnU1@news.dfncis.de>
Tony Lawrence <pcunix@gmail.com> wrote in comp.lang.perl.misc:
> Can someone explain this to me?
>
> (full text at http://aplawrence.com/Unix/perl_readonly.html ,
> abbreviated version here)
>
> Test code:
[snip code that doesn't show the problem]
> foreach ("foo3","ba3") {
> # doesn't like this
> $dayval=$_;
> caroomba($dayval);
> }
>
>
>
> sub caroomba {
> my $p=shift;
> print "Caroomba called $p\n";
> open(I,"./t");
> while (<I>) {
> # stuff..
> }
> close I;
> }
>
>
> Caroomba called foo3 Modification of a read-only value attempted at
> ./t.pl line 23, <I> line 23.
>
> Why?
>
> Something to do with anonymous arrays, but I don't grok it.
Which anonymous array? I don't see any.
The problem is the nesting (through a sub call) of the outer
for-loop and the inner while-loop. The outer "for" aliases $_
to the read-only literal "foo3". This alias is still in effect
inside the sub. The while-loop now tries to use the variable
$_ as its implicit variable. Since $_ is aliased to a read-only
value, that fails with the error you see.
Anno
------------------------------
Date: Thu, 14 Sep 2006 23:17:31 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: perl on windows - possible bug?
Message-Id: <eeco4c.u8.1@news.isolution.nl>
lililevy@hotmail.com schreef:
> I'm using perl58.dll (version 5.8.4, build 810) in a c++ application
> with several threads that runs on win2000SP4.
> Every thread creates a perl interpreter that runs a perl script from
> an arbitrary file.
> After a while I'm experiencing a deadlock.
Maybe the perl5.porters mailing list is a better place for this
question.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 9728
***************************************