[30189] in Perl-Users-Digest
Perl-Users Digest, Issue: 1432 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 8 18:10:29 2008
Date: Tue, 8 Apr 2008 15:09:19 -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, 8 Apr 2008 Volume: 11 Number: 1432
Today's topics:
Re: Can I iterate through a file on a CGI page? <rich@example.net>
Re: Can I iterate through a file on a CGI page? <rich@example.net>
Re: Can I iterate through a file on a CGI page? <glex_no-spam@qwest-spam-no.invalid>
can you write to a dos format while in unix <mmccaws@comcast.net>
Re: can you write to a dos format while in unix <joost@zeekat.nl>
Re: can you write to a dos format while in unix <cbigam@somewhereelse.shaw.ca>
Re: can you write to a dos format while in unix <rich@example.net>
Re: can you write to a dos format while in unix <mmccaws@comcast.net>
Re: can you write to a dos format while in unix <mmccaws@comcast.net>
Re: can you write to a dos format while in unix <mmccaws@comcast.net>
Re: can you write to a dos format while in unix <mmccaws@comcast.net>
Re: Create two-dimensional Array from string <tzz@lifelogs.com>
Re: perl should be improved and perl6 <get@bentsys.com>
Re: perl should be improved and perl6 <tzz@lifelogs.com>
Re: somewhat unusual way to define a sub <Peter@PSDT.com>
Re: somewhat unusual way to define a sub <ro.naldfi.scher@gmail.com>
Re: somewhat unusual way to define a sub <uri@stemsystems.com>
Re: somewhat unusual way to define a sub <uri@stemsystems.com>
Re: Win32::OLE "Member not found" Adam.L.MacKinnon@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 08 Apr 2008 17:34:35 GMT
From: Rich Grise <rich@example.net>
Subject: Re: Can I iterate through a file on a CGI page?
Message-Id: <pan.2008.04.08.18.34.01.629797@example.net>
On Thu, 03 Apr 2008 04:10:07 +0000, John W. Krahn wrote:
> Jim Gibson wrote:
>> In article <pan.2008.04.02.19.52.30.989027@example.net>, Rich Grise
>>
>>> So, anybody got a quick and dirty script that will make 38,000 symlinks?
>>
>> for my $i ( 1..38000 ) {
>> symlink( '/path/to/somefile', sprintf("symlink%5.5d",$i));
>> }
>
> for my $name ( 'aaaaaa' .. 'aacefn' ) {
> symlink '/path/to/somefile', $name;
> }
>
Thanks for these. :-)
OK, so now I've got $mypath/source-links/symlink00000 through
$mypath/source-links/symlink19634 , and I figured out how to iterate them:
my $thislink=`ls source-links | head -1` , but then when I use the link in
an <img src=... tag, it shows the pic, but how do I get the actual name of
the actual file that the link is pointing to? I suppose I could do an ls
-l and parse the link, but isn't there an easier/quicker/more elegant way
to get that info? (I think they call it "dereferencing", but I'm not sure.)
In other words, I want to show the pic, and show its "real" name, not the
link name; can that be done easily?
Thanks,
Rich
Now, I've got source-links/
------------------------------
Date: Tue, 08 Apr 2008 20:48:22 GMT
From: Rich Grise <rich@example.net>
Subject: Re: Can I iterate through a file on a CGI page?
Message-Id: <pan.2008.04.08.21.47.47.19680@example.net>
On Tue, 08 Apr 2008 17:34:35 +0000, Rich Grise wrote:
> the actual file that the link is pointing to? I suppose I could do an ls
> -l and parse the link, but isn't there an easier/quicker/more elegant way
> to get that info? (I think they call it "dereferencing", but I'm not sure.)
Nah:
### start script ###
#!/usr/bin/perl -w
my $line=`ls -l source-links | head -2 | tail -1`;
chomp $line;
my $linkname = substr("$line", 50, 12);
my $targetname = substr("$line", 66);
print("$line\n");
print("name = $linkname, target = $targetname\n");
### end script ###
$ parse-ls
lrwxrwxrwx 1 richgrise users 75 2008-04-07 13:47 symlink00000 -> /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
name = symlink00000, target = /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
$
Cheers!
Rich
------------------------------
Date: Tue, 08 Apr 2008 16:50:56 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Can I iterate through a file on a CGI page?
Message-Id: <47fbe8c0$0$33227$815e3792@news.qwest.net>
Rich Grise wrote:
> On Tue, 08 Apr 2008 17:34:35 +0000, Rich Grise wrote:
>
>> the actual file that the link is pointing to? I suppose I could do an ls
>> -l and parse the link, but isn't there an easier/quicker/more elegant way
>> to get that info? (I think they call it "dereferencing", but I'm not sure.)
>
> Nah:
> ### start script ###
> #!/usr/bin/perl -w
>
> my $line=`ls -l source-links | head -2 | tail -1`;
>
> chomp $line;
>
> my $linkname = substr("$line", 50, 12);
> my $targetname = substr("$line", 66);
>
> print("$line\n");
>
> print("name = $linkname, target = $targetname\n");
Do you have your own print() subroutine? No need for '()'.
> ### end script ###
>
> $ parse-ls
> lrwxrwxrwx 1 richgrise users 75 2008-04-07 13:47 symlink00000 -> /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
> name = symlink00000, target = /C/Documents and Settings/Administrator/My Documents/My Pictures/Sample.jpg
Not very reliable. If the owner or group change to something
of different length, it could easily return the wrong data. Using
split would be more reliable, but still not very good.
Use the correct function: perldoc -f readlink
------------------------------
Date: Tue, 8 Apr 2008 13:06:43 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: can you write to a dos format while in unix
Message-Id: <3e0e8978-3ec4-4b2f-98a0-8002eb5200da@l64g2000hse.googlegroups.com>
My users are will be uploading a file from unix. I'm trying to save a
step by formatting the file while in unix so they don't have to format
it with
"perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
The resulting file after copied to windows did not have a readable
format. Is this a process that can only be done after the file
transfer?
Mike
------------------------------
Date: Tue, 08 Apr 2008 22:12:18 +0200
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: can you write to a dos format while in unix
Message-Id: <87zls4qf6l.fsf@zeekat.nl>
mmccaws2 <mmccaws@comcast.net> writes:
> My users are will be uploading a file from unix. I'm trying to save a
> step by formatting the file while in unix so they don't have to format
> it with
>
> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> The resulting file after copied to windows did not have a readable
> format. Is this a process that can only be done after the file
> transfer?
No, you're doing it wrong.
*ON UNIX*, you can do:
perl -p -e 's/\n/\r\n/' < $infile > $dosfile
Final results are dependent on the transfer protocol (i.e. do NOT
transfer those files with FTP in ASCII mode).
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Tue, 08 Apr 2008 20:48:39 GMT
From: "Colin B." <cbigam@somewhereelse.shaw.ca>
Subject: Re: can you write to a dos format while in unix
Message-Id: <HSQKj.34813$rd2.25238@pd7urf3no>
mmccaws2 <mmccaws@comcast.net> wrote:
> My users are will be uploading a file from unix. I'm trying to save a
> step by formatting the file while in unix so they don't have to format
> it with
>
> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> The resulting file after copied to windows did not have a readable
> format. Is this a process that can only be done after the file
> transfer?
Unless I'm missing something, you should just be able to do:
$unix2dos $infile > $outfile
Colin
------------------------------
Date: Tue, 08 Apr 2008 20:54:48 GMT
From: Rich Grise <rich@example.net>
Subject: Re: can you write to a dos format while in unix
Message-Id: <pan.2008.04.08.21.54.14.69345@example.net>
On Tue, 08 Apr 2008 22:12:18 +0200, Joost Diepenmaat wrote:
> mmccaws2 <mmccaws@comcast.net> writes:
>
>> My users are will be uploading a file from unix. I'm trying to save a
>> step by formatting the file while in unix so they don't have to format
>> it with
>>
>> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>>
>> The resulting file after copied to windows did not have a readable
>> format. Is this a process that can only be done after the file
>> transfer?
>
> No, you're doing it wrong.
>
> *ON UNIX*, you can do:
>
> perl -p -e 's/\n/\r\n/' < $infile > $dosfile
>
> Final results are dependent on the transfer protocol (i.e. do NOT
> transfer those files with FTP in ASCII mode).
What's wrong with
$ todos < $infile > $dosfile
?
Thanks,
Rich
------------------------------
Date: Tue, 8 Apr 2008 14:16:26 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: can you write to a dos format while in unix
Message-Id: <e1da558e-6eb3-42af-b440-569daa0ecd9a@y21g2000hsf.googlegroups.com>
On Apr 8, 1:54 pm, Rich Grise <r...@example.net> wrote:
> On Tue, 08 Apr 2008 22:12:18 +0200, Joost Diepenmaat wrote:
> > mmccaws2 <mmcc...@comcast.net> writes:
>
> >> My users are will be uploading a file from unix. I'm trying to save a
> >> step by formatting the file while in unix so they don't have to format
> >> it with
>
> >> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> >> The resulting file after copied to windows did not have a readable
> >> format. Is this a process that can only be done after the file
> >> transfer?
>
> > No, you're doing it wrong.
>
> > *ON UNIX*, you can do:
>
> > perl -p -e 's/\n/\r\n/' < $infile > $dosfile
>
> > Final results are dependent on the transfer protocol (i.e. do NOT
> > transfer those files with FTP in ASCII mode).
>
> What's wrong with
> $ todos < $infile > $dosfile
> ?
>
> Thanks,
> Rich
we're using scp that comes on HPUX. The results did seem to change.
Mike
------------------------------
Date: Tue, 8 Apr 2008 14:19:33 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: can you write to a dos format while in unix
Message-Id: <5543fe41-9598-42b3-bcf5-c2f1cc4116a5@s50g2000hsb.googlegroups.com>
On Apr 8, 1:54 pm, Rich Grise <r...@example.net> wrote:
> On Tue, 08 Apr 2008 22:12:18 +0200, Joost Diepenmaat wrote:
> > mmccaws2 <mmcc...@comcast.net> writes:
>
> >> My users are will be uploading a file from unix. I'm trying to save a
> >> step by formatting the file while in unix so they don't have to format
> >> it with
>
> >> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> >> The resulting file after copied to windows did not have a readable
> >> format. Is this a process that can only be done after the file
> >> transfer?
>
> > No, you're doing it wrong.
>
> > *ON UNIX*, you can do:
>
> > perl -p -e 's/\n/\r\n/' < $infile > $dosfile
>
> > Final results are dependent on the transfer protocol (i.e. do NOT
> > transfer those files with FTP in ASCII mode).
>
> What's wrong with
> $ todos < $infile > $dosfile
> ?
>
> Thanks,
> Rich
Sorry that wasn't quite right. I made the change and then scp'd. scp
on XP which is a product of Attachmate.
Mike
------------------------------
Date: Tue, 8 Apr 2008 14:29:25 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: can you write to a dos format while in unix
Message-Id: <9ad7dab3-81b9-4afb-be94-c5706f2e347e@p25g2000hsf.googlegroups.com>
On Apr 8, 2:19 pm, mmccaws2 <mmcc...@comcast.net> wrote:
> On Apr 8, 1:54 pm, Rich Grise <r...@example.net> wrote:
>
>
>
> > On Tue, 08 Apr 2008 22:12:18 +0200, Joost Diepenmaat wrote:
> > > mmccaws2 <mmcc...@comcast.net> writes:
>
> > >> My users are will be uploading a file from unix. I'm trying to save a
> > >> step by formatting the file while in unix so they don't have to format
> > >> it with
>
> > >> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> > >> The resulting file after copied to windows did not have a readable
> > >> format. Is this a process that can only be done after the file
> > >> transfer?
>
> > > No, you're doing it wrong.
>
> > > *ON UNIX*, you can do:
>
> > > perl -p -e 's/\n/\r\n/' < $infile > $dosfile
>
> > > Final results are dependent on the transfer protocol (i.e. do NOT
> > > transfer those files with FTP in ASCII mode).
>
> > What's wrong with
> > $ todos < $infile > $dosfile
> > ?
>
> > Thanks,
> > Rich
>
> Sorry that wasn't quite right. I made the change and then scp'd. scp
> on XP which is a product of Attachmate.
>
> Mike
How does one print hidden characters like '\n' in perl or cl?
Mike
------------------------------
Date: Tue, 8 Apr 2008 14:37:09 -0700 (PDT)
From: mmccaws2 <mmccaws@comcast.net>
Subject: Re: can you write to a dos format while in unix
Message-Id: <ab798ffd-5741-47bd-b940-644ec6038894@a70g2000hsh.googlegroups.com>
On Apr 8, 2:29 pm, mmccaws2 <mmcc...@comcast.net> wrote:
> On Apr 8, 2:19 pm, mmccaws2 <mmcc...@comcast.net> wrote:
>
>
>
> > On Apr 8, 1:54 pm, Rich Grise <r...@example.net> wrote:
>
> > > On Tue, 08 Apr 2008 22:12:18 +0200, Joost Diepenmaat wrote:
> > > > mmccaws2 <mmcc...@comcast.net> writes:
>
> > > >> My users are will be uploading a file from unix. I'm trying to save a
> > > >> step by formatting the file while in unix so they don't have to format
> > > >> it with
>
> > > >> "perl -p -e 's/\r/\r\n/' < $infile > $dosfile"
>
> > > >> The resulting file after copied to windows did not have a readable
> > > >> format. Is this a process that can only be done after the file
> > > >> transfer?
>
> > > > No, you're doing it wrong.
>
> > > > *ON UNIX*, you can do:
>
> > > > perl -p -e 's/\n/\r\n/' < $infile > $dosfile
>
> > > > Final results are dependent on the transfer protocol (i.e. do NOT
> > > > transfer those files with FTP in ASCII mode).
>
> > > What's wrong with
> > > $ todos < $infile > $dosfile
> > > ?
>
> > > Thanks,
> > > Rich
>
> > Sorry that wasn't quite right. I made the change and then scp'd. scp
> > on XP which is a product of Attachmate.
>
> > Mike
>
> How does one print hidden characters like '\n' in perl or cl?
>
> Mike
Also, I've never used unix2dos, is this a module or program?
Mike
------------------------------
Date: Tue, 08 Apr 2008 11:04:28 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Create two-dimensional Array from string
Message-Id: <863apw9vub.fsf@lifelogs.com>
On Mon, 7 Apr 2008 06:50:46 -0700 (PDT) "pjfalbe@gmail.com" <pjfalbe@gmail.com> wrote:
pc> I went ahead and tried selectall_arrayref and as I thought it did no
pc> better than it's cousin fetchall_arrayref.
pc> The problem is a MULTISET returned by DBI/DBD as a varchar and the
pc> driver doesn't know how to parse
pc> it into an array. There are 2 solutions to this 1) separate the
pc> mutliset into a separate query and loop through original cursor. or
pc> 2) manipulate the varchar into an array like above with the eval or
pc> use 's//g' and splits to manipulate
pc> into a array. Luckily MULTISETs are pretty reliable in what they
pc> return so the eval approach works great. And it's
pc> performance problems are better than network latency by looping.
pc> Thank you for your suggestion got me to look at selectall_arrayref,
pc> I've had a habit of using fetchall_arrayref
pc> but will use selectall_arrayref more in the future.
Well, I owe you an apology because I thought MULTISETs were parseable by
the DBI. So you do need a custom parser or to split the results up.
Maybe a temporary table would work best for you if there are only a few
results (but you'll have to have an extra field to distinguish between
multiple instances of the same query, and it gets ugly quickly).
I've posted in the past here about the dangers of evaluating data,
especially data you don't control. So the eval-based parser worried me
(and others who have responded). I would use a regular expression as
you mentioned, if possible, or write a more complex state-based parser.
Ted
------------------------------
Date: Tue, 8 Apr 2008 07:33:32 -0700
From: "Gordon Etly" <get@bentsys.com>
Subject: Re: perl should be improved and perl6
Message-Id: <661e1vF2i759iU1@mid.individual.net>
David Formosa (aka ? the Platypus) wrote:
> On Mon, 7 Apr 2008 15:42:57 -0700, szr <szrRE@szromanMO.comVE> wrote:
> > David Formosa (aka ? the Platypus) wrote:
> [...]
> > > So emacs is an acronym for Eight Megs And Constantly Swapping.
> >
> > No, the man page for "emacs" defines it as "emacs - GNU project
> > Emacs", while for perl (either via man or perldoc) defines it as
> > "perl - Practical Extraction and Report Language".
>
> But neather of those are definitions, there abstracts.
That may be, and perhaps definition was too strong a wording to describe
it, but it's still written as providing some sort of meaning for each
letter in Perl, in Perl's own documentation.
Giving a meaning for each letter results in an acronym, and using all
caps or all lowercase to describe an acronym that has no explicit mixed
case should be fair game, should it not?
There for the FAQ that says not to use "PERL" should be corrected imho,
as it is perfectly reasonable to use it as "perl" or "PERL" when
referring to it as an acronym.
--
G.Etly
------------------------------
Date: Tue, 08 Apr 2008 11:08:56 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: perl should be improved and perl6
Message-Id: <86y77o8h2f.fsf@lifelogs.com>
On Mon, 07 Apr 2008 19:10:43 -0700 Andrew DeFaria <Andrew@DeFaria.com> wrote:
AD> Man you are naive aren't you. I don't post nor read here in the
AD> hopes of making money - I make money elsewhere... Lots of it...
I just wanted to mention that I love how you've managed to pull so many
classic troll tricks, including the money gambit. Very nice.
Ted
------------------------------
Date: Tue, 08 Apr 2008 13:07:38 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: somewhat unusual way to define a sub
Message-Id: <pan.2008.04.08.13.07.38.326033@PSDT.com>
On Mon, 07 Apr 2008 20:55:32 +0000, Uri Guttman wrote:
>>>>>> "R" == Ronny <ro.naldfi.scher@gmail.com> writes:
>
> R> I found in a program a piece of code which basically looked like this:
> R> my $n="myname";
> R> *$n=sub { .... };
>
> R> The whole think was of course guided by no strict 'refs'. My question:
>
> R> Is this just a unusual way to write
>
> R> sub myname { ... }
>
> R> or did I miss something here?
>
> it is just a wacko way to define a sub. it puts a code ref (the anon
> sub) into the code slot in the *myname typeglob. it makes no sense to do
> that unless the sub name was generated on the fly. and even that makes
> little sense unless he has variant subs for the same name. and that is
> better done with a dispatch table than munging the symbol table. i would
> stay away from that code and coder if i were you!
I beg to differ. I do this frequently to populate a class with a
number of similar methods, e.g.:
use Log::Log4Perl;
BEGIN {
for my $method ( keys %Log::Log4perl::Level::PRIORITY ) {
no strict 'refs';
*$method = sub {
my $self = shift;
my $logger = Log::Log4Perl->get_logger( ref $self );
$logger->$method( @_ );
}
};
}
Or there's just-in-time method creation (traditional objects):
sub AUTOLOAD {
(my $method = our $AUTOLOAD) =~ s/.*://;
return if $method eq 'DESTROY';
croak "No such attribute" unless $ALLOWED_ATTR{$method};
no strict 'refs';
*$method = sub {
my $self = shift;
$self->{$method} = shift if @_;
return $self->{$method};
};
goto &$method;
}
I don't think a dispatch table is a better solution for those cases.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Tue, 8 Apr 2008 06:58:57 -0700 (PDT)
From: Ronny <ro.naldfi.scher@gmail.com>
Subject: Re: somewhat unusual way to define a sub
Message-Id: <5fce402d-7e63-45f1-b58b-060c64db59ea@r9g2000prd.googlegroups.com>
On Apr 8, 3:07 pm, Peter Scott <Pe...@PSDT.com> wrote:
> On Mon, 07 Apr 2008 20:55:32 +0000, Uri Guttman wrote:
> > it is just a wacko way to define a sub. it puts a code ref (the anon
> > sub) into the code slot in the *myname typeglob. it makes no sense to do
> > that unless the sub name was generated on the fly.
> I beg to differ. I do this frequently to populate a class with a
> number of similar methods, e.g.:
>
> use Log::Log4Perl;
> BEGIN {
> for my $method ( keys %Log::Log4perl::Level::PRIORITY ) {
> no strict 'refs';
> *$method = sub {
> my $self = shift;
> my $logger = Log::Log4Perl->get_logger( ref $self );
> $logger->$method( @_ );
> }
> };
>
> }
Well, your case *does* make sense, because $method is a different
string on every execution. My original example, however, was that
the method name was "constant" (i.e. set to the same string on every
execution), so I agree with Uri that this could have done more
naturally
in the conventional way of defineing a sub.
Ronald
>
> Or there's just-in-time method creation (traditional objects):
>
> sub AUTOLOAD {
> (my $method = our $AUTOLOAD) =~ s/.*://;
> return if $method eq 'DESTROY';
> croak "No such attribute" unless $ALLOWED_ATTR{$method};
> no strict 'refs';
> *$method = sub {
> my $self = shift;
> $self->{$method} = shift if @_;
> return $self->{$method};
> };
> goto &$method;
>
> }
>
> I don't think a dispatch table is a better solution for those cases.
>
> --
> Peter Scotthttp://www.perlmedic.com/http://www.perldebugged.com/
------------------------------
Date: Tue, 08 Apr 2008 17:18:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: somewhat unusual way to define a sub
Message-Id: <x74pacmfiu.fsf@mail.sysarch.com>
>>>>> "PS" == Peter Scott <Peter@PSDT.com> writes:
PS> On Mon, 07 Apr 2008 20:55:32 +0000, Uri Guttman wrote:
>>>>>>> "R" == Ronny <ro.naldfi.scher@gmail.com> writes:
>>
R> I found in a program a piece of code which basically looked like this:
R> my $n="myname";
R> *$n=sub { .... };
>>
R> The whole think was of course guided by no strict 'refs'. My question:
>>
R> Is this just a unusual way to write
>>
R> sub myname { ... }
>>
R> or did I miss something here?
>>
>> it is just a wacko way to define a sub. it puts a code ref (the anon
>> sub) into the code slot in the *myname typeglob. it makes no sense to do
>> that unless the sub name was generated on the fly. and even that makes
>> little sense unless he has variant subs for the same name. and that is
>> better done with a dispatch table than munging the symbol table. i would
>> stay away from that code and coder if i were you!
PS> I beg to differ. I do this frequently to populate a class with a
PS> number of similar methods, e.g.:
PS> use Log::Log4Perl;
PS> BEGIN {
PS> for my $method ( keys %Log::Log4perl::Level::PRIORITY ) {
PS> no strict 'refs';
PS> *$method = sub {
PS> my $self = shift;
PS> my $logger = Log::Log4Perl->get_logger( ref $self );
PS> $logger->$method( @_ );
PS> }
PS> };
PS> }
i have done similar things when i autogenerated accessors. i did say
autogenerate is ok in my comment but i forgot about this case.
PS> I don't think a dispatch table is a better solution for those cases.
ditto for autoload. again guilty of doing that.
but the example from the OP was neither of those (unless there was
missing code to show that).
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, 08 Apr 2008 17:21:27 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: somewhat unusual way to define a sub
Message-Id: <x7zls4l0tk.fsf@mail.sysarch.com>
>>>>> "R" == Ronny <ro.naldfi.scher@gmail.com> writes:
R> On Apr 8, 3:07 pm, Peter Scott <Pe...@PSDT.com> wrote:
>> On Mon, 07 Apr 2008 20:55:32 +0000, Uri Guttman wrote:
>> > it is just a wacko way to define a sub. it puts a code ref (the anon
>> > sub) into the code slot in the *myname typeglob. it makes no sense to do
>> > that unless the sub name was generated on the fly.
>> I beg to differ. I do this frequently to populate a class with a
>> number of similar methods, e.g.:
>>
>> use Log::Log4Perl;
>> BEGIN {
>> for my $method ( keys %Log::Log4perl::Level::PRIORITY ) {
>> no strict 'refs';
>> *$method = sub {
>> my $self = shift;
>> my $logger = Log::Log4Perl->get_logger( ref $self );
>> $logger->$method( @_ );
>> }
>> };
>>
>> }
R> Well, your case *does* make sense, because $method is a different
R> string on every execution. My original example, however, was that
R> the method name was "constant" (i.e. set to the same string on every
R> execution), so I agree with Uri that this could have done more
R> naturally
R> in the conventional way of defineing a sub.
note that these aren't strings being compiled but anon subs. and the
only way it makes sense is if they are closures which hold private
versions of lexicals. this way each pass through the loop generates a
slightly different customized closure (in this case the name of the
method to call is in $method and private to each closure).
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, 8 Apr 2008 12:20:48 -0700 (PDT)
From: Adam.L.MacKinnon@gmail.com
Subject: Re: Win32::OLE "Member not found"
Message-Id: <70b5e273-b960-4f7c-9985-30b228724b44@a22g2000hsc.googlegroups.com>
On Apr 8, 6:09 am, Thomas Kratz <ThomasKr...@REMOVEwebCAPS.de> wrote:
> Adam.L.MacKin...@gmail.com wrote:
> > Hi,
>
> > Am attempting to run the simple script as follows (sourced from:
> >http://techtasks.com/code/viewbookcode/443)
>
> This code is buggy and I suspect nobody ever tested it.
>
>
>
> > use strict;
> > use warnings;
> > use Data::Dumper;
> > useWin32::OLE;
> > $Win32::OLE::Warn = 3;
>
> > #use lib 'H:\dev\perl\NSLC-Store-Mgmt\lib';
> > #use NSLC::Store::Mgmt;
>
> > my %args;
>
> > $args{name} = 'TESTVAR';
> > $args{value} = 'TESTVALUE';
> > $args{target} = '.';
>
> > set_env_var(\%args);
>
> > sub set_env_var {
> > my ($args,) = @_;
> > my $strVarName = $args->{name};
> > my $strVarValue = $args->{value};
> > my $strComputer = $args->{target};
>
> > my $objVarClass =Win32::OLE->GetObject('winmgmts://' .
> > $strComputer . '/root/cimv2:Win32_Environment');
> > my $objVar = $objVarClass->SpawnInstanceobjVar->Name eq
> > $strVarName;
>
> These have to be 2 statements:
>
> my $objVar = $objVarClass->SpawnInstance_ # note the underscore
> $objVar->{Name} = $strVarName;
>
> > $objVar->{VariableValue} = $strVarValue;
> > $objVar->{UserName} = '<SYSTEM>';
> > $objVar->PutWScript->Echo('Created environment variable ' .
> > $strVarName);
>
> and again:
>
> $objVar->Put_;
> WScript->Echo('Created environment variable ' . $strVarName);
> # at least I think so, I don't know WScript
>
>
>
> > }
>
> > The following message is returned.
> > retrying default method at C:/Perl/site/lib/Win32/OLE/Lite.pm line
> > 156.
> >Win32::OLE(0.1403) error 0x80020003: "Member not found"
> > in METHOD/PROPERTYGET "" at H:\dev\perl\test\setenv.pl line 28
> > shell returned 9
>
> > I am completely new to using perl in a windows environment and am not
> > sure where to start debugging. I have read all that I can via module
> > docs and web information but am still having no luck.
> > As far as I can tell, syntactically the script is fine but I am not
> > sure how the guts of $objVarClass->SpawnInstanceobjVar->Name eq
> > $strVarName; is working. I am running this on XP pro using activeperl
> > 5.8.8(820).
>
> For using the WMI interface the M$ WMI Reference is the best information
>
> http://msdn2.microsoft.com/en-us/library/aa394572%28VS.85%29.aspx
>
> Thomas
>
> --
> $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
> s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
> $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
> '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
> print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
Oh man....did I really miss that? Thanks, I have it somewhat working
now :).
------------------------------
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 1432
***************************************