[22527] in Perl-Users-Digest
Perl-Users Digest, Issue: 4748 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 23 11:05:40 2003
Date: Sun, 23 Mar 2003 08:05:06 -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 Sun, 23 Mar 2003 Volume: 10 Number: 4748
Today's topics:
Re: Changeing Scope of a Sub Reference <steven.smolinski@sympatico.ca>
Re: Changeing Scope of a Sub Reference <grazz@nyc.rr.com>
Re: Changeing Scope of a Sub Reference <aran@bluefeet.net>
Re: Changeing Scope of a Sub Reference <aran@bluefeet.net>
Editor with Perl as macro language? <Norbert_Schmidt@DU3.MAUS.DE>
Re: Editor with Perl as macro language? <tassilo.parseval@rwth-aachen.de>
Re: Editor with Perl as macro language? <Norbert_Schmidt@DU3.MAUS.DE>
Re: Editor with Perl as macro language? (Randal L. Schwartz)
Re: Editor with Perl as macro language? <dfox@ia.net>
Re: Editor with Perl as macro language? <tassilo.parseval@rwth-aachen.de>
Re: Editor with Perl as macro language? <tassilo.parseval@rwth-aachen.de>
How stable is 'Magic'? <im_not_giving_it_here@i_hate_spam.com>
Re: How to interchange fields and sorting in perl <barryk2@SPAM-KILLER.mts.net>
Re: Idea for holding a C++ pointer in a Perl scalar wit <im_not_giving_it_here@i_hate_spam.com>
Re: Iraqis Greeting Americans with Kisses & Handshakes? <mike_solomon@lineone.net>
Looped variable interpolation <michael@weigel.com>
Re: Looped variable interpolation (Jay Tilton)
Re: Looped variable interpolation (Tad McClellan)
Re: Looped variable interpolation <michael@weigel.com>
Re: Looped variable interpolation <michael@weigel.com>
Perl ODBC and SQL <bigus NO @ SPAM creationfactor .net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 23 Mar 2003 08:04:41 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: Changeing Scope of a Sub Reference
Message-Id: <tUdfa.3$Yz2.135@news20.bellglobal.com>
Aran Deltac <aran@bluefeet.net> wrote:
> Passing arguments is fine, and something any perl nympho understands.
> I'm actually looking for something a little more in depth, as I
> described in my original question.
Your original question needs more depth. Here it is:
> I have this big lengthy program written that needs this ability.
> Instead of posting a bunch of meaningless code, here's a sample
> (conceptually) of what I am trying to do:
> use strict;
> my $sub_ref = sub{ print $i; };
> sub run_ref { my $i = 'Hello!'; &{$sub_ref}; }
> run_ref();
[...]
> I want to get around this [scope error] and scope a sub reference in
> to whatever black/package I want to without having to re-reference the
> code.
That's not clear. Is your question how to reference a scalar (that's
what a sub reference is) in another package?
Is your question how to reference a subroutine in another package?
Is your question how to access the $i variable from another package?
Both your $i and your $sub_ref are lexicals anyway, not package
variables, so they aren't even in the symbol table.
You also only show one package. So everything you reference will be
either lexical or in the same package. And lexical variables in blocks
are not referencable outside of the block, unless you explicitly return
a ref to them.
So what are you trying to do?
Steve
--
Steven Smolinski => http://arbiter.ca/
GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
=> or email me with 'auto-key' in the subject.
Key Fingerprint => 08C8 6481 3A7B 2A1C 7C26 A5FC 1A1B 66AB F637 495D
------------------------------
Date: Sun, 23 Mar 2003 08:21:03 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: Changeing Scope of a Sub Reference
Message-Id: <P7efa.8112$pi.1066460@twister.nyc.rr.com>
Aran Deltac <aran@bluefeet.net> wrote:
> "Steven Smolinski" <steven.smolinski@sympatico.ca> wrote:
>> Aran Deltac <aran@bluefeet.net> wrote:
>> So pass arguments. Globals are a pain to manage anyway.
>
> Passing arguments is fine, and something any perl nympho
> understands.
Intriguing.
> I'm actually looking for something a little more in depth,
> as I described in my original question.
But you can't rebind a closure.
You might be able to kluge something together with string
eval, but until you tell us why you want an "in-depth"
solution the obvious approach -- passing arguments -- will
look like the way to go.
--
Steve
s||Just another Perl Nympho||tr|Nm|tr||s|ph|||print
------------------------------
Date: Sun, 23 Mar 2003 15:43:51 GMT
From: "Aran Deltac" <aran@bluefeet.net>
Subject: Re: Changeing Scope of a Sub Reference
Message-Id: <XCkfa.13531$xE1.542119@twister.southeast.rr.com>
"Steve Grazzini" <grazz@nyc.rr.com> wrote in message
news:P7efa.8112$pi.1066460@twister.nyc.rr.com...
> Aran Deltac <aran@bluefeet.net> wrote:
> > "Steven Smolinski" <steven.smolinski@sympatico.ca> wrote:
> >> Aran Deltac <aran@bluefeet.net> wrote:
> >> So pass arguments. Globals are a pain to manage anyway.
> >
[snip]
> But you can't rebind a closure.
Oh ok, I think thats the answer I was looking for. Well, I guess I'm just
going to be passing chunks of code around and eval() them, as you suggested,
so that they have scope (or closure, not sure if my terminology is correct)
in the right places. Kinda inefficient tho. Argh! :-)
Thanks,
Aran
> You might be able to kluge something together with string
> eval, but until you tell us why you want an "in-depth"
> solution the obvious approach -- passing arguments -- will
> look like the way to go.
>
> --
> Steve
>
> s||Just another Perl Nympho||tr|Nm|tr||s|ph|||print
------------------------------
Date: Sun, 23 Mar 2003 15:56:47 GMT
From: "Aran Deltac" <aran@bluefeet.net>
Subject: Re: Changeing Scope of a Sub Reference
Message-Id: <3Pkfa.13534$xE1.544125@twister.southeast.rr.com>
"Steven Smolinski" <steven.smolinski@sympatico.ca> wrote in message
news:tUdfa.3$Yz2.135@news20.bellglobal.com...
> Aran Deltac <aran@bluefeet.net> wrote:
>
> > Passing arguments is fine, and something any perl nympho understands.
> > I'm actually looking for something a little more in depth, as I
> > described in my original question.
>
> Your original question needs more depth. Here it is:
>
[snip]
>
> That's not clear. Is your question how to reference a scalar (that's
> what a sub reference is) in another package?
Not really. Actually, I think my problem was terminology. I want to change
the closure of a subroutine reference to wherever I want whenever I want.
Sounds like, from what Steve Grazzini posted, that thats not a possiblity.
:( In any case, I'm just going to be passing around chunks of code and
eval()ing them all over the place to get the scope I'm
looking for.
So, unless you know of some magic, or if I'm just being dumb...
Thanks,
Aran
PS: I answered all your questions below as best I could.
> Is your question how to reference a subroutine in another package?
Somewhat, I'm trying to change the closure location of a code reference at
run-time without having to re-create the reference (i.e. do an eval()( every
time I want to run the code.
> Is your question how to access the $i variable from another package?
Nope. I'm more trying to figure out how to create a lexical, and changing
my code ref's closure to wherever I want to make that lexical and other
things in-scope to the code ref when I call it. And, doing all that without
passing arguments or messing with package variables.
> Both your $i and your $sub_ref are lexicals anyway, not package
> variables, so they aren't even in the symbol table.
Right.
> You also only show one package. So everything you reference will be
> either lexical or in the same package. And lexical variables in blocks
> are not referencable outside of the block, unless you explicitly return
> a ref to them.
Agreed.
> So what are you trying to do?
>
> Steve
> --
> Steven Smolinski => http://arbiter.ca/
> GnuPG Public Key => http://arbiter.ca/steves_public_key.txt
> => or email me with 'auto-key' in the subject.
> Key Fingerprint => 08C8 6481 3A7B 2A1C 7C26 A5FC 1A1B 66AB F637 495D
------------------------------
Date: Sun, 23 Mar 2003 12:52:06 +0100
From: Norbert Schmidt <Norbert_Schmidt@DU3.MAUS.DE>
Subject: Editor with Perl as macro language?
Message-Id: <l87r7v4jn9viiik7k5aogrkvvrpav4shue@4ax.com>
Hello folks,
does anyone know of a program editor for Linux and/or Windows that
uses Perl as a macro language or is even written itself in Perl? (I'm
not talking about syntax highlighting.) I would like (X)Emacs, but
Lisp gives me the creeps.
Am I the only one who wants that or have I just looked in the wrong
places?
Thanks, Norbert
------------------------------
Date: 23 Mar 2003 12:36:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Editor with Perl as macro language?
Message-Id: <b5k9oj$sjb$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Norbert Schmidt:
> does anyone know of a program editor for Linux and/or Windows that
> uses Perl as a macro language or is even written itself in Perl? (I'm
> not talking about syntax highlighting.) I would like (X)Emacs, but
> Lisp gives me the creeps.
You can use a Perl-enabled vim. Such a vim knows about the :perl and
:perldo commands that can run any Perl code. Thus you can remote-control
the whole of vim through Perl or even use something like:
:perl $_ =~ s/(?same fancy pattern)/replace/;
to use Perl for manipulating your buffer. Of course you are also free to
use any CPAN module with this embedded perl.
I have written my use.perl.org blogger with a vim/Perl combo and am
quite happy with it.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 23 Mar 2003 14:26:14 +0100
From: Norbert Schmidt <Norbert_Schmidt@DU3.MAUS.DE>
Subject: Re: Editor with Perl as macro language?
Message-Id: <otcr7vcrdapjqtg9spi5hbtvbd0dj6g91c@4ax.com>
Hi Tassilo,
>You can use a Perl-enabled vim.
sounds nice, except for one thing: Is the "normal" usage (keyboard) as
sick (IMHO) as vi's? I never could get used to vi.
Regards, Norbert
------------------------------
Date: Sun, 23 Mar 2003 14:42:55 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Norbert Schmidt <Norbert_Schmidt@DU3.MAUS.DE>
Subject: Re: Editor with Perl as macro language?
Message-Id: <38316234ce56d27e12af9961de50a7d1@news.teranews.com>
>>>>> "Norbert" == Norbert Schmidt <Norbert_Schmidt@DU3.MAUS.DE> writes:
Norbert> Hello folks,
Norbert> does anyone know of a program editor for Linux and/or Windows that
Norbert> uses Perl as a macro language or is even written itself in Perl? (I'm
Norbert> not talking about syntax highlighting.) I would like (X)Emacs, but
Norbert> Lisp gives me the creeps.
You can get the best/worst of both worlds by "perl-enabling" your
Emacs build. I'm not sure if they've kept up the latest patches, but
it looked pretty cool at one point. It's in the CPAN, sample location
is <http://search.cpan.org/author/JTOBEY/Emacs-PerlmacsPatch-0.16/>.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Sun, 23 Mar 2003 08:44:40 -0600
From: Dennis Fox <dfox@ia.net>
Subject: Re: Editor with Perl as macro language?
Message-Id: <v7ri2pgo59jp29@corp.supernews.com>
Tassilo v. Parseval wrote:
> Also sprach Norbert Schmidt:
>
>
>>does anyone know of a program editor for Linux and/or Windows that
>>uses Perl as a macro language or is even written itself in Perl? (I'm
>>not talking about syntax highlighting.) I would like (X)Emacs, but
>>Lisp gives me the creeps.
>
>
> You can use a Perl-enabled vim. Such a vim knows about the :perl and
> :perldo commands that can run any Perl code. Thus you can remote-control
> the whole of vim through Perl or even use something like:
>
> :perl $_ =~ s/(?same fancy pattern)/replace/;
>
> to use Perl for manipulating your buffer. Of course you are also free to
> use any CPAN module with this embedded perl.
>
> I have written my use.perl.org blogger with a vim/Perl combo and am
> quite happy with it.
>
> Tassilo
Tassilo, could you enlighten us as to which vim/perl combos you have
tried and which you like the best?
Dennis
------------------------------
Date: 23 Mar 2003 14:50:25 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Editor with Perl as macro language?
Message-Id: <b5khjh$60o$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Norbert Schmidt:
> Hi Tassilo,
>
>>You can use a Perl-enabled vim.
>
> sounds nice, except for one thing: Is the "normal" usage (keyboard) as
> sick (IMHO) as vi's?
If you are referring to the distinction between command (<ESC>) and
insert (i) mode you are out of luck as vim does it, too. You don't have
to use 'h', 'j', 'k' and 'l' for moving in the buffer. ':set nocompatible'
(which is the default AFAIK) and the arrow keys, Pg(Dwn|Up) etc. work
just as nicely as with (X)emacs.
> I never could get used to vi.
I wouldn't want to us vi, either. vim is easy to get used to (if you
survive the first two hours;-) and I'm using it for all tasks that
involve writing and modifying (news, emails, programming, config-files) and
reading (for instance 'xxd file.bin | vim -' for the sake of its
syntax-highlighting).
Anyway, it's getting slightly off-topic so f'up set.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: 23 Mar 2003 14:59:41 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Editor with Perl as macro language?
Message-Id: <b5ki4t$6fm$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Dennis Fox:
> Tassilo v. Parseval wrote:
>> I have written my use.perl.org blogger with a vim/Perl combo and am
>> quite happy with it.
> Tassilo, could you enlighten us as to which vim/perl combos you have
> tried and which you like the best?
I have only tried one so far which gave no reason to complain:
http://packages.debian.org/testing/editors/vim-perl.html
Other Linux distributions probably have similar packages. Otherwise you
can still compile it from source.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 23 Mar 2003 10:36:25 +0000
From: Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com>
Subject: How stable is 'Magic'?
Message-Id: <b5k2kr$964$1@newsg3.svr.pol.co.uk>
I asked this is a previous post, but it might not get answered:
How stable is the 'Magic variables' API? It says in perlguts it is at
'patch level 0, and could change at any time'.
Thanks.
------------------------------
Date: Sun, 23 Mar 2003 08:11:31 -0600
From: Barry Kimelman <barryk2@SPAM-KILLER.mts.net>
Subject: Re: How to interchange fields and sorting in perl
Message-Id: <MPG.18e77c90fde8bb3a98975c@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <a067d211.0303220829.69280f45@posting.google.com>, siva
(sivaran@yahoo.com) says...
> Hi
>
> I am looking for following results through a perl program on a ascii
> file
>
> f1 f2 f3
> siva:kumar:234
> abcd:field:345
> hydf:field:745
>
> i want to read that file write back in sorting order f2,f3 and putting
> f2 in 1st postion f1 in second postion(inter change the files) . my
> output should look like this
>
> field:abcd:345
> field:hydf:745
> kumar:siva:234
>
> Any help welcomed ....
$filename = $ARGV[0];
$newfile = $filename . "new";
open(INPUT,"<$filename") or
die("Can't read file $filename : $!\n");
open(OUTPUT,">$newfile") or
die("Can't create file $newfile : $!\n");
while ( $buffer = <INPUT> ) {
chomp $buffer;
@fields = split(/\:/,$buffer);
print OUTPUT @fields[1,0,2],"\n";
}
close INPUT;
close OUTPUT;
--
---------
Barry Kimelman
Winnipeg, Manitoba, Canada
email : bkimelman@hotmail.com
------------------------------
Date: Sun, 23 Mar 2003 10:32:31 +0000
From: Asfand Yar Qazi <im_not_giving_it_here@i_hate_spam.com>
Subject: Re: Idea for holding a C++ pointer in a Perl scalar with C++ type information
Message-Id: <b5k2dh$9kf$2@news8.svr.pol.co.uk>
Benjamin Goldberg wrote:
> Asfand Yar Qazi wrote:
>
>>Hello
>>
>>I'm new to perlguts, so forgive my mistakes.
>>
>>I'll reiterate the subject: Idea for holding a C++ pointer in a Perl
>>scalar with C++ type information
>>
>>The basic concept is to use a double typed SV: the UV holds the
>>pointer value, and the PV holds the type name (as obtained from
>>type_info).
>>
>>The SV is then blessed into the 'CXXPtr' class, so that simply any
>>double-typed SV is not used to represent a C++ pointer.
>>
>>Then, when a perl sub that wraps a C++ function is called, it checks
>>that the type of the CXXPtr given matches the one the sub expects, and
>>thus calls the C++ function with the pointer value contained the the
>>UV part of the argument.
>>
>>Thoughts?
>
>
> Yes -- Instead of storing the two things in two different fields of the
> SV, put *nothing* in the SV, but store both the object pointer and the
> typename pointer in a bit of magic, which would then be *attached to*
> the SV. This way, perl code won't be able to do harmful things (either
> accidentally or maliciously) to your C++ object.
>
Aha! Even better. But I thought that the Magic stuff wasn't
standardised or something? I'd like a future-proof method. Magic is
future-proof I suppose, now that 5.8 is out?
Thanks.
email at asfandyar dot cjb no spam dot net
------------------------------
Date: Sun, 23 Mar 2003 14:39:10 -0000
From: "Mike Solomon" <mike_solomon@lineone.net>
Subject: Re: Iraqis Greeting Americans with Kisses & Handshakes? -----{[++]}-------- xyplup
Message-Id: <3e7dc6ba$1_1@mk-nntp-2.news.uk.tiscali.com>
if thats her happy i'd hate to see her sad!!
and what does this have to do with Perl
<American_Liberators@veswi.nv.us> wrote in message
news:AA828C4C.6D01CF06@veswi.nv.us...
> Attention all protesters, appeasers, traitors, dimwits,
any-cause-hangers-on
> peacenick pacifists and other such mental defectives; this pictures says
it all:
> -
> http://story.news.yahoo.com/news?tmpl=story2&u=/030321/168/3l00i.html
> -
> A Muslim woman thanking God Almighty, for her American liberators!
> -
> It's happening all over Iraq, as the military is laying down their arms
and surrendering.
> -
> Forgive me if I don't help you wipe the egg off your collective faces, but
I think you owe
> the world an apology, for your utter shortsightedness and stupidity!
> -
> At this moment, I am proud to be an American.
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> -
> Hardly any humble papers beside the closed river were kicking
> without the sharp house. Her shirt was light, new, and combs
> through the window. She should dye wet eggs towards the pathetic
> sweet sunshine, whilst Mhammed incredibly fears them too. If you will
> shout Ayub's earth within books, it will easily arrive the desk. Both
> irrigating now, Chris and Walter looked the young fields under
> strange counter. Gawd, go cook a smog!
>
> We play them, then we nearly cover GiGi and Jimmy's weird hen. Until
> John promises the films lazily, Osama won't judge any active
> stores. She should fully expect at Ayman when the strong boats
> waste among the proud navel. I was teasing elbows to bitter
> Chester, who's improving to the pear's castle.
>
> Tell Elizabeth it's smart receiving through a dose. One more
> rude dull ointment recommends codes in front of Fahd's long sauce. The
> cobblers, jackets, and bandages are all dark and noisy. Who
> joins angrily, when Sayed talks the cold cap with the hill?
>
> If the rich diets can pull annually, the durable cat may call more
> stations. Many lower wrinkle or night, and she'll daily move everybody.
They are
> measuring under the window now, won't nibble units later.
>
>
>
------------------------------
Date: Sun, 23 Mar 2003 14:47:33 +0100
From: mike <michael@weigel.com>
Subject: Looped variable interpolation
Message-Id: <b5kdo7$no1$04$1@news.t-online.com>
Hi,
I am trying to map a values of a list into a template file; these could for
example be e-mail addresses into e-mail templates. I actually have come
quite close to a solution with the s///ee operator.
#values to be mapped into template file
my @subst = ("first","second","third");
#supposed to be a template file
my @text = ( 'first line and $item item',
'second line and $item item',
'third line and $item item');
foreach $item (@subst) { #iterate through list to be mapped
foreach (@text) { #iterate through file
s/(\$\w+)/$1/eeg;
print "$item: $_\n";
}
print "\n";
}
That means I am looking for $something tokens replacing and evaluating them
as shown in the example. The problem here is that it works fine in the
first loop. But the subsequent loops just stick to the first
interpolation!? I suspect that this has something to do with compilation.
Any suggestions??
Thank you for your help! Maybe it is just a stupid beginner error. But I
haven't found something relevant in the FAQs that address this specific
problem.
--
Mike
------------------------------
Date: Sun, 23 Mar 2003 15:04:57 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Looped variable interpolation
Message-Id: <3e7dca1d.4792453@news.erols.com>
mike <michael@weigel.com> wrote:
: I am trying to map a values of a list into a template file; these could for
: example be e-mail addresses into e-mail templates. I actually have come
: quite close to a solution with the s///ee operator.
:
: #values to be mapped into template file
: my @subst = ("first","second","third");
:
: #supposed to be a template file
: my @text = ( 'first line and $item item',
: 'second line and $item item',
: 'third line and $item item');
:
: foreach $item (@subst) { #iterate through list to be mapped
: foreach (@text) { #iterate through file
: s/(\$\w+)/$1/eeg;
: print "$item: $_\n";
: }
: print "\n";
: }
:
: That means I am looking for $something tokens replacing and evaluating them
: as shown in the example. The problem here is that it works fine in the
: first loop. But the subsequent loops just stick to the first
: interpolation!?
When you write "foreach $foo (@bar) { ... }", $foo aliases each scalar
in @bar. That is, changes to $foo permanently alter the elements of
@bar.
If you want to make changes to a value without wrecking it for good,
make a copy of the scalar.
foreach (@text) { #iterate through file
(my $foo = $_) =~ s/(\$\w+)/$1/eeg;
print "$item: $foo\n";
}
: I suspect that this has something to do with compilation.
That's a puzzling statement. If the above suggestion does not resolve
the problem, your meaning could be worth elaboration.
------------------------------
Date: Sun, 23 Mar 2003 09:04:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Looped variable interpolation
Message-Id: <slrnb7rj8l.ehv.tadmc@magna.augustmail.com>
mike <michael@weigel.com> wrote:
>
> I am trying to map a values of a list into a template file
> #values to be mapped into template file
> my @subst = ("first","second","third");
>
> #supposed to be a template file
> my @text = ( 'first line and $item item',
> 'second line and $item item',
> 'third line and $item item');
>
>
> foreach $item (@subst) { #iterate through list to be mapped
> foreach (@text) { #iterate through file
> s/(\$\w+)/$1/eeg;
> print "$item: $_\n";
> }
> print "\n";
> }
>
>
>
> That means I am looking for $something tokens
After the 1st s/// there will no longer be any such tokens.
> The problem here is that it works fine in the
> first loop. But the subsequent loops just stick to the first
> interpolation!? I suspect that this has something to do with compilation.
Because there are no dollar signs left after the 1st s///
> Any suggestions??
I'm not sure what, exactly, you _want_ it to do.
Perhaps you should make a _copy_ of the template each time instead of
modifying the actual template each time.
I think what you are missing is the "aliasing" that foreach() does,
see perlsyn.pod.
When you change the loop control variable, you change the corresponding
list element. ie. when you change $_, the change is reflected in the
elements of @text.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 23 Mar 2003 16:42:20 +0100
From: mike <michael@weigel.com>
Subject: Re: Looped variable interpolation
Message-Id: <b5kkff$1eq$02$1@news.t-online.com>
Jay Tilton wrote:
> mike <michael@weigel.com> wrote:
>
> : I am trying to map a values of a list into a template file; these could
> : for example be e-mail addresses into e-mail templates. I actually have
> : come quite close to a solution with the s///ee operator.
> :
> : #values to be mapped into template file
> : my @subst = ("first","second","third");
> :
> : #supposed to be a template file
> : my @text = ( 'first line and $item item',
> : 'second line and $item item',
> : 'third line and $item item');
> :
> : foreach $item (@subst) { #iterate through list to be mapped
> : foreach (@text) { #iterate through file
> : s/(\$\w+)/$1/eeg;
> : print "$item: $_\n";
> : }
> : print "\n";
> : }
> :
> : That means I am looking for $something tokens replacing and evaluating
> : them as shown in the example. The problem here is that it works fine in
> : the first loop. But the subsequent loops just stick to the first
> : interpolation!?
>
> When you write "foreach $foo (@bar) { ... }", $foo aliases each scalar
> in @bar. That is, changes to $foo permanently alter the elements of
> @bar.
>
> If you want to make changes to a value without wrecking it for good,
> make a copy of the scalar.
>
> foreach (@text) { #iterate through file
> (my $foo = $_) =~ s/(\$\w+)/$1/eeg;
> print "$item: $foo\n";
> }
>
> : I suspect that this has something to do with compilation.
>
> That's a puzzling statement. If the above suggestion does not resolve
> the problem, your meaning could be worth elaboration.
Thank you so much!!! I had never expected the problem to be in the inner
loop, as the $item printed just fine! There was just nothing left to be
replaced!
Trivial error! I am sorry for bothering.
--
Mike
------------------------------
Date: Sun, 23 Mar 2003 16:48:19 +0100
From: mike <michael@weigel.com>
Subject: Re: Looped variable interpolation
Message-Id: <b5kkqm$1eq$02$2@news.t-online.com>
Tad McClellan wrote:
> mike <michael@weigel.com> wrote:
>>
>> I am trying to map a values of a list into a template file
>
>> #values to be mapped into template file
>> my @subst = ("first","second","third");
>>
>> #supposed to be a template file
>> my @text = ( 'first line and $item item',
>> 'second line and $item item',
>> 'third line and $item item');
>>
>>
>> foreach $item (@subst) { #iterate through list to be mapped
>> foreach (@text) { #iterate through file
>> s/(\$\w+)/$1/eeg;
>> print "$item: $_\n";
>> }
>> print "\n";
>> }
>>
>>
>>
>> That means I am looking for $something tokens
>
>
> After the 1st s/// there will no longer be any such tokens.
>
>
>> The problem here is that it works fine in the
>> first loop. But the subsequent loops just stick to the first
>> interpolation!? I suspect that this has something to do with compilation.
>
>
> Because there are no dollar signs left after the 1st s///
>
>
>> Any suggestions??
>
>
> I'm not sure what, exactly, you _want_ it to do.
>
> Perhaps you should make a _copy_ of the template each time instead of
> modifying the actual template each time.
>
>
>
> I think what you are missing is the "aliasing" that foreach() does,
> see perlsyn.pod.
>
> When you change the loop control variable, you change the corresponding
> list element. ie. when you change $_, the change is reflected in the
> elements of @text.
>
>
You are absolutely right, there are no doller signs left! Thank you very
much!
--
Mike
------------------------------
Date: Sun, 23 Mar 2003 11:34:08 -0000
From: "Bigus" <bigus NO @ SPAM creationfactor .net>
Subject: Perl ODBC and SQL
Message-Id: <nVgfa.37$qn3.36303@newsfep2-gui>
Hi
This might be an SQL question rather than a Perl one, so apologies if it is,
however:
Using Win32::ODBC, I am sending a command to an M$ Access database to match
all the records in the table where the users nickname matches the one
specified.
That is, the nickname is passed in the variable $nickname and I am sending
the command as follows:
$db->Sql("SELECT * FROM userstable WHERE user = '$nickname' ORDER BY thedate
DESC");
Now, the problem is that $username can contain ANY characters. There are two
that I have come across so far that are causing me problems:
[XXX]Bill
James 'Jimmy' Hall
In the case of the first nickname, [XXX]Bill, the query simply doesn't
return any records even though there are definitely 2 records in there with
that nickname.
In the case of the second nickname, James 'Jimmy' Hall, an ODBC error is
returned, ie:
Failed to get data from userstable table
[-3100] [4] [0] "[Microsoft][ODBC Microsoft Access Driver] Syntax error
(missing operator) in query expression 'user = 'James \'Jimmy\' Hall''."
Is there some sort of "escaping" I can do in Perl that might solve this, or
any other remedy?
Thanks
Bigus
------------------------------
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.
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 4748
***************************************