[28353] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9717 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 12 14:06:11 2006

Date: Tue, 12 Sep 2006 11:05: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           Tue, 12 Sep 2006     Volume: 10 Number: 9717

Today's topics:
    Re: Decode data of different charsets into UTF8 (Perl i <hjp-usenet2@hjp.at>
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? <simon.chao@fmr.com>
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? anno4000@radom.zrz.tu-berlin.de
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? <brian.d.foy@gmail.com>
    Re: FAQ 9.7 How do I make a pop-up menu in HTML? <simon.chao@fmr.com>
    Re: gah! <jurgenex@hotmail.com>
    Re: localtime is now wrong after server change <tadmc@augustmail.com>
    Re: Maximum number of sockets <bik.mido@tiscalinet.it>
    Re: Modifying and printing a string variable <tadmc@augustmail.com>
    Re: Modifying and printing a string variable <josef.moellers@fujitsu-siemens.com>
        Parsing strings and obeying quotes <nospam@cox.net>
    Re: Parsing strings and obeying quotes <1usa@llenroc.ude.invalid>
    Re: Parsing strings and obeying quotes <glex_no-spam@qwest-spam-no.invalid>
    Re: Parsing strings and obeying quotes <no@email.com>
        Search and replace problem ironmanda@yahoo.com
    Re: Search and replace problem <David.Squire@no.spam.from.here.au>
    Re: Search and replace problem <mritty@gmail.com>
    Re: Search and replace problem <someone@example.com>
    Re: variable inheritance xhoster@gmail.com
    Re: variable inheritance <uri@stemsystems.com>
        XML content element parsing <mislam@spam.uiuc.edu>
    Re: XML content element parsing <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 12 Sep 2006 18:48:51 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Decode data of different charsets into UTF8 (Perl internal format)
Message-Id: <slrnegdp7j.5u0.hjp-usenet2@yoyo.hjp.at>

On 2006-09-12 11:09, Dr.Ruud <rvtol+news@isolution.nl> wrote:
> Peter J. Holzer schreef:
>> iso-8859-1 and cp437 are easy as the ranges for accented characters
>> overlap very little. In fact the range where most accented characters
>> are in cp437 isn't even defined in iso-8859-1, so if you find a
>> character in this range it can't be iso-8859-1 (but it might be
>> win-1252).
>
> The character map "ISO_8859-1:1987", more commonly known by its
> preferred MIME name of "ISO-8859-1" (note the extra hyphen over "ISO
> 8859-1"), has both the ranges 00-1F and 80-9F defined.

According to
ISO/IEC 8859-1:1997 (http://anubis.dkuug.dk/JTC1/SC2/WG3/docs/n411.pdf):

| The shaded positions in the code table correspond
| to bit combinations that do not represent graphic
| characters. Their use is outside the scope of
| ISO/IEC 8859; it is specified in other International
| Standards, for example ISO/IEC 6429.

The shaded positions are 00-1F and 7F-9F.

In practice, even if the C1 block is defined in some standard, none of
these control characters is likely to appear in text (not even 85 NEL,
which would be a sane replacement for the LF/CRLF/CR mess), so for the
purpose of distinguishing character sets on a heuristic basis,
appearance of any character in this range is a very strong indication
that the text isn't ISO-8859-* (as is the appearance of any character
from the C0 range except LF, TAB, and CR (and maybe BS)).


> ISO-8859-1 is also incorporated as the first 256 code points of Unicode.

True. However, Unicode 2.0 didn't define any character in the C1 range -
all of them are just marked "Ctrl". Unicode 4.0 defined only U+0085 NEL.
Only Unicode 5.0 (which isn't finished) will define most of these
characters.

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 12 Sep 2006 06:40:46 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <1158068446.174221.266380@e63g2000cwd.googlegroups.com>


PerlFAQ Server wrote:
> This is an excerpt from the latest version perlfaq9.pod, which
> comes with the standard Perl distribution. These postings aim to
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>
> --------------------------------------------------------------------
>
> 9.7: How do I make a pop-up menu in HTML?
>
>     Use the <SELECT> and <OPTION> tags. The CGI.pm module (available from
>     CPAN) supports this widget, as well as many others, including some that
>     it cleverly synthesizes on its own.
>
>
>
> --------------------------------------------------------------------

Is this really On Topic?



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

Date: 12 Sep 2006 13:57:33 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <4mnsmdF71tfbU1@news.dfncis.de>

it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote in comp.lang.perl.misc:
> 
> PerlFAQ Server wrote:
> > This is an excerpt from the latest version perlfaq9.pod, which
> > comes with the standard Perl distribution. These postings aim to
> > reduce the number of repeated questions as well as allow the community
> > to review and update the answers. The latest version of the complete
> > perlfaq is at http://faq.perl.org .
> >
> > --------------------------------------------------------------------
> >
> > 9.7: How do I make a pop-up menu in HTML?
> >
> >     Use the <SELECT> and <OPTION> tags. The CGI.pm module (available from
> >     CPAN) supports this widget, as well as many others, including some that
> >     it cleverly synthesizes on its own.
> >
> >
> >
> > --------------------------------------------------------------------
> 
> Is this really On Topic?

I don't know, but everything that guides CGI users towards CGI.pm is
fine with me.

Anno


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

Date: Tue, 12 Sep 2006 09:58:55 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <120920060958557253%brian.d.foy@gmail.com>

In article <1158068446.174221.266380@e63g2000cwd.googlegroups.com>,
it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote:

> PerlFAQ Server wrote:

> > --------------------------------------------------------------------

> > 9.7: How do I make a pop-up menu in HTML?

> Is this really On Topic?

As a frequently asked question about Perl, it got an entry in perlfaq9.
You'll find lots of CGI questions and answers in there.

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: 12 Sep 2006 09:53:41 -0700
From: "it_says_BALLS_on_your forehead" <simon.chao@fmr.com>
Subject: Re: FAQ 9.7 How do I make a pop-up menu in HTML?
Message-Id: <1158080021.047145.187740@i42g2000cwa.googlegroups.com>


brian d foy wrote:
> In article <1158068446.174221.266380@e63g2000cwd.googlegroups.com>,
> it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote:
>
> > PerlFAQ Server wrote:
>
> > > --------------------------------------------------------------------
>
> > > 9.7: How do I make a pop-up menu in HTML?
>
> > Is this really On Topic?
>
> As a frequently asked question about Perl, it got an entry in perlfaq9.
> You'll find lots of CGI questions and answers in there.

Ok, I was just concerned that this would be viewed as a hole through
which any one could ask any HTML question to this newsgroup and have
that question be considered On Topic.

Many times I have seen people ask HTML questions, with the response
from the regulars being that those questions are Off Topic.

This FAQ (in my mind, at least), legitimizes some of those queries. A
change in the verbiage of the Subject to include a reference to the
CGI.pm would mitigate this (somewhat). Just my $0.02.



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

Date: Tue, 12 Sep 2006 14:42:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: gah!
Message-Id: <0HzNg.7576$xC3.93@trnddc06>

Don Corleone wrote:

[Subject: Re: gah!]

Don't you think this is a useless use of a useless subject? Whatever you 
article is about, I bet it is not about "gah" (whatever that is).

> Thanks for some of the comments.

What comments? I don't see any reference to comments in your posting.

> In a nutshell this is what i am trying to make the program do:
>
> 1. get a directory name (works ok)
> 2. Get a list of all the tif files in this directory (works ok)

Ok, then I won't comment on those.

> 3. perform a msdos file operation on each file returned by 2 above
> (doesnt work).

Most people would probably use system() or backticks or qx or something 
similar to just call the OS to perform the action.

> thats it. I dont get why 3 isnt working, any help appreciated.

Well, you didn't show us any code or even give vaguely enough detail to make 
any assessment of what might be going wrong.
Have you seen the posting guidelines for this NG? I stronlgy suggest to post 
a minimal sample program that demonstrates your problem.

jue 




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

Date: Tue, 12 Sep 2006 01:22:27 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: localtime is now wrong after server change
Message-Id: <slrnegckh3.2lb.tadmc@magna.augustmail.com>

Jason <jwcarlton@gmail.com> wrote:

> but when did
> everyone on this NG get to be so rude?


Last Thursday.


> Anyone remember how we 


You used to post here?


> used to all be helpful and sharing,

> We would have never called someone a whimpering
> moron just for not understanding the purpose of a line of code. 


For not understanding the purpose of a line of code *that you wrote yourself* ?

You must have had some purpose in mind when you wrote it...


If "we" would never have called someone out for cargo-culting code,
then things are _better_ now than then.


> I guess
> this is what we have to look forward to with the next generation.


Oh, are you an old guy or something?


>> Because you are adding one hour to the current time. How hard is that to
>> figure out?
> 
> While working on old code, after having been awake for more than 48
> hours... very hard! Be fair; 


Be a programmer.

(and is seems disrespectful of others to dump your problem on them
 when in such a state.
)

> if you weren't familiar with the logic,
> what would make you think that 60*60 was equivalent to an hour?


There is no logic there, only straightforward arithmetic.


>> > though, because through WHM
>>
>> WTF is WHM?
> 
> That's the name 


With no vowels?


> of the server management program that I use.

> I figured you all were aware of it


Most uses of Perl are *not* in a CGI environment.

Perl is not CGI.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 12 Sep 2006 17:56:35 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Maximum number of sockets
Message-Id: <luldg298tc27bg5tooj1u1k7hbn2qp9vl4@4ax.com>

On Mon, 11 Sep 2006 10:53:45 -0400, "A Ma" <angusma@attglobal.net>
wrote:

>> Not quite. In this case I suspect it does change the rules, but you
>> need to make sure that everyone who needs to know the new rule has read
>> the sign.  So I'm gussing you need to rebuild perl.
>
>I suspect I have to recompile Perl but I am using ActiveState Perl and I 

Indeed. Thus it is obvious that

: sockets that I can open is 64. I found the parameter PERL_FD_SETSIZE in 
: c:\perl\lib\core\sys\socket.h. I changed that number but it did not take 

>don't have the source. So I am not sure how I can do that. Any further 
>suggestions would be helpful. 

Get a C compiler, Perl sources which are freely available and rebuild
perl. Now, this may be a hassle for the average quadratic user on
Windows. Hopefully that Vanilla/Strawberry stuff will make all this
first or later. However AIUI it is still in its very early days. You
may try giving a peek into it, anyway...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Tue, 12 Sep 2006 08:23:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Modifying and printing a string variable
Message-Id: <slrnegdd6c.3tt.tadmc@magna.augustmail.com>

JC <offthedome@gmail.com> wrote:

> I have a hash, with key bodybgcolor pointing to a hexadecimal color
> string "#FF9966". Problem is, I'm not allowed to pring the "#" sign, 


   print substr $hash{bodybgcolor}, 1;


> so
> I need to print "FEDCBA". 


Why do you need to print "FEDCBA" when the value is "#FF9966"?

I would have thought you need to print "FF9966" for that value...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 12 Sep 2006 15:53:47 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Modifying and printing a string variable
Message-Id: <ee6ed2$jeg$1@nntp.fujitsu-siemens.com>

kens wrote:
> Josef Moellers wrote:
>=20
>>JC wrote:
>>
>>>I have a hash, with key bodybgcolor pointing to a hexadecimal color
>>>string "#FF9966". Problem is, I'm not allowed to pring the "#" sign, s=
o
>>>I need to print "FEDCBA". How do I do that?
>>>
>>
>>What have you tried and where did it fail to meet your expectations?
>>
>>As it is a veeeery simple problem with numerous possible solutions (a
>>truly TMTOWTDI):
>>
>>my $string =3D '#FF9966';
>>
>>my $result1 =3D substr($string, 1);
>>my $result2; ($string2 =3D $string) =3D~ s/^#//;
>>my $result3; ($string3 =3D $string) =3D~ tr/^#//d;
>>
>=20
>=20
> I assume you meant:
>=20
> my $result2; ($result2 =3D $string) =3D~ s/^#//;
> my $result3; ($result3 =3D $string) =3D~ tr/^#//d;

Yesindeedsir ;-)

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Tue, 12 Sep 2006 09:54:24 -0700
From: Mia <nospam@cox.net>
Subject: Parsing strings and obeying quotes
Message-Id: <%CBNg.3347$AP2.33@fed1read10>

Hi All,

I'm trying to parse a string into an array of words or phrases, 
something like:

my $string = "abc def ghi";
my @words = split(/ /,$string);

 ...but I also want to handle the case where there are quoted phrases 
within the string, i.e.:

my $string = 'abc "def ghi"';
or
my $string = "abc 'def ghi'";

I want to preserve the quoted phrase as one element.  Such a simple 
thing, one would think, but I've not found a technique yet.

Anyone have a hint for me?

-Mia



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

Date: Tue, 12 Sep 2006 17:15:45 +0000 (UTC)
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Parsing strings and obeying quotes
Message-Id: <Xns983C86EA8233Casu1cornelledu@132.236.56.8>

Mia <nospam@cox.net> wrote in news:%CBNg.3347$AP2.33@fed1read10:

> I'm trying to parse a string into an array of words or phrases, 
> something like:
> 
> my $string = "abc def ghi";
> my @words = split(/ /,$string);
> 
> ...but I also want to handle the case where there are quoted phrases 
> within the string, i.e.:
> 
> my $string = 'abc "def ghi"';
> or
> my $string = "abc 'def ghi'";
> 
> I want to preserve the quoted phrase as one element.  Such a simple 
> thing, one would think, but I've not found a technique yet.
> 
> Anyone have a hint for me?

You should read the Perl FAQ before posting your question:

perldoc -q inside

Sinan



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

Date: Tue, 12 Sep 2006 12:20:42 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Parsing strings and obeying quotes
Message-Id: <4506eb89$0$3580$815e3792@news.qwest.net>

Mia wrote:
> Hi All,
> 
> I'm trying to parse a string into an array of words or phrases, 
> something like:
> 
> my $string = "abc def ghi";
> my @words = split(/ /,$string);
> 
> ...but I also want to handle the case where there are quoted phrases 
> within the string, i.e.:
> 
> my $string = 'abc "def ghi"';
> or
> my $string = "abc 'def ghi'";
> 
> I want to preserve the quoted phrase as one element.  Such a simple 
> thing, one would think, but I've not found a technique yet.
> 
> Anyone have a hint for me?

  perldoc -q delimited





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

Date: Tue, 12 Sep 2006 18:28:56 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Parsing strings and obeying quotes
Message-Id: <4mo921F77csjU1@individual.net>

A. Sinan Unur wrote:

> Mia <nospam@cox.net> wrote in news:%CBNg.3347$AP2.33@fed1read10:
> 
>> I'm trying to parse a string into an array of words or phrases,
>> something like:
>> 
>> my $string = "abc def ghi";
>> my @words = split(/ /,$string);
>> 
>> ...but I also want to handle the case where there are quoted phrases
>> within the string, i.e.:
>> 
>> my $string = 'abc "def ghi"';
>> or
>> my $string = "abc 'def ghi'";
>> 
>> I want to preserve the quoted phrase as one element.  Such a simple
>> thing, one would think, but I've not found a technique yet.
>> 
>> Anyone have a hint for me?
> 
> You should read the Perl FAQ before posting your question:
> 
> perldoc -q inside


In addition to this FAQ entry, I have had success with Damian Conway's
Text::Balanced for stuff similar to this.

http://search.cpan.org/~dconway/Text-Balanced-1.98/lib/Text/Balanced.pm


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: 12 Sep 2006 10:37:23 -0700
From: ironmanda@yahoo.com
Subject: Search and replace problem
Message-Id: <1158082643.231702.18430@p79g2000cwp.googlegroups.com>

I'm trying to build a general way of handling search and replace
of strings.  The regexp in the commented out part works perfectly.
But, the foreach part doesn't work.  The thing is, \1 is being
interpreted literally.  Any ideas?

David

#!/usr/local/bin/perl

my $str="http://www.xxx.com/yyy/zzz/25331/2";

$repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";

# $str=~s/([0-9]*)\/[0-9]+$/\1/g;
# print "$str\n";
# exit 0;

foreach $key (sort keys %repurl) {
    print "$key - $repurl{$key}\n";
    $str=~s/$key/$repurl{$key}/g;
}

print "$str\n";



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

Date: Tue, 12 Sep 2006 18:48:26 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Search and replace problem
Message-Id: <ee6rta$o4k$1@gemini.csx.cam.ac.uk>

ironmanda@yahoo.com wrote:
> I'm trying to build a general way of handling search and replace
> of strings.  The regexp in the commented out part works perfectly.
> But, the foreach part doesn't work.  The thing is, \1 is being
> interpreted literally.  Any ideas?

Ermmm... read the documentation on Perl regular expressions?

perldoc perlre
perldoc perlretut

In particular, look at the difference between backreferences (\1, \2,
etc.) used within a regular expression, and match (or capture) variables
($1, $2, etc.) used *outside* regular expressions (e.g. in a replacement
string).


DS


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

Date: 12 Sep 2006 10:53:24 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Search and replace problem
Message-Id: <1158083604.391631.76630@m73g2000cwd.googlegroups.com>

ironmanda@yahoo.com wrote:
> I'm trying to build a general way of handling search and replace
> of strings.  The regexp in the commented out part works perfectly.
> But, the foreach part doesn't work.  The thing is, \1 is being
> interpreted literally.  Any ideas?
>
> David
>
> #!/usr/local/bin/perl
>
> my $str="http://www.xxx.com/yyy/zzz/25331/2";
>
> $repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";
>
> # $str=~s/([0-9]*)\/[0-9]+$/\1/g;
> # print "$str\n";
> # exit 0;

Run this part again, and this time turn warnings on.  Why aren't they
turned on to begin with?

Does that warning help you figure out what you should have done
instead?

Paul Lalli



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

Date: Tue, 12 Sep 2006 18:04:33 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Search and replace problem
Message-Id: <RECNg.2815$KA6.860@clgrps12>

ironmanda@yahoo.com wrote:
> I'm trying to build a general way of handling search and replace
> of strings.  The regexp in the commented out part works perfectly.
> But, the foreach part doesn't work.  The thing is, \1 is being
> interpreted literally.  Any ideas?
> 
> 
> #!/usr/local/bin/perl
> 
> my $str="http://www.xxx.com/yyy/zzz/25331/2";
> 
> $repurl{"([0-9]*)\\/[0-9]+\$"}="\\1";
> 
> # $str=~s/([0-9]*)\/[0-9]+$/\1/g;
> # print "$str\n";
> # exit 0;
> 
> foreach $key (sort keys %repurl) {
>     print "$key - $repurl{$key}\n";
>     $str=~s/$key/$repurl{$key}/g;
> }
> 
> print "$str\n";

$ perl -Mwarnings -Mstrict -e'
my $str = q[http://www.xxx.com/yyy/zzz/25331/2];

my %repurl = ( q[(\d*)/\d+$] => q[$1] );

for my $key ( sort keys %repurl ) {
    print "$key - $repurl{$key}\n";
    $str =~ s/$key/$repurl{$key}/eeg;
    print "$str\n";
}
'
(\d*)/\d+$ - $1
http://www.xxx.com/yyy/zzz/25331



John
-- 
use Perl;
program
fulfillment


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

Date: 12 Sep 2006 15:26:35 GMT
From: xhoster@gmail.com
Subject: Re: variable inheritance
Message-Id: <20060912112724.869$ll@newsreader.com>

"Matt Garrish" <mgarrish@gmail.com> wrote:
> I'm faced with the problem of one module serving up data for 10
> different applications, where the only difference is the data being
> generated. Without going into the gory details, each year the data
> structure (the database) can change for each application and the
> applications have no relation to each other.

If the data can change independently, the structure of the data can change
independently, and the applications have no relation to each other, then
why even bother trying to tie them together?

> For this reason, I've set up 10 separate modules each defining the same
> set of variables so that my generic class can access the configuration
> information without needing to know which application it is dealing
> with. Some of the data is the same between applications,

Just by accident?  Does this shared data change frequently?  When it does
change, is it highly likely to change in concert across all apps?  If
either of these are "no" then it seems like it would be better just to copy
this data into each of 10 independent modules.

> so I keep that
> in the base class and then the subclasses override the variables that
> are specific to each of the children. As I'm sure the above must sound
> like gibberish, take for example:
>
> ### DataBase.pm
>
> package DataBase;
>
> use Exporter;
> @ISA = qw/Exporter/;
> @EXPORT = qw/%appInfo %someOtherConfig/;
>
> # this variable will get overriden by the child module
> # but declaring it here means I can use it in the
> # module

You can use it in which module?  You can't use it in *this* module,
as it won't be initialized (other than to an empty list) in this module.
Why would you want to use it if it contains nothing useful?

> # and avoid problems with strictures
> # not finding the variable before the child require

And if you don't use it in *this* module, then strictures won't have any
problem with it.

 ...
> The above will print the correct 'table1' key, but my question is am I
> setting myself up for disaster if I actually try and go this route? I'm
> not saying it's the most elegant code, but since it's not a true object
> that I want but more of a configuration file is there any danger in my
> assumption that the require will properly result in the %appInfo being
> the child version.

That seems to be correct, in the main package (or whichever package
executed the require).  Not for other packages, however.

> I currently have the data all in one big configuration file but it's
> quickly becoming unwieldy and too large

What does that mean?  It is taking too long to parse?  It is taxing your
server memory?  It is causing your text editor to crash when you try to
edit it?  It is taxing you mental ability to understand it all?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 12 Sep 2006 12:52:42 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: variable inheritance
Message-Id: <x7ejuhkox1.fsf@mail.sysarch.com>

>>>>> "MG" == Matt Garrish <mgarrish@gmail.com> writes:

  MG> The problem in a nutshell is how do I make the variable "exist" in the
  MG> eyes of strictures but not know what it contains until the require
  MG> happens. I was trying to come up with any trickery I could just in the
  MG> interests of seeing what else was possible, but I think I'll just go
  MG> back to tried and true.

as we tell others when they do a config with tons of scalars:

	use a hash.

then you can declare it with our %config in each of the required files
(assuming they are all in the same name space). in each file you just
execute a set of assignments (or a large slice assignment) to the config
hash. you can even have a my hash in the file and assign it with a slice
to the main config

if you load the required files in the correct order (and some required
files will load others) you can control the order of the assignments to
get what you want. this is not true inheritance but good enough.

and i recall talking to michael schwern about a module to make data
inheritance work. i can't find it under his cpan id. but there might be
something like it on cpan. as always i find that kind of design to be
overkill.

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: Tue, 12 Sep 2006 10:34:34 -0500
From: Sharif Islam <mislam@spam.uiuc.edu>
Subject: XML content element parsing
Message-Id: <ee6k2a$sho$1@news.ks.uiuc.edu>

Hi,
I have a question on parsing multiple element
content. This is an example from the Perl & XML, O'Reilly book, changed 
little bit.


#: initialize the parser

use strict;
use XML::Parser::PerlSAX;

my $parser = XML::Parser::PerlSAX->new( Handler => MyHandler->new() );
if( my $file = shift @ARGV ) {
     $parser->parse( Source => {SystemId => $file} );
} else {
     my $input = "";
     while( <STDIN> ) { $input .= $_; }
     $parser->parse( Source => {String => $input} );
}

exit;

### Document Handler Package
###

package MyHandler;

my %record;
my ($id,$context,$rv);

#
# initialize the handler package
#
sub new {
     my $type = shift;
     return bless {}, $type;
}

#
# handle a start-of-element event: output start tag and attributes
#
sub start_element {
    my( $self, $elements ) = @_;
   # save the element name
    $context = $elements->{'Name'};
    my %attributes = %{$elements->{'Attributes'}};
         foreach( keys( %attributes )) {
    # save the login id
          $id = $attributes{$_} ;
      }

}

sub characters {
   my ($self, $elements) = @_;
    $rv = $elements->{'Data'} ;
    $rv =~ s/\s+//g;
    $record{$id}{$context} .= $rv;
}

sub end_element {
     my( $self, $elements ) = @_;
    if ($elements->{'Name'} eq 'person' )
  # this means end of the person's record, so print it out
  {
    print "$id\t";
    print "$record{$id}{'email'}\t";
    print "$record{$id}{'empnumber'}\t";
    print "\n";
  }
}
sample.xml:
<people>
<person login='joe1'>
<empnumber>12345</empnumber>
</person>
<person login='jane2'>
<empnumber>45678</empnumber>
<email>jane2@company.com</email>
</person>
<person login='mary5'>
<empnumber>99876</empnumber>
</person>
</people>

This is working fine:
joe1            12345
jane2   jane2@company.com       45678
mary5           99876

However, some employee has more than one empnumber so then xml entries 
for that person will look like:

<person login='jane2'>
<empnumbers>
<empnumber>45678</empnumber>
<empnumber>123456</empnumber>
</empnumbers>
<email>jane2@company.com</email>
</person>

I am not sure how to print that out like this:
joe1            12345
jane2   jane2@company.com       45678
jane2   jane2@company.com       123456
mary5           99876

So I will have two entries for jane2. I can look for the element name 
'empnumbers', then inside that have a counter for empnumber. If it is 
more than one, then save those numbers in an array. and print it out.

Thanks.
--sharif


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

Date: Tue, 12 Sep 2006 11:22:39 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: XML content element parsing
Message-Id: <4506ddee$0$34067$815e3792@news.qwest.net>

Sharif Islam wrote:
[...]
> However, some employee has more than one empnumber so then xml entries 
> for that person will look like:

I'd have to question the data. Typically an employee has one employee 
number.. but I digress..

> 
> <person login='jane2'>

Shouldn't the value for an element's attributes be in double quotes?

> <empnumbers>
> <empnumber>45678</empnumber>
> <empnumber>123456</empnumber>
> </empnumbers>
> <email>jane2@company.com</email>
> </person>
> 
> I am not sure how to print that out like this:
> joe1            12345
> jane2   jane2@company.com       45678
> jane2   jane2@company.com       123456
> mary5           99876
> 
> So I will have two entries for jane2. I can look for the element name 
> 'empnumbers', then inside that have a counter for empnumber. If it is 
> more than one, then save those numbers in an array. and print it out.

Store all 'empnumber' values in an array.  No need to count anything.

untested..

sub characters {
   my ($self, $elements) = @_;
   my $rv = $elements->{'Data'} ;
   $rv =~ s/\s+//g;

   if ( $content eq 'empnumber' )
   {
     push( @{ $record{$id}{$context} }, $rv );
   }
   else
   {
     $record{$id}{$context} .= $rv; #why .=  ???
   }
}

 ...
To print:

if ($elements->{'Name'} eq 'person' )
  # this means end of the person's record, so print it out
{
    print "$id\t";

    for my $emp_no ( @{ $record{ $id }{ 'empnumber' } } )
    {
        print join( "\t", $record{ $id }{ 'email' }, $emp_no ), "\n";
    }
    # or a bit more concise as..
    # print join( "\t", $record{ $id }{ 'email' }, $_ ), "\n"
    #    for @{ $record{ $id }{ 'empnumber' } }
}


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

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


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