[26872] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8877 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jan 22 21:05:16 2006

Date: Sun, 22 Jan 2006 18:05:05 -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, 22 Jan 2006     Volume: 10 Number: 8877

Today's topics:
        3 layer hash none@non.non
    Re: 3 layer hash <abigail@abigail.nl>
    Re: 3 layer hash non@non.non
    Re: 3 layer hash non@non.non
        [OT] Re: cpp-style include for perl? <1usa@llenroc.ude.invalid>
        cpp-style include for perl? <dont_w@nt_spam.org>
    Re: cpp-style include for perl? <uri@stemsystems.com>
    Re: cpp-style include for perl? <dont_w@nt_spam.org>
    Re: cpp-style include for perl? <1usa@llenroc.ude.invalid>
    Re: cpp-style include for perl? (Randal L. Schwartz)
    Re: cpp-style include for perl? (Anno Siegel)
    Re: crash in regex with encoding utf8 <VJBDONFBFOPG@spammotel.com>
        use list to assign hash... <seanatpurdue@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 22 Jan 2006 23:44:11 +0000
From: none@non.non
Subject: 3 layer hash
Message-Id: <1a58t1plpml6cn4cn61lib04c6m29vinb2@4ax.com>



Hi.  I am sweating aftre hours of trial and error and hope you can
help me please:)



3 layer hash

I need to access the 3rd layer , I have the key value from the first
and third layers but not from the second 

I thought the following would get me the second layer

$xml->{name1}->[0]->{name3} 

but doesnt
the keys in layer 1 and 3 are constant.. the changing key is layer 2.
i need to loop through without knowing..


please point me in right direction... help ... thank you :)





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

Date: 23 Jan 2006 00:33:16 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: 3 layer hash
Message-Id: <slrndt892c.s0s.abigail@alexandra.abigail.nl>

none@non.non (none@non.non) wrote on MMMMDXXVII September MCMXCIII in
<URL:news:1a58t1plpml6cn4cn61lib04c6m29vinb2@4ax.com>:
:)  
:)  
:)  Hi.  I am sweating aftre hours of trial and error and hope you can
:)  help me please:)
:)  
:)  
:)  
:)  3 layer hash
:)  
:)  I need to access the 3rd layer , I have the key value from the first
:)  and third layers but not from the second 
:)  
:)  I thought the following would get me the second layer
:)  
:)  $xml->{name1}->[0]->{name3} 


That would address the element 'name3' stored in the first element
of the array whose reference is stored under the key 'name1' in a hash
whose reference is stored in the scalar $xml.

:)  
:)  but doesnt
:)  the keys in layer 1 and 3 are constant.. the changing key is layer 2.
:)  i need to loop through without knowing..


I'd use 'each':

    while (my ($key, $value) = each %{$hash {name1}}) {
        my $element = $$value {$name3};
        ...
    }



Abigail
-- 
tie $" => A; $, = " "; $\ = "\n"; @a = ("") x 2; print map {"@a"} 1 .. 4;
sub A::TIESCALAR {bless \my $A => A} #  Yet Another silly JAPH by Abigail
sub A::FETCH     {@q = qw /Just Another Perl Hacker/ unless @q; shift @q}


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

Date: Mon, 23 Jan 2006 00:54:50 +0000
From: non@non.non
Subject: Re: 3 layer hash
Message-Id: <89a8t15ma24n2bam7cc9hs4pv676sfq5hu@4ax.com>


>:)  the keys in layer 1 and 3 are constant.. the changing key is layer 2.
>:)  i need to loop through without knowing..
>
>
>I'd use 'each':
>
>    while (my ($key, $value) = each %{$hash {name1}}) {
>        my $element = $$value {$name3};
>        ...
>    }


Thank you that works great :)

I have
x1 {name1} 
	->x? {unknown} 
		->  x5 {name3}

Your answer loops through main1 which i only have 1 or does it go
through each layer automatically and simply store all keys-values


$$value {$name3} works perfectly but how does it know to get the data
from layer three... suppose the key-value of name3 also exists in
name2 ?  



I apologise for the no brainers... but i would like to learn as well
as use the answer... please :)



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

Date: Mon, 23 Jan 2006 01:00:35 +0000
From: non@non.non
Subject: Re: 3 layer hash
Message-Id: <tia8t11me6qnibnt14g4t1hc4nhr9f31qe@4ax.com>

