[31080] in Perl-Users-Digest
Perl-Users Digest, Issue: 2325 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 7 18:09:41 2009
Date: Tue, 7 Apr 2009 15:09:08 -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, 7 Apr 2009 Volume: 11 Number: 2325
Today's topics:
Re: Extremely long Perl debugger output in Windows <jurgenex@hotmail.com>
Re: Extremely long Perl debugger output in Windows <rvtol+usenet@xs4all.nl>
Re: Function alias <smallpond@juno.com>
Re: Function alias sln@netherlands.com
Re: Function alias <n@solenttechnology.co.uk>
Re: Function alias <uri@stemsystems.com>
Re: Function alias sln@netherlands.com
Re: Function alias <cwilbur@chromatico.net>
Re: Function alias <tadmc@seesig.invalid>
I hate having to say the exists argument twice jidanni@jidanni.org
Re: I hate having to say the exists argument twice <rvtol+usenet@xs4all.nl>
Re: I hate having to say the exists argument twice <smallpond@juno.com>
perl values for batch script to use <slick.users@gmail.com>
Re: perl values for batch script to use <1usa@llenroc.ude.invalid>
Re: perl values for batch script to use <jurgenex@hotmail.com>
Re: perl values for batch script to use <tadmc@seesig.invalid>
Re: perl values for batch script to use <darkon.tdo@gmail.com>
Re: perl values for batch script to use sln@netherlands.com
Re: perl values for batch script to use sln@netherlands.com
Re: perl values for batch script to use <rkb@i.frys.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 07 Apr 2009 09:00:39 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Extremely long Perl debugger output in Windows
Message-Id: <eptmt4pg1mhsm8cbg622nl86p7m6kmr56c@4ax.com>
Artemis Fowl <neokrish@gmail.com> wrote:
>I am facing a minor issue while I am debugging my perl script. It
>contains a lot of "PRINT" statements and when I let it run in the
>debugger, in the command prompt in Windows, I lose out on a lot of
>output.
I'm not sure what you mean by "lose out". Do you mean the output scrolls
off the top of the window resp. out of the screen buffer? You are aware
that you can scroll through the whole screen buffer and that you can
increase the screen buffer to 9999 lines?
> But I would like to capture this.
Can't you just redirect the (regular) output into a file or does that
interfere with the debugger?
>Also, when I evaluate some hash, array in my program - the output
>still exceeds the command prompt window.
???
Hashes and arrays are data structures. Normally you evaluate code, not
data.
jue
------------------------------
Date: Tue, 07 Apr 2009 23:31:26 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Extremely long Perl debugger output in Windows
Message-Id: <49dbc62e$0$189$e4fe514c@news.xs4all.nl>
ccc31807 wrote:
> %perl my_prog.plx > output.txt
Or even
perl my_prog.plx 2>&1 > output.txt
or more even
perl my_prog.plx 2>output.err > output.txt
--
Ruud
------------------------------
Date: Tue, 7 Apr 2009 06:59:21 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: Function alias
Message-Id: <a66d8443-e810-4843-828c-d2ed05f778f1@q16g2000yqg.googlegroups.com>
On Apr 7, 6:46 am, Frank Seitz <devnull4...@web.de> wrote:
> smallpond wrote:
> > On Apr 7, 6:16 am, Frank Seitz <devnull4...@web.de> wrote:
> >> neilsolent wrote:
>
> >>> How can I call the subroutine that is named in a scalar variable
> >>> $func?
> >> { no strict 'refs'; &$func(); }
>
> > What's wrong with being strict?
>
> > #!/usr/bin/perl
> > use warnings;
> > use strict;
>
> > sub Test1
> > {
> > print "Test1\n";
> > }
>
> > sub Test2
> > {
> > print "Test2\n";
> > }
>
> > foreach my $func ( \&Test1, \&Test2 ) {
> > &$func();
> > }
>
> > Test1
> > Test2
>
> He has a name not a reference.
>
> Frank
I just don't answer questions literally, I suppose.
He wants to call a sub based on the value in a scalar.
It's a philosophical distinction of whether to answer
the question that was asked or show a more standard way.
------------------------------
Date: Tue, 07 Apr 2009 11:03:45 -0700
From: sln@netherlands.com
Subject: Re: Function alias
Message-Id: <q20nt4h0o7fjgt3pubnd0n383dl7f8dmvo@4ax.com>
On Tue, 7 Apr 2009 02:37:01 -0700 (PDT), neilsolent <n@solenttechnology.co.uk> wrote:
>I have a question on Perl syntax. Given a couple of functions:
>
>#########
>sub Test1
>{
> print "Test1\n";
>}
>
>sub Test2
>{
> print "Test2\n";
>}
>
>#######
>
>How can I call the subroutine that is named in a scalar variable
>$func?
>Here, the scalar $func will contain either "Test1" or "Test2"
>
>e.g. this doesn't work:
>
>&($func)
>
>Thanks,
>Neil
Typically, uses are as a callback or dispatch table.
Each require the function address or reference to be
generically passed in and stored in another variable.
OR, knowing the KEY or INDEX where a particular handler's
function pointer or reference is stored.
In the old days for instance, packet handler adresses
in C were stored in an array of function pointers.
The packet was put together with the enum of the index into
this array imbedded into an inner layer, then sent down the pipe
where the reciever extracted the data layer containing the index,
then passed the data to the handler.
Still though, there is always a resolution to a fixed VARIABLE containing
the function address or reference. This instead of a symbolic reference.
Callbacks and handlers are a way for the caller to set a user defined function
that the callee calls at a later time in responce to some trigger. This can
be set any time but typically called sometime later.
Using methods as callbacks are a little trickier and may need wrappers.
In Perl, the caller needs to identify the handler (if many are used) to
the callee. The identifier can be an exported (if the callee is a module) constant
or a disposable key name, either of which are passed as an identifier, along with
the function reference and/or other data to the callee who either calls the function
immediatly or stores the reference into a callee provided variable, either hash or
scalar array.
At this point the callee can do basic checks like ref($val) eq 'CODE' or such as
that.
Anyway, the use of & when calling a function allows the callee to see the callers
@_ when dispatching functions and is usually used as a pass through, for example,
when called from the replacement side of a s///e regex.
Anyway, here are some examples. Perlsub should give more info. But in general,
symbolic reference is bad.
-sln
----------------------------
use warnings;
use strict;
sub Test1
{
print "@_ Test1\n";
}
sub Test2
{
print "@_ Test2\n";
}
my %funcref = (
Test1 => \&Test1,
Test2 => \&Test2,
Test3 => sub {print "@_ Test3 anonymous sub\n";},
Test4 => sub {print "@_ Test4 anonymous sub\n";},
);
@_ = ('some', 'stuff');
for my $code (sort keys %funcref)
{
print ".. $code\n";
my $fn = $funcref { $code };
$fn->();
&$fn;
$funcref{ $code }();
&{$funcref{ $code }};
$funcref{ $code }->();
print "\t---\n";
}
__END__
.. Test1
Test1
some stuff Test1
Test1
some stuff Test1
Test1
---
.. Test2
Test2
some stuff Test2
Test2
some stuff Test2
Test2
---
.. Test3
Test3 anonymous sub
some stuff Test3 anonymous sub
Test3 anonymous sub
some stuff Test3 anonymous sub
Test3 anonymous sub
---
.. Test4
Test4 anonymous sub
some stuff Test4 anonymous sub
Test4 anonymous sub
some stuff Test4 anonymous sub
Test4 anonymous sub
---
------------------------------
Date: Tue, 7 Apr 2009 11:09:09 -0700 (PDT)
From: neilsolent <n@solenttechnology.co.uk>
Subject: Re: Function alias
Message-Id: <7af4b5c9-7a28-42a7-80f7-7f483896a115@f32g2000vbf.googlegroups.com>
Thanks for the answers everyone.
Yes I understand the risks, I was mainly just interested in what the
syntax was.
------------------------------
Date: Tue, 07 Apr 2009 14:34:25 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Function alias
Message-Id: <x7fxgkia8e.fsf@mail.sysarch.com>
>>>>> "n" == neilsolent <n@solenttechnology.co.uk> writes:
n> Thanks for the answers everyone.
n> Yes I understand the risks, I was mainly just interested in what the
n> syntax was.
you don't understand the risks if you are curious to use symrefs. that
is the whole point! the safest and best way for many reasons is a
dispatch table. using symrefs means you are using a specialized hash
(the symbol table) for general purpose data structures. it is the same
thing as a dispatch table but with nasty side effects. so why use
symrefs at all! the rule is you use symrefs when you want to mung the
symbol table, not for general data.
now google for dispatch tables as there are many threads which cover it
well and also why symrefs are not a good solution.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Tue, 07 Apr 2009 12:23:06 -0700
From: sln@netherlands.com
Subject: Re: Function alias
Message-Id: <um9nt4d8ak737jms0r32dmbkvocfmgm4na@4ax.com>
On Tue, 07 Apr 2009 11:03:45 -0700, sln@netherlands.com wrote:
>
>In the old days for instance, packet handler adresses
>in C were stored in an array of function pointers.
^^^^^^^^^^^^^^^^^^^^^^^^^^
As an aside, I challenge anybody to write a prototype in C
of a named array of function pointers with typed parameters, that
return a type. I can do it.
-sln
------------------------------
Date: Tue, 07 Apr 2009 15:37:12 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Function alias
Message-Id: <86ws9wmf13.fsf@mithril.chromatico.net>
>>>>> "n" == neilsolent <n@solenttechnology.co.uk> writes:
n> Thanks for the answers everyone. Yes I understand the risks, I
n> was mainly just interested in what the syntax was.
You have an answer, so it's not like I'll prevent you, but my usual
response to this is that this is something that is bad programming
practice, and so if you don't know how to do it, that's a sign that you
really shouldn't be doing it.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Tue, 7 Apr 2009 14:46:10 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Function alias
Message-Id: <slrngtnbc2.9ch.tadmc@tadmc30.sbcglobal.net>
sln@netherlands.com <sln@netherlands.com> wrote:
> , I challenge anybody to write a prototype in C
comp.lang.c is over thataway ==>
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 08 Apr 2009 05:42:23 +0800
From: jidanni@jidanni.org
Subject: I hate having to say the exists argument twice
Message-Id: <87iqlgnnsw.fsf@jidanni.org>
I hate having to say things twice,
print $h{$key}{$_} if exists $h{$key}{$_};
But I can't do
print if exists $_ for $h{$key}{$_};
Bzzt: exists argument is not a HASH or ARRAY element.
------------------------------
Date: Tue, 07 Apr 2009 23:54:17 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: I hate having to say the exists argument twice
Message-Id: <49dbcb8a$0$184$e4fe514c@news.xs4all.nl>
jidanni@jidanni.org wrote:
> I hate having to say things twice,
> print $h{$key}{$_} if exists $h{$key}{$_};
> But I can't do
> print if exists $_ for $h{$key}{$_};
> Bzzt: exists argument is not a HASH or ARRAY element.
print for exists_or $h{$key}, $_;
;)
--
Ruud
------------------------------
Date: Tue, 7 Apr 2009 14:57:23 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: I hate having to say the exists argument twice
Message-Id: <c02f7aee-0c50-4dab-9aba-b2bb2a00c271@e38g2000vbe.googlegroups.com>
On Apr 7, 5:42 pm, jida...@jidanni.org wrote:
> I hate having to say things twice,
> print $h{$key}{$_} if exists $h{$key}{$_};
> But I can't do
> print if exists $_ for $h{$key}{$_};
> Bzzt: exists argument is not a HASH or ARRAY element.
Is it a case where you can use defined instead of exists?
print $h{$key}{$_} // "";
------------------------------
Date: Tue, 7 Apr 2009 10:58:35 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: perl values for batch script to use
Message-Id: <3d15fb7e-c92e-4d40-8e52-ee8d9ccc367b@d25g2000prn.googlegroups.com>
I have a filename (file.txt)
file.txt contains:
Sample4.1.2009_US
Sample4.2.2009_ASIA
I can parse this file in Perl fine. Now I want this value to be
available to use in a batch script.
I try using "set" but the info get clear once I exit perl script.
perl_script.pl
open file.txt
parse info
use system to execute command ("set xxyz_US=Sample4.1.2009_US")
("set xxyz_ASIA=Sample4.2.2009_ASIA")
batch.bat
call perl perl_script.pl
@echo on
@echo %xxyz_US%
@echo %xxyz_ASIA%
call perl script2. %xxyz_US% %xxyz_ASIA%
This %___% will be use in my other Perl scripts as well.
All I need to do is edit file.txt and the batch script will update the
value on it own through a schedule task.
What's a good solution to approach this?
------------------------------
Date: Tue, 07 Apr 2009 18:10:52 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: perl values for batch script to use
Message-Id: <Xns9BE6903F48F5Basu1cornelledu@127.0.0.1>
Slickuser <slick.users@gmail.com> wrote in news:3d15fb7e-c92e-4d40-8e52-
ee8d9ccc367b@d25g2000prn.googlegroups.com:
> I have a filename (file.txt)
>
> file.txt contains:
> Sample4.1.2009_US
> Sample4.2.2009_ASIA
>
> I can parse this file in Perl fine. Now I want this value to be
> available to use in a batch script.
> I try using "set" but the info get clear once I exit perl script.
> perl_script.pl
> open file.txt
> parse info
> use system to execute command ("set xxyz_US=Sample4.1.2009_US")
> ("set xxyz_ASIA=Sample4.2.2009_ASIA")
Those variables only exist in the shell that was invoked by the system
function call. By the time the call returns, that shell no longer
exists.
You can write out a batch file and CALL it from the other batch files.
Alternatively, you can set values in %ENV and invoke the batch files
from within your Perl script.
An example of the latter:
C:\Temp> cat one.bat
@echo %MYVAR1%
C:\Temp> cat two.bat
@echo %MYVAR2%
C:\Temp> cat t.pl
#!/usr/bin/perl
use strict;
use warnings;
$ENV{MYVAR1} = 'This is MYVAR1';
$ENV{MYVAR2} = 'This is MYVAR2';
system qw( one.bat );
system qw( two.bat );
__END__
C:\DOCUME~1\asu1\LOCALS~1\Temp> t
This is MYVAR1
This is MYVAR2
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Tue, 07 Apr 2009 12:15:59 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: perl values for batch script to use
Message-Id: <rc9nt49hg1b6qck17m35bt8mkjqa76cl4r@4ax.com>
Slickuser <slick.users@gmail.com> wrote:
>I have a filename (file.txt)
>
>file.txt contains:
>Sample4.1.2009_US
>Sample4.2.2009_ASIA
>
>I can parse this file in Perl fine. Now I want this value to be
>available to use in a batch script.
Please define "batch". I know that term only to describe a concept, but
not at the name of a programming or script language.
>I try using "set" but the info get clear once I exit perl script.
[...]
>use system to execute command ("set xxyz_US=Sample4.1.2009_US")
>("set xxyz_ASIA=Sample4.2.2009_ASIA")
Actually, that value is already cleared the moment, when the new process
that was used execute the external command terminated.
See 'perldoc -q env':
I {changed directory, modified my environment} in a perl script. How
come the change disappeared when I exited the script? How do I get my
changes to be visible?
jue
------------------------------
Date: Tue, 7 Apr 2009 14:50:09 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: perl values for batch script to use
Message-Id: <slrngtnbjh.9ch.tadmc@tadmc30.sbcglobal.net>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Slickuser <slick.users@gmail.com> wrote:
>>Now I want this value to be
>>available to use in a batch script.
>
> Please define "batch".
http://en.wikipedia.org/wiki/Batch_files
> I know that term only to describe a concept, but
> not at the name of a programming or script language.
What M$ calls a "batch script" is what is called a "shell script" by
most of the rest of the world.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 7 Apr 2009 16:06:46 -0400
From: "darkon" <darkon.tdo@gmail.com>
Subject: Re: perl values for batch script to use
Message-Id: <b-adnV_vbaXLL0bUnZ2dnUVZ_u2dnZ2d@supernews.com>
Tad J McClellan <tadmc@seesig.invalid> wrote:
> Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Slickuser <slick.users@gmail.com> wrote:
>
>>>Now I want this value to be
>>>available to use in a batch script.
>>
>> Please define "batch".
>
>
> http://en.wikipedia.org/wiki/Batch_files
>
>
>> I know that term only to describe a concept, but
>> not at the name of a programming or script language.
>
>
> What M$ calls a "batch script" is what is called a "shell script" by
> most of the rest of the world.
They're .bat files, flying in on little leathery wings to perform routine
tasks. :-)
Windows calls daemons by the boring name of "services". Bleah.
------------------------------
Date: Tue, 07 Apr 2009 13:18:33 -0700
From: sln@netherlands.com
Subject: Re: perl values for batch script to use
Message-Id: <6rcnt4h5kl41a7d5o91svsc9aaueonkf3h@4ax.com>
On Tue, 7 Apr 2009 14:50:09 -0500, Tad J McClellan <tadmc@seesig.invalid> wrote:
>Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Slickuser <slick.users@gmail.com> wrote:
>
>>>Now I want this value to be
>>>available to use in a batch script.
>>
>> Please define "batch".
>
>
> http://en.wikipedia.org/wiki/Batch_files
>
>
>> I know that term only to describe a concept, but
>> not at the name of a programming or script language.
>
>
>What M$ calls a "batch script" is what is called a "shell script" by
>most of the rest of the world.
So I guess Perl would be "batch script shell compiler"
-sln
------------------------------
Date: Tue, 07 Apr 2009 13:21:32 -0700
From: sln@netherlands.com
Subject: Re: perl values for batch script to use
Message-Id: <kadnt4hgri2fkq94i9cv4unlc1k29ul7vu@4ax.com>
On Tue, 7 Apr 2009 16:06:46 -0400, "darkon" <darkon.tdo@gmail.com> wrote:
>
>Tad J McClellan <tadmc@seesig.invalid> wrote:
>> Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> Slickuser <slick.users@gmail.com> wrote:
>>
>>>>Now I want this value to be
>>>>available to use in a batch script.
>>>
>>> Please define "batch".
>>
>>
>> http://en.wikipedia.org/wiki/Batch_files
>>
>>
>>> I know that term only to describe a concept, but
>>> not at the name of a programming or script language.
>>
>>
>> What M$ calls a "batch script" is what is called a "shell script" by
>> most of the rest of the world.
>
>They're .bat files, flying in on little leathery wings to perform routine
>tasks. :-)
>
>Windows calls daemons by the boring name of "services". Bleah.
How come thier not 1-liners you can enter on the command line, that do a lot of
program calls? When does it get it bat wings?
-sln
------------------------------
Date: Tue, 7 Apr 2009 14:09:10 -0700 (PDT)
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: perl values for batch script to use
Message-Id: <d9f99da7-3cf2-461d-b334-8ac9ac8d5a84@z19g2000vbz.googlegroups.com>
On Apr 7, 10:58=A0am, Slickuser <slick.us...@gmail.com> wrote:
> I have a filename (file.txt)
>
> file.txt contains:
> Sample4.1.2009_US
> Sample4.2.2009_ASIA
>
> I can parse this file in Perl fine. Now I want this value to be
> available to use in a batch script.
> I try using "set" but the info get clear once I exit perl script.
>
> perl_script.pl
> open file.txt
> parse info
> use system to execute command ("set xxyz_US=3DSample4.1.2009_US")
> ("set xxyz_ASIA=3DSample4.2.2009_ASIA")
>
Use setenv instead of the set command.
http://barnyard.syr.edu/~vefatica/#SETENV
Or, you could use the standard set command and then use Win32::API to
call 2 C functions (RegFlushKey and BroadcastSystemMessage) to force
that setting to be retained after the perl script ends, which is
basically what setenv does.
Win32::API
http://search.cpan.org/~cosimo/Win32-API-0.58/API.pm
RegFlushKey in Advapi32.lib
http://msdn.microsoft.com/en-us/library/ms724867(VS.85).aspx
BroadcastSystemMessage in user32.dll
http://msdn.microsoft.com/en-us/library/ms644932(VS.85).aspx
------------------------------
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 V11 Issue 2325
***************************************