[21857] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4061 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 3 18:06:16 2002

Date: Sun, 3 Nov 2002 15:05:06 -0800 (PST)
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, 3 Nov 2002     Volume: 10 Number: 4061

Today's topics:
    Re: [Q]How to print contents of nested HASH in Perl? (Sri Shivananda)
    Re: [Q]How to print contents of nested HASH in Perl? <goldbb2@earthlink.net>
        CPAN (Bavan)
    Re: CPAN <mgjv@tradingpost.com.au>
    Re: Limit output of examine (x) and return (r) in debug (tî'pô)
    Re: Limit output of examine (x) and return (r) in debug (tî'pô)
    Re: Perl -e "print qq!    Tips and Tricks   !" <goldbb2@earthlink.net>
        Perl question.... (Grant)
    Re: Perl question.... <bart.lateur@pandora.be>
    Re: Perl question.... <jurgenex@hotmail.com>
    Re: scripture regex (HealYourChurchWebsite)
    Re: scripture regex <pinyaj@rpi.edu>
    Re: trouble sorting Thanks! <gbh.DELETE@REMOVE.fpcc.net>
    Re: trouble sorting <vm.mayer@comcast.net>
    Re: utf-8 in Matt's Form Mail <webmasterone@kidwatch-uk.net>
    Re: whatever happened to "static typing hints"? <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 2 Nov 2002 22:46:45 -0800
From: srishivananda@yahoo.com (Sri Shivananda)
Subject: Re: [Q]How to print contents of nested HASH in Perl?
Message-Id: <25b95416.0211022246.485893b7@posting.google.com>

Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3DC4627A.7060209@rochester.rr.com>...
> Stoone wrote:
> 
> ...
> 
> 
> > I am trying to print the nested hash tables under Perl.
> > For example, when there are hash tables like this,
> > 
> > $hash{key1}=valule1;
> > $hash{key2}{keya}=value2;
> > $hash{key2}{keyb}=value3;
> > $hash{key2}{keyc}=value4;
> > $hash{key2}{keyd}{A}=value5;
> > ......
> > .....
> > 
> > Someone please tell me how to print the key/value in the hash tables such as
> > above?
> 
> You should start with:
> 
>      use Data::Dumper;
> 
> and do:
> 
>      print Dumper(\%hash);
> 
> in order to see exactly what it is you have.  That also, I suppose, 
> meets the strict definition of "print the nested hash tables under 
> Perl", but I suppose that's not really what you want.  To do what you 
> want, you will need to be able to detect what sort of value is stored as 
> the value of each key, and then take appropriate action based on whether 
> it is a string or a reference.  The ref function will handle that, 
> returning false if the value is not a reference, and "HASH" if the value 
> is a reference to a hash (unless the reference has been blessed, in 
> which case it will return the package name into which it was blessed -- 
> in that case, use UNIVERSAL::isa($br,'HASH') to determine if the blessed 
> reference $br is to a hash or not).  From that info, you should be able 
> to figure out how to do what you want to do.


Another choice would be to use XML::Dumper.

Test Script
-----------
use XML::Dumper;
my $d = new XML::Dumper; 
print $d->pl2xml( {1 => { "one" => {"foo" => "1" } } } );'

Results
-------
<perldata>
 <hash>
  <item key="1">
   <hash>
    <item key="one">
     <hash>
      <item key="foo">1</item>
     </hash>
    </item>
   </hash>
  </item>
 </hash>
</perldata>

ThanX
Sri Shivananda


------------------------------

Date: Sun, 03 Nov 2002 02:06:04 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: [Q]How to print contents of nested HASH in Perl?
Message-Id: <3DC4CADC.B3B10F7A@earthlink.net>

Stoone wrote:
> 
> Hi,
> 
> I am trying to print the nested hash tables under Perl.
> For example, when there are hash tables like this,
> 
> $hash{key1}=valule1;
> $hash{key2}{keya}=value2;
> $hash{key2}{keyb}=value3;
> $hash{key2}{keyc}=value4;
> $hash{key2}{keyd}{A}=value5;
> ......
> .....
> 
> Someone please tell me how to print the key/value in the hash tables
> such as above?

my @x = ( '$hash', \%hash );
while( @x ) {
   my ($prefix, $hashref) = splice @x, -2, 2;

   print($prefix, "={}\n"), next if !keys %$hashref;

   while( my ($subkey, $value) = each(%$hashref) ) {
      my $hashexpr = $prefix . '{' . $subkey . '}';
      if( UNIVERSAL::isa( $value, "HASH" ) ) {
         push @x, $hashexpr, $value;
      } else {
         print $hashexpr, "=", $value, "\n";
      }
   }
}
[untested]

Note that this will not produce valid perl code that you could paste
into your program or eval() -- for that, you'll want Data::Dumper.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


------------------------------

Date: 3 Nov 2002 00:52:40 -0800
From: bavan@www.com (Bavan)
Subject: CPAN
Message-Id: <8022e6ee.0211030052.2bf83175@posting.google.com>

What are the modules needed form CPAN to run a search in Google?

Can any body explain?

regards,
bavan


------------------------------

Date: Sun, 3 Nov 2002 21:02:49 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: CPAN
Message-Id: <slrnas9t29.1s6.mgjv@martien.heliotrope.home>

On 3 Nov 2002 00:52:40 -0800,
	Bavan <bavan@www.com> wrote:
> What are the modules needed form CPAN to run a search in Google?

Go to search.cpan.org, and search for google.

> Can any body explain?

The links that pop up point to documentation. Read it, and pick the one
that suits what you want to do.

Martien
-- 
                        | 
Martien Verbruggen      | That's not a lie, it's a terminological
                        | inexactitude.
                        | 


------------------------------

Date: Sun, 03 Nov 2002 10:01:39 +0200
From: "Teh (tî'pô)" <teh@mindless.com>
Subject: Re: Limit output of examine (x) and return (r) in debugger.
Message-Id: <isl9su4ns5p63nseq1ppdfubbgn1bnpv7h@4ax.com>

Ilya Zakharevich bravely attempted to attach 17 electrodes of
knowledge to the nipples of comp.lang.perl.misc by saying:
>[A complimentary Cc of this posting was sent to
>Teh (tî'pô)
><teh@mindless.com>], who wrote in article <k2p1suo1oesajjcvff2keahe4e6nb8snvs@4ax.com>:
>> >It should not.  I tried it with
>> >
>> >  x (0..10000)
>> >
>> >and it does not.  (Both 5.005_53 and 5.6.1 I have nearby.)
>
>> You're right, when I test it on trivial samples (like your array and
>> the nested hashes in my previous mail) I get my debugger prompt back.
>> I don't know why this doesn't happen in my real life project.
>
>Do you install $SIG{INT}?

Looks like I do.

Thanks!


------------------------------

Date: Sun, 03 Nov 2002 10:34:22 +0200
From: "Teh (tî'pô)" <teh@mindless.com>
Subject: Re: Limit output of examine (x) and return (r) in debugger.
Message-Id: <u1m9suk8qau2cvode003mcjphukscgv97e@4ax.com>

Peter Scott bravely attempted to attach 18 electrodes of knowledge to
the nipples of comp.lang.perl.misc by saying:
>In article <apu5cr$tqf$1@plover.com>,
> mjd@plover.com (Mark Jason Dominus) writes:
>>In article <s0p1suknk1di5bra5o49upar5pejlr7tcb@4ax.com>,
>>Teh (tî'pô) <teh@mindless.com> wrote:
>>>Sadly I'm using an older version.
>>
>>
>>But you can obtain the perl5db.pl from 5.8.0 and use it instead of the
>>one you were using, without having to change the version of Perl you
>>are using.
>
>And also update dumpvar.pl at the same time, which has at least one
>new function in that's called from the new perl5db.pl (not for any of the
>things the poster was asking about, though).

Great, this looks like what I'm looking for.

I hope this isn't a FAQ, but I can't figure out how to download
specific files from perl 5.8 without downloading the whole thing.


------------------------------

Date: Sun, 03 Nov 2002 00:32:46 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl -e "print qq!    Tips and Tricks   !"
Message-Id: <3DC4B4FE.D8E5FAE9@earthlink.net>

zzapper wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3DC2F1CC.3988B114@earthlink.net>...
> > zzapper wrote:
> 
> $_=",.,,,.,,.,,.,,,,..,,,,,,,,.,,,,,,,,,,,,,.,,,,,,,,,.,,,,,,,..,..,,.,,,,,
>    ,,,,";s/\s//gs;tr/,./05/;@a=split(//);$_=<DATA>;tr/~`'"^/0-4/;map{$o
>    .=$a[$i]+$_;$i++}split(//);@a=$o=~m!...!g;map{print chr}@a;
> __DATA__
> ~'^``'``~```~"'~^'``~```````~^`~```^~"'~"~`~```^`~"~"'`~^~^'~^^`~'`~```^~`~
> 
> Bejamin I found this "stinker" JAPH
> 
> It's not a perl -e, but does it fit your "anything resembling
> plaintext is insuffienctly obscure"

It does, but it's too long -- a good JAPH will be 4 lines or fewer, the
standard usenet convention for a signature.

Also, although the data is *slightly* obfuscated, by being split into
two parts and added together, the code is essentially the same as:

print chr for <<"EOS" =~ /.../g;
074117115116032097110111116104101114032080101114108032104097099107101114010
EOS

Which isn't really very special.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


------------------------------

Date: 3 Nov 2002 08:54:56 -0800
From: tonearm@email.com (Grant)
Subject: Perl question....
Message-Id: <d6cf0719.0211030854.119c3d34@posting.google.com>

Hi, I need to change strings like "Cool Posters" to "cool_posters".  I
need to have all capitals reduced to lower-cased letters, all spaces
converted to "_" characters, and all "." characters simply removed. 
Please show me how this can be done in Perl.  Thanks a lot!


------------------------------

Date: Sun, 03 Nov 2002 16:59:15 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Perl question....
Message-Id: <lclasuk5u77u2tdmesvfamijigu1fmv21n@4ax.com>

Grant wrote:

>Hi, I need to change strings like "Cool Posters" to "cool_posters".  I
>need to have all capitals reduced to lower-cased letters, all spaces
>converted to "_" characters, and all "." characters simply removed. 
>Please show me how this can be done in Perl.  Thanks a lot!

	$orig = 'Cool Posters';
	($result = lc $orig) =~ tr/ ./_/d;
	print $result;

-- 
	Bart.


------------------------------

Date: Sun, 03 Nov 2002 17:22:30 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl question....
Message-Id: <qXcx9.14387$7W2.6336@nwrddc01.gnilink.net>

Grant wrote:
> Hi, I need to change strings like "Cool Posters" to "cool_posters".  I
> need to have all capitals reduced to lower-cased letters, all spaces
> converted to "_" characters, and all "." characters simply removed.
> Please show me how this can be done in Perl.  Thanks a lot!

Please see
    perldoc -f tr (don't forget to look at modifier d, too)
    perldoc -f lc

jue




------------------------------

Date: 3 Nov 2002 03:49:27 -0800
From: healthychurchwebsite@yahoo.com (HealYourChurchWebsite)
Subject: Re: scripture regex
Message-Id: <7750146a.0211030349.5d5b2a18@posting.google.com>

> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message 

You are the man! I made some redjustments to "my $verses" to
accomodate spaces and references within the same chapter.

Here's something that is VERRRYYY VERRY close to what I want. Close
enough to proceed. Much in thanks to your help:

my $volumes = "I+|1st|2nd|3rd|First|Second|Third|1|2|3";
my $books = "Genesis|Exodus|Leviticus|Numbers|Deuteronomy|Joshua|Judges|Ruth|Samuel|Kings|Chronicles|Ezra|Nehemiah|Esther|Job|Psalm|Proverbs|Ecclesiastes|Song
of Solomon|Isaiah|Jeremiah|Lamentations|Ezekiel|Daniel|Hosea|Joel|Amos|Obadiah|Jonah|Micah|Nahum|Habakkuk|Zephaniah|Haggai|Zechariah|Malachi|Matthew|Mark|Luke|John|Acts|Romans|Corinthians|Galatians|Ephesians|Philippians|Colossians|Thessalonians|Timothy|Titus|Philemon|Hebrews|James|Peter|Jude|Revelation";

while(<DATA>) {

  # include instances of James 2:1-13, 14 - 16, 17 & 18
  my $verses = qr{ \d+ (: \d+)* \s* (?: [-&] \s* \d+)*	 }x;
  my $passage;

  # don't just match, replace
  s/
	(?:($volumes)\s*)*		   # any number of vols.
    \s*
    ($books)                               # the book
    \s*
	( $verses (?: \s* , \s* $verses)* )
   /$passage = ($1 ? "$1 ":"").($2 ? $2:"").($3 ? " $3":"");
   "<scripRef passage=\"$passage\">$passage<\/scripRef>"
   /gcex;

   print $_;	
}
	
__DATA__
$Date: October 20, 2002
$Type: Sermon
$Scripture: James 2:1-13, 14 & 15		
$Version: NIV
$Title: How Faith Works: "Determining the Worth of a Person"
1 Fred 2:24
III John 1:2-4, 2:1&2
III John 1:2-4, 2:1&2; 2nd Peter 2:1

$Text:
Well, that gives us somewhat of an idea of how uncomfortable
situations like this might have been in the years of the early church
as these first Christians began to mature spiritually to the point
that they could understand that all people ARE equal in God's sight.
Perhaps this situation is what Paul was thinking of when he wrote in
Galatians 3 and said,  "There is neither Jew nor Greek, SLAVE NOR
FREE, male nor female, for you are all ONE in Christ Jesus."
(Galatians 3:28)

So James is saying to his peers in the early church that favoring the
rich is not thinking like God thinks.  In essence he says it makes no
"heavenly sense." But he also says, "Hey guys-it doesn't make any
earthly sense either. Remember? These rich people are the ones who are
persecuting you." And they were-it was the rich Sadducees who arrested
Peter and John in Acts 4. Acts 13:50 says it was the wealthy "leading
men" of the city of Antioch who persecuted Paul and Barnabas. Acts 16
says the wealthy owners of a demon-possessed girl dragged Paul into
court and Acts 19 tells of  the wealthy silversmiths in Ephesus who
very nearly led a mob to kill him. James also says that it was the
rich of that day who slandered the name of Jesus.


------------------------------

Date: Sun, 3 Nov 2002 08:54:51 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: scripture regex
Message-Id: <Pine.A41.3.96.1021103085259.17156A-100000@cortez.sss.rpi.edu>

On 3 Nov 2002, HealYourChurchWebsite wrote:

>> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message 
>
>You are the man! I made some redjustments to "my $verses" to
>accomodate spaces and references within the same chapter.

Glad I could help you. :)

Isaiah 58:12 ;)

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



------------------------------

Date: Sun, 03 Nov 2002 09:19:46 -0700
From: Gary Hodges <gbh.DELETE@REMOVE.fpcc.net>
Subject: Re: trouble sorting Thanks!
Message-Id: <3DC54CA2.2CFC7F72@REMOVE.fpcc.net>

Thanks much for all the suggestions!  I'm going to try them all.

Cheers,
Gary




------------------------------

Date: Sun, 03 Nov 2002 01:00:08 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: trouble sorting
Message-Id: <vm.mayer-2B2B97.01000703112002@news-east.giganews.com>

In article <3DC4A370.D3DB2F84@REMOVE.fpcc.net>,
 Gary Hodges <gbhDELETE@fpcc.net> wrote:

> ActiveState 5.6.0 build 623 installed on Win2000
> 
> I'm having some trouble sorting.  Using the following file names as
> examples:
> file_b.drw.2
> file_b.drw.20
> file_b.drw.100
> file_a.xls.9
> file_a.xls.19
> file_a.xls.190
> 
> I would like to group them (group order not important) based on the
> basename.xxx and then reverse sort by the last digit extension giving:
> file_a.xls.190
> file_a.xls.19
> file_a.xls.9
> file_b.drw.100
> file_b.drw.20
> file_b.drw.2
> 

#!/usr/bin/perl

use strict;

my ($path,$cmd) = (".",$0);
if( $0 =~ /\/([^\/]+)$/ ) { ($path,$cmd) = ($`,$1); }

# Examine the list
#    Find all extensions associated with a given base

my %list;
open(SRC,"data") || die "Cannot open data: $!\n";
while(<SRC>) {
  next unless /(\S+)\.(\d+)$/;
  push @{$list{$1}}, $2;
}
close SRC;

# (Reverse) Sort the extensions

foreach my $base (keys %list) {
  my @ext = sort { $b <=> $a } @{$list{$base}};
  $list{$base} = [@ext];
}

# Do whatever you need with the list
#   I'll print them as an example

foreach my $base (sort keys %list) {
  foreach my $ext (@{$list{$base}}) {
    print "$base.$ext\n";
  }
}

hth
mike


------------------------------

Date: Sun, 3 Nov 2002 10:09:18 -0000
From: "TrickieDickie" <webmasterone@kidwatch-uk.net>
Subject: Re: utf-8 in Matt's Form Mail
Message-Id: <8y6x9.8388$VM5.402039@newsfep2-win.server.ntli.net>


"Alan J. Flavell" <flavell@mail.cern.ch> wrote - in part

> But the original poster is already active - separately - on
> c.i.w.a.html and alt.html
>>snip<<
> Now it appears that he feels ready to tackle not only the i18n input
> to a script, but also packaging it up into appropriate email formats
> (as well as storing it into databases, as a separate thread
> indicates).
>
> With the greatest of respect to his ambitions, I feel that's somewhat
> premature after only a couple of days study.  But I could be wrong!

Mr Flavell -
A few home truths.
Indeed, I wish myself and my other colleagues had the time
and indeed the inclination to study and expound on the
esoterica of  "form submission and i18n".  That is not the
case.
All three 'webmasters' - an honorary title I can assure you,
at Kidwatch are all full time case-officers dealing with
missing and runaway children within the EEC.  None of
us have had any web authoring experience whatsoever.
And, frankly do not have the time to obtain it.  This operation
is a non-profit organization and certainly has no funds to
pay for professional mark-up.  We therefore muddle along
as best we can and glean as much from NG's as is available
to us.
    Increasingly, however, I am seeing that the NG's that
could really benefit novices trying to learn a little are being
dominated by self-styled 'guru's' who seem more worried
that a post is exactly on point or meets a sufficient degree
of obfuscation before they will deign to share their knowledge.
  I was of the impression that the origination of the NG
was to be a channel for the passing and dissemination
of information, knowledge and learning.

Now, why have we switched our 'unwanted' postings
from where we were to a perl NG?
Simple, Mr. Flavell.  We were just unable, in our ignorance,
to get our heads around ASP in the context of UTF-8 in
Forms and from there storing the messages in an Access
Database.  It just was not working.  So, we decided of
trying the route, a little more around the houses for sure,
of having the messages handled by a cgi/perl script that
would correctly maintain the inputted character integrity
until it arrived on our desk as an e-mail and from thence
transfer it back into an html page that could be searched.

So, until I am told it cannot be done, I will pursue this
new possibility,
We have only one aim in life and that is communication
worldwide on the matter of missing, runaway, abducted
and disappeared children.  If we tread on a few 'gurus'
toes on the way or do not quite use the correct NG etiquette -
so be it.
Now - is this a flame?  Let one of the gurus tell me!

--
Regards
Dick Rosser
webmasterone@kidwatch-uk.net
http://www.kidwatch-uk.net




------------------------------

Date: Sun, 03 Nov 2002 22:57:13 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: whatever happened to "static typing hints"?
Message-Id: <2nrasu8te2jinqg9f3f0afirc8aei6d5hl@4ax.com>

On Wed, 30 Oct 2002 18:04:57 -0500, Benjamin Goldberg
<goldbb2@earthlink.net> wrote:

>Yes, it would ... unless at the first use of this optomization,

[completely OT] Is it just a repeated typo, you writing
"optomization", or is "optomization" something different from
"optimization"?


Sorry if this is obvious, but I'm not a native english speaker (if
that matters...).


Michele
-- 
Liberta' va cercando, ch'e' si' cara,
Come sa chi per lei vita rifiuta.
           [Dante Alighieri, Purg. I, 71-72]

I am my own country - United States Confederate of Me!
           [Pennywise, "My own country"]


------------------------------

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 4061
***************************************


home help back first fref pref prev next nref lref last post