O
>I apologise for the no brainers... but i would like to learn as well
>as use the answer... please :)


Because I need to know the value of the key ie {name2} (as well). can
you help with that please?


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

Date: Sun, 22 Jan 2006 21:15:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: [OT] Re: cpp-style include for perl?
Message-Id: <Xns9753A56E5189Aasu1cornelledu@127.0.0.1>

Uri Guttman <uri@stemsystems.com> wrote in
news:x77j8syr76.fsf@mail.sysarch.com: 

> <and yes, i am back! :)>

It was about time :) Great to have you back.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: Sun, 22 Jan 2006 19:35:34 GMT
From: Mike Ballard <dont_w@nt_spam.org>
Subject: cpp-style include for perl?
Message-Id: <m23bjgnjq0.fsf@west_f1.net>


Howdy - 

I have a number of scripts where many have identical blocks of code
(subroutines, some variable setting, etc.); have been reading through some
posts on packages/use/require and am getting a little lost in the
intricacies when really all I'm looking for is a cpp-style "#include" stmt
("C preprocessor", not C++) - is there anything like that for perl?


Mike
-- 




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

Date: Sun, 22 Jan 2006 14:53:49 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: cpp-style include for perl?
Message-Id: <x77j8syr76.fsf@mail.sysarch.com>

>>>>> "MB" == Mike Ballard <dont_w@nt_spam.org> writes:

  MB> I have a number of scripts where many have identical blocks of
  MB> code (subroutines, some variable setting, etc.); have been reading
  MB> through some posts on packages/use/require and am getting a little
  MB> lost in the intricacies when really all I'm looking for is a
  MB> cpp-style "#include" stmt ("C preprocessor", not C++) - is there
  MB> anything like that for perl?

what is confusing you? require is the proper way to load common source
in perl. use is a higher level form which works fine too. if you don't
use any package commands, they will all load into main:: and you should
see your subs just fine. variables are a different matter if you want
them to be lexical. but you need to show some of the data you want to
include and why you want to do that. in many cases that is a bad design
and can be done in other ways.

<and yes, i am back! :)>

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sun, 22 Jan 2006 20:46:55 GMT
From: Mike Ballard <dont_w@nt_spam.org>
Subject: Re: cpp-style include for perl?
Message-Id: <m2r770m1ml.fsf@west_f1.net>


On Sun Jan 22, I was peacefully napping until Uri Guttman said:

> >>>>> "MB" == Mike Ballard <dont_w@nt_spam.org> writes:
> 
>   MB> I have a number of scripts where many have identical blocks of
>   MB> code (subroutines, some variable setting, etc.); have been reading
>   MB> through some posts on packages/use/require and am getting a little
>   MB> lost in the intricacies when really all I'm looking for is a
>   MB> cpp-style "#include" stmt ("C preprocessor", not C++) - is there
>   MB> anything like that for perl?
> 
> what is confusing you? require is the proper way to load common source
> in perl. use is a higher level form which works fine too. if you don't
> use any package commands, they will all load into main:: and you should
> see your subs just fine. variables are a different matter if you want
> them to be lexical. but you need to show some of the data you want to
> include and why you want to do that. in many cases that is a bad design
> and can be done in other ways.
> 

Thanks on "use/require/pkg" info since I was very unclear on the
suitability of each for what I'm trying to do; "require" seems to be it.

The scripts are meant to be run from $path and within a dir containing
various input files.  So I have this (in multiple scripts):

    @filelist = `/bin/ls -1 abs*`;

Using "require" I always get a shell error:

    /bin/ls: abs*: No such file or directory


Fearing divergence into var scope issues that (truthfully) I'm just not
interested in, felt using something I already know (cpp-type include) was
quickest to getting back to what's really important to me...

Mike
-- 


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

Date: Sun, 22 Jan 2006 21:18:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: cpp-style include for perl?
Message-Id: <Xns9753A5F712096asu1cornelledu@127.0.0.1>

Mike Ballard <dont_w@nt_spam.org> wrote in
news:m2r770m1ml.fsf@west_f1.net: 

> 
> On Sun Jan 22, I was peacefully napping until Uri Guttman said:
> 
>> >>>>> "MB" == Mike Ballard <dont_w@nt_spam.org> writes:
>> 
>>   MB> I have a number of scripts where many have identical blocks of
>>   MB> code (subroutines, some variable setting, etc.); 

 ...

