[30389] in Perl-Users-Digest
Perl-Users Digest, Issue: 1632 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 11 18:09:46 2008
Date: Wed, 11 Jun 2008 15:09:08 -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, 11 Jun 2008 Volume: 11 Number: 1632
Today's topics:
Re: Can't locate object method is_initial_req <jcharth@gmail.com>
Re: ConTEXT editor and Perl <1usa@llenroc.ude.invalid>
Re: FAQ 7.26 How can I find out my current package? <mjcarman@mchsi.com>
Re: FAQ 7.26 How can I find out my current package? <cwilbur@chromatico.net>
How to close all started Internet Explorer from perl sc <pero@tupwerwt.ch>
OT: please help me for my script <danrumney@warpmail.net>
Re: OT: please help me for my script <john.swilting@wanadoo.fr>
Re: OT: please help me for my script <danrumney@warpmail.net>
Re: OT: please help me for my script <jurgenex@hotmail.com>
Re: OT: please help me for my script <john.swilting@wanadoo.fr>
OT: Question on learning Perl <danrumney@warpmail.net>
Re: OT: Question on learning Perl <jurgenex@hotmail.com>
Re: Question on learning Perl <tzz@lifelogs.com>
Re: Question on learning Perl <jurgenex@hotmail.com>
Re: Range of number <spam-here@memowe.de>
Re: sorting a hash / 2008-06-01 <dave@nospam.deezee.org>
Re: sorting a hash / 2008-06-01 <jimsgibson@gmail.com>
Re: Time and again <simon.chao@fmr.com>
Re: Time and again <bill@ts1000.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Jun 2008 07:59:53 -0700 (PDT)
From: joe <jcharth@gmail.com>
Subject: Re: Can't locate object method is_initial_req
Message-Id: <bf12c7fc-d633-4696-abd5-7b58b6689248@d45g2000hsc.googlegroups.com>
Found the problem. Not sure how it got to be like this. but I had to
add require Apache2::RequestUtil; to the list or required libs in
AuthDBI.pm.
require Apache2::Const;
require Apache2::RequestRec;
require Apache2::RequestUtil;
------------------------------
Date: Wed, 11 Jun 2008 22:01:49 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: ConTEXT editor and Perl
Message-Id: <Xns9ABAB769C64A5asu1cornelledu@127.0.0.1>
Bill H <bill@ts1000.us> wrote in news:d2072c83-acdf-4532-b3a8-
ff10878b2267@25g2000hsx.googlegroups.com:
> Has anyone used ConTEXT (http://www.contexteditor.org/) when working
> on perl code?
...
> Currently I use good old edit.com for large programs or notepad to
> make a few minor changes.
Given your experience, I would submit to you that you are not in a
position to evaluate the quality of said editor.
Try some other editors first. Then, re-evaluate your experience with
ConTEXT. That is going to be better than asking for others' opinions of
editors (only marginally relevant IMHO).
The choice of an editor for programming is a very personal matter. You
need to use a few to decide which one *you* should use.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Wed, 11 Jun 2008 14:50:52 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: FAQ 7.26 How can I find out my current package?
Message-Id: <gDR3k.149590$TT4.28337@attbi_s22>
Uri Guttman wrote:
>>>>>> "MC" == Michael Carman <mjcarman@mchsi.com> writes:
>
> >> 7.26: How can I find out my current package?
> MC> The answer doesn't mention caller() but probably should.
>
> the question is current package, not the called from
> package. __PACKAGE__ is all that is needed.
Mentioning caller() here seems just as appropriate as the mention of
ref(). I can understand the subtleties of why you'd consider ref() to be
the current package but the people who need this FAQ answer won't.
I don't think a strict interpretation of this question (or FAQ questions
in general) is warranted. It's likely that people wanting the called
from package will search for "perldoc -q package" and they'll find...
nothing, because there's a seemingly innocuous qualifier in front of it.
From a searching point of view I read this question as "How can I find
[some words to make a proper sentence] package?" The word "current" is
incidental -- placed there at the whim of whomever first wrote this
entry -- not a crucial part of the question.
From a practical point of view there doesn't appear to be an FAQ entry
for the called from package. (Neither "perldoc -q package" nor "perldoc
-q call" find anything.) It would fit nicely here.
-mjc
------------------------------
Date: Wed, 11 Jun 2008 11:44:19 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: FAQ 7.26 How can I find out my current package?
Message-Id: <864p80c6y4.fsf@mithril.chromatico.net>
>>>>> "MC" == Michael Carman <mjcarman@mchsi.com> writes:
MC> From a practical point of view there doesn't appear to be an FAQ
MC> entry for the called from package. (Neither "perldoc -q package"
MC> nor "perldoc -q call" find anything.) It would fit nicely here.
I'm sure a patch would be welcome.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Thu, 12 Jun 2008 00:08:05 +0200
From: "Pero" <pero@tupwerwt.ch>
Subject: How to close all started Internet Explorer from perl scripts?
Message-Id: <g2pic5$kr0$1@localhost.localdomain>
How to close all started Internet Explorer from perl scripts?
Tnx.
------------------------------
Date: Wed, 11 Jun 2008 09:11:01 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: OT: please help me for my script
Message-Id: <484fcedf$0$31745$4c368faf@roadrunner.com>
Ben Bullock wrote:
> On Wed, 11 Jun 2008 13:05:20 +0200, swilting wrote:
>
>> i dont understand my script doesnt execute in apache
>
>> sub en_tete_standard {
>> print header(),
> ^
> This "," should be ";".
>
Nice catch Ben.
I ran the script on my command line and noticed that the header didn't
print, but couldn't account for it. Didn't spend enough time looking at
the code to find out why.
From what I can figure:
print "abc", print "xyz";
means
Display "abz" and whatever 'print "xyz"' returns (which is 1)
In order to find out what 'print "xyz"' returns, it must perform the
fucntion (and so "xyz" is displayed first). This returns the 1, and so
"abc" and 1 are displayed second.
Sneaky little bug that
------------------------------
Date: Wed, 11 Jun 2008 17:28:30 +0200
From: swilting <john.swilting@wanadoo.fr>
Subject: Re: OT: please help me for my script
Message-Id: <484fef2b$0$921$ba4acef3@news.orange.fr>
Dan Rumney wrote:
> Ben Bullock wrote:
>> On Wed, 11 Jun 2008 13:05:20 +0200, swilting wrote:
>>
>>> i dont understand my script doesnt execute in apache
>>
>>> sub en_tete_standard {
>>> print header(),
>> ^
>> This "," should be ";".
>>
>
> Nice catch Ben.
>
> I ran the script on my command line and noticed that the header didn't
> print, but couldn't account for it. Didn't spend enough time looking at
> the code to find out why.
>
> From what I can figure:
>
> print "abc", print "xyz";
>
> means
>
> Display "abz" and whatever 'print "xyz"' returns (which is 1)
>
> In order to find out what 'print "xyz"' returns, it must perform the
> fucntion (and so "xyz" is displayed first). This returns the 1, and so
> "abc" and 1 are displayed second.
>
> Sneaky little bug that
error !!
not error syntaxic
its lexical error
not trool i am funny enrolment for perl
------------------------------
Date: Wed, 11 Jun 2008 12:12:13 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: Re: OT: please help me for my script
Message-Id: <484ff941$0$31719$4c368faf@roadrunner.com>
swilting wrote:
[snip]
>>
>> Sneaky little bug that
> error !!
> not error syntaxic
>
> its lexical error
>
> not trool i am funny enrolment for perl
Actually, I believe it's a semantic error (also known as a logic error).
------------------------------
Date: Wed, 11 Jun 2008 16:22:24 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: OT: please help me for my script
Message-Id: <2kuv44lur7gltk6hj076258pvfkvh7rgau@4ax.com>
swilting <john.swilting@wanadoo.fr> wrote:
>Dan Rumney wrote:
>> print "abc", print "xyz";
>> means
>> Display "abz" and whatever 'print "xyz"' returns (which is 1)
>>
> Sneaky little bug that error !!
>not error syntaxic
>
>its lexical error
Certainly not! It is completely valid Perl code and there is nothing
wrong with that line on neither the lexical, the syntax, nor the context
level.
jue
------------------------------
Date: Wed, 11 Jun 2008 21:53:04 +0200
From: swilting <john.swilting@wanadoo.fr>
Subject: Re: OT: please help me for my script
Message-Id: <48502d20$0$890$ba4acef3@news.orange.fr>
Dan Rumney wrote:
> swilting wrote:
> [snip]
>>>
>>> Sneaky little bug that
>> error !!
>> not error syntaxic
>>
>> its lexical error
>>
>> not trool i am funny enrolment for perl
>
> Actually, I believe it's a semantic error (also known as a logic error).
the new script function well
alse the png image is not view
the png code is pretty read !!!
and dont understood
#!/usr/bin/perl -w
use diagnostics;
use strict;
use CGI qw(:standard escapeHTML);
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP;
##use FileHandle;
use File::Copy;
use GD;
use GD::Text::Wrap;
require "Random.pm";
my $cgi;
my $key;
my %etats;
my $ecran_actuel;
$cgi = new CGI;
%etats = (
'defaut' =>\&saisie_commande,
'validation_code' =>\&validation_code,
'annulation' =>\&annulation,
);
$ecran_actuel = param(".Etat") || "defaut";
die "Pas d'ecran pour $ecran_actuel" unless $etats{$ecran_actuel};
## engendre le document courant
en_tete_standard();
while ( my ($nom_ecran,$fonction) = each %etats){
$fonction->($nom_ecran eq $ecran_actuel);
}
pied_de_page_standard();
########################################################################
## fonctions d en tete , de pied de page ,de menu ################
########################################################################
sub en_tete_standard {
print header(),
start_html(-Title => "commande" , -BGCOLOR=>"White");
print start_form();
}
sub menu_boutique {
print p(vers_doc("annulation"),
vers_doc("validation_code"));
}
sub saisie_commande {
my($actif) = @_;
return unless $actif;
print p("Tous les champs sont obligatoires");
print p("un code de securite vous seras demandé dans la prochaine
page");
print pre ( p ("Nom: ",textfield("nom")),
p ("Adresse: ",textfield("adresse")),
p ("Ville: ",textfield("ville")),
p ("Code Postal: ",textfield("code_postal")),
p ("Pays: ",textfield("pays")),
p ("e-mail: ",textfield("mail")));
print p ( "Selectionner validation_code pour continuer\n",
"autrement selectionner Annulation\n");
menu_boutique();
}
sub validation_code {
my($actif) = @_;
return unless $actif;
my $nom = param ('nom');
my $adresse = param ('adresse');
my $ville = param ('ville');
my $code_postal = param ('code_postal');
my $pays = param ('pays');
my $mail = param ('mail');
# create a new
sub image_capcha {
my $text = new Random;
my $im = new GD::Image(800,600);
# allocate some colors
my $white = $im->colorAllocate(255,255,255);
my $black = $im->colorAllocate(0,0,0);
my $red = $im->colorAllocate(255,0,0);
my $blue = $im->colorAllocate(0,0,255);
my $wrapbox = GD::Text::Wrap->new( $im,
line_space => 4,
color => $black,
text => $text,
);
$wrapbox->set_font(gdMediumBoldFont);
$wrapbox->set_font('arial',12);
$wrapbox->set(align => 'center', width => 120);
$wrapbox->draw(10,140);
$im->rectangle($wrapbox->get_bounds(10,140),$red);
##print $cgi->header( -type => "image/png", -expires => "-1d");
binmode STDOUT ;
print $im->png();
}
my $image = &image_capcha();
print img {src=>$image,align=>'LEFT'};
## mail($numero_commande,$nom,$adresse,$ville,$code_postal,$pays
$telephone,$mail,$image);
## cpandrename($image);
}
sub annulation {
my($actif) = @_;
return unless $actif;
print p ("vous etes une mauvaise personne ou un robot spammeur");
}
sub pied_de_page_standard{ print end_form(),end_html() }
sub vers_doc { submit (-NAME => ".Etat", -VALUE => shift) }
sub mail {
my($numero_commande,$nom,$adresse,$ville,$code_postal,$pays,$telephone
$mail,$image) = @_;
my $smtp = Net::SMTP->new('127.0.0.1');
$smtp->mail($ENV{USER});
$smtp->to($mail);
$smtp->data();
$smtp->datasend("To: ",$mail);
$smtp->datasend("\n");
$smtp->datasend("Cc: john.swilting\@wanadoo.fr","\n");
$smtp->datasend("Cc: flew10\@hotmail.com","\n");
$smtp->datasend("\n");
$smtp->datasend("Subject: facture ",$numero_commande,"\n");
$smtp->datasend("coordonnes personnelle\n");
$smtp->datasend($nom);
$smtp->datasend("\n");
$smtp->datasend($adresse);
$smtp->datasend("\n");
$smtp->datasend($ville,"\n",$code_postal,"\n",$pays);
$smtp->datasend("\n");
$smtp->datasend($telephone);
$smtp->datasend("\n");
$smtp->datasend($mail);
$smtp->datasend("\n");
$smtp->datasend("image commandee ",$image,"\n");
$smtp->dataend();
$smtp->quit;
}
sub cpandrename {
my($image) = @_;
## `cp images/$image temp/`;
## `cp images/commander.gif temp/`;
## rename ("temp/commander.gif", "temp/$image");
## `cp -f temp/$image images/`;
my $filehandle = "/var/www/html/jeanluc/images/";
$filehandle .= $image;
copy ($filehandle,"/var/www/html/jeanluc/temp/") or die "$!";
copy
("/var/www/html/jeanluc/images/commandergimp.gif","/var/www/html/jeanluc/temp/")
or die "$!";
my $filehandletemp = "/var/www/html/jeanluc/temp/";
$filehandletemp .=$image;
my @args = ("rm","-f",$filehandle);
system(@args) == 0 or die "systems @args failed :$?";
rename ("/var/www/html/jeanluc/temp/commandergimp.gif",$filehandletemp);
## `cp -f $filehandletemp /var/www/html/jeanluc/images`;
copy ($filehandletemp,"/var/www/html/jeanluc/images/");
## unlink $filehandletemp;
## my $filehandlebase = FileHandle->new($filehandle , "r");
## cp($filehandlebase , "/var/www/html/jeanluc/temp/") or die "$!";
## my $filehandleold = "/var/www/html/jeanluc/images/commander.gif";
## my $filehandleoldbase = FileHandle->new($filehandleold , "r");
## cp ($filehandleoldbase , "/var/www/html/jeanluc/temp/") or die "$!";
## rename( $filehandleold ,$filehandle);
## my $filehandlenew = "/var/www/html/jeanluc/temp/";
## $filehandlenew .=$image;
## rename ($filehandleoldbase , $filehandlenew);
## my $filehandletemp = FileHandle->new($filehandlenew , "r");
## cp ($filehandletemp , "/var/www/html/jeanluc/images/") or die "$!";
}
------------------------------
Date: Wed, 11 Jun 2008 13:19:34 -0400
From: Dan Rumney <danrumney@warpmail.net>
Subject: OT: Question on learning Perl
Message-Id: <48500912$0$31723$4c368faf@roadrunner.com>
Jürgen Exner wrote:
> Ted Zlatanov <tzz@lifelogs.com> wrote:
>> On Tue, 10 Jun 2008 23:36:16 -0700 Andrew DeFaria <Andrew@DeFaria.com> wrote:
>>
>> AD> Jürgen Exner wrote:
>>>> Dan Rumney <danrumney@warpmail.net> wrote:
>>>>>>
[snip]
This thread is off-topic and nonconstructive
Time to let it die perhaps?
------------------------------
Date: Wed, 11 Jun 2008 17:35:11 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: OT: Question on learning Perl
Message-Id: <153054l8evbbrcritfjffp3ockgooh2sjd@4ax.com>
Dan Rumney <danrumney@warpmail.net> wrote:
>This thread is off-topic and nonconstructive
>
>Time to let it die perhaps?
You know, somehow you got a very good point :-)
jue
------------------------------
Date: Wed, 11 Jun 2008 11:29:00 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Question on learning Perl
Message-Id: <867icwq6k3.fsf@lifelogs.com>
On Tue, 10 Jun 2008 23:36:16 -0700 Andrew DeFaria <Andrew@DeFaria.com> wrote:
AD> Jürgen Exner wrote:
>> Dan Rumney <danrumney@warpmail.net> wrote:
>>>> When you first started using the language called English did you memorize most of the words, their meanings, etc.?
>> Oh yes, vey much so. Every week some 20-40 new words and the teacher would check them at the beginning of each class.
AD> Ah no you didn't. According to http://hypertextbook.com/facts/2001/JohnnyLing.shtml
AD> "The statistics of English are astonishing. Of all the world's
AD> languages (which now number some 2,700), it is arguably the richest
AD> in vocabulary. The compendious /Oxford English Dictionary/ lists
AD> about 500,000 words;
AD> So by "most" you'll need at least 50% or 250,000 words memorized
AD> before you started using English actively. Somehow I doubt you got
AD> those 1/4 million words down beforehand...
I think the original quote meant "most of the words you learn at first"
not "most of the English words." 100-1000 words cover 50-75% of English
vocabulary by frequency[1], so memorization is quite possible although
it's definitely the wrong approach.
English is very rich in vocabulary, but every modern language has about
the same number of basic terms, so that quote is a bit misleading.
Expresiveness comes from optimization of the basic word set. For
example, the 25 most frequently used verbs in English are one-syllable
words[1]. This is actually relevant to Perl, which is very expressive
because it has pronouns and default usages (e.g. print()) and optimizes
a lot of common usage. Languages of the C family, on the other hand,
are limited to nouns and verbs and need macros to take syntactic
shortcuts.
Ted
[1] http://www.askoxford.com/oec/mainpage/oec02/?view=uk
------------------------------
Date: Wed, 11 Jun 2008 16:55:08 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Question on learning Perl
Message-Id: <kivv44tmvgfso6p86psnnvg73lg559pdbh@4ax.com>
Ted Zlatanov <tzz@lifelogs.com> wrote:
>On Tue, 10 Jun 2008 23:36:16 -0700 Andrew DeFaria <Andrew@DeFaria.com> wrote:
>
>AD> Jürgen Exner wrote:
>>> Dan Rumney <danrumney@warpmail.net> wrote:
>>>>> When you first started using the language called English did you memorize most of the words, their meanings, etc.?
>>> Oh yes, vey much so. Every week some 20-40 new words and the teacher would check them at the beginning of each class.
>AD> Ah no you didn't.
How would you know? Have you been in my English class? I don't remember
seeing you there.
>>According to http://hypertextbook.com/facts/2001/JohnnyLing.shtml
>
>AD> "The statistics of English are astonishing. Of all the world's
>AD> languages (which now number some 2,700), it is arguably the richest
>AD> in vocabulary. The compendious /Oxford English Dictionary/ lists
>AD> about 500,000 words;
>
>AD> So by "most" you'll need at least 50% or 250,000 words memorized
>AD> before you started using English actively. Somehow I doubt you got
>AD> those 1/4 million words down beforehand...
WTF does that have to do with anything? Studies have shown that you can
have a basic understanding with just 150-200 words (like asking for
directions or ordering a meal). You need 600-800 for a basic
conversation and many people never use more than 1000-1500 active words
regularly although they understand (i.e. use passively) much more.
Whoever said anything about learning a quarter milliion words? I guess
you are very well placed at the bottom of my killfile.
>I think the original quote meant "most of the words you learn at first"
>not "most of the English words." 100-1000 words cover 50-75% of English
>vocabulary by frequency[1], so memorization is quite possible although
>it's definitely the wrong approach.
Arguable. There is something to be said in favour of systematically
memorizing spellings, plurals, conjugations, etc.
To me that's most obviuos in English spelling, where I have seen
atrocities like "Closed at nite" even on official road signs. A bit
memorization (or maybe just common sense in using a spell checker)
wouldn't have hurt the dimwit who printed that sign.
jue
------------------------------
Date: Thu, 12 Jun 2008 00:04:35 +0200
From: Mirko Westermeier <spam-here@memowe.de>
Subject: Re: Range of number
Message-Id: <g2pi6g$ej5$1@sagnix.uni-muenster.de>
One schrieb:
> I have a pre-determined low number and a pre-determined high number.
> I simply need to know if my variable is within that range, and if so
> print YES
$ perl -nle '$n=$_;print+(grep$n==$_=>17..4217)?"YES":"NO"'
3
NO
100
YES
4217
YES
4218
NO
;-) Mirko
------------------------------
Date: 11 Jun 2008 16:25:24 GMT
From: "Dave Saville" <dave@nospam.deezee.org>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <fV45K0OBJxbE-pn2-Oh63rjwfG98s@localhost>
On Fri, 30 May 2008 13:11:22 UTC, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
> dn.perl@gmail.com wrote:
> > I want to sort a hash. The hash contains a list of cities and their
> > temperature
>
> Well, I'd rather say it contains three hash references.
>
> This is one sensible way to sort that data structure:
>
> foreach my $state ( sort keys %hash ) {
> print "State: $state\n";
> foreach my $city ( sort { $a cmp $b } keys %{ $hash{$state} } ) {
> print "$city = $hash{$state}{$city}{max_temp}\n";
> }
> print "\n";
> }
Sorry to jump in with another question but I have a very similar
problem. I am processing a consolidated apache2 logfile. I have
multiple virtual hosts. All I care about are the site, the page
served, a counter and the date.
So my hash looks like $urls{$site}{$url} Beyond that I have a counter
and date thus:
$urls{$site}{$url}[0]++; # count
$urls{$site}{$url}[1] = $date;
This works fine and I can list by site the page, count and date.
foreach $site ( keys %urls)
{
foreach my $url (keys %{$urls{$site}})
{
print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
}
}
Putting a sort into the url loop gives me the results sorted by page
as expected. What I cannot figure out is how to do it by count and by
date.
I have tried various ideas I found by google but they all tend to be
similar to this
sub by_count
{
$urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] or $a cmp $b;
}
But this throws lots of "Use of uninitialized value....." errors on
that line and in doing so gets the wrong pages attributed to a site. I
have tried with yet another hash on the end with count & date keys
instead of the array, but it does not help.
I would be grateful for any pointers.
--
Regards
Dave Saville
NB Remove nospam. for good email address
------------------------------
Date: Wed, 11 Jun 2008 14:39:54 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: sorting a hash / 2008-06-01
Message-Id: <110620081439544352%jimsgibson@gmail.com>
In article <fV45K0OBJxbE-pn2-Oh63rjwfG98s@localhost>, Dave Saville
<dave@nospam.deezee.org> wrote:
> On Fri, 30 May 2008 13:11:22 UTC, Gunnar Hjalmarsson
> <noreply@gunnar.cc> wrote:
>
> > dn.perl@gmail.com wrote:
> > > I want to sort a hash. The hash contains a list of cities and their
> > > temperature
> >
> > Well, I'd rather say it contains three hash references.
> >
> > This is one sensible way to sort that data structure:
> >
> > foreach my $state ( sort keys %hash ) {
> > print "State: $state\n";
> > foreach my $city ( sort { $a cmp $b } keys %{ $hash{$state} } ) {
> > print "$city = $hash{$state}{$city}{max_temp}\n";
> > }
> > print "\n";
> > }
>
>
> Sorry to jump in with another question but I have a very similar
> problem. I am processing a consolidated apache2 logfile. I have
> multiple virtual hosts. All I care about are the site, the page
> served, a counter and the date.
>
> So my hash looks like $urls{$site}{$url} Beyond that I have a counter
> and date thus:
> $urls{$site}{$url}[0]++; # count
> $urls{$site}{$url}[1] = $date;
>
> This works fine and I can list by site the page, count and date.
>
> foreach $site ( keys %urls)
> {
> foreach my $url (keys %{$urls{$site}})
> {
> print "$site $url $urls{$site}{$url}[0] $urls{$site}{$url}[1]\n";
> }
> }
>
> Putting a sort into the url loop gives me the results sorted by page
> as expected. What I cannot figure out is how to do it by count and by
> date.
>
> I have tried various ideas I found by google but they all tend to be
> similar to this
>
> sub by_count
> {
> $urls{$site}{$b}[0] <=> $urls{$site}{$a}[0] or $a cmp $b;
> }
>
> But this throws lots of "Use of uninitialized value....." errors on
> that line and in doing so gets the wrong pages attributed to a site. I
> have tried with yet another hash on the end with count & date keys
> instead of the array, but it does not help.
>
> I would be grateful for any pointers.
Are you trying to sort all of your records at once, regardless of site?
You can't do that with a simple sort. If you just want to sort the data
by site, here is an example:
#!/usr/local/bin/perl
use strict;
use warnings;
my %urls = (
site1 => {
url1_1 => [ 3, '2008-01-01' ],
url1_2 => [ 2, '2008-02-02' ],
url1_3 => [ 5, '2008-02-03' ],
url1_4 => [ 4, '2008-03-05' ],
},
site2 => {
url2_1 => [ 7, '2008-09-11' ],
url2_2 => [ 4, '2008-03-10' ],
url2_3 => [ 1, '2008-02-24' ],
url2_4 => [ 8, '2008-03-31' ],
}
);
print "Sorted by site, url:\n";
for my $site ( sort keys %urls ) {
for my $url ( sort keys %{$urls{$site}} ) {
my( $count, $date ) = @{$urls{$site}{$url}};
print "$site, $url, $count, $date\n";
}
}
print "Sorted by site, count:\n";
for my $site ( sort keys %urls ) {
for my $url (
sort { $urls{$site}{$a}->[0] <=> $urls{$site}{$b}->[0] }
keys %{$urls{$site}} )
{
my( $count, $date ) = @{$urls{$site}{$url}};
print "$site, $url, $count, $date\n";
}
}
If you want something else, please post a complete program showing what
you are trying to do. Thanks.
--
Jim Gibson
------------------------------
Date: Wed, 11 Jun 2008 07:34:48 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Time and again
Message-Id: <c1ad5067-e1b7-4154-89d2-fa3e037b74b8@m36g2000hse.googlegroups.com>
On Jun 10, 5:27=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
> Bill H <b...@ts1000.us> wrote:
> > If you are printing localtime() to a file so that it is readable and
> > know that you are going to want to sort it later, why not just do
>
> > print qq~localtime()|time()~;
>
> Did you try that code before posting it?
>
> ...
>
> I didn't think so.
>
# ./try_time.pl
localtime()|time()#
------------------------------
Date: Wed, 11 Jun 2008 10:24:42 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Time and again
Message-Id: <8ddcbab6-e8ee-4707-a8e7-0ea1cb321fa1@34g2000hsf.googlegroups.com>
On Jun 11, 10:34=A0am, nolo contendere <simon.c...@fmr.com> wrote:
> On Jun 10, 5:27=A0pm, Tad J McClellan <ta...@seesig.invalid> wrote:
>
> > Bill H <b...@ts1000.us> wrote:
> > > If you are printing localtime() to a file so that it is readable and
> > > know that you are going to want to sort it later, why not just do
>
> > > print qq~localtime()|time()~;
>
> > Did you try that code before posting it?
>
> > ...
>
> > I didn't think so.
>
> # ./try_time.pl
> localtime()|time()#
Actually no - my bad. I was trying to illustrate what I mean and used
a very poor example of it.
Bill H
------------------------------
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 1632
***************************************