[28279] in Perl-Users-Digest
Perl-Users Digest, Issue: 9643 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 24 14:06:12 2006
Date: Thu, 24 Aug 2006 11:05:07 -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 Thu, 24 Aug 2006 Volume: 10 Number: 9643
Today's topics:
Re: [OT] IO::Select::select() says no readable data eve <rvtol+news@isolution.nl>
Re: Calling another cgi program using CGI.pm dmedhora@gmail.com
Re: Calling another cgi program using CGI.pm <tadmc@augustmail.com>
Re: Calling another cgi program using CGI.pm xhoster@gmail.com
Re: how can I find the driver list in perl <scobloke2@infotop.co.uk>
Re: Indirectly called code xhoster@gmail.com
Re: Indirectly called code <uri@stemsystems.com>
Re: Indirectly called code <mritty@gmail.com>
Re: Indirectly called code <klaus03@gmail.com>
Re: Multiple copies of perl anno4000@radom.zrz.tu-berlin.de
Re: readdir conflict problem? <tony_curtis32@_NOSPAM_yahoo.com>
Re: Reg. Exp. Question: How to minimally match backward <rvtol+news@isolution.nl>
Re: Reg. Exp. Question: How to minimally match backward anno4000@radom.zrz.tu-berlin.de
Re: Reg. Exp. Question: How to minimally match backward <benmorrow@tiscali.co.uk>
Re: regular expression variables under debugger <mritty@gmail.com>
Re: regular expression variables under debugger <rvtol+news@isolution.nl>
Re: regular expression variables under debugger <xicheng@gmail.com>
Splitting a string to access a multilevel hash <w.n.humann@agilent.com>
Re: Splitting a string to access a multilevel hash anno4000@radom.zrz.tu-berlin.de
Re: warnings (was Re: Most useful standard module?) anno4000@radom.zrz.tu-berlin.de
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 24 Aug 2006 12:21:53 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: [OT] IO::Select::select() says no readable data even if there are
Message-Id: <eck5r2.17k.1@news.isolution.nl>
Ben Morrow schreef:
> anno4000:
>> Ben Morrow:
>>> jari.eskelinen:
>>>> are data
>>>
>>> :) It's nice to see someone getting it right...
>>
>> Are you saying it is always wrong to use "data" with a singular verb?
>>
>> My understanding is that in English "data" can mean a collection of
>> individual facts, in which case it is plural. It can also mean a
>> body of facts, synonymous with "information" and as such is
>> construed singular.
>
> Traditionally, 'data' was always plural, a straight steal from Latin.
> It has become common practice to use it as a singular (continuous)
> noun, and this in turn has become one of the things people who
> complain about grammar complain about :). In particular, in a
> statistical/whatever context, 'The data suggests <foo>' is definitely
> wrong.
>
> However, when one is using the pipe analogy of data flowing from one
> place to another, it is very hard to resist using a continuous noun,
> so I would say usage has changed and in some cases the singular is
> correct. After all, we're dealing with rather more than just a few
> sets of numbers nowadays, so a continuous noun is really more
> appropriate.
In Dutch you can on top of that choose between data and datums, where
both data and datums can mean "multiple points in time" (as the English
"dates", but then <g> mostly without the place-connotation).
http://en.wikipedia.org/wiki/Datum http://en.wikipedia.org/wiki/Data
http://nl.wikipedia.org/wiki/Datum http://nl.wikipedia.org/wiki/Data
http://de.wikipedia.org/wiki/Datum http://de.wikipedia.org/wiki/Daten
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 24 Aug 2006 03:34:04 -0700
From: dmedhora@gmail.com
Subject: Re: Calling another cgi program using CGI.pm
Message-Id: <1156415644.090641.40120@75g2000cwc.googlegroups.com>
Hi and Thanks for your replies,
I did what you said but I'm getting this message:-
Status: 301 Location: http://localhost/cgi-bin/index2.pl
as soon as i press the submit button.
Note I tried using the function oriented as well as the OO styles.
Here is my very basic index.pl and index2.pl
( The main page and the called page )
index.pl
======
#!/usr/bin/perl
use CGI;
$cgi=new CGI;
print $cgi->header,
$cgi->start_html,
$cgi->start_form,
"Username ",
$cgi->textfield(-name=>'username',-default=>'user1'),
"Password ",
$cgi->textfield(-name=>'password',-default=>'pass1'),
$cgi->submit(-name=>'login',-value=>'Login');
if($cgi->param("username") eq "user1")
{
#As per your suggestion
print
$cgi->redirect(-uri=>"http://localhost/cgi-bin/index2.pl",-status=>301);
}
$cgi->endform;
index2.pl
=======
#!/usr/bin/perl
use CGI qw/:all/;
print header,
start_html('My Title'),
start_form,
"To be continued...",p;
print endform;
Thanks!:)
alpha_beta_release wrote:
> or use CGI.pm,
>
> -----------------------------
> use CGI;
>
> my $page = new CGI;
>
> # assuming validate_ok() is the function to validate your user
>
> if (validate_ok($page->param('user'), $page->param('password')) {
> print $page->redirect(
> 'http://tosomewhere.cgi?user='.$page->param('user'));
> }
>
> # else, print login form
>
> -----------------------------
>
> Tad McClellan wrote:
> > [ Please do not top-post! }
> >
> >
> > dmedhora@gmail.com <dmedhora@gmail.com> wrote:
> >
> > > Lets say if the index.pl program above validates the user/password
> > > successfully then how do I continue to another html page?
> > > say, continue.pl
> >
> >
> > If continue.pl accepts GET requests, you can issue a "redirect":
> >
> > print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";
> >
> > or some such.
> >
> >
> >
> > [ snip TOFU]
> >
> > --
> > Tad McClellan SGML consulting
> > tadmc@augustmail.com Perl programming
> > Fort Worth, Texas
------------------------------
Date: Thu, 24 Aug 2006 07:53:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Calling another cgi program using CGI.pm
Message-Id: <slrneer8b0.kl2.tadmc@magna.augustmail.com>
dmedhora@gmail.com <dmedhora@gmail.com> wrote:
> Hi and Thanks for your replies,
Many folks will think that your thanks are not sincere when
you ignore the content of the replies.
>> Tad McClellan wrote:
>> > [ Please do not top-post! }
Please do not top-post!
It is seen as being rude.
If you don't want to be seen as rude, then stop doing it.
If you don't know what top-posting is, then you should find out
what it is if you don't want to be seen as rude.
Have you seen the Posting Guidelines that are posted here frequently?
[ snip yet more TOFU ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 24 Aug 2006 16:09:54 GMT
From: xhoster@gmail.com
Subject: Re: Calling another cgi program using CGI.pm
Message-Id: <20060824121036.585$7B@newsreader.com>
Tad McClellan <tadmc@augustmail.com> wrote:
> [ Please do not top-post! }
>
> dmedhora@gmail.com <dmedhora@gmail.com> wrote:
>
> > Lets say if the index.pl program above validates the user/password
> > successfully then how do I continue to another html page?
> > say, continue.pl
>
> If continue.pl accepts GET requests, you can issue a "redirect":
>
> print "Location: http://www.yoursite.com/cgi-bin/continue.pl\n\n";
But then someone could go bypass the validation page and go directly
to http://www.yoursite.com/cgi-bin/continue.pl
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 24 Aug 2006 12:18:18 +0100
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: how can I find the driver list in perl
Message-Id: <LaidnfE8QdxgF3DZRVnyvA@bt.com>
Over G top-posted:
> Its amazing how much time you people spend to answer this long and
> lengthy answers, this all discussion could have ended, if one would
> have just answer it simple and clear, instead, people like you prefer
> to go line by line on my paragraph, tell me how much I am wrong using
> this line instead of that line,
http://www.catb.org/~esr/faqs/smart-questions.html#not_losing
> Is it Perl group?
> Or English literature group>?
http://world.std.com/~swmcd/steven/perl/linguistics.html
------------------------------
Date: 24 Aug 2006 16:11:30 GMT
From: xhoster@gmail.com
Subject: Re: Indirectly called code
Message-Id: <20060824121212.863$ko@newsreader.com>
"Ferry Bolhar" <bol@adv.magwien.gv.at> wrote:
> Hi,
>
> I try to find out, where Perl may run code besides the "main script" and
> the modules and methods it will use (lets' call it "indirectly called
> code").
> Currently, I know about these ways (Perl 5.8.8):
>
> o) Tying
> o) BEGIN/CHECK/INIT/END blocks
> o) AUTOLOAD subroutines and DESTROY methods
> o) Operator overloading
> o) User attributes
> o) I/O layers
> o) Source filters
> o) Import facility (@INC)
> o) Debugger hooks
>
> Are there some more?
%SIG handlers?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 24 Aug 2006 12:23:45 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Indirectly called code
Message-Id: <x7pseqcdbi.fsf@mail.sysarch.com>
>>>>> "x" == xhoster <xhoster@gmail.com> writes:
x> "Ferry Bolhar" <bol@adv.magwien.gv.at> wrote:
>> Hi,
>>
>> I try to find out, where Perl may run code besides the "main script" and
>> the modules and methods it will use (lets' call it "indirectly called
>> code").
>> Currently, I know about these ways (Perl 5.8.8):
>>
>> o) Tying
>> o) BEGIN/CHECK/INIT/END blocks
>> o) AUTOLOAD subroutines and DESTROY methods
>> o) Operator overloading
>> o) User attributes
>> o) I/O layers
>> o) Source filters
>> o) Import facility (@INC)
i wouldn't call @INC the import facility. importing is a symbol table
thing in perl. @INC is for finding source files to load.
>> o) Debugger hooks
>>
>> Are there some more?
x> %SIG handlers?
callbacks from many many different modules. event loops, parsers, state
machines, etc.
what about code generated on the fly with eval? that also includes subs
(code refs) generated by eval and closures which are used in variables
or stuffed into the symbol table. you can't track all that down. a sub
made with eval can also call eval to make more code, ad infinitum. and
any of that generated code can have any of that 'indirectly called
code'.
i am scared to ask the OP why he is looking for this? i will guess he
wants to make sure all such code is secure or something like that.
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: 24 Aug 2006 09:23:00 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Indirectly called code
Message-Id: <1156436580.723042.188540@h48g2000cwc.googlegroups.com>
Ferry Bolhar wrote:
> I try to find out, where Perl may run code besides the "main script" and
> the modules and methods it will use (lets' call it "indirectly called
> code").
> Currently, I know about these ways (Perl 5.8.8):
>
> o) Tying
> o) BEGIN/CHECK/INIT/END blocks
> o) AUTOLOAD subroutines and DESTROY methods
> o) Operator overloading
> o) User attributes
> o) I/O layers
> o) Source filters
> o) Import facility (@INC)
> o) Debugger hooks
>
> Are there some more?
Command-line/shebang switches (-w, -l, -n, -p, -i, etc)
Paul Lalli
------------------------------
Date: 24 Aug 2006 09:24:56 -0700
From: "Klaus" <klaus03@gmail.com>
Subject: Re: Indirectly called code
Message-Id: <1156436696.014374.280240@p79g2000cwp.googlegroups.com>
xhoster@gmail.com wrote:
> "Ferry Bolhar" <bol@adv.magwien.gv.at> wrote:
> > I try to find out, where Perl may run code besides the "main script" and
> > the modules and methods it will use (lets' call it "indirectly called
> > code").
> > Currently, I know about these ways (Perl 5.8.8):
> >
> > o) Tying
> > o) BEGIN/CHECK/INIT/END blocks
> > o) AUTOLOAD subroutines and DESTROY methods
> > o) Operator overloading
> > o) User attributes
> > o) I/O layers
> > o) Source filters
> > o) Import facility (@INC)
> > o) Debugger hooks
> >
> > Are there some more?
>
> %SIG handlers?
>
> Xho
eval ?
forking ?
system() and qx() ?
regexes and qr// ?
------------------------------
Date: 24 Aug 2006 12:28:38 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Multiple copies of perl
Message-Id: <4l5kbmFbsn3U1@news.dfncis.de>
Ben Morrow <benmorrow@tiscali.co.uk> wrote in comp.lang.perl.misc:
>
> Quoth rashmiek@gmail.com:
> >
> > I am struck with a problem.I have a perl script that takes UART port
> > number as a command line input. Using this input the same perl script
> > will have to be run on different hardware platforms.
>
> You can do cross-platform serial port stuff with Win32::SerialPort and
> Device::SerialPort.
>
> > Basically, I want to execute multiple copies of the same perl script.
> > Not sure how to achieve this.
>
> Err... fork?
>
> I don't understand what you are asking for. Please specify your problem
> more clearly.
The phrase "run on different hardware platforms" makes me think of
something like
cat script.pl | ssh user@machine perl - arg1 arg2
which has little Perl content.
Oh the joy of guessing what a badly-put question may mean while the
putter has long moved on...
Anno
------------------------------
Date: 24 Aug 2006 07:52:25 -0400
From: Tony Curtis <tony_curtis32@_NOSPAM_yahoo.com>
Subject: Re: readdir conflict problem?
Message-Id: <y6zspseqpczq.fsf@post.queensu.ca>
>> On 24 Aug 2006 09:03:54 GMT,
>> anno4000@radom.zrz.tu-berlin.de said:
> David Squire <David.Squire@no.spam.from.here.au> wrote
> in comp.lang.perl.misc:
>> Davy wrote: > Hi all,
>> >
>> > I write a program to generate file list and directory
>> list seperately > from a directory. > But I found the
>> readdir run correctly only once. The second readdir >
>> always read in a null list? why?
>>
> c) rewinddir(), which exists explicitly for the purpose
> of reading a directory handle again from the beginning.
d) use readdir in scalar context in a loop, then you don't
need 2 passes, and you don't need to store all the
directory entries in memory.
hth
t
------------------------------
Date: Thu, 24 Aug 2006 12:52:30 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Reg. Exp. Question: How to minimally match backwards as well as forwards?
Message-Id: <eck7ju.1k4.1@news.isolution.nl>
anno4000 schreef:
> [postmark matching]
> nothing stops a mail author from including a complete,
> well-formed mail message in the body of its text. That would *have*
> to be interpreted as an additional spurious message, especially if
> you make sure a valid chunk doesn't contain another valid chunk.
Yes, so the agent that delivers the message to the mbox-file should
escape any lines in the body that start with "From ".
Sometimes the Content-Length header field can be of help.
See also `man formail` and look for "postmark". formail is installed on
about every *ix machine, so just use that if available (see
the -b -d -e -f -s options).
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 24 Aug 2006 10:29:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Reg. Exp. Question: How to minimally match backwards as well as forwards?
Message-Id: <4l5dc7Fat4nU1@news.dfncis.de>
David Coppit <newspost@coppit.org> wrote in comp.lang.perl.misc:
> Hi all,
>
> I have a quick question about regular expressions. Is there any way to write an
> expression such that the match doesn't also have a substring (other than the
> entire match) that matches?
>
> The context is this: I'm trying to match the "^From " at the start of an email
> in an mbox. However, sometimes MUA's fail to escape "^From " that appears
> within the body of an email.
[rest snipped, I'm only discussing general terms]
That's bad because it poses a basically unsolvable problem. After all,
nothing stops a mail author from including a complete, well-formed mail
message in the body of its text. That would *have* to be interpreted as
an additional spurious message, especially if you make sure a valid
chunk doesn't contain another valid chunk.
The best you can do is detect "From " lines that are not well-formed or
not well-positioned and ignore them. I'm talking of *lines* because a
mail expert assures me that line feeds cannot validly appear in a "From "
specification.
So for well-formedness you'd have to recognize "From " followed by an email
address, followed by a date (not sure what else is possible but I think
that's it). There are modules that parse mail addresses (even
Regex::Common has something AFAIK). For the date, Date::Parse comes
to mind.
A well positioned "From " line would have to appear directly in front
of a complete set of colon-marked header lines, terminated by at least
two newlines, whatever constitutes a complete set.
From later remarks (now snipped) it appears that you are running a loop
like
while ( $mail =~ /some regex/g ) {
# ...
}
That is a good technique for a simple series of matches, but it has the
disadvantage that you can't easily use another match in the body, it
upsets the loop. All in all, the problem seems rather to require a
real parser instead of a plain regex solution.
Anno
Anno
------------------------------
Date: Thu, 24 Aug 2006 11:55:51 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Reg. Exp. Question: How to minimally match backwards as well as forwards?
Message-Id: <n6d0s3-phb.ln1@osiris.mauzo.dyndns.org>
Quoth anno4000@radom.zrz.tu-berlin.de:
> David Coppit <newspost@coppit.org> wrote in comp.lang.perl.misc:
> > Hi all,
> >
> > I have a quick question about regular expressions. Is there any way to
> write an
> > expression such that the match doesn't also have a substring (other than the
> > entire match) that matches?
> >
> > The context is this: I'm trying to match the "^From " at the start of an email
> > in an mbox. However, sometimes MUA's fail to escape "^From " that appears
> > within the body of an email.
>
> [rest snipped, I'm only discussing general terms]
>
> That's bad because it poses a basically unsolvable problem. After all,
> nothing stops a mail author from including a complete, well-formed mail
> message in the body of its text. That would *have* to be interpreted as
> an additional spurious message, especially if you make sure a valid
> chunk doesn't contain another valid chunk.
>
> The best you can do is detect "From " lines that are not well-formed or
> not well-positioned and ignore them. I'm talking of *lines* because a
> mail expert assures me that line feeds cannot validly appear in a "From "
> specification.
>
> So for well-formedness you'd have to recognize "From " followed by an email
> address, followed by a date (not sure what else is possible but I think
> that's it). There are modules that parse mail addresses (even
> Regex::Common has something AFAIK). For the date, Date::Parse comes
> to mind.
From http://www.jwz.org/doc/content-length.html :
|
| Essentially the only safe way to parse [a BSD mailbox] is to consider
| all lines which begin with the characters ``From '' (From-space),
| which are preceded by a blank line or beginning-of-file, to be the
| division between messages. That is, the delimiter is "\n\nFrom .*\n"
| except for the very first message in the file, where it is
| "^From .*\n".
|
| Some people will tell you that you should do stricter parsing on those
| lines: check for user names and dates and so on. They are wrong. [...]
|
| In the BSD format, the only safe way to add a message to a file is to
| mangle occurrences of the ``From '' delimiter in the body of messages
| to some other string, usually ``>From ''.
See that page for more details, and the differences between BSD and
Solaris mailboxes.
To the OP: it looks like either your system uses Solaris mailboxes, or
you've got some sort of mess of both-sorts-of-message-in-one-file. In
either case a simple regex is not going to be an adequate solution; in
the latter, there is no real solution beyond guessing.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit.|benmorrow@tiscali.co.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: 24 Aug 2006 03:49:32 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: regular expression variables under debugger
Message-Id: <1156416572.652744.198020@74g2000cwt.googlegroups.com>
wlcna wrote:
> I have a program I was running through the debugger that had a usage
> like this (this is not the code but similar):
Why don't you just post the *real* code? Create a short-but-complete
script that demonstrates the problem you're seeing. That should be the
first step to debugging any problem.
> 1: my $str = "hello there yes i am here";
> 2: $str =~ /([a-z]*)s/;
> 3: $yes = $1;
>
> So, I'm running this in the debugger to check things out, make sure it's
> working as I expect, and the debugger when I get to line 3 tells me that
> $1 is "undef", and past line 3 it tells me that $yes did not receive any
> value, it's "undef" as well.
I cannot duplicate your problem:
$ cat clpm.pl
my $str = "hello there yes i am here";
$str =~ /([a-z]*)s/;
$yes = $1;
$ perl -d clpm.pl
Loading DB routines from perl5db.pl version 1.27
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(clpm.pl:1): my $str = "hello there yes i am here";
DB<1> n
main::(clpm.pl:2): $str =~ /([a-z]*)s/;
DB<1> n
main::(clpm.pl:3): $yes = $1;
DB<1> p $1
ye
DB<2> p $yes
DB<3> n
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<3> p $yes
ye
DB<4>
Please post a SHORT but COMPLETE script that actually demonstrates your
problem, rather than code that you claim is similar to your code, which
demonstrates that your problem does not exist.
Paul Lalli
------------------------------
Date: Thu, 24 Aug 2006 12:38:05 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regular expression variables under debugger
Message-Id: <eck6nj.1ps.1@news.isolution.nl>
wlcna schreef:
> I have a program I was running through the debugger that had a usage
> like this (this is not the code but similar):
>
> 1: my $str = "hello there yes i am here";
> 2: $str =~ /([a-z]*)s/;
> 3: $yes = $1;
>
> So, I'm running this in the debugger to check things out, make sure
> it's working as I expect, and the debugger when I get to line 3 tells
> me that $1 is "undef", and past line 3 it tells me that $yes did not
> receive any value, it's "undef" as well.
>
> I run this same program *NOT IN THE DEBUGGER* and everything is
> normal, and I check by doing old-fashioned print statements. $yes is
> "yes" as expected.
That is strange, it should be "ye".
perl -le '
$_ = "hello there yes i am here" ;
/([a-z]*)s/ ;
print $1
'
prints: ye
For me it works (with -d) as you expect.
Did you also try to add watch expressions with -w for $str and $1?
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 24 Aug 2006 04:40:27 -0700
From: "Xicheng Jia" <xicheng@gmail.com>
Subject: Re: regular expression variables under debugger
Message-Id: <1156419627.585589.49800@h48g2000cwc.googlegroups.com>
wlcna wrote:
> I have a program I was running through the debugger that had a usage
> like this (this is not the code but similar):
>
> 1: my $str = "hello there yes i am here";
> 2: $str =~ /([a-z]*)s/;
> 3: $yes = $1;
>
> So, I'm running this in the debugger to check things out, make sure it's
> working as I expect, and the debugger when I get to line 3 tells me that
> $1 is "undef", and past line 3 it tells me that $yes did not receive any
> value, it's "undef" as well.
>
> I run this same program *NOT IN THE DEBUGGER* and everything is normal,
> and I check by doing old-fashioned print statements.
> $yes is "yes" as expected.
how come??
> I've noticed problems before with viewing regular expression variables
> in teh debugger.
>
> I now assume that regular expressions and the debugger just don't mix
> but prior to tonight I NEVER IMAGINED that something like my $yes
> variable above would also not show the correct value in the debugger. I
> had assumed the special regex variables scope meant if I tried to print
> them directly from the debugger prompt, (i.e. p $1 or p $&) that
> wouldn't work, but of course I thought running the program from inside
> the debugger and watching its variables get set should still work
> properly.
>
> But now I don't even think that works. So what am I missing?
the result of 'p' is not well-formatted, using 'x' instead of 'p'
command is better:
bash: ~$ perl -d test.pl
.......
main::(t1.pl:5): my $str = "hello there yes i am here";
DB<1> n
main::(t1.pl:6): $str =~ /([a-z]*)s/;
DB<1> n
main::(t1.pl:7): $yes = $1;
DB<2> x $1
'ye'
DB<3> x $yes
undef
DB<4> n
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<5> x $1
undef
DB<6> x $yes
'ye'
DB<7> p $yes ye
DB<8> q
____
After copy/paste the line "<DB> p $yes" to a text editor, you'll
probably see the result of 'p $yes' at the rightmost of the same line.
Xicheng
------------------------------
Date: Thu, 24 Aug 2006 16:47:58 +0800
From: Wolfram Humann <w.n.humann@agilent.com>
Subject: Splitting a string to access a multilevel hash
Message-Id: <1156415737.33763@newsreg.cos.agilent.com>
Suppose I have a string "a.b.c.d" (for instance as an entry path in a Tk::HList) and want to
translate this into access to a hash value $data{a}{b}{c}{d}, is there anything more elegant (and
possibly more efficient) than the for-loop in the following sample code:
my %data;
$data{a}{b}{c}{d} = "alphabet";
my $entryPath = "a.b.c.d";
my $tmp = \%data;
$tmp = $tmp->{$_} for split '\.', $entryPath;
print "tmp is now: $tmp\n";
This prints:
tmp is now: alphabet
If nothing better is available I would consider using $data{a.b.c.d} as a key instead, even though
this would leave my data less structured and will probably have problematic sideeffects.
Thanks for any hint,
Wolfram
------------------------------
Date: 24 Aug 2006 11:15:45 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Splitting a string to access a multilevel hash
Message-Id: <4l5g31Fbvk2U1@news.dfncis.de>
Wolfram Humann <w.n.humann@agilent.com> wrote in comp.lang.perl.misc:
> Suppose I have a string "a.b.c.d" (for instance as an entry path in a
> Tk::HList) and want to
> translate this into access to a hash value $data{a}{b}{c}{d}, is there
> anything more elegant (and
> possibly more efficient) than the for-loop in the following sample code:
>
> my %data;
> $data{a}{b}{c}{d} = "alphabet";
> my $entryPath = "a.b.c.d";
>
> my $tmp = \%data;
> $tmp = $tmp->{$_} for split '\.', $entryPath;
> print "tmp is now: $tmp\n";
>
> This prints:
> tmp is now: alphabet
>
> If nothing better is available I would consider using $data{a.b.c.d} as
> a key instead, even though
> this would leave my data less structured and will probably have
> problematic sideeffects.
You can use "multidimensional array emulation" as a compromise. That
is the use of multiple keys with what is otherwise syntactically a hash
value access:
my %h;
$h{ qw( a b c d)} = 'alphabet';
print "$h{ qw( a b c d)}\n";
Perl really uses "join( $;, qw( a b c d))" for the hash key, so if
you set $; = '.' you get exactly the hash you considered above only
with different syntax.
Speaking of syntax... To apply multidimensional syntax when the
set of indices is a real array (not a statically recognizable list
as above) you need a little trick:
my @ind = split /\./, 'abcd';
$h{ @ind} = 'alphabet';
evaluates @ind in scalar context and sets $h{ 4}. To force list context
in the index position you can use
$h{ (), @ind} = 'alphabet';
I'm not saying this multidimensional array emulation is necessarily a
good solution for your problem (I know too little about it to say), but
it is a little-known Perl feature that deserves consideration.
Anno
------------------------------
Date: 24 Aug 2006 10:43:10 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: warnings (was Re: Most useful standard module?)
Message-Id: <4l5e5uFat4nU2@news.dfncis.de>
fishfry <BLOCKSPAMfishfry@your-mailbox.com> wrote in comp.lang.perl.misc:
> In article <slrneepsnp.go5.tadmc@magna.augustmail.com>,
> Tad McClellan <tadmc@augustmail.com> wrote:
> > Some people want a friend that helps them _discover_ problems too...
>
> That's what endusers are for :-)
Banana Software: Maturing after delivery.
Anno
------------------------------
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 9643
***************************************