[25375] in Perl-Users-Digest
Perl-Users Digest, Issue: 7620 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 7 21:05:46 2005
Date: Fri, 7 Jan 2005 18:05:15 -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 Fri, 7 Jan 2005 Volume: 10 Number: 7620
Today's topics:
3 dimension array <tanja@verso.co.izbaciovo>
Re: 3 dimension array <usenet@plenz.com>
Re: checking at runtime if modul is installed (Anno Siegel)
Re: Extarcting And Storing a String <mjl69mjl69@myaccmyacc.net>
Re: Extarcting And Storing a String <hx_101@hotmail.com>
Re: Extarcting And Storing a String <spamtrap@dot-app.org>
Re: IPC looking for simple/best way to communicate xhoster@gmail.com
Re: IPC looking for simple/best way to communicate <jgibson@mail.arc.nasa.gov>
Re: Regex help, need to find all "<script src" calls bu <tadmc@augustmail.com>
Re: Returning two hashes <wyzelli@yahoo.com>
Re: Returning two hashes <matthew.garrish@sympatico.ca>
Some question?! <tanja@verso.co.izbaciovo>
Re: Some question?! <jgibson@mail.arc.nasa.gov>
Re: Some question?! <nospam@bigpond.com>
Re: Some question?! <matthew.garrish@sympatico.ca>
Re: Some question?! <wyzelli@yahoo.com>
Re: Some question?! <tadmc@augustmail.com>
Subs: Returning two hashes <b1gus AT creationfactor DOT net>
Re: Subs: Returning two hashes <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Subs: Returning two hashes <tadmc@augustmail.com>
Re: Take ownership of Windows registry key <rrindels@spinn.net>
why aren't these checkboxes checked? ioneabu@yahoo.com
Re: why aren't these checkboxes checked? <spamtrap@dot-app.org>
Re: why aren't these checkboxes checked? ioneabu@yahoo.com
Re: why aren't these checkboxes checked? xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 2 Jan 2005 10:28:32 +0100
From: "Tanja" <tanja@verso.co.izbaciovo>
Subject: 3 dimension array
Message-Id: <41d7bec2$1@news.s5.net>
a.. How to make 3 dimensional array
b.. How to check pattern with asterix (wild) character?
e.g.: word linux
and I have word li??x, or ?inux to check
linux
li??x is OK
?inux is OK
------------------------------
Date: 2 Jan 2005 09:34:42 GMT
From: Julius Plenz <usenet@plenz.com>
Subject: Re: 3 dimension array
Message-Id: <slrnctfg1i.lj1.usenet@plenz.com>
* Tanja <tanja@verso.co.izbaciovo> [2005-01-02]:
> a.. How to make 3 dimensional array
my @array = [ # first dimension
[[1,2,3], [1,2,3]],
[[1,2,3], [1,2,3], [1,2,3]].
];
Access: $a[0][1][2] => 3
> b.. How to check pattern with asterix (wild) character? e.g.: word
> linux and I have word li??x, or ?inux to check
>
> linux
> li??x is OK
> ?inux is OK
Hm, I don't have a nice solution, but try this:
/[l?][i?][n?][u?][x?]/
Julius
------------------------------
Date: 7 Jan 2005 23:09:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: checking at runtime if modul is installed
Message-Id: <crn4rk$44k$1@mamenchi.zrz.TU-Berlin.DE>
Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
> >
> >>Wrap it up in an eval() and check for errors. Be sure to put the eval()
> >>in a BEGIN block so it happens at compile time, like use() normally does.
> >>
> >>BEGIN {
> >> unless (eval "use Time::HiRes qw(time)") {
> >> warn "Couldn't load Time::HiRes: $@";
> >> }
> >>}
> >
> >
> > That isn't quite right. "use" returns nothing at run time, whether it
> > succeeded or not.
>
> Use() doesn't return anything, but it *does* die if the module can't be
> found, and the eval() returns false if that happens. So you can put the
> eval() in a conditional block, or check $@ afterwards - it works either way.
It also returns false when it *can* load the module. Watch
my $succ;
BEGIN { $succ = eval "use Time::HiRes" }
print Time::HiRes::time, "\n"; # show it's loaded
print "undefined\n" unless defined $succ;
... which prints
1105138968.24501
undefined
>
> > Also, I would use block eval when string eval isn't necessary. So
> >
> > BEGIN {
> > eval { use Time::HiRes qw(time) };
> > warn "Couldn't load module: $@" if $@;
> > }
>
> A string eval *is* necessary here because of the different semantics of
Yes, I noticed. I had been playing with "require" and didn't make
the switch, sorry.
Anno
------------------------------
Date: 7 Jan 2005 19:36:52 GMT
From: "mjl69" <mjl69mjl69@myaccmyacc.net>
Subject: Re: Extarcting And Storing a String
Message-Id: <3486mkF48fc24U1@individual.net>
Gunnar Hjalmarsson wrote:
> Digger wrote:
> > Sherm Pendley wrote:
> >> Digger wrote:
> >>> How can I get that single url out of a file and store it to be
> >>> used for something else?
> >>
> >> You left out a critical bit of information: What format is the file
> >> in? If it's HTML, use HTML::Parser.
> >
> > Sorry, yes......
> >
> > It's a flat text log file.....
> >
> > date : error message: url: other garbage
>
> What part of the task do you have difficulties with? Show us what you
> have tried so far, and somebody may be able to point you in the right
> direction.
>
> A hint: check out the split() function.
#!/usr/bin/perl
use strict;
use warnings;
open my $file, 'log.txt' or die "error: could not open file: $!";
for (<$file>)
{
print if s/.*url:\s+(\S+)\s+.*/$1/;
}
For the flat text log file described, I was thinking of something like
this, but it won't work if the url has spaces in it (like local paths
in Windows) or if there is not at least one space on each side of the
url.
mjl
------------------------------
Date: Fri, 07 Jan 2005 17:06:38 -0500
From: Digger <hx_101@hotmail.com>
Subject: Re: Extarcting And Storing a String
Message-Id: <3r1ut0pk90iclh2n0814obb8kfapq88eg3@4ax.com>
On 7 Jan 2005 18:20:33 GMT, "mjl69" <mjl69mjl69@myaccmyacc.net> wrote:
>Digger wrote:
>
>> I am trying to extract a url from a file and store it, the problem is
>> I only want the first occurance of that url that meets certain
>> criteria.
>>
>> How can I get that single url out of a file and store it to be used
>> for something else?
>>
>> Thanks
>
>use HTML::LinkExtor;
>
>mjl
The criteria to extract the URL with bee either "FAILED" or
"SUCCESS"...
Example...
[2004-12-25 9:20:12] FAILED http://hotmail.com/bla
[2004-12-25 9:25:12] SUCCESS http://hotmail.com/bla
[2004-12-25 9:26:12] FAILED http://abc.com
[2004-12-25 9:27:12] FAILED http://123.com
etc.....
------------------------------
Date: Fri, 07 Jan 2005 17:34:26 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Extarcting And Storing a String
Message-Id: <E4mdnRYRFt7uk0LcRVn-2Q@adelphia.com>
Digger wrote:
> The criteria to extract the URL with bee either "FAILED" or
> "SUCCESS"...
>
> Example...
>
>
> [2004-12-25 9:20:12] FAILED http://hotmail.com/bla
> [2004-12-25 9:25:12] SUCCESS http://hotmail.com/bla
> [2004-12-25 9:26:12] FAILED http://abc.com
> [2004-12-25 9:27:12] FAILED http://123.com
Just loop through the lines in the file. Use a regex to examine each
line and use last to exit from the loop as soon as you find what you're
looking for.
For example:
#!/usr/bin/perl
use strict;
use warnings;
# These are declared outside the while loop so you
# can use them after the loop exits
my $flag;
my $url;
while(<>) {
($flag, $url) = /(FAILED|SUCCESS) (.*)$/;
last if ($flag && $flag eq 'SUCCESS');
}
# Do something with $url ...
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 07 Jan 2005 20:24:52 GMT
From: xhoster@gmail.com
Subject: Re: IPC looking for simple/best way to communicate
Message-Id: <20050107152452.501$c7@newsreader.com>
whansen_at_corporate-image_dot_com@us.com wrote:
> I'm trying to find the best way to do something. I've got 50 processes
> (may have 200 soon) that need to broadcast simple messages to each of
> them. I tried doing this with sockets, but although I was able to get
> them to read a socket without halting succesfully I found that when
> one process reads a socket it removes the message from the socket and
> the other processes don't see it.
You need a separate socket to each process, and send the message to each of
those sockets. I'd probably have one house-keeper process which collects
messages from all 50 processes and redistributes them to all 50 processes,
although I don't know that that is necessary.
> My current solution works using
> IPC::Shareable, but is slow and hogs memory as well as the CPU.
> Shareable lets you set a variablle that multiple programs can read and
> write to. In my case they read and write to the list that they all run
> off.
You probably shouldn't do it that way. Make just an array holding
exceptions to the main array be shared. Then periodically update the
(local) main array based on the shared exception array.
> Basicly each process is iterating over a list (array) and every so
> often a process gets a result that means that item no longer needs to
> be ran, so it should remove it from it's list and notify the other
> processes so that they can remove it from theirs as well.
What are the consequences if a process doesn't get the message and runs
that task anyway? Is it just a waste of resources, or is it fatal to the
whole thing you are trying to do?
How many such removal messages do you generate, in relation to the full
size of the array to iterate over? If small, it would probably be most
efficient to just run even the "removed" tasks and then filter them out in
post-processing.
How does it work that your processes are iterating over an array which
is changing during the iteration? That seems like a problem waiting to
happen.
> Whith
> IPC::Shareable it works nicely as when one process removes the item,
> all the others have it removed also, but it appers that the shareable
> module is slowing things down considerablly (CPU usage doubled).
>
> If someone could point me in the right direction, that would be great.
> I have an idea for speeding up shareable a little, but it's still not
> going to be fast.
Each process could keep their own private version of the array, and
only refresh it against the shared version (or against a shared
exception list) every now and then. How often it would do this refresh
would depend on the cost of the refresh vs. the wasted effort that goes
into processing tasks that have been removed since the last refresh.
When I had to do something sort of like this I used a much simpler
approach. Each parallel child process was given a batch to do, then would
reported back to the house-keeper on which things should be removed, and
then exited. The house-keeper would process those exception to make a new
set of batches, and spawn another round of child processes.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Fri, 07 Jan 2005 12:29:16 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: IPC looking for simple/best way to communicate
Message-Id: <070120051229169402%jgibson@mail.arc.nasa.gov>
In article <41ded263.3951491@news.sonic.net>,
<whansen_at_corporate-image_dot_com@us.com> wrote:
> I'm trying to find the best way to do something. I've got 50 processes
> (may have 200 soon) that need to broadcast simple messages to each of
> them. I tried doing this with sockets, but although I was able to get
> them to read a socket without halting succesfully I found that when
> one process reads a socket it removes the message from the socket and
> the other processes don't see it. My current solution works using
> IPC::Shareable, but is slow and hogs memory as well as the CPU.
> Shareable lets you set a variablle that multiple programs can read and
> write to. In my case they read and write to the list that they all run
> off.
Sockets implement a data connection between two processes, potentially
on different systems. Three or more processes cannot share a socket.
When you write data to a socket that connects two processes, only the
reading process will get the data. Any other process will be reading
from its own unique socket and will not receive the data. You would
have to connect each pair of processes with a unique socket pair. For
200 processes, that would mean 39800 separate sockets.
A better approach using sockets would implement a single dispatcher
process that sends the current list to each of the 200 analysis
processes (or whatever you want to call them). Each analysis process
would send the updated list to the central dispatching process.
If all of your processes are on the same system, then internet protocol
(IP) domain sockets impose a network overhead that is unnecessary. You
are better off using Unix domain sockets (assuming you are on Unix,
that is).
However, it would seem for this application that shared memory is the
fastest way to go, and IPC::Shareable gives you access to shared memory
(disclaimer: I have not used it). If you are having performance
problems, then can try to optimize your use of shared memory. One
suggestion would be to make a local copy of the shared memory list and
iterate over the local copy. This works if you can use an old list when
the list gets modified for a short period of time. You can check
periodically (using another shared variable perhaps) if the list has
been modified and fetch the new version. You can use a simple counter
to indicate when the list has been updated.
If you can't get IPC::Shareable to work, you can put the list into a
file, periodically read the file if it is unlocked, and have any
process that wants to update the file lock it and re-write it.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Fri, 7 Jan 2005 19:26:16 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regex help, need to find all "<script src" calls but not if the call has menu.js in it.
Message-Id: <slrnctudlo.kda.tadmc@magna.augustmail.com>
John <jgdoke@ra.rockwell.com> wrote:
> I have been reading but cannot find a way to find all strings that
> start with <script src but disreguard the ones that have menu.js as
> the call.
"Parsing" HTML with regular expressions is only OK is some
special situations. I'll assume you know for a fact that your
particular situation is suitably special. (If you need it to
work reliably, use a real parser for HTML.)
Use a negative look-ahead:
---------------------------------
#!/usr/bin/perl
use warnings;
use strict;
while ( <DATA> ) {
print if /<script src=(?!menu\.js)/;
}
__DATA__
<script src=script.js></script> (keep)
<script src=/widjets/footer.js></script> (keep)
<script src=/thingys/left_nav.js></script> (keep)
<script src=menu.js></script> (throw away)
---------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 08 Jan 2005 01:15:02 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Returning two hashes
Message-Id: <quGDd.109181$K7.94978@news-server.bigpond.net.au>
"Bigus" <b1gus AT creationfactor DOT net> wrote in message
news:5oKdnecSUY9Zs0LcRVnyjQ@giganews.com...
:I want to return two hashes from a subroutine, eg:
:
: sub init {
: [..]
: return (%fd, %vars);
: }
:
: However, when I try and pick up the returned hashes in the main program,
: using:
:
: my (%fd, %vars) = init();
:
: only the first, %fd, seems to be defined.
Re read perlsub about what is returned, then perlref for how to return
references to the hashes you want.
Specifically from the first page of perlsub:
___
The return value of a subroutine is the value of the last expression
evaluated. More explicitly, a return statement may be used to exit the
subroutine, optionally specifying the returned value, which will be
evaluated in the appropriate context (list, scalar, or void) depending on
the context of the subroutine call. If you specify no return value, the
subroutine returns an empty list in list context, the undefined value in
scalar context, or nothing in void context. If you return one or more
aggregates (arrays and hashes), these will be flattened together into one
large indistinguishable list.
___
You will find everything you expect to be in %vars is in fact in %fd.
P
--
http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&rd=1&item=4516341671
print "Just another Perl Hacker";
------------------------------
Date: Fri, 7 Jan 2005 20:10:25 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Returning two hashes
Message-Id: <1qGDd.68012$P%3.2357607@news20.bellglobal.com>
"Bigus" <b1gus AT creationfactor DOT net> wrote in message
news:5oKdnecSUY9Zs0LcRVnyjQ@giganews.com...
>I want to return two hashes from a subroutine, eg:
>
> sub init {
> [..]
> return (%fd, %vars);
> }
>
> However, when I try and pick up the returned hashes in the main program,
> using:
>
> my (%fd, %vars) = init();
>
> only the first, %fd, seems to be defined.
>
> What am I doing wrong?
>
You have to pass two references to the hashes:
my ($href1, $href2) = init();
And in init:
return \%hash1, \%hash2;
See the section "Pass by reference" in perlsub for a complete explanation.
Matt
------------------------------
Date: Fri, 7 Jan 2005 22:10:41 +0100
From: "Tanja" <tanja@verso.co.izbaciovo>
Subject: Some question?!
Message-Id: <41defac5$1@news.s5.net>
Please help me:
I have some problem, is perl is good choices for solve it?
1.) Is it possible to run IE and fill web form, with perl program?
2.) How to check subject line in E-mail message in mailbox (on Internet)
with perl script
(started in Windows based PC)
3.) Where to find free version of Cron for Windows?
4.) Can you compare speed of program written in perl, and program written in
C or Pascal?
In seconds of execution identical program written in different
language.
Thanks
------------------------------
Date: Fri, 07 Jan 2005 13:41:26 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Some question?!
Message-Id: <070120051341269893%jgibson@mail.arc.nasa.gov>
In article <41defac5$1@news.s5.net>, Tanja <tanja@verso.co.izbaciovo>
wrote:
> Please help me:
> I have some problem, is perl is good choices for solve it?
>
> 1.) Is it possible to run IE and fill web form, with perl program?
It is possible to write a stand-alone Perl program that will submit a
form request to a web server without using IE.
> 2.) How to check subject line in E-mail message in mailbox (on Internet)
> with perl script
> (started in Windows based PC)
It is possible to retrieve and parse e-mail messages from an e-mail
server.
> 3.) Where to find free version of Cron for Windows?
Don't know.
> 4.) Can you compare speed of program written in perl, and program written in
> C or Pascal?
> In seconds of execution identical program written in different
> language.
In general, Perl will be faster to implement and slower to execute.
Googling for "perl vs. c benchmarks" revealed this link:
<http://dada.perl.it/shootout/>.
The Perl FAQ also contains this advice:
"How does Perl compare with other languages like Java, Python, REXX,
Scheme, or Tcl?
"Favorably in some areas, unfavorably in others. Precisely which areas
are good and bad is often a personal choice, so asking this question on
Usenet runs a strong risk of starting an unproductive Holy War.
"Probably the best thing to do is try to write equivalent code to do a
set of tasks. These languages have their own newsgroups in which you
can learn about (but hopefully not argue about) them.
"Some comparison documents can be found at
http://www.perl.com/doc/FMTEYEWTK/versus/ if you really can't stop
yourself."
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Sat, 08 Jan 2005 08:54:51 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Some question?!
Message-Id: <348i9rF48f0hpU2@individual.net>
Tanja wrote:
> Please help me:
> I have some problem, is perl is good choices for solve it?
>
> 1.) Is it possible to run IE and fill web form, with perl program?
> 2.) How to check subject line in E-mail message in mailbox (on Internet)
> with perl script
> (started in Windows based PC)
> 3.) Where to find free version of Cron for Windows?
> 4.) Can you compare speed of program written in perl, and program written
> in C or Pascal?
> In seconds of execution identical program written in different
> language.
>
> Thanks
Yes.
gtoomey
------------------------------
Date: Fri, 7 Jan 2005 20:22:05 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Some question?!
Message-Id: <ZAGDd.68194$P%3.2359787@news20.bellglobal.com>
"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
news:070120051341269893%jgibson@mail.arc.nasa.gov...
>
>> 3.) Where to find free version of Cron for Windows?
>
> Don't know.
>
Start -- Settings -- Control Panel -- Scheduled Tasks
Matt
------------------------------
Date: Sat, 08 Jan 2005 01:38:38 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: Some question?!
Message-Id: <yQGDd.109202$K7.61130@news-server.bigpond.net.au>
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:ZAGDd.68194$P%3.2359787@news20.bellglobal.com...
:
: "Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
: news:070120051341269893%jgibson@mail.arc.nasa.gov...
: >
: >> 3.) Where to find free version of Cron for Windows?
: >
: > Don't know.
: >
:
: Start -- Settings -- Control Panel -- Scheduled Tasks
Or on WinNT and 2k,
Start - Run - 'Cmd' - 'AT'
P
--
http://cgi.ebay.com.au/ws/eBayISAPI.dll?ViewItem&rd=1&item=4516341671
print "Just another Perl Hacker";
------------------------------
Date: Fri, 7 Jan 2005 19:41:48 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Some question?!
Message-Id: <slrnctueis.kda.tadmc@magna.augustmail.com>
Tanja <tanja@verso.co.izbaciovo> wrote:
> Subject: Some question?!
Please put the subject of your article in the Subject of your article.
> Please help me:
Please check the Perl FAQ *before* posting to the Perl newsgroup.
> 1.) Is it possible to run IE and fill web form, with perl program?
No.
You do not need IE at all. You only need something that knows
about HTTP requests and responses, Perl has a module available
that knows about those things.
perldoc -q form
How do I automate an HTML form submission?
> 2.) How to check subject line in E-mail message in mailbox (on Internet)
> with perl script
perldoc -q mail
How do I parse a mail header?
How do I read mail?
> 3.) Where to find free version of Cron for Windows?
That is not a Perl question, you are in the wrong newsgroup.
> 4.) Can you compare speed of program written in perl, and program written in
> C or Pascal?
You do not know enough about programming to be asking that question.
If you expect that performance will truly be an issue (it seldom is),
then you should hire someone with enough knowledge to evaluate that
for your particular situation.
The Perl program will be faster to write, slower (probably, but not
by enough to matter in most cases) to run.
The C program will be slower to write, faster to run.
Which do you pay more for, labor or CPU cycles?
Cycles are cheap, programming hours are expensive, *optimize for labor*.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 8 Jan 2005 00:52:20 -0000
From: "Bigus" <b1gus AT creationfactor DOT net>
Subject: Subs: Returning two hashes
Message-Id: <5oKdnecSUY9Zs0LcRVnyjQ@giganews.com>
I want to return two hashes from a subroutine, eg:
sub init {
[..]
return (%fd, %vars);
}
However, when I try and pick up the returned hashes in the main program,
using:
my (%fd, %vars) = init();
only the first, %fd, seems to be defined.
What am I doing wrong?
Thanks
Bigus
------------------------------
Date: Fri, 7 Jan 2005 17:21:47 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Subs: Returning two hashes
Message-Id: <c6p3b2xgur.ln2@goaway.wombat.san-francisco.ca.us>
On 2005-01-08, Bigus <> wrote:
> I want to return two hashes from a subroutine, eg:
>
> sub init {
> [..]
> return (%fd, %vars);
> }
>
> However, when I try and pick up the returned hashes in the main program,
> using:
>
> my (%fd, %vars) = init();
>
> only the first, %fd, seems to be defined.
perldoc -q 'pass/return'
perldoc perlsub
Basically, (%fd,%vars) is squashed into one big list in this context, so
%vars remains empty.
--keith
--
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
------------------------------
Date: Fri, 7 Jan 2005 19:48:46 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Subs: Returning two hashes
Message-Id: <slrnctuevu.kda.tadmc@magna.augustmail.com>
Bigus <> wrote:
> I want to return two hashes from a subroutine, eg:
> return (%fd, %vars);
> What am I doing wrong?
Letting the 2 hashes get smushed into a single list in the return().
Pass 2 references to the hashes instead:
return (\%fd, \%vars);
Then learn how to de-reference them in the calling program:
perldoc perlreftut
perldoc perlref
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 2 Jan 2005 09:08:42 -0700
From: "Rodney Rindels" <rrindels@spinn.net>
Subject: Re: Take ownership of Windows registry key
Message-Id: <10tg6tugqfcmn21@corp.supernews.com>
Have the domain administrator fix this with the GPO.
<ntdude4@hotmail.com> wrote in message
news:1104600118.607445.221450@c13g2000cwb.googlegroups.com...
> I use Perl to check the values of registry entries on Win2k pro boxes.
> I am finding a good percentage of workstations that have an issue with
> a specific key. The problem is that when I check the permissions of the
> key, in regedit, there is no owner or permissions. I have no idea how
> this happened, but about 10% of our machines that were recently
> migrated to an AD have this condition. I can manually connect to the
> workstation and take ownership with the registry editor, but there are
> several hundred machines that need the owner fix. Luckily there is only
> one registry key that is so far affected.
>
> Does anyone know if it is possible to programmatically take ownership
> of a registry key on a remote machine. I can push permissions through
> group policy, but there needs to be an owner first.
>
> Thanks
>
> vm
>
------------------------------
Date: 7 Jan 2005 13:48:07 -0800
From: ioneabu@yahoo.com
Subject: why aren't these checkboxes checked?
Message-Id: <1105134487.121231.4840@f14g2000cwb.googlegroups.com>
#!/usr/bin/perl
use warnings;
use strict;
use CGI (':standard');
my $items = param('items');
my @defaults = split ' ', $items;
chomp @defaults;
print header(),start_html();
print start_form();
print table({-border=>1},Tr(td(\@defaults)));
print br(), textfield(-name=>'items');
print br(), checkbox_group(-name=>'boxes',
-values=>\@defaults,
-defaults=>\@defaults);
print br(), submit();
print end_form();
This is a CGI program in which you can type a word or a list of words
separated by a space in the textfield and a checkbox group is generated
from those words. They should all be checked because of the default
setting. Why are they not being checked by default?
Thanks!
wana
------------------------------
Date: Fri, 07 Jan 2005 17:21:51 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: why aren't these checkboxes checked?
Message-Id: <442dnW-lBb_ilkLcRVn-1A@adelphia.com>
ioneabu@yahoo.com wrote:
> print br(), checkbox_group(-name=>'boxes',
> -values=>\@defaults,
> -defaults=>\@defaults);
>
> This is a CGI program in which you can type a word or a list of words
> separated by a space in the textfield and a checkbox group is generated
> from those words. They should all be checked because of the default
> setting. Why are they not being checked by default?
Not certain *why* it happens exactly, but it appears to depend on the
name you give the group. If I use 'boxes', it (mis)behaves as you've
described. If I name it 'my_boxes' or 'BOXES', it works as it should.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: 7 Jan 2005 15:55:17 -0800
From: ioneabu@yahoo.com
Subject: Re: why aren't these checkboxes checked?
Message-Id: <1105142117.368667.295640@f14g2000cwb.googlegroups.com>
Sherm Pendley wrote:
> ioneabu@yahoo.com wrote:
>
> > print br(), checkbox_group(-name=>'boxes',
> > -values=>\@defaults,
> > -defaults=>\@defaults);
> >
> > This is a CGI program in which you can type a word or a list of
words
> > separated by a space in the textfield and a checkbox group is
generated
> > from those words. They should all be checked because of the
default
> > setting. Why are they not being checked by default?
>
> Not certain *why* it happens exactly, but it appears to depend on the
> name you give the group. If I use 'boxes', it (mis)behaves as you've
> described. If I name it 'my_boxes' or 'BOXES', it works as it should.
>
> sherm--
>
> --
> Cocoa programming in Perl: http://camelbones.sourceforge.net
> Hire me! My resume: http://www.dot-app.org
I found a possible solution but not sure why I need to do it.
print br(), checkbox_group(-name=>'boxes',
-values=>\@defaults,
-defaults=>\@defaults,
-override=>1);
I don't know why I have to override in this situation, but there is
mention of it in the CGI.pm text which is not on the CGI.pm home page.
That discussion is more about using a checkbox_group where you have
another item with the same name.
It's like the philosophy that turning a machine off and on is the first
thing to try in fixing a problem. Always try -override=>1 if your
widget doesn't behave as expected.
In this case, I don't understand the logic behind it.
Thanks!
wana
------------------------------
Date: 08 Jan 2005 00:37:07 GMT
From: xhoster@gmail.com
Subject: Re: why aren't these checkboxes checked?
Message-Id: <20050107193707.176$sQ@newsreader.com>
ioneabu@yahoo.com wrote:
>
> I found a possible solution but not sure why I need to do it.
>
> print br(), checkbox_group(-name=>'boxes',
> -values=>\@defaults,
> -defaults=>\@defaults,
> -override=>1);
>
> I don't know why I have to override in this situation, but there is
> mention of it in the CGI.pm text which is not on the CGI.pm home page.
> That discussion is more about using a checkbox_group where you have
> another item with the same name.
Once I read this then it was obvious what was going on.
The very first time the script is invoked (with no parameters), the script
does exactly what you want, it prints all the checkboxes as being checked.
But since there are zero checkboxes at this point, you don't get to see
this fact (unless you look at the hidden .cgifields parameter).
Once you fill out that form and submit (causing the second invocation of
your script), CGI does just what it promises when you don't specify
"override" or "nosticky". It ignores the default values you specify in
your code, and instead uses values that were just submitted. The values
that were just submitted for the form element named "boxes" are, of course,
the empty list. So that is what it uses.
If you simply do:
print br(), checkbox_group(-name=>'boxes',
-values=>\@defaults,
-defaults=>\@defaults) if @defaults;
Then it will also work the way you wanted (or maybe not, I'm not exactly
sure what you wanted!)
Perhaps the sticky CGI should us some extra hidden fields so that in the
case of checkbox groups, it remember not only which ones were checked, but
also which ones were offered but not checked. That way it could use our
coded defaults for new members of the group, while being "sticky" only with
respect the old members.
But anyway, when parts of a form depend on what was submitted from the
previous form, it is bad practise to ignore the fact that at least once,
there was no previous form submittion.
Xho
>
> It's like the philosophy that turning a machine off and on is the first
> thing to try in fixing a problem. Always try -override=>1 if your
> widget doesn't behave as expected.
> In this case, I don't understand the logic behind it.
>
> Thanks!
>
> wana
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 7620
***************************************