[28367] in Perl-Users-Digest
Perl-Users Digest, Issue: 9731 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 18:10:24 2006
Date: Fri, 15 Sep 2006 15:10:06 -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: 9731
Today's topics:
Sum the middle column for a given unique volser. <Noatec@gmail.com>
Re: Sum the middle column for a given unique volser. <mritty@gmail.com>
Re: Sum the middle column for a given unique volser. <mritty@gmail.com>
Re: Sum the middle column for a given unique volser. <Noatec@gmail.com>
Re: Sum the middle column for a given unique volser. <glex_no-spam@qwest-spam-no.invalid>
Re: Sum the middle column for a given unique volser. <mritty@gmail.com>
Re: Sum the middle column for a given unique volser. <Noatec@gmail.com>
Re: Sum the middle column for a given unique volser. <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Sep 2006 11:28:12 -0700
From: "Noatec" <Noatec@gmail.com>
Subject: Sum the middle column for a given unique volser.
Message-Id: <1158344892.592614.281260@b28g2000cwb.googlegroups.com>
If I have a data set like the one below.
1st column = tape volser.
2nd column = the number of reads in the last hour.
3rd column = the last write date.
I need to sum the 2nd column for each unique volser and spit out
volser,sum,last write date.
Would anyone be interested in helping me incorporate the hash?
Sample Data:
300000,1,2003-08-22
300000,1,2003-08-22
300000,1,2003-08-22
300000,1,2003-08-22
300000,1,2003-08-22
300000,1,2003-08-22
300000,2,2003-08-22
300000,2,2003-08-22
300000,2,2003-08-22
300000,2,2003-08-22
300000,3,2003-08-22
300000,3,2003-08-22
300001,1,2003-04-21
300001,1,2003-04-21
300001,1,2003-04-21
300001,1,2003-04-21
300001,1,2003-04-21
300001,1,2003-04-21
So on an so forth for 1500 volsers.
This is all I have so far.
#!/usr/bin/perl
use warnings;
my $line = mlist;
my $sum = 0;
# open the file
open(MLIST,"$line") or die "Unable to open mlist:$!\n";
# read it in one record at a time
while ($line = <MLIST>) {
my ($volser,$reads,$lwd) = split(/,/,$line);
printf "$volser $reads $lwd"
}
# close the file
close(MLIST);
------------------------------
Date: 15 Sep 2006 11:33:18 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158345198.136276.144170@i3g2000cwc.googlegroups.com>
Noatec wrote:
[[ snip the same problem description as posted in
http://groups.google.com/group/perl.beginners/browse_frm/thread/5e1dc096d6d7ca13/5fed15f7d9ea1837?lnk=st&q=&rnum=1#5fed15f7d9ea1837
]]
> This is all I have so far.
No, that's what someone else was gracious enough to GIVE you.
> #!/usr/bin/perl
> use warnings;
> my $line = mlist;
> my $sum = 0;
>
> # open the file
> open(MLIST,"$line") or die "Unable to open mlist:$!\n";
>
> # read it in one record at a time
> while ($line = <MLIST>) {
> my ($volser,$reads,$lwd) = split(/,/,$line);
>
>
> printf "$volser $reads $lwd"
> }
>
> # close the file
> close(MLIST);
If you didn't understand the code you were given, why didn't you ask
the person who gave it to you for a clarification? Why are you now
posting in a completely different group, pretending that you came up
with this on your own?
Paul Lalli
------------------------------
Date: 15 Sep 2006 11:35:13 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158345313.851338.300310@p79g2000cwp.googlegroups.com>
Paul Lalli wrote:
> Noatec wrote:
>
> [[ snip the same problem description as posted in
> http://groups.google.com/group/perl.beginners/browse_frm/thread/5e1dc096d6d7ca13/5fed15f7d9ea1837?lnk=st&q=&rnum=1#5fed15f7d9ea1837
> ]]
>
>
> > This is all I have so far.
>
> No, that's what someone else was gracious enough to GIVE you.
>
> > #!/usr/bin/perl
> > use warnings;
> > my $line = mlist;
> > my $sum = 0;
> >
> > # open the file
> > open(MLIST,"$line") or die "Unable to open mlist:$!\n";
> >
> > # read it in one record at a time
> > while ($line = <MLIST>) {
> > my ($volser,$reads,$lwd) = split(/,/,$line);
> >
> >
> > printf "$volser $reads $lwd"
> > }
> >
> > # close the file
> > close(MLIST);
>
> If you didn't understand the code you were given, why didn't you ask
> the person who gave it to you for a clarification? Why are you now
> posting in a completely different group, pretending that you came up
> with this on your own?
>
Bah. I completely misread the thread I referenced above. The code
posted is what the OP posted there as well. My apologies. However, my
question still stands as to why you are suddenly jumping groups and
asking for a fresh start rather than following up to that thread.
Someone there did help you out with putting your data into a hash. If
you don't understand that code, ask about it there.
Paul Lalli
------------------------------
Date: 15 Sep 2006 11:41:03 -0700
From: "Noatec" <Noatec@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158345663.375521.52480@k70g2000cwa.googlegroups.com>
Paul Lalli wrote:
> Paul Lalli wrote:
> > Noatec wrote:
> >
> > [[ snip the same problem description as posted in
> > http://groups.google.com/group/perl.beginners/browse_frm/thread/5e1dc096d6d7ca13/5fed15f7d9ea1837?lnk=st&q=&rnum=1#5fed15f7d9ea1837
> > ]]
> >
> >
> > > This is all I have so far.
> >
> > No, that's what someone else was gracious enough to GIVE you.
> >
> > > #!/usr/bin/perl
> > > use warnings;
> > > my $line = mlist;
> > > my $sum = 0;
> > >
> > > # open the file
> > > open(MLIST,"$line") or die "Unable to open mlist:$!\n";
> > >
> > > # read it in one record at a time
> > > while ($line = <MLIST>) {
> > > my ($volser,$reads,$lwd) = split(/,/,$line);
> > >
> > >
> > > printf "$volser $reads $lwd"
> > > }
> > >
> > > # close the file
> > > close(MLIST);
> >
> > If you didn't understand the code you were given, why didn't you ask
> > the person who gave it to you for a clarification? Why are you now
> > posting in a completely different group, pretending that you came up
> > with this on your own?
> >
>
> Bah. I completely misread the thread I referenced above. The code
> posted is what the OP posted there as well. My apologies. However, my
> question still stands as to why you are suddenly jumping groups and
> asking for a fresh start rather than following up to that thread.
> Someone there did help you out with putting your data into a hash. If
> you don't understand that code, ask about it there.
>
> Paul Lalli
Paul,
Thanks for taking another look at the post.
I was unable to get the provided code to work right.
my %volsers=();
for my $line (split(/\n/, $data)){
my ($volser, $reads, $date) = split(/\,/,$line);
$volsers{$volser}{reads}+=$reads;
$volsers{$volser}{date}=$date;
Just was just looking for another perspective on the problem.
------------------------------
Date: Fri, 15 Sep 2006 13:58:21 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <450af6f8$0$10307$815e3792@news.qwest.net>
Noatec wrote:
> Paul Lalli wrote:
>> Paul Lalli wrote:
>>> Noatec wrote:
>>>
>>> [[ snip the same problem description as posted in
>>> http://groups.google.com/group/perl.beginners/browse_frm/thread/5e1dc096d6d7ca13/5fed15f7d9ea1837?lnk=st&q=&rnum=1#5fed15f7d9ea1837
>>> ]]
>>>
>>>
>>>> This is all I have so far.
>>> No, that's what someone else was gracious enough to GIVE you.
>>>
>>>> #!/usr/bin/perl
>>>> use warnings;
>>>> my $line = mlist;
>>>> my $sum = 0;
>>>>
>>>> # open the file
>>>> open(MLIST,"$line") or die "Unable to open mlist:$!\n";
>>>>
>>>> # read it in one record at a time
>>>> while ($line = <MLIST>) {
>>>> my ($volser,$reads,$lwd) = split(/,/,$line);
>>>>
>>>>
>>>> printf "$volser $reads $lwd"
>>>> }
>>>>
>>>> # close the file
>>>> close(MLIST);
>>> If you didn't understand the code you were given, why didn't you ask
>>> the person who gave it to you for a clarification? Why are you now
>>> posting in a completely different group, pretending that you came up
>>> with this on your own?
>>>
>> Bah. I completely misread the thread I referenced above. The code
>> posted is what the OP posted there as well. My apologies. However, my
>> question still stands as to why you are suddenly jumping groups and
>> asking for a fresh start rather than following up to that thread.
>> Someone there did help you out with putting your data into a hash. If
>> you don't understand that code, ask about it there.
>>
>> Paul Lalli
>
> Paul,
> Thanks for taking another look at the post.
> I was unable to get the provided code to work right.
>
> my %volsers=();
> for my $line (split(/\n/, $data)){
What's $data??
> my ($volser, $reads, $date) = split(/\,/,$line);
Why escape the comma??
> $volsers{$volser}{reads}+=$reads;
> $volsers{$volser}{date}=$date;
maybe replace those with:
$volsers{$volser}{$date}{'read'} += $reads;
}
>
> Just was just looking for another perspective on the problem.
>
That doesn't look like the code you originally posted. Please post your
actual code; something that others can run, as is, to help pinpoint the
problem.
------------------------------
Date: 15 Sep 2006 11:57:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158346624.191802.147420@i42g2000cwa.googlegroups.com>
Noatec wrote:
> Paul Lalli wrote:
> > Paul Lalli wrote:
> > > Noatec wrote:
> > > > #!/usr/bin/perl
> > > > use warnings;
> > > > my $line = mlist;
> > > > my $sum = 0;
> > > >
> > > > # open the file
> > > > open(MLIST,"$line") or die "Unable to open mlist:$!\n";
> > > >
> > > > # read it in one record at a time
> > > > while ($line = <MLIST>) {
> > > > my ($volser,$reads,$lwd) = split(/,/,$line);
> > > >
> > > >
> > > > printf "$volser $reads $lwd"
> > > > }
> > > >
> > > > # close the file
> > > > close(MLIST);
> > >
>
> Thanks for taking another look at the post.
> I was unable to get the provided code to work right.
That is a horrible error description. How is it not "working right"
for you? What errors are you seeing? Syntax errors? Runtime errors?
Incorrect output? No output? Infinite loop? Crash? Computer bursts
into flames?
>
> my %volsers=();
> for my $line (split(/\n/, $data)){
> my ($volser, $reads, $date) = split(/\,/,$line);
> $volsers{$volser}{reads}+=$reads;
> $volsers{$volser}{date}=$date;
Other than the missing } that I assume you missed when copying, there's
nothing wrong with that code. Therefore, there's something wrong with
your usage of it. Please post a SHORT but COMPLETE script that
demonstrates the problem you're seeing.
> Just was just looking for another perspective on the problem.
How can anyone have a different perspective when you haven't told
anyone what's wrong with this perspective?
Paul Lalli
------------------------------
Date: 15 Sep 2006 12:26:10 -0700
From: "Noatec" <Noatec@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158348370.330264.137790@i3g2000cwc.googlegroups.com>
Paul Lalli wrote:
> Noatec wrote:
> > Paul Lalli wrote:
> > > Paul Lalli wrote:
> > > > Noatec wrote:
>
> > > > > #!/usr/bin/perl
> > > > > use warnings;
> > > > > my $line = mlist;
> > > > > my $sum = 0;
> > > > >
> > > > > # open the file
> > > > > open(MLIST,"$line") or die "Unable to open mlist:$!\n";
> > > > >
> > > > > # read it in one record at a time
> > > > > while ($line = <MLIST>) {
> > > > > my ($volser,$reads,$lwd) = split(/,/,$line);
> > > > >
> > > > >
> > > > > printf "$volser $reads $lwd"
> > > > > }
> > > > >
> > > > > # close the file
> > > > > close(MLIST);
> > > >
> >
> > Thanks for taking another look at the post.
> > I was unable to get the provided code to work right.
>
> That is a horrible error description. How is it not "working right"
> for you? What errors are you seeing? Syntax errors? Runtime errors?
> Incorrect output? No output? Infinite loop? Crash? Computer bursts
> into flames?
>
> >
> > my %volsers=();
> > for my $line (split(/\n/, $data)){
> > my ($volser, $reads, $date) = split(/\,/,$line);
> > $volsers{$volser}{reads}+=$reads;
> > $volsers{$volser}{date}=$date;
>
>
> Other than the missing } that I assume you missed when copying, there's
> nothing wrong with that code. Therefore, there's something wrong with
> your usage of it. Please post a SHORT but COMPLETE script that
> demonstrates the problem you're seeing.
>
> > Just was just looking for another perspective on the problem.
>
> How can anyone have a different perspective when you haven't told
> anyone what's wrong with this perspective?
>
> Paul Lalli
Paul,
Are you always this critical of people who are trying to learn?
I wouldn't think a teacher of technology would want to turn people off
of learning a new language.
Your posts are very condescending and borderline rude.
I'm truly not looking for someone to solve this for me.
I really want to learn it.
I'm trying to incorporate the hash into this working code that will
simply list every row.
I don't know what $data should be.
#!/usr/bin/perl
use warnings;
#my $line = $ARGV[0];
my $line = mlist;
my $sum = 0;
# open the file
open(MLIST,"$line") or die "Unable to open mlist:$!\n";
# read it in one record at a time
while ($line = <MLIST>) {
my ($volser,$reads,$lwd) = split(/,/,$line);
printf "$volser,$reads,$lwd"
}
# close the file
close(MLIST);
------------------------------
Date: 15 Sep 2006 13:59:56 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Sum the middle column for a given unique volser.
Message-Id: <1158353995.886296.278310@b28g2000cwb.googlegroups.com>
Noatec wrote:
> Paul Lalli wrote:
> > Noatec wrote:
> > > Paul Lalli wrote:
> > > > Paul Lalli wrote:
> > > > > Noatec wrote:
> >
> > > > > > #!/usr/bin/perl
> > > > > > use warnings;
> > > > > > my $line = mlist;
> > > > > > my $sum = 0;
> > > > > >
> > > > > > # open the file
> > > > > > open(MLIST,"$line") or die "Unable to open mlist:$!\n";
> > > > > >
> > > > > > # read it in one record at a time
> > > > > > while ($line = <MLIST>) {
> > > > > > my ($volser,$reads,$lwd) = split(/,/,$line);
> > > > > >
> > > > > >
> > > > > > printf "$volser $reads $lwd"
> > > > > > }
> > > > > >
> > > > > > # close the file
> > > > > > close(MLIST);
> > > > >
> > >
> > > Thanks for taking another look at the post.
> > > I was unable to get the provided code to work right.
> >
> > That is a horrible error description. How is it not "working right"
> > for you? What errors are you seeing? Syntax errors? Runtime errors?
> > Incorrect output? No output? Infinite loop? Crash? Computer bursts
> > into flames?
> >
> > >
> > > my %volsers=();
> > > for my $line (split(/\n/, $data)){
> > > my ($volser, $reads, $date) = split(/\,/,$line);
> > > $volsers{$volser}{reads}+=$reads;
> > > $volsers{$volser}{date}=$date;
> >
> >
> > Other than the missing } that I assume you missed when copying, there's
> > nothing wrong with that code. Therefore, there's something wrong with
> > your usage of it. Please post a SHORT but COMPLETE script that
> > demonstrates the problem you're seeing.
> >
> > > Just was just looking for another perspective on the problem.
> >
> > How can anyone have a different perspective when you haven't told
> > anyone what's wrong with this perspective?
> Are you always this critical of people who are trying to learn?
You do not appear to be trying to learn. You appear to be wanting
someone to do your work for you.
> I wouldn't think a teacher of technology would want to turn people off
> of learning a new language.
You are not trying to learn. And as for "teacher of technology",
you're not one of my students. You're a guy posting to Usenet looking
for a freebie.
> Your posts are very condescending and borderline rude.
No, I've passed beyond borderline now, and I'm definately being
flat-out rude. That's because your method of posting and asking
questions has been at least equally rude. You post a question to one
list, and got an answer. Rather than following up with that question,
you posted to another group, made no mention of the answer you already
got, and posted no further attempt to solve the problem based on the
answer you already got. Then when someone confronts you on it, you
simply say "it didn't work", with no attempt to explain in what way it
didn't work, or show the attempt you made that lead to it "not
work"ing. That is an astonishing amount of time of other people which
you have wasted. That is extremely rude.
> I'm truly not looking for someone to solve this for me.
> I really want to learn it.
Then why haven't you posted your best attempt? How can anyone correct
it for you? Why haven't you posted any specific questions beyond "How
do I do this?"?
> I'm trying to incorporate the hash into this working code that will
> simply list every row.
> I don't know what $data should be.
So why didn't you ask that in the first place? Why have you wasted all
this time making people guess as to your level of understanding? If
you didn't understand what the code you were given is doing, why didn't
you ask about that code?
> #!/usr/bin/perl
You forgot:
use strict;
> use warnings;
> #my $line = $ARGV[0];
> my $line = mlist;
What the hell is this? Is this a function? Is it a bareword string?
Where did it come from, and what does it represent?
> my $sum = 0;
>
> # open the file
> open(MLIST,"$line") or die "Unable to open mlist:$!\n";
perldoc -q quoting
So $line is supposed to be the name of the file you want to open?
Doesn't that seem to be a REALLY bad variable name to you?
Change those two lines to:
my $filename = 'mlist';
open my $MLIST, '<', $filename or die "Unable to open $filename: $!\n";
> # read it in one record at a time
> while ($line = <MLIST>) {
Now you're using $line for something completely different. Granted,
here $line makes sense.
while (my $line = <$MLIST>) {
> my ($volser,$reads,$lwd) = split(/,/,$line);
So now you have your three variables. So now put them into the hash
the way it was explained to you already. The only difference is that
while you called the line from the file $line, the poster who gave you
that code called it $data.
> printf "$volser,$reads,$lwd"
> }
>
> # close the file
> close(MLIST);
Now loop through the keys of the hash and print out the values.
Once you've actually made an ATTEMPT to do this, if it doesn't work,
post a SHORT but COMPLETE script that demonstrates your error.
Paul Lalli
------------------------------
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 9731
***************************************