>> what is confusing you? 

 ...

> The scripts are meant to be run from $path and within a dir containing
> various input files.  So I have this (in multiple scripts):
> 
>     @filelist = `/bin/ls -1 abs*`;
> 
> Using "require" I always get a shell error:
> 
>     /bin/ls: abs*: No such file or directory
> 
> 
> Fearing divergence into var scope issues that (truthfully) I'm just
> not interested in, 

This has nothing to with scoping. The error you get is from ls. It 
indicates that the current directory is not what you think it is.

See

perldoc -f chdir
perldoc -f opendir
perldoc -f readdir
perldoc -f closedir
perldoc -f glob

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 22 Jan 2006 13:24:54 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: cpp-style include for perl?
Message-Id: <867j8s7y6x.fsf@blue.stonehenge.com>

>>>>> "Mike" == Mike Ballard <dont_w@nt_spam.org> writes:

Mike> Using "require" I always get a shell error:

Mike>     /bin/ls: abs*: No such file or directory

Apparently, your current directory is wrong.  Or a whole bunch
of other things.

Also, why the -1 on the ls command?

Also, why use an external command when Perl's glob does the job just fine?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 22 Jan 2006 23:33:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: cpp-style include for perl?
Message-Id: <dr14nm$r57$1@mamenchi.zrz.TU-Berlin.DE>

Uri Guttman  <uri@stemsystems.com> wrote in comp.lang.perl.misc:

> <and yes, i am back! :)>

Oh... good you mention it, otherwise I would have.

Welcome back!

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Sun, 22 Jan 2006 21:26:06 +0100
From: Christian Eyrich <VJBDONFBFOPG@spammotel.com>
Subject: Re: crash in regex with encoding utf8
Message-Id: <dr0pj2$89d$1@news1.nefonline.de>

Alan J. Flavell wrote:

>> use encoding 'iso 8859-1';
> 
> The official form of that encoding seems to be 'iso-8859-1': some 
> alternatives might be tolerated, but I'd recommend sticking to the one 
> shown in the documentation examples.

Thanks for the clarification. I actually used utf8 all the time but
wanted to go with latin1 for the example. The spelling used I saw in
http://perldoc.perl.org/encoding.html#EXAMPLE---Greekperl where it says
use encoding "iso 8859-7"; in the example.

>> open(INPUTFILE, "namelist_latin1.txt")
>> 	or die "Can't open inputfile: $!";
> 
> I'm not quite sure if this is what you really intend.  Take a look at 
> http://perldoc.perl.org/encoding.html
> 
> The primary purpose of "use encoding" is to allow you to include
> a particular encoding of characters /in your Perl source code/.
> 
> It may also (subject to a few ifs and buts) have the effect of 
> opening STDIN and STDOUT with that encoding.

That's true and I knew that. Originally I used use encoding "utf8" for
my scripts because they're encoded in UTF-8. And since I'm dealing with
UTF-8 data an display it on the console, I realized the statement causes
UTF-8-umlauts displayed correctly.

> But you're not dealing with STDIN or STDOUT here.  If you want your 
> data file (INPUTFILE) to be opened for that encoding, you need to 
> say so when you open it - or use the appropriate form of binmode().
> 
> does that help?

Maybe my code was simplified to much. But I wanted to make visible that
it's not the other hundred lines of code that lead to the crash.
At the bottom of my post I wrote
> I also get it with utf8 data (using use open ':utf8'; and
> use encoding 'utf8';)
So I guess I open the file the right way, for why I used 'use encoding'
see above.

I mean, the crash is nothing worldshaking and nothing I couldn't work
around in this case. But my POV is that a real hard crash is always an
error of the crashing app. And if Perl isn't going to be corrected I'd
at least like to know why it crashes.

Thanks,
Christian


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

Date: Sun, 22 Jan 2006 20:13:50 -0500
From: Sean <seanatpurdue@hotmail.com>
Subject: use list to assign hash...
Message-Id: <dr1ake$hbm$1@mailhub227.itcs.purdue.edu>

After the following code, memory of hash is like
{
"fact"=>undef,
"story"=>undef,
}
Is it true?
----------------------------
#!/usr/bin/perl;
use strict;
my %hash;
my @my_list = ("fact", "story");
@hash{@my_list} =();
-------------------------------


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

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


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