[23400] in Perl-Users-Digest
Perl-Users Digest, Issue: 5618 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 5 11:06:41 2003
Date: Sun, 5 Oct 2003 08: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 Sun, 5 Oct 2003 Volume: 10 Number: 5618
Today's topics:
Accessing parent objects <email@christoph-haas.de>
code with style (Pedro)
Re: code with style (Pedro)
Re: data varification code logic <king21122@yahoo.com>
Re: data varification code logic <king21122@yahoo.com>
Re: data varification code logic (Tad McClellan)
Re: data varification code logic (Tad McClellan)
Re: data varification code logic <king21122@yahoo.com>
Re: examples of sprintf <mikeflan@earthlink.net>
Re: How To activate command line history in debugger? (Peter Scott)
I like GWB (dweezel)
Re: I like GWB <nospam@rainx.cjb.net>
Re: Null value in print string <REMOVEsdnCAPS@comcast.net>
Re: two regexs <perl@my-header.org>
Re: Unexpected alteration of array's content <dha@panix.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 05 Oct 2003 15:50:11 +0200
From: Christoph Haas <email@christoph-haas.de>
Subject: Accessing parent objects
Message-Id: <blp7ii$edv4t$1@ID-164271.news.uni-berlin.de>
Hi, group...
After hours of reading kilobytes of documentation I'm desperate enough
to bother you. :)
I have an object (child) created within another object (parent).
(See below for the "trivial" source code.) Methods of the parent package
can easily handle children objects like $parent->{'children'}. But is
there a way to do this vice-versa? Assume I'm a child and I want to know
what other children there are. I need a handle to "go up" the object
tree to check the parent object.
There are two possible solution I can think of:
a) Give each child a handle to its parents like
$parent->new_child($parent);
(This could break if the object is not a member of "parent"
and the children assume they have parent.)
b) Use global variables for children (then how do I access them
from inside of each package? can I "tie" them somehow and use
them simultaneously from every children object?)
What is the best way to handle this?
================================================
Parent.pm:
==========
package Parent;
use Child;
sub new
{
my $package = shift;
my $self = { };
my %children = ();
$self->{'children'} = \%children;
bless($self, $package);
return $self;
}
sub new_child
{
my $self = shift;
my $name = shift;
$self->{'children'}->{$name} = new Child;
}
=========
Child.pm:
=========
package Child;
sub new
{
my $package = shift;
my $self = { };
bless($self, $package);
return $self;
}
================================================
Thanks for your ideas...
Christoph
------------------------------
Date: Sun, 05 Oct 2003 15:32:17 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (Pedro)
Subject: code with style
Message-Id: <pedro.fabre.NO-SPAM-0510031532170001@192.168.0.5>
Hi all,
I was trying to calculate the max number of variations of the columns on
an array.
I have worked the code on this way. It works fine and I get what I need
but I think that still my style is not too perl.
The idea is that I have to take the length of the array in order to
operate by columns and then go for every element of the row.
I am not fully convinced with my style, and I guess this can be done in a
simpler way.
Any suggestion?
Thanks for your help
P
use strict;
my @a = (
[qw/1 2 3 4 5/],
[qw/2 2 3 2 4/],
[qw/3 1 2 4 5/]
);
my $var = maximum_multiplicity(\@a);
print "$var\n";
sub maximum_multiplicity{
my ($a_ref)= @_;
my $mm=0; # maximum multiplicity
my $length = @{ @$a_ref[0]}; #length of the row
for (my $i = 0; $i<$length;$i++){
my %var=();
for my $r (0..$#$a_ref){
$var{ $a_ref->[$r][$i] } =1; # new key for every new variation
my @al = keys %var; # store var in array
# if the number of var for this column is
# greater than before set $m value as var number
$mm= scalar @al if (scalar @al >$mm);
}
}
return $mm;
}
------------------------------
Date: Sun, 05 Oct 2003 16:03:57 +0100
From: pedro.fabre.NO-SPAM@gen.gu.se (Pedro)
Subject: Re: code with style
Message-Id: <pedro.fabre.NO-SPAM-0510031603570001@192.168.0.5>
In article <pedro.fabre.NO-SPAM-0510031532170001@192.168.0.5>,
pedro.fabre.NO-SPAM@gen.gu.se (Pedro) wrote:
> Hi all,
>
> I was trying to calculate the max number of variations of the columns on
> an array.
>
> I have worked the code on this way. It works fine and I get what I need
> but I think that still my style is not too perl.
>
> The idea is that I have to take the length of the array in order to
> operate by columns and then go for every element of the row.
>
>
> I am not fully convinced with my style, and I guess this can be done in a
> simpler way.
>
> Any suggestion?
>
>
> Thanks for your help
> P
... skipped ....
>
> for (my $i = 0; $i<$length;$i++){
>
> my %var=();
>
> for my $r (0..$#$a_ref){
>
> $var{ $a_ref->[$r][$i] } =1; # new key for every new variation
> my @al = keys %var; # store var in array
>
> # if the number of var for this column is
> # greater than before set $m value as var number
> $mm= scalar @al if (scalar @al >$mm);
>
> }
> }
Opps, the above code is like that:
for (my $i = 0; $i<$length;$i++){
my %var=();
for my $r (0..$#$a_ref){
$var{ $a_ref->[$r][$i] } =1; # new key for every new variation
}
my @al = keys %var; # store var in array
# if the number of var for this column is
# greater than before set $m value as var number
$mm= scalar @al if (scalar @al >$mm);
}
>
> return $mm;
> }
------------------------------
Date: Sun, 05 Oct 2003 17:18:42 +1000
From: King <king21122@yahoo.com>
Subject: Re: data varification code logic
Message-Id: <3F7FC5D2.5090509@yahoo.com>
Tad McClellan wrote:
> King <king21122@yahoo.com> wrote:
>
>
>
>>my @col = map { (split)[0] } <DATA>; # untested
>
>
>>this code will not work if it is in the same program with another
>>statement which is also using the <DATA> .
>
>
>
> Maybe, maybe not. We would need to see the actual code to tell (hint!).
>
>
>
>>if I comment the first
>>block(s) then it works. where do I find some reading about this if this
>>is the correct behaviour, if not then what is going on?
>
>
>
> I'm forced to guess at what is going on in the unseen code.
>
> The input operator above ( <DATA> ) is in "list context"
> (see "Context" section in perldata.pod).
>
> The input operator in list context reads _all_ of the lines
> from the filehandle, so you will be at end-of-file afterwards.
> (see the named function corresponding to <>: perldoc -f readline)
>
> BTW, the DATA filehandle is meant to be "meta" here, ie: you should
> replace it with some other properly open()ed filehandle in your
> real program.
>
> Sounds like you are trying to use the same filehandle for 2 different
> things. Can't you use 2 filehandles (and 2 files) for the 2 different
> things?
>
>
>
>>another point:
>>since I need to write DATA to another file FH, should I make an array
>>with those $seen{key} > 1 and then as I loop through the DATA check each
>>key to see weather to write this line out or to ask for <STDIN> to
>>choose which line to keep and ignore the rest of the duplicates? or
>>someother logic is better to do this?
>>
>>notice I changed the __DATA__ below in-order to better reflect what I am
>>trying to explain,
>
>
>
> If you change the requirements, the code is likely to be different.
>
> My earlier code is not very helpful given this new requirement.
>
> You can avoid lots of similar round-and-round by getting the
> requirements clear up-front.
>
> Too many iterations and you'll end up using all of your coupons
> before you get an answer that you can actually use...
>
>
>
>>I am trying to get the code to show me the whole
>>lines of DATA with the same keys and allow me to select which line to
>>keep and disregard the rest. so according to the DATA it should say
>>1: one two1
>>2: one two2
>>please select the line to keep:
>>if <STDIN> = 2 then donot copy "one two1" to the new file and do next
>
> ^
> ^ you cannot assign to the input operator, should be == ?
>
>
> We are still missing an essential requirement:
>
> Can we be sure that the entire file will fit into memory?
>
> The code (and algorithm) are likely to be very different
> depending on the answer to that question.
>
> I'll assume we can put the whole thing into memory.
>
>
> The best data structure seems to me to be a HoL (Hash of Lists,
> more accurately: a hash of references to arrays).
>
> --------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Data::Dumper; # invaluable for debugging data structures
>
> ### load up the data structure
> my %data; # HoL
> while ( <DATA> ) {
> my $key = (split)[0]; # or: my($key) = /^(\S*)/;
>
> push @{ $data{$key} }, $_; # save lines associated with the key
> }
> #print Dumper \%data; # see what it is that we have built thus far
>
>
> ### make the output
> my $outfile = 'tmp';
> open OUT, ">$outfile" or die "could not open '$outfile' $!";
> foreach my $key ( sort keys %data ) {
> print OUT select_line( $data{$key} ); # pass a ref-to-array
> }
> close OUT;
>
>
> sub select_line {
> my($linesref) = @_;
>
> return $linesref->[0] unless @$linesref > 1; # there is only one line
>
> print "$_: $linesref->[$_]" for 0 .. $#$linesref;
> print " please select the line to keep: ";
> chomp(my $index = <STDIN>);
> return $linesref->[$index];
> }
>
>
> __DATA__
> one two
> one two
> One Two
> one three
> Two five
> two three
> Two three
> --------------------------------------------
>
>
most of the below code is my previous effort + help from others
it misses some lines from the file for a reason I don't know. I would
like to know why if you have the time to review it. just for my
understanding.
#!/usr/bin/perl
#use lib "/usr/local/lib/perl/5.6.1";
use warnings;
use strict;
my $infile = "/home/data/avg";
my $outfile = "/home/data/data";
my %table;
open DATA, $infile or die $!;
while (<DATA>) {
if ( $. > 1 ) { # if line number more than 1 = 'not the first line'
my ($key, @value) = split;
push @{ $table{ dateconvert($key) } }, [ @value ];
# if there is a sub like ^^^^^ which apply to the $key where in your
code that should go?
}
}
for my $k (keys %table) {
my $tnum = $#{$table{$k} };
my $keep = 0;
if ($tnum > 0) {
for my $i (0..$tnum) {
print $i+1, ": ", join " ", ($k, @{$table{$k}[$i]}), "\n";
}
print "please enter the line number to keep: ";
chomp ( $keep = <STDIN> );
if ($keep-1 > 0 ) {
@{$table{$k}[0]} = @{$table{$k}[$keep-1]};
until ($tnum-- == 0 ) {pop @{$table{$k}}};
}
else {
until ($tnum-- == 0 ) {pop @{$table{$k}}};
}
}
}
open OUT, ">$outfile" or die $!;
for my $k (sort keys %table) {
print OUT "$k @{$table{$k}[0]}\n";
}
sub dateconvert {
my $date = shift;
my %months = (
Jan => 1, Feb => 2, Mar => 3, Apr => 4,
May => 5, Jun => 6, Jul => 7, Aug => 8,
Sep => 9, Oct => 10, Nov => 11, Dec => 12
);
my ($day, $month, $year) = split /-/, $date;
$year += $year > 35 ? 1900 : 2000;
$month = $months{$month};
return sprintf '%d%02d%02d', $year, $month, $day;
}
------------------------------
Date: Sun, 05 Oct 2003 17:38:10 +1000
From: King <king21122@yahoo.com>
Subject: Re: data varification code logic
Message-Id: <3F7FCA62.10100@yahoo.com>
King wrote:
> Tad McClellan wrote:
>
>> King <king21122@yahoo.com> wrote:
>>
>>
>>
>>> my @col = map { (split)[0] } <DATA>; # untested
>>
>>
>>
>>> this code will not work if it is in the same program with another
>>> statement which is also using the <DATA> .
>>
>>
>>
>>
>> Maybe, maybe not. We would need to see the actual code to tell (hint!).
>>
>>
>>
>>> if I comment the first block(s) then it works. where do I find some
>>> reading about this if this is the correct behaviour, if not then what
>>> is going on?
>>
>>
>>
>>
>> I'm forced to guess at what is going on in the unseen code.
>>
>> The input operator above ( <DATA> ) is in "list context"
>> (see "Context" section in perldata.pod).
>>
>> The input operator in list context reads _all_ of the lines
>> from the filehandle, so you will be at end-of-file afterwards.
>> (see the named function corresponding to <>: perldoc -f readline)
>>
>> BTW, the DATA filehandle is meant to be "meta" here, ie: you should
>> replace it with some other properly open()ed filehandle in your
>> real program.
>>
>> Sounds like you are trying to use the same filehandle for 2 different
>> things. Can't you use 2 filehandles (and 2 files) for the 2 different
>> things?
>>
>>
>>
>>> another point:
>>> since I need to write DATA to another file FH, should I make an array
>>> with those $seen{key} > 1 and then as I loop through the DATA check
>>> each key to see weather to write this line out or to ask for <STDIN>
>>> to choose which line to keep and ignore the rest of the duplicates?
>>> or someother logic is better to do this?
>>>
>>> notice I changed the __DATA__ below in-order to better reflect what I
>>> am trying to explain,
>>
>>
>>
>>
>> If you change the requirements, the code is likely to be different.
>>
>> My earlier code is not very helpful given this new requirement.
>>
>> You can avoid lots of similar round-and-round by getting the
>> requirements clear up-front.
>>
>> Too many iterations and you'll end up using all of your coupons
>> before you get an answer that you can actually use...
>>
>>
>>
>>> I am trying to get the code to show me the whole lines of DATA with
>>> the same keys and allow me to select which line to keep and disregard
>>> the rest. so according to the DATA it should say
>>> 1: one two1
>>> 2: one two2
>>> please select the line to keep:
>>> if <STDIN> = 2 then donot copy "one two1" to the new file and do next
>>
>>
>> ^
>> ^ you cannot assign to the input operator, should be == ?
>>
>>
>> We are still missing an essential requirement:
>>
>> Can we be sure that the entire file will fit into memory?
>>
>> The code (and algorithm) are likely to be very different
>> depending on the answer to that question.
>>
>> I'll assume we can put the whole thing into memory.
>>
>>
>> The best data structure seems to me to be a HoL (Hash of Lists, more
>> accurately: a hash of references to arrays).
>>
>> --------------------------------------------
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> use Data::Dumper; # invaluable for debugging data structures
>>
>> ### load up the data structure
>> my %data; # HoL
>> while ( <DATA> ) {
>> my $key = (split)[0]; # or: my($key) = /^(\S*)/;
>>
>> push @{ $data{$key} }, $_; # save lines associated with the key
>> }
>> #print Dumper \%data; # see what it is that we have built thus far
>>
>>
>> ### make the output
>> my $outfile = 'tmp';
>> open OUT, ">$outfile" or die "could not open '$outfile' $!";
>> foreach my $key ( sort keys %data ) {
>> print OUT select_line( $data{$key} ); # pass a ref-to-array
>> }
>> close OUT;
>>
>>
>> sub select_line {
>> my($linesref) = @_;
>>
>> return $linesref->[0] unless @$linesref > 1; # there is only one line
>>
>> print "$_: $linesref->[$_]" for 0 .. $#$linesref;
>> print " please select the line to keep: ";
>> chomp(my $index = <STDIN>);
>> return $linesref->[$index];
>> }
>>
>>
>> __DATA__
>> one two
>> one two
>> One Two
>> one three
>> Two five
>> two three
>> Two three
>> --------------------------------------------
>>
>>
>
> most of the below code is my previous effort + help from others
> it misses some lines from the file for a reason I don't know. I would
> like to know why if you have the time to review it. just for my
> understanding.
>
>
> #!/usr/bin/perl
> #use lib "/usr/local/lib/perl/5.6.1";
> use warnings;
> use strict;
>
> my $infile = "/home/data/avg";
> my $outfile = "/home/data/data";
>
> my %table;
> open DATA, $infile or die $!;
>
> while (<DATA>) {
> if ( $. > 1 ) { # if line number more than 1 = 'not the first line'
this line aboe is being run for each turn, it there a better way to have
the loop start from the second line and not from the first and save this
extra processing power for somthing else?
> my ($key, @value) = split;
> push @{ $table{ dateconvert($key) } }, [ @value ];
> # if there is a sub like ^^^^^ which apply to the $key where in your
> code that should go?
>
> }
> }
>
> for my $k (keys %table) {
> my $tnum = $#{$table{$k} };
> my $keep = 0;
> if ($tnum > 0) {
> for my $i (0..$tnum) {
> print $i+1, ": ", join " ", ($k, @{$table{$k}[$i]}), "\n";
> }
> print "please enter the line number to keep: ";
> chomp ( $keep = <STDIN> );
> if ($keep-1 > 0 ) {
> @{$table{$k}[0]} = @{$table{$k}[$keep-1]};
> until ($tnum-- == 0 ) {pop @{$table{$k}}};
> }
> else {
> until ($tnum-- == 0 ) {pop @{$table{$k}}};
> }
> }
> }
>
> open OUT, ">$outfile" or die $!;
> for my $k (sort keys %table) {
> print OUT "$k @{$table{$k}[0]}\n";
> }
>
>
> sub dateconvert {
> my $date = shift;
> my %months = (
> Jan => 1, Feb => 2, Mar => 3, Apr => 4,
> May => 5, Jun => 6, Jul => 7, Aug => 8,
> Sep => 9, Oct => 10, Nov => 11, Dec => 12
> );
> my ($day, $month, $year) = split /-/, $date;
> $year += $year > 35 ? 1900 : 2000;
> $month = $months{$month};
> return sprintf '%d%02d%02d', $year, $month, $day;
> }
>
------------------------------
Date: Sun, 5 Oct 2003 09:07:46 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: data varification code logic
Message-Id: <slrnbo09di.djp.tadmc@magna.augustmail.com>
King <king21122@yahoo.com> wrote:
> King wrote:
[ snip 150 lines of unneeded quoting. ]
Please trim your replies.
Please start doing that on your very next followup.
Thank you.
>> while (<DATA>) {
>> if ( $. > 1 ) { # if line number more than 1 = 'not the first line'
>
>
> this line aboe is being run for each turn, it there a better way to have
> the loop start from the second line and not from the first and save this
> extra processing power for somthing else?
<DATA>; # discard a line
while (<DATA>) {
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 5 Oct 2003 09:16:37 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: data varification code logic
Message-Id: <slrnbo09u5.djp.tadmc@magna.augustmail.com>
King <king21122@yahoo.com> wrote:
[ snip 150 unneeded lines of quoting yet again! ]
> my ($key, @value) = split;
> push @{ $table{ dateconvert($key) } }, [ @value ];
There is no need to make a copy:
push @{ $table{ dateconvert($key) } }, \@value;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 06 Oct 2003 00:39:27 +1000
From: King <king21122@yahoo.com>
Subject: Re: data varification code logic
Message-Id: <3F802D1F.6020002@yahoo.com>
King wrote:
> King wrote:
>
>> Tad McClellan wrote:
>>
>>> King <king21122@yahoo.com> wrote:
>>>
>>>
>>>
>>>> my @col = map { (split)[0] } <DATA>; # untested
>>>
>>>
>>>
>>>
>>>> this code will not work if it is in the same program with another
>>>> statement which is also using the <DATA> .
>>>
>>>
>>>
>>>
>>>
>>> Maybe, maybe not. We would need to see the actual code to tell (hint!).
>>>
>>>
>>>
>>>> if I comment the first block(s) then it works. where do I find some
>>>> reading about this if this is the correct behaviour, if not then
>>>> what is going on?
>>>
>>>
>>>
>>>
>>>
>>> I'm forced to guess at what is going on in the unseen code.
>>>
>>> The input operator above ( <DATA> ) is in "list context"
>>> (see "Context" section in perldata.pod).
>>>
>>> The input operator in list context reads _all_ of the lines
>>> from the filehandle, so you will be at end-of-file afterwards.
>>> (see the named function corresponding to <>: perldoc -f readline)
>>>
>>> BTW, the DATA filehandle is meant to be "meta" here, ie: you should
>>> replace it with some other properly open()ed filehandle in your
>>> real program.
>>>
>>> Sounds like you are trying to use the same filehandle for 2 different
>>> things. Can't you use 2 filehandles (and 2 files) for the 2 different
>>> things?
>>>
>>>
>>>
>>>> another point:
>>>> since I need to write DATA to another file FH, should I make an
>>>> array with those $seen{key} > 1 and then as I loop through the DATA
>>>> check each key to see weather to write this line out or to ask for
>>>> <STDIN> to choose which line to keep and ignore the rest of the
>>>> duplicates? or someother logic is better to do this?
>>>>
>>>> notice I changed the __DATA__ below in-order to better reflect what
>>>> I am trying to explain,
>>>
>>>
>>>
>>>
>>>
>>> If you change the requirements, the code is likely to be different.
>>>
>>> My earlier code is not very helpful given this new requirement.
>>>
>>> You can avoid lots of similar round-and-round by getting the
>>> requirements clear up-front.
>>>
>>> Too many iterations and you'll end up using all of your coupons
>>> before you get an answer that you can actually use...
>>>
>>>
>>>
>>>> I am trying to get the code to show me the whole lines of DATA with
>>>> the same keys and allow me to select which line to keep and
>>>> disregard the rest. so according to the DATA it should say
>>>> 1: one two1
>>>> 2: one two2
>>>> please select the line to keep:
>>>> if <STDIN> = 2 then donot copy "one two1" to the new file and do next
>>>
>>>
>>>
>>> ^
>>> ^ you cannot assign to the input operator, should be == ?
>>>
>>>
>>> We are still missing an essential requirement:
>>>
>>> Can we be sure that the entire file will fit into memory?
>>>
>>> The code (and algorithm) are likely to be very different
>>> depending on the answer to that question.
>>>
>>> I'll assume we can put the whole thing into memory.
>>>
>>>
>>> The best data structure seems to me to be a HoL (Hash of Lists, more
>>> accurately: a hash of references to arrays).
>>>
>>> --------------------------------------------
>>> #!/usr/bin/perl
>>> use strict;
>>> use warnings;
>>> use Data::Dumper; # invaluable for debugging data structures
>>>
>>> ### load up the data structure
>>> my %data; # HoL
>>> while ( <DATA> ) {
>>> my $key = (split)[0]; # or: my($key) = /^(\S*)/;
>>>
>>> push @{ $data{$key} }, $_; # save lines associated with the key
>>> }
>>> #print Dumper \%data; # see what it is that we have built thus far
>>>
>>>
>>> ### make the output
>>> my $outfile = 'tmp';
>>> open OUT, ">$outfile" or die "could not open '$outfile' $!";
>>> foreach my $key ( sort keys %data ) {
>>> print OUT select_line( $data{$key} ); # pass a ref-to-array
>>> }
>>> close OUT;
>>>
>>>
>>> sub select_line {
>>> my($linesref) = @_;
>>>
>>> return $linesref->[0] unless @$linesref > 1; # there is only one
>>> line
>>>
>>> print "$_: $linesref->[$_]" for 0 .. $#$linesref;
>>> print " please select the line to keep: ";
>>> chomp(my $index = <STDIN>);
>>> return $linesref->[$index];
>>> }
>>>
>>>
>>> __DATA__
>>> one two
>>> one two
>>> One Two
>>> one three
>>> Two five
>>> two three
>>> Two three
>>> --------------------------------------------
>>>
>>>
>>
>> most of the below code is my previous effort + help from others
>> it misses some lines from the file for a reason I don't know. I would
>> like to know why if you have the time to review it. just for my
>> understanding.
>>
>>
>> #!/usr/bin/perl
>> #use lib "/usr/local/lib/perl/5.6.1";
>> use warnings;
>> use strict;
>>
>> my $infile = "/home/data/avg";
>> my $outfile = "/home/data/data";
>>
>> my %table;
>> open DATA, $infile or die $!;
>>
>> while (<DATA>) {
>> if ( $. > 1 ) { # if line number more than 1 = 'not the first line'
>
>
>
> this line aboe is being run for each turn, it there a better way to have
> the loop start from the second line and not from the first and save this
> extra processing power for somthing else?
>
while ( <DATA> ) {
if ( $. > 1 ) { # if line number more than 1 = 'not the first line'
my $newdate = dateconvert ( (split)[0] );
s/^(\S+)\b/$newdate/;
my $key = (split)[0]; # or: my($key) = /^(\S*)/;
push @{ $data{$key} }, $_; # save lines associated with the key
}
}
------------------------------
Date: Sun, 05 Oct 2003 14:19:44 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: examples of sprintf
Message-Id: <3F80292A.190B5305@earthlink.net>
King wrote:
> Hello
>
> are there some easy examples on how to use the sprintf, examples that
> will assume you don't know any thing about the function and takes you
> one step at the time teaching you the ins and outs on its usage?
> I have read the online docs, but need more easy examples.
>
> I am trying to add numbers 20 infront of the format %d%02d%02d and could
> not find an example on how to do it.
>
> thanks
We wish there was. Perl documentation is short on
examples. The sprintf function is the one I'd most
like to see examples included in the documentation.
------------------------------
Date: Sun, 05 Oct 2003 14:00:16 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: How To activate command line history in debugger?
Message-Id: <QtVfb.24090$6C4.10770@pd7tw1no>
Kurt Kronschnabl <kurt.kronschnabl-nospam@ica-intercom-akademie.de> wrote:
>Hello Peter.
>
>As already told, there is no "ReadKey.pm" in a Knoppix and Suse 8.2
>installation. ReadLine is available in both distries. But only under
>Suse it works.
My news server spasmed and dropped this thread from its spool, and I didn't
see any reply to my emails to you. Install Term::ReadKey as root with
perl -MCPAN -e shell
CPAN> install Term::ReadKey
CAPAN> q
and email me if that doesn't fix the problem.
--
Peter Scott
http://www.perldebugged.com
------------------------------
Date: 5 Oct 2003 06:17:27 -0700
From: ksjdksjdksjd@yahoo.com (dweezel)
Subject: I like GWB
Message-Id: <b12eb1f9.0310050517.43d4ec81@posting.google.com>
blah
------------------------------
Date: 5 Oct 2003 23:20:26 +1000
From: "Kadaitcha Man" <nospam@rainx.cjb.net>
Subject: Re: I like GWB
Message-Id: <AKyiPs5y6bFo08785658kod7SizXWdOM@a.ns.infonomix.com>
dweezel wrote:
> blah
GWB? I s that like an MGB?
--
Kadaitcha Man: Kicking fuckwits in the head on Usenet since 1989
http://kadaitcha.kicks-ass.org:83/
Linux makes you stupid
------------------------------
Date: Sun, 05 Oct 2003 06:56:20 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Null value in print string
Message-Id: <Xns940B50BBD85CCsdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
anderson@glen-net.ca (David G Anderson) wrote in
news:ea22dbc.0310041857.31e461a5@posting.google.com:
> I wish to protect against a null value in the print string below:
>
> foreach my $result (@{$response->{Details}}) {
> print
> join "\n",
> $result->{ProductName}[0]||"no title",
> $result->{Asin}[0] . "\t" .
> $result->{ListPrice}[0] . "\n\n";
> }
You need more parentheses. Check the precedence of "||" and ".".
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP4AG2GPeouIeTNHoEQJLJQCeOzPRuL88PDNQtICUOCTMC72ICcgAoMRN
L6yKkfLOip2AyVA8UEYhNha/
=EEIU
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 05 Oct 2003 15:23:09 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: two regexs
Message-Id: <6n60ov407q1d0ut9hg0mohfjdqj000jivc@4ax.com>
X-Ftn-To: Greg Bacon
gbacon@hiwaay.net (Greg Bacon) wrote:
>: I would like to match each value from @str with only one regex. I come
>: to,
>: if ( /="(.+?)"|=(\S+)/ ) { print $1 || $2 }
>:
>: but I'm not sure if this is the best matching solution?
>
>How about the following?
It's fine but I was thinking about /alternative/ method for "match
everything between quotes OR match all consecutive non white chars". Since I
need this to parse html forms, I ended up with,
my $atr = qr/(?:["'](.*?)["']|([^>\s]+))/;
And here is the reinvented wheel with some known limitations(it doesn't
support group of checkboxes with same names).
=================================================
use strict;
my(%Q, $doc1);
{ local $/;
$doc1 = <DATA>;
}
$Q{IME} = 'user input';
$Q{_split} = ','; #for multiple select values
ParseForm(\$doc1);
print $doc1;
sub ParseForm {
##################################################
#
# popuni $$doc formu prema ulaznim parametrima
#
##################################################
use vars qw/%Q/;
my($doc, $i) = @_;
$doc ||= \$_;
$i ||= \%Q;
#atr regex
my $atr = qr/(?:["'](.*?)["']|([^>\s]+))/;
#text|hidden|password|checkbox|radio
$$doc =~ s{(<input.+?)(\s*/?>)}{
my($tag, $ending) = ($1, $2);
my $type = lc join'', $tag =~ /type=$atr/i;
if ($type) {
my $name = join'', $tag =~ /name=$atr/i;
my $value = $i->{$name};
#text|hidden|password
if ($type =~ /text|hidden|password/) {
$value = '' unless defined $value;
$value =~ s/"/"/g;
$tag =~ s/\s+value=$atr//i;
$tag .= qq{ value="$value"};
}
#checkbox|radio
elsif ($type =~ /checkbox|radio/) {
$tag =~ s/\s+checked//i;
if (($type eq 'checkbox' and defined $value) or
($tag =~ /value=$atr/i and ($1||$2) eq $value))
{
$tag .= ' checked';
}
}
}
"$tag$ending";
}iges;
#select|textarea
$$doc =~ s{(<(select|textarea).+?>)(.*?)(</\2>)}{
my($tag, $type, $cont, $ending) = ($1, lc $2, $3, $4);
my $name = join'', $tag =~ /name=$atr/i;
my $value = $i->{$name};
#textarea
if ($type eq 'textarea') { $cont = $value }
#select
else {
$cont =~ s/\s+selected(?=>)//ig;
my $split = $i->{'_split'};
my @vals = $split ? (split /$split/, $value) : $value;
$cont =~ s/(<[^>]+?=(?:["']$_["']|$_))/$1 selected/ for @vals;
}
"$tag$cont$ending";
}iges;
}
__DATA__
<form ....>
<input type=text name=IME size=50 maxlength=50 value="Default">
</form>
--
Matija
------------------------------
Date: Sun, 5 Oct 2003 08:33:16 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Unexpected alteration of array's content
Message-Id: <slrnbnvlqb.5km.dha@panix2.panix.com>
In article <3ee08638.0310041405.34a8e888@posting.google.com>, Roy Johnson wrote:
> Brian McCauley <nobull@mail.com> wrote in message news:<u9oewydvo3.fsf@wcl-l.bham.ac.uk>...
>>
>> No, map returns a _list_ not an _array_. It is quite possible for a
>> function that returns a list to return a list of lvalues.
>
> Alrighty, then. I don't see the importance of the distinction here,
> but I'm quite certain you are correct.
Perhaps a look at "What is the difference between a list and an array?"
in perlfaq4 might be in order then... unless you just mean you don't
see the importance in this *specific* case.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Sturgeon's Law: 90% of everything is crap.
Cassell's Corollary: Sturgeon would have upped that number if he'd
seen the Internet.
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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.
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 5618
***************************************