[29212] in Perl-Users-Digest
Perl-Users Digest, Issue: 456 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 00:10:14 2007
Date: Wed, 23 May 2007 21:09:10 -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 Wed, 23 May 2007 Volume: 11 Number: 456
Today's topics:
A simple way to make a code folder available as a modul <ilias@lazaridis.com>
Re: Date comparison.. <ts@dionic.net>
Re: Date comparison.. <paduille.4061.mumia.w+nospam@earthlink.net>
Re: Date comparison.. <tadmc@augustmail.com>
Re: Date comparison.. clearguy02@gmail.com
Re: Date comparison.. <purlgurl@purlgurl.net>
Re: Date comparison.. <tadmc@augustmail.com>
Re: Hashed to death... help needed. <zrogon@poczta.onet.pl>
Re: Hashed to death... help needed. xhoster@gmail.com
Re: Hashed to death... help needed. <jgibson@mail.arc.nasa.gov>
Re: Hashed to death... help needed. <zrogon@poczta.onet.pl>
Re: Hashed to death... help needed. <zrogon@poczta.onet.pl>
Re: localtime(time()) <noreply@gunnar.cc>
Re: make money by visiting websites krakle@visto.com
Re: Question about pack function in 64bit 2 core CPU <sisyphus1@nomail.afraid.org>
text substitution <pauls@pauls.seanet.com>
Re: text substitution <noreply@gunnar.cc>
Re: text substitution <tadmc@augustmail.com>
Re: text substitution <pauls@pauls.seanet.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 May 2007 20:16:58 -0700
From: Ilias Lazaridis <ilias@lazaridis.com>
Subject: A simple way to make a code folder available as a module
Message-Id: <1179976618.258711.24550@q66g2000hsg.googlegroups.com>
I have a folder with several perl code modules, organized in several
sub-folders.
I've checked out the code via svn on several machines and things run
fine.
Now I have to make the code (under development) available system-wide.
I've looked in several articles and documentation, but got mostly
confused.
My questions are basicly:
a) How can I make a=CE=BD svn checked out folder available as a system-wide
importable module (e.g. a command which adds the folder to the "perl
module search path").
b) How can I convert existing code into a module? (e.g. a command
which creates an installable package)
.
--
http://dev.lazaridis.com/lang/wiki/Perl
------------------------------
Date: Wed, 23 May 2007 23:12:55 +0100
From: Tim S <ts@dionic.net>
Subject: Re: Date comparison..
Message-Id: <4654bc67$0$642$5a6aecb4@news.aaisp.net.uk>
clearguy02@gmail.com wrote:
> On May 23, 2:01 pm, cleargu...@gmail.com wrote:
>> Hi folks,
>>
>> I need to convert a date from the original format 2007-05-27 00:00:00
>> to 5/27/2007.
>>
>> >From the original date, I should strip off all the trailing stuff
>>
>> (00:00:00) and the months (03, 04, 05 etc) should appear as 3, 4, 5
>> etc.
>>
>> I am trying to use the sprintf function and some truncating stuff, but
>> I am not getting the desired results.
>>
>> Can some one tell me how I can achieve the desired result?
>>
>> Thanks
>> -J
>
> Sorry for fogetting to post my code:
>
> +++++++++++++++++++++
>
> $date1 = "2007-05-27 00:00:00";
> $date1 =~ s/(.*)\s+(.*)/($1)($2)/;
> $date2 = $1;
> $date2 =~ s/(.*)-(.*)-(.*)/$1$2$3/;
> $year = $1;
> $month = $2;
> $date = $3;
> $month =~ s/0//;
> $date3 = "$month/$date/$year";
> print "$date3\n";
> ++++++++++++++++++++++++++++
>
> Is there a shorter way to do it?
With your code format, this would be the same but more concise:
my $date1 = "2007-05-27 00:00:00";
my ($year, $month, $day) = ($date1 =~ m/^(\d+)-(\d+)-(\d+)\s/) or
die "[$date1] Doesn't look like a date";
printf "%d/%d/%d", $month, $day, $year;
Note you must use "or" not "||" as the precedence is different.
Date::Manip may be of interest too.
HTH
Tim
------------------------------
Date: Wed, 23 May 2007 22:36:26 GMT
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Date comparison..
Message-Id: <Kl35i.14469$j63.1241@newsread2.news.pas.earthlink.net>
On 05/23/2007 04:50 PM, clearguy02@gmail.com wrote:
> On May 23, 2:01 pm, cleargu...@gmail.com wrote:
>> Hi folks,
>>
>> I need to convert a date from the original format 2007-05-27 00:00:00
>> to 5/27/2007.
>> [ code snipped ]
>
> Is there a shorter way to do it?
>
> Thanks
> -J
>
Using Date::Parse would make it much shorter.
------------------------------
Date: Wed, 23 May 2007 18:00:51 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Date comparison..
Message-Id: <slrnf59ht3.ph5.tadmc@tadmc30.august.net>
clearguy02@gmail.com <clearguy02@gmail.com> wrote:
> On May 23, 2:01 pm, cleargu...@gmail.com wrote:
>> Hi folks,
>>
>> I need to convert a date from the original format 2007-05-27 00:00:00
>> to 5/27/2007.
> Sorry for fogetting to post my code:
>
>
> $date1 = "2007-05-27 00:00:00";
> $date1 =~ s/(.*)\s+(.*)/($1)($2)/;
> $date2 = $1;
You should never use the dollar-digit variables unless you
have first tested to ensure that the match succeeded.
> $date2 =~ s/(.*)-(.*)-(.*)/$1$2$3/;
> $year = $1;
> $month = $2;
> $date = $3;
> $month =~ s/0//;
> $date3 = "$month/$date/$year";
> print "$date3\n";
> ++++++++++++++++++++++++++++
>
> Is there a shorter way to do it?
$date1 =~ s#(\d+)-0*(\d+)-0*(\d+).*#$2/$3/$1#;
or
$date1 = join '/', ($date1 =~ /0*(\d+)/g)[1,2,0]; # list slice
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 23 May 2007 16:25:11 -0700
From: clearguy02@gmail.com
Subject: Re: Date comparison..
Message-Id: <1179962711.726782.313510@p47g2000hsd.googlegroups.com>
On May 23, 4:00 pm, Tad McClellan <t...@augustmail.com> wrote:
> cleargu...@gmail.com <cleargu...@gmail.com> wrote:
> > On May 23, 2:01 pm, cleargu...@gmail.com wrote:
> >> Hi folks,
>
> >> I need to convert a date from the original format 2007-05-27 00:00:00
> >> to 5/27/2007.
> > Sorry for fogetting to post my code:
>
> > $date1 = "2007-05-27 00:00:00";
> > $date1 =~ s/(.*)\s+(.*)/($1)($2)/;
> > $date2 = $1;
>
> You should never use the dollar-digit variables unless you
> have first tested to ensure that the match succeeded.
>
> > $date2 =~ s/(.*)-(.*)-(.*)/$1$2$3/;
> > $year = $1;
> > $month = $2;
> > $date = $3;
> > $month =~ s/0//;
> > $date3 = "$month/$date/$year";
> > print "$date3\n";
> > ++++++++++++++++++++++++++++
>
> > Is there a shorter way to do it?
>
> $date1 =~ s#(\d+)-0*(\d+)-0*(\d+).*#$2/$3/$1#;
> or
> $date1 = join '/', ($date1 =~ /0*(\d+)/g)[1,2,0]; # list slice
>
> --
> Tad McClellan SGML consulting
> t...@augustmail.com Perl programming
> Fort Worth, Texas
Thanks to all of you. Now I realize that I need to compare two dates
(example: 3/18/2007 and 2007-03-18 11.23.54) to see if they are equal
or not from the date comparison point of view, not from the string
comparison point.
Can any one tell me how I can do it?
------------------------------
Date: Wed, 23 May 2007 18:28:29 -0700
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: Date comparison..
Message-Id: <CZGdnXYsFMjdd8nbnZ2dneKdnZydnZ2d@giganews.com>
clearguy02 wrote:
> I need to convert a date from the original format 2007-05-27 00:00:00
> to 5/27/2007.
(snipped)
#!perl
$date = "2007-01-07 00:00:00";
$year = substr ($date, 0, 4);
$month = substr ($date, 5, 2);
$day = substr ($date, 8, 2);
$month += 0;
$day += 0;
print "$month/$day/$year";
You will discover more examples and discussion in the
other group to which you provide your article.
Work at writing to only one group to avoid duplication
of reader articles and reader effort.
--
Purl Gurl
--
"Then again what can you expect from a fat-assed, champagne swilling,
half-breed just off the Rez?"
- Joe Kline
------------------------------
Date: Wed, 23 May 2007 20:37:48 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Date comparison..
Message-Id: <slrnf59r3c.qv6.tadmc@tadmc30.august.net>
clearguy02@gmail.com <clearguy02@gmail.com> wrote:
> I need to compare two dates
> (example: 3/18/2007 and 2007-03-18 11.23.54) to see if they are equal
> or not from the date comparison point of view, not from the string
> comparison point.
>
> Can any one tell me how I can do it?
If you normalize to a carefully thought out form, then
you _can_ use the string comparison point of view.
-----------------------------------
#!/usr/bin/perl
use warnings;
use strict;
my $date1 = '2007-03-18 11.23.54';
my $date2 = '3/18/2007';
$date1 =~ s/ .*//;
$date2 =~ s#(\d+)/(\d+)/(\d+)# sprintf '%4d-%02d-%02d', $3, $1, $2#e;
print "they are equal\n" if $date1 eq $date2;
-----------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 24 May 2007 00:16:36 +0100
From: "Teq" <zrogon@poczta.onet.pl>
Subject: Re: Hashed to death... help needed.
Message-Id: <f32i2m$3ja$1@news.onet.pl>
"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
news:230520071458272369%jgibson@mail.arc.nasa.gov...
> Have you taken the time to read the guidelines for posting to this
> group?
[...]
> That is as far as I wished to analyze your program. If you fix up the
> peculiarities mentioned and re-post it (albeit a shorter version that
> uses <DATA>), I or someone else can probably help you.
Admittedly I deserved that :(
Thanks for the tips, I've redesigned the program (loosing about 50 lines of
code, sweet ;)), but this time I'll post only the part that is of
consequence ;)
----------------------------------------------
#!/usr/bin/perl -w
use strict;
use warnings;
my %dane;
while (<DATA>) {
my ( $x, $y, undef, $z ) = split;
push @{ $dane{$x}->{$z} }, $y;
}
foreach my $pdbID ( keys %dane ) {
foreach my $secID ( keys %{ $dane{$pdbID} } ) {
my @resnums = ( $dane{$pdbID}->{$secID}->[0],
$dane{$pdbID}->{$secID}->[-1] );
print "$pdbID @resnums $secID\n";
}
}
__DATA__
1b6g 1 M \N
1b6g 2 V \N
1b6g 3 N \N
1b6g 4 N H
1b6g 5 N H
1b6g 6 N \N
3hba 7 W H
2cdg 8 N H
2cdg 9 V \N
2cdg 10 M \N
2cdg 11 A B
2cdg 12 M \N
-------------------------------------
the output is
3hba 7 7 H
1b6g 4 5 H
1b6g 1 6 \N
2cdg 8 8 H
2cdg 9 12 \N
2cdg 11 11 B
and I don't know how to get that sucker to identify when secStructID has
changed and finish one entity, and only store sequential groups of secondary
structures for the same pdbID.
the output should be:
1b6g 1 3 \N
1b6g 4 5 H
1b6g 6 6 \N
3hba 7 8 H
2cdg 9 10 \N
2cdg 11 A B
2cdg 12 M \N
And no, it's not homework ;) I'm trying to redo something that I have
written in Java some time ago, at the same time I'm learning perl, hence all
the weird loops in original code, instead of the perl-typical code. All I
know of hashes I have read in the last 7 hours, so please have mercy ;)
Before I started seeking help, it was 250 lines of code (mostly
java-style), doing less than the above. I will appreciate any hints as, I am
stuck.
Cheers,
Matt
------------------------------
Date: 24 May 2007 00:21:52 GMT
From: xhoster@gmail.com
Subject: Re: Hashed to death... help needed.
Message-Id: <20070523202155.966$Pa@newsreader.com>
"Teq" <zrogon@poczta.onet.pl> wrote:
>
> ----------------------------------------------
> #!/usr/bin/perl -w
> use strict;
> use warnings;
>
> my %dane;
> while (<DATA>) {
> my ( $x, $y, undef, $z ) = split;
> push @{ $dane{$x}->{$z} }, $y;
> }
>
> foreach my $pdbID ( keys %dane ) {
> foreach my $secID ( keys %{ $dane{$pdbID} } ) {
> my @resnums = ( $dane{$pdbID}->{$secID}->[0],
> $dane{$pdbID}->{$secID}->[-1] );
>
> print "$pdbID @resnums $secID\n";
> }
> }
>
> __DATA__
> 1b6g 1 M \N
> 1b6g 2 V \N
> 1b6g 3 N \N
> 1b6g 4 N H
> 1b6g 5 N H
> 1b6g 6 N \N
> 3hba 7 W H
> 2cdg 8 N H
> 2cdg 9 V \N
> 2cdg 10 M \N
> 2cdg 11 A B
> 2cdg 12 M \N
>
> -------------------------------------
>
> the output is
> 3hba 7 7 H
> 1b6g 4 5 H
> 1b6g 1 6 \N
> 2cdg 8 8 H
> 2cdg 9 12 \N
> 2cdg 11 11 B
>
> and I don't know how to get that sucker to identify when secStructID has
> changed and finish one entity,
It is not clear that a hash is the right way to go about this. It seems
like you want to address the data in the same sequence that it is
presented, rather than storing everything in a mostly orderless data
structure. If so, then you need to record the PDBid and seqID from the
last time through the loop and check to see if it changed on this time
through the loop. That kind of code is conceptually simple but alas it is
tedious and ugly (in any language, as far as I know). Out of curiosity,
how did you do it in Java?
This is what I came up with:
my ( $x, $y, undef, $z ) = split ' ', <DATA>;
my ($last_x,$last_z,$min,$max)=($x,$z,$y,$y);
while (<DATA>) {
my ( $x, $y, undef, $z ) = split;
if ($x ne $last_x or $z ne $last_z) {
print "$last_x $min $max $last_z\n";
($last_x,$last_z,$min,$max)=($x,$z,$y,$y);
};
$max=$y;
}
print "$last_x $min $max $last_z\n";
It is ugly because the print has to happen in two places (in the loop
and after the loop) and the assignment has to happen in two places
(before the loop and in the loop), but as I say this is a very common
piece of ugliness.
> and only store sequential groups of
> secondary structures for the same pdbID.
>
> the output should be:
> 1b6g 1 3 \N
> 1b6g 4 5 H
> 1b6g 6 6 \N
> 3hba 7 8 H
Is this really what you want? 7 was in 3hba and 8 was in 2cdg, so you
didn't detect the transition from 3hba to 2cdg, contrary to what you say
above about "for the same pdbID".
> 2cdg 9 10 \N
> 2cdg 11 A B
> 2cdg 12 M \N
> And no, it's not homework ;) I'm trying to redo something that I have
> written in Java some time ago, at the same time I'm learning perl, hence
> all the weird loops in original code, instead of the perl-typical code.
> All I know of hashes I have read in the last 7 hours, so please have
> mercy ;) Before I started seeking help, it was 250 lines of code (mostly
> java-style), doing less than the above. I will appreciate any hints as, I
> am stuck.
Going back to your hash-based code: In stead of taking the first and last
element of the array @{$dane{$pdbID}->{$secID}}, like you currently do,
you could detect gaps in the values of this array and take the first and
last elements of each non-contiguous chunk. You could probably even do
this in a single grep or map statement, but I think doing so would be
overly clever.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Wed, 23 May 2007 17:49:32 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Hashed to death... help needed.
Message-Id: <230520071749320480%jgibson@mail.arc.nasa.gov>
In article <f32i2m$3ja$1@news.onet.pl>, Teq <zrogon@poczta.onet.pl>
wrote:
> "Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
> news:230520071458272369%jgibson@mail.arc.nasa.gov...
> > Have you taken the time to read the guidelines for posting to this
> > group?
> [...]
> > That is as far as I wished to analyze your program. If you fix up the
> > peculiarities mentioned and re-post it (albeit a shorter version that
> > uses <DATA>), I or someone else can probably help you.
>
> Admittedly I deserved that :(
> Thanks for the tips, I've redesigned the program (loosing about 50 lines of
> code, sweet ;)), but this time I'll post only the part that is of
> consequence ;)
Thank you for that.
>
> ----------------------------------------------
> #!/usr/bin/perl -w
> use strict;
> use warnings;
>
> my %dane;
> while (<DATA>) {
> my ( $x, $y, undef, $z ) = split;
You are discarding your third field, yet it shows up in your output
below (last two lines). Either save it here or don't expect it to be
output.
>
> push @{ $dane{$x}->{$z} }, $y;
> }
>
> foreach my $pdbID ( keys %dane ) {
> foreach my $secID ( keys %{ $dane{$pdbID} } ) {
> my @resnums = ( $dane{$pdbID}->{$secID}->[0],
> $dane{$pdbID}->{$secID}->[-1] );
You are printing the first and last values for each pdbID and secID
pair, and not accounting for the possibility that some values are
skipped. You need to add logic for that case, which is part of your
test data and reflected in your desired output.
>
> print "$pdbID @resnums $secID\n";
> }
> }
>
> __DATA__
> 1b6g 1 M \N
> 1b6g 2 V \N
> 1b6g 3 N \N
> 1b6g 4 N H
> 1b6g 5 N H
> 1b6g 6 N \N
> 3hba 7 W H
> 2cdg 8 N H
The above two lines have the same value in field 4, but different
values in field 1. Your desired output ignores the different value in
field 1 of the second of the two records. Is that correct?
> 2cdg 9 V \N
> 2cdg 10 M \N
> 2cdg 11 A B
> 2cdg 12 M \N
>
> -------------------------------------
>
> the output is
> 3hba 7 7 H
> 1b6g 4 5 H
> 1b6g 1 6 \N
> 2cdg 8 8 H
> 2cdg 9 12 \N
> 2cdg 11 11 B
>
> and I don't know how to get that sucker to identify when secStructID has
> changed and finish one entity, and only store sequential groups of secondary
> structures for the same pdbID.
You need to compare each record read with the previous record and see
if the relevant fields have changed. For this, a hash is not the best
data type. An array would be better.
>
> the output should be:
> 1b6g 1 3 \N
> 1b6g 4 5 H
> 1b6g 6 6 \N
> 3hba 7 8 H
> 2cdg 9 10 \N
> 2cdg 11 A B
> 2cdg 12 M \N
You want the output in the same order as the input. But plain hashes do
not preserve the order in which elements are inserted (unless you use a
special "tied" hash -- see perldoc -q "hash remember")
>
> And no, it's not homework ;) I'm trying to redo something that I have
> written in Java some time ago, at the same time I'm learning perl, hence all
> the weird loops in original code, instead of the perl-typical code. All I
> know of hashes I have read in the last 7 hours, so please have mercy ;)
> Before I started seeking help, it was 250 lines of code (mostly
> java-style), doing less than the above. I will appreciate any hints as, I am
> stuck.
Here is a program that gives your desired output, except for the
discarded element in the original record. I leave that as an exercise
for the reader.
#!/usr/local/bin/perl
use strict;
use warnings;
my $c = ['',0,'',0];
my @dane;
while (<DATA>) {
chomp;
my $d = [(split)[0,1,3]];
push(@$d,$d->[1]);
if( ($d->[2] eq $c->[2]) ) {
if( $d->[1] eq $c->[3]+1 ) {
$c->[3] = $d->[1];
}else{
push(@dane,[(@$c)[0,1,3,2]]) if $c->[0];
$c = $d;
}
}else{
push(@dane,[(@$c)[0,1,3,2]]) if $c->[0];
$c = $d;
}
}
push(@dane,[(@$c)[0,1,3,2]]) if $c->[0];
for (@dane) {
print join("\t",@$_),"\n";
}
__DATA__
1b6g 1 M \N
1b6g 2 V \N
1b6g 3 N \N
1b6g 4 N H
1b6g 5 N H
1b6g 6 N \N
3hba 7 W H
2cdg 8 N H
2cdg 9 V \N
2cdg 10 M \N
2cdg 11 A B
2cdg 12 M \N
__OUTPUT__
1b6g 1 3 \N
1b6g 4 5 H
1b6g 6 6 \N
3hba 7 8 H
2cdg 9 10 \N
2cdg 11 11 B
2cdg 12 12 \N
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Thu, 24 May 2007 02:41:12 +0100
From: "Teq" <zrogon@poczta.onet.pl>
Subject: Re: Hashed to death... help needed.
Message-Id: <f32qre$ftq$1@news.onet.pl>
<xhoster@gmail.com> wrote in message
news:20070523202155.966$Pa@newsreader.com...
> It is not clear that a hash is the right way to go about this. It seems
> like you want to address the data in the same sequence that it is
> presented, rather than storing everything in a mostly orderless data
> structure. If so, then you need to record the PDBid and seqID from the
> last time through the loop and check to see if it changed on this time
> through the loop. That kind of code is conceptually simple but alas it is
> tedious and ugly (in any language, as far as I know). Out of curiosity,
> how did you do it in Java?
In Java the source was very much different because it was a raw file, these
here are already pre-processed by other scripts.
For each pdb file the data would be parsed and I would iterate through my
original parser-output arrays extracting data into variables, which then I
used to create AAObjects (containing resNum, resID, secStructID), which in
turn were then moved into aaObjectList - an array of objects.
Then I used these objects to create secondary structure objects and
secondary structure array of objects.
I would iterate around the initial aaObjectList checking for secStructID
(e.g. E,G,H) and each time I would discover a new one I'd set start
position, each time I'd encounter a different one I'd set end position (-1)
and pass the secStructID along with the length of the object start-to-end,
resID list from start position to the end position into a new object
SSObject.
Obviously as you said - the data was in proper order, unlike in case of
hashes, of which I was not aware :/
Java for me is more straightforward, but it's overkill for some tasks (my
original dssp parser was with all the bling ;) and it was something around 3
thousand lines), hence me working perl.
Still, it took me 3 days to understand that I can't really work with objects
in perl like I do in Java, and another 2 to realize that java-like loops of
30 lines+ can be compressed into 1 line of code (for this I thank Jim which
was kind enough to point it out ;))
> This is what I came up with:
[code cut]
Thank you very much for the code, I will work it out tomorrow, it's almost
3am here, I'm going to bed ;)
>> 1b6g 6 6 \N
>> 3hba 7 8 H
> Is this really what you want? 7 was in 3hba and 8 was in 2cdg, so you
> didn't detect the transition from 3hba to 2cdg, contrary to what you say
> above about "for the same pdbID".
You are absolutely right, my bad - these should have been separated, that's
what happens when I sit at my computer after midnight ;(.
> Going back to your hash-based code: In stead of taking the first and last
> element of the array @{$dane{$pdbID}->{$secID}}, like you currently do,
> you could detect gaps in the values of this array and take the first and
> last elements of each non-contiguous chunk.
The idea with using a hash here is mostly because I want to learn it, and
because it was adviced by another usenet user :) not because it is a good
practice (also currently I am such a newbie that I don't really know what is
good practice in the first place) - I have managed to conquer this problem
with a set of nested if, elsif's but it was UGLY and a couple HUNDRED lines
longer than a perl script should be, I will follow your tips. Thank you !
Cheers,
Matt
------------------------------
Date: Thu, 24 May 2007 02:57:19 +0100
From: "Teq" <zrogon@poczta.onet.pl>
Subject: Re: Hashed to death... help needed.
Message-Id: <f32rfj$gj9$2@news.onet.pl>
"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
news:230520071749320480%jgibson@mail.arc.nasa.gov...
>> my %dane;
>> while (<DATA>) {
>> my ( $x, $y, undef, $z ) = split;
>
> You are discarding your third field, yet it shows up in your output
> below (last two lines). Either save it here or don't expect it to be
> output.
hmm, I'll double check but I'm almost sure it's not in the output, I am
considering using it, but it'll have to wait until I have finished the
database schema.
>> foreach my $pdbID ( keys %dane ) {
>> foreach my $secID ( keys %{ $dane{$pdbID} } ) {
>> my @resnums = ( $dane{$pdbID}->{$secID}->[0],
>> $dane{$pdbID}->{$secID}->[-1] );
>
>> 3hba 7 W H
>> 2cdg 8 N H
>
> The above two lines have the same value in field 4, but different
> values in field 1. Your desired output ignores the different value in
> field 1 of the second of the two records. Is that correct?
no no, that was a stupid mistake of mine, as Xho has pointed out in the
earlier message, the output should actually differentiate between these two
3hba 7 7 H
2cdg 8 8 H
> You need to compare each record read with the previous record and see
> if the relevant fields have changed. For this, a hash is not the best
> data type. An array would be better.
> You want the output in the same order as the input. But plain hashes do
> not preserve the order in which elements are inserted (unless you use a
> special "tied" hash -- see perldoc -q "hash remember")
I completely disregarded the fact that the data in the hash is unordered
assuming that the identification by pdbID and sequence of values in resNum
would be sufficient, I have to think about this.
> Here is a program that gives your desired output, except for the
> discarded element in the original record. I leave that as an exercise
> for the reader.
Thank you very much for all your trouble. Although the code by Xho above
seems far simpler I will definitely try to work out the idea with hashes,
best time to learn it is now :).
Regards,
Matt
------------------------------
Date: Thu, 24 May 2007 03:09:41 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: localtime(time())
Message-Id: <5bk73gF2t5grkU1@mid.individual.net>
Tony Curtis wrote:
> Gunnar Hjalmarsson wrote:
>> Tony Curtis wrote:
>>> Well, you've answered your own question...but simpler is:
>>>
>>> use POSIX qw( strftime );
>>>
>>> print strftime '%Y-%m-%d', localtime();
>>
>> I'm not sure that using POSIX is simpler, since at least I would need
>> to look up the applicable conversion specifiers.
>>
>> I would do:
>>
>> my ($d, $m, $y) = ( localtime )[3..5];
>> printf '%d-%02d-%02d', $y+1900 , $m+1, $d;
>
> "Simpler" of course depends on the metric(s) you use to measure complexity,
> but I would definitely argue that strftime() is certainly much easier to
> read,
> especially *for other people*, and thus produces "simpler" code.
Working with localtime() and (s)printf() is simple enough even for
beginner level Perl programmers. Whoelse would you be coding for? ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 23 May 2007 21:02:02 -0700
From: krakle@visto.com
Subject: Re: make money by visiting websites
Message-Id: <1179979322.547855.138920@o5g2000hsb.googlegroups.com>
On May 23, 4:00 am, palanivel <tpr...@gmail.com> wrote:
> As the name implies, you make money by simply visiting websites for at
> least 30 seconds/visit. We will pay you $0.01 for each website you
> visit and $0.01 for each website your referrals visit. The best part
> is you can have an unlimited amount of referrals!
What are you an absolute idiot? Visiting web sites in 30 second
interval means you can view a max of 120 web sites an hour. Which pays
$1.20/hr. If you decide to spend 24/7 surfing the web (without sleep,
bathroom breaks, food, or slowing down your surfing rate) for 1 whole
week you will barely break $200. Which would be $140 LESS than a full
time Mcdonalds employee working 67% less hours. Maybe that's great in
india............but that's a complete joke anywhere else. Especially
offtopic in a Perl newsgroup you moron.
------------------------------
Date: Thu, 24 May 2007 09:39:24 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Question about pack function in 64bit 2 core CPU
Message-Id: <4654d08d$0$27448$afc38c87@news.optusnet.com.au>
"Peter J. Holzer" <hjp-usenet2@hjp.at> wrote in message
news:slrnf58to8.sia.hjp-usenet2@zeno.hjp.at...
> On 2007-05-23 16:01, Sisyphus <sisyphus1@nomail.afraid.org> wrote:
.
.
>>
>> Yes - I was referring specifically to ActivePerl, where
>> 'perl -V:longsize'
>> is '4' on both the 32-bit and 64-bit versions.
>
> Yes, but my point was that size of 'N' is independent of 'perl
> -V:longsize'. Even on systems where the latter is 8, pack('N', ...)
> still returns 4 bytes.
>
Aaaah ... I understand (now). Thanks.
Cheers,
Rob
------------------------------
Date: 23 May 2007 17:42:09 -0700
From: pula58 <pauls@pauls.seanet.com>
Subject: text substitution
Message-Id: <1179967329.322216.219940@r3g2000prh.googlegroups.com>
I have a text file with many occurances of the following text:
dev/group
I want to replace the (above) text with the following:
$ dev/group
But, I am having trouble when I use this code:
s/dev/group/$ dev/group
due to use of $ and /
Any tips on how I can do the replacement?
Thanks
P
------------------------------
Date: Thu, 24 May 2007 03:01:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: text substitution
Message-Id: <5bk6kbF1fu628U1@mid.individual.net>
pula58 wrote:
> I have a text file with many occurances of the following text:
>
> dev/group
>
> I want to replace the (above) text with the following:
>
> $ dev/group
>
> But, I am having trouble when I use this code:
>
> s/dev/group/$ dev/group
>
> due to use of $ and /
>
> Any tips on how I can do the replacement?
s|(dev/group)|\$ $1|g;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 23 May 2007 20:44:02 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: text substitution
Message-Id: <slrnf59rf2.qv6.tadmc@tadmc30.august.net>
pula58 <pauls@pauls.seanet.com> wrote:
> I have a text file with many occurances of the following text:
>
> dev/group
>
> I want to replace the (above) text with the following:
>
>
> $ dev/group
>
> But, I am having trouble when I use this code:
>
> s/dev/group/$ dev/group
>
> due to use of $ and /
>
> Any tips on how I can do the replacement?
Put a backslash in front of the meta characters that you
want to be literal:
s/dev\/group/\$ dev\/group/;
or use single quote as the delimiter:
s'dev/group'$ dev/group';
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 23 May 2007 19:52:21 -0700
From: pula58 <pauls@pauls.seanet.com>
Subject: Re: text substitution
Message-Id: <1179975141.296182.33570@u36g2000prd.googlegroups.com>
On May 23, 6:44 pm, Tad McClellan <t...@augustmail.com> wrote:
> pula58 <p...@pauls.seanet.com> wrote:
> > I have a text file with many occurances of the following text:
>
> > dev/group
>
> > I want to replace the (above) text with the following:
>
> > $ dev/group
>
> > But, I am having trouble when I use this code:
>
> > s/dev/group/$ dev/group
>
> > due to use of $ and /
>
> > Any tips on how I can do the replacement?
>
> Put a backslash in front of the meta characters that you
> want to be literal:
>
> s/dev\/group/\$ dev\/group/;
>
> or use single quote as the delimiter:
>
> s'dev/group'$ dev/group';
>
> --
> Tad McClellan SGML consulting
> t...@augustmail.com Perl programming
> Fort Worth, Texas- Hide quoted text -
>
> - Show quoted text -
That did the trick, thank you very much (to you both)!
P.
------------------------------
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 V11 Issue 456
**************************************