[25277] in Perl-Users-Digest
Perl-Users Digest, Issue: 7522 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 15 18:05:46 2004
Date: Wed, 15 Dec 2004 15:05:05 -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 Wed, 15 Dec 2004 Volume: 10 Number: 7522
Today's topics:
Re: [Slightly OT] Perl interpreter (win32) single "thre <not@home.net>
Re: [Slightly OT] Perl interpreter (win32) single "thre <emschwar@pobox.com>
Can't get past 'use strict' :( <_karlo_@_mosor.net_>
Re: Can't get past 'use strict' :( <leendert@wouter.unitedknowledge.net>
Re: Can't get past 'use strict' :( <rzilavec@tcn.net>
Re: Can't get past 'use strict' :( <phaylon@dunkelheit.at>
Re: Can't get past 'use strict' :( <matternc@comcast.net>
Re: Can't get past 'use strict' :( <matternc@comcast.net>
Re: Can't get past 'use strict' :( <noreply@gunnar.cc>
Re: Can't get past 'use strict' :( <_karlo_@_mosor.net_>
Re: go to a link, save the page and email it out? dalewz@gmail.com
How to go to a link and save a page and email it out? dalewz@gmail.com
Re: Pattern Matching <nospam@nospam.com>
Re: Quick easy question... (IFR LIT MET\)
Re: Session management for cgi, ldap, oracle? <apeiron+usenet@coitusmentis.info>
Re: Session management for cgi, ldap, oracle? <amead@comcast.net>
Re: socket script dies <dontmewithme@got.it>
use external files as "HERE-docs" (and avoid the undefi <abrey@gmx.net>
Re: use external files as "HERE-docs" (and avoid the un <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Dec 2004 20:03:01 GMT
From: "JayEs" <not@home.net>
Subject: Re: [Slightly OT] Perl interpreter (win32) single "threaded"?
Message-Id: <VL0wd.40043$bP2.13090@newssvr12.news.prodigy.com>
> The code we're looking for is the code that exhibits the problem that
> makes you think it might be single-threaded. I, and possibly others,
> have a sneaking suspicion that the problem is in your code, or
> possibly in Windows, not in Perl. But until we see your code, we
> don't know if your question is even relevant to your real problem.
My suspicion is no longer sneaking, it is throdding down the hill in a 4X4
with monster tires. And we of course disagree. I do not know how Perl
handles http requests (as that is what my code -- for the moment anyway --
is all about) but unless the problem is with Mech or IE::Mech, it has to be
this particular windows distribution (ActiveState 5.8)
> This is also known as an X-Y problem. You're asking for X-- whether
> or not Perl is single-threaded, but you really want Y-- the ability to
> modify one file from multiple programs at once. If we see the code
> you're using, we may be able to make suggestions as to how to
> accomplish your goals another way, but we can't do that without code.
Not really, you are correct in assuming that X = "Is Perl (on Win32) Single
threaded", but Y != "ability to modify one file from multiple programs".
There is a Y (there always is) but it's not releveant to X in that for now X
is a showstopper. If I can't "fix" X, then everything else becomes
irrelevant. I need the ability to spawn multiple Perl scripts from 1
application that is not written in Perl. I can justify rewriting portions of
this app to work with Perl, I cannot justify rewriting the entire
application to work with Perl.
> I have no idea if you have any Computer Science background,
That's OK, I never told you I did ;-) Of course the words computer and
science are an oxymoron to begin with, but that is a different discussion.
> but Rule
> #1 that is pounded into every undergraduate's head from their first
> "Pascal for Barely Subliterate Morons" class
Never took Pascal, lucky me!
> It doesn't matter what you
> think you're doing right, the compiler is fine, it's your code that's
> broken.
I have to agree. This particular problem goes a bit beyond that though. The
code runs fine in the IDE and runs fine by itself when started through the
compiler as well as compiled into an executable (There! I said it I am on a
windows platform, so slap me already <g>)
> You're assuming it's Perl's
> fault, and we're not.
I am not passing judgement. I am assuming that this particular distribution
of Perl has a threading mechanism that cause the aforementioned behavior
when simultaneous copies are started. There could be a very good reason for
that, I am certainly not aware of it and I have never written any compilers
nor do I feel the desire to. Perl or any other languages that I've used do
me just fine.
> But until we can see your code, we can't know whether
> you're right or not, because any attempts we make to reproduce the
> problem are most likely going to fail because we don't use the
> peculiar combintion and ordering of functions that are exposing the
> particular problem you see.
Nothing really peculiar about it. The code is navigates to a URL, fills in
some fields, clicks on a button and saves the output to a variable. The
problem is that we are using a web server that has no connection going
outside (it's a testmachine) and that the HTML documents we are accessing
with the perl scripts are thus not available to the NG community at large.
To remedy this, we would have to open the server to the outside (not gonna
happen) or you would have to reproduce our test-intranet (or at least parts
of it) on your web server (highly unlikely). So what I am left with is
posting some psuedo-version of the scripts which is highly advised against
in posting guidelines.
> The problem is that you're wrong--
> it IS relevant, and your increasingly combative tone is reducing the
> quality of answers you're going to get by offending the most
> knowledgeable posters here.
The problem with any NG, not just this one, is that you can never know (for
sure) what the skill level on the other end is. You might be dealing with a
total noobie or a skilled developer. Some of that information can be gained
by reading the OP. Obviously a question like: Why does this not work,
followed by code such as:
my $var = "test"
print 'I am printing $var'
is coming from a) Ignoramus that didn't read the faq or b) Someone entirely
clueless. My "increasingly combaitive tone" comes from being treated (by
default) as A or B, while I consider myself to be C. I am the kind of person
that responds far better to replies like "Why do you think it is not in your
code?" then to replies "Post code - Read guidelines"
> And all anyone here is doing is trying to tell you how to get it. You
> don't seem stupid, and I'm hoping you're educable, or else I've wasted
> my time composing this message, and I hate wasting my time.
I think I am halfway educable... I was going to say, look at what I have
accomplished so far in life but then I realized that there are total morons
out there that have accomplished far more than myself by total happenstance,
so I will gladly forfit the patting myself on the back.
Thank you for your time to reply. I really appreciate it. I hope you can see
my dillema, we either assume it's not in the code but with the distribution
and can have a discussion about it or we assume it *IS* in the code and
we'll never know the answer....
Regards,
JS
------------------------------
Date: Wed, 15 Dec 2004 14:09:22 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: [Slightly OT] Perl interpreter (win32) single "threaded"?
Message-Id: <etois73z2t9.fsf@wilson.emschwar>
"JayEs" <not@home.net> writes:
> Thank you for your time to reply. I really appreciate it. I hope you can see
> my dillema, we either assume it's not in the code but with the distribution
> and can have a discussion about it or we assume it *IS* in the code and
> we'll never know the answer....
But if we have your code, then we WILL know the answer! I'm starting
to wonder why I'm bothering-- you're clearly not stupid, but you seem
impressively resistant to learning. The point is, if we see your
actual, honest-to-Ghu code, not your necessarily vague description of
it, that's the only way we CAN rule out your code being at fault.
But it seems you don't actually want any help, so I will stop
bothering here. If you post code, you'll get help. If you don't, you
won't. Have fun, either way.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 15 Dec 2004 16:37:05 GMT
From: Karlo Lozovina <_karlo_@_mosor.net_>
Subject: Can't get past 'use strict' :(
Message-Id: <Xns95C0B356F954Bkarlomosornet@130.133.1.4>
Here I go again: the following code:
while(my $line = <DIRLIST>) {
my $dir_list[$i] = $line;
chomp($dir_list[$i]);
$i++;
}
produces this error:
syntax error at ./backup.pl line 24, near "$dir_list["
when i use "use strict". I read Programming Perl's chapter on strict,
but I can't get this thing working :(.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----.
| || _ | _ | Na osami blizu mora, dok se sunce zemlji smije
|__|_|__||_____|_____| Balun gledat, za njin letit...
------------------------------
Date: Wed, 15 Dec 2004 17:59:01 +0100
From: "Leendert Bottelberghs" <leendert@wouter.unitedknowledge.net>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <pan.2004.12.15.16.59.01.133207@wouter.unitedknowledge.net>
Op Wed, 15 Dec 2004 16:37:05 +0000, schreef Karlo Lozovina:
> Here I go again: the following code:
>
> while(my $line = <DIRLIST>) {
> my $dir_list[$i] = $line;
> chomp($dir_list[$i]);
> $i++;
> }
>
> produces this error:
>
> syntax error at ./backup.pl line 24, near "$dir_list["
>
I'm not sure where the problem lies, but this can definitely be done more
efficient. Try:
chomp(my @line = <DIRLIST>);
-leendert bottelberghs
------------------------------
Date: Wed, 15 Dec 2004 12:07:52 -0500
From: "Richard Zilavec" <rzilavec@tcn.net>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <cppqvp$40v$1@utornnr1pp.grouptelecom.net>
"Karlo Lozovina" <_karlo_@_mosor.net_> wrote in message
news:Xns95C0B356F954Bkarlomosornet@130.133.1.4...
> Here I go again: the following code:
>
> while(my $line = <DIRLIST>) {
> my $dir_list[$i] = $line;
^^^^^^^^^^^ this is an array.... declare it above
> chomp($dir_list[$i]);
> $i++;
> }
>
use strict;
my(@dir_list, $i);
while(my $line = <DIRLIST>) {
$dir_list[$i] = $line;
# Removed my();
chomp($dir_list[$i]);
$i++;
}
Richard Zilavec
------------------------------
Date: Wed, 15 Dec 2004 18:05:10 +0100
From: Robert Sedlacek <phaylon@dunkelheit.at>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <pan.2004.12.15.17.05.07.6154@dunkelheit.at>
Karlo Lozovina wrote:
> while(my $line = <DIRLIST>) {
> my $dir_list[$i] = $line;
^^ ^ ^ ^
> chomp($dir_list[$i]);
> $i++;
> }
Besides Leendert's much better hint:
I think you meant to define @dir_list out of this loop and just push new
elements to the array. You don't have to declare every element of that ary.
How about this (untested):
my @dir_list;
while(my $line = <DIRLIST>) {
chomp $line;
push @dir_list, $line;
}
my $i = @dir_list # if needed, but i don't think so..
g,
Robert
--
http://www.dunkelheit.at/
thou shallst fear...
------------------------------
Date: Wed, 15 Dec 2004 12:32:56 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <lYGdnQXSRfXX6F3cRVn-hw@comcast.com>
Karlo Lozovina wrote:
> Here I go again: the following code:
>
> while(my $line = <DIRLIST>) {
> my $dir_list[$i] = $line;
> chomp($dir_list[$i]);
> $i++;
> }
>
> produces this error:
>
> syntax error at ./backup.pl line 24, near "$dir_list["
>
> when i use "use strict". I read Programming Perl's chapter on strict,
> but I can't get this thing working :(.
>
You can't declare an array variable like that. Nor can I see
*why* you'd want to declare an array variable like that. You
can get it to compile like this:
while (my $line = <DIRLIST>) {
my @dir_list;
$dir_list[$i] = $line;
chomp($dir_list[$i]);
$i++;
}
This makes @dir_list disappear as soon as your while loop
ends. Is this what you want? If you want @dir_list to
be visible outside the list, then you want this:
my @dir_list;
while (my $line = <DIRLIST>) {
$dir_list[$i] = $line;
chomp($dir_list[$i]);
$i++;
}
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Wed, 15 Dec 2004 12:34:16 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <lYGdnQTSRfUF6F3cRVn-hw@comcast.com>
Leendert Bottelberghs wrote:
> Op Wed, 15 Dec 2004 16:37:05 +0000, schreef Karlo Lozovina:
>> Here I go again: the following code:
>>
>> while(my $line = <DIRLIST>) {
>> my $dir_list[$i] = $line;
>> chomp($dir_list[$i]);
>> $i++;
>> }
>>
>> produces this error:
>>
>> syntax error at ./backup.pl line 24, near "$dir_list["
>>
>
> I'm not sure where the problem lies, but this can definitely be done more
> efficient. Try:
>
> chomp(my @line = <DIRLIST>);
>
Well, yes, that's the best way, but let's go one step at a time...
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Wed, 15 Dec 2004 18:48:43 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <32bc74F3kb86uU1@individual.net>
Chris Mattern wrote:
> You can get it to compile like this:
>
> while (my $line = <DIRLIST>) {
> my @dir_list;
> $dir_list[$i] = $line;
> chomp($dir_list[$i]);
> $i++;
> }
>
> This makes @dir_list disappear as soon as your while loop
> ends.
Not only does it go out of scope, but it also contains only the last
line before doing so, since my() clears the array at each iteration.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 15 Dec 2004 18:20:04 GMT
From: Karlo Lozovina <_karlo_@_mosor.net_>
Subject: Re: Can't get past 'use strict' :(
Message-Id: <Xns95C0C4CD5353Dkarlomosornet@130.133.1.4>
Chris Mattern <matternc@comcast.net> wrote in
news:lYGdnQXSRfXX6F3cRVn-hw@comcast.com:
> my @dir_list;
> while (my $line = <DIRLIST>) {
> $dir_list[$i] = $line;
> chomp($dir_list[$i]);
> $i++;
> }
Yup, this is what I needed. Thank you very much for clearing this out.
I had one day to write a rather big Perl program today, but I never
programmed in Perl before. Althoug Perl is quite easy to catch up,
after a days work it is easy to mix things up :).
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----.
| || _ | _ | Na osami blizu mora, dok se sunce zemlji smije
|__|_|__||_____|_____| Balun gledat, za njin letit...
------------------------------
Date: 15 Dec 2004 09:02:23 -0800
From: dalewz@gmail.com
Subject: Re: go to a link, save the page and email it out?
Message-Id: <1103130143.018741.321080@f14g2000cwb.googlegroups.com>
HTML::Mail works for some web sites. But some web sites have
protections for reading some files, which is expected. THe results are:
C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.
C:\Perl\scripts>
-----Mail.pm
164 my $response = $self->{'_ua'}->get($uri);
165
166 if (!$response->is_success) {
167 die "Error while making request [ GET ", $response->request->uri,
"]\n", $response->status_line;
168 }
However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?
Thanks a lot. -Dale
------------------------------
Date: 15 Dec 2004 08:18:45 -0800
From: dalewz@gmail.com
Subject: How to go to a link and save a page and email it out?
Message-Id: <1103127525.493114.311790@c13g2000cwb.googlegroups.com>
Thanks for helps here. I tried the simple method - HTML::Mail.
HTML::Mail works for some web sites. But it does not work for some. The
results are:
C:\Perl\scripts>mailp.pl
Error while making request [ GET
http://www.macom.com/Images/darkblue_bgcolor.gi
f]
404 Object Not Found at C:/Perl/lib/HTML/Mail.pm line 167.
C:\Perl\scripts>
-----Mail.pm
164 my $response = $self->{'_ua'}->get($uri);
165
166 if (!$response->is_success) {
167 die "Error while making request [ GET ", $response->request->uri,
"]\n", $response->status_line;
168 }
However, if I use IE to open www.macom.com, I can save the page with
all images. Any suggestions?
Thanks a lot. -Dale
PS> my script is:
use HTML::Mail;
### initialisation
my $html_mail = HTML::Mail->new(
HTML => 'http://www.macom.com',
>From => 'supertrader49@verizon.net',
To => 'dalewz@yahoo.com, daledale66@yahoo.com',
Subject => 'Alert page');
### Send the email ("inherited" from MIME::Lite)
# $html_mail->send();
$html_mail->send('smtp','outgoing.verizon.net');
#### Remove text representation
$html_mail->set_Text();
### Rebuild the message and send
$html_mail->build->send;
### Serialise to file for later reuse
$html_mail->dump_file('c:/html_mail.data');
### Restore from file
my $restored = HTML::Mail->restore_file('c:/html_mail.data');
------------------------------
Date: Wed, 15 Dec 2004 11:26:25 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: Pattern Matching
Message-Id: <1103127970.610582@nntp.acecape.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:obZvd.5916$mn6.1824@trnddc07...
> Sorry for asking the obvious, but if this is so, then why don't you simply
> negate the character class?
well this is the cleanest i have gotten it so far:
if($last_name =~ /[^\w`\']|_|\s/ |[0-9])
{
....insert invalid msg here
}
and it's not as ugly as the other one, but again, it just leads me to think,
what did i miss, or leave out? and as someone pointed out, in different
languages there are accented letters, ALT 0193 for instance. so was hoping
a shortcut existed that covered "legal names"
------------------------------
Date: Wed, 15 Dec 2004 16:00:00 -0500
From: "Richards Noah \(IFR LIT MET\)" <Noah.Richards@infineon.com>
Subject: Re: Quick easy question...
Message-Id: <cpq8ki$ej7$1@athen03.muc.infineon.com>
"Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com> wrote in message
news:328p0iF3hnftcU1@individual.net...
> "Richard Gration" <richard@zync.co.uk> wrote in message
> > >> How about this?
> > >>
> > >> perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
> > >
> > > Hey, that's a joke, right? You can't be serious...
> > >
> > > Anno
> >
> > Well, it's a joke in the sense that I thought I smelled homework
> therefore
> > tried to obfuscate the answer :-)
>
> I may have just been someone who is just starting out. I've yet to se
> Perl taught in college courses (I haven't seen any available in any
> colleges around here nor where I've attended.)
>
Perl is tought in schools near mine and including mine (RIT). While that
has
no bearing on whether or not this question was homework, you're reasoning
doesn't really debunk anything (well, I've never seen it, so it must not
exist).
> Even if it was home work, sometimes it can help a learner from working
> by examples. When I was first learning Perl a few years ago, I was
> constantly trying new things, see what would work, looking up examples
> online and in docs, and in deja/google-groups.
Learning by example is incredibly useful, but learning by others doing your
homework questions for you isn't exactly ethical.
> True he could of found the answer by looking elsewhere (I think this one
> might be in the FAQ), though I think pushing someone like this in the
> right direction, who may not have /yet/ gotten a feel of how things work
> around here. That is, tell them where the many good places are to look
> (google, FAQ, perldoc, etc), instead of confusing them even more :-)
Whether or not you are familiar with the newsgroup, submitting homework
questions for others to due is tantamount to plagiarism. Of course, this
may
not be homework, which is why people responded with "what have you tried
so far, and what has occurred?"
The sad thing, really, is that people do resort to newsgroups to answer
homework
questions. It has happened at my school often enough for professors to
check all
major homework/project submissions against each other (in terms of coding
styles,
which is automated by some program/script) and some minor homework against
internet sources.
------------------------------
Date: 15 Dec 2004 16:43:32 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Session management for cgi, ldap, oracle?
Message-Id: <slrncs0qdk.29gt.apeiron+usenet@prophecy.dyndns.org>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-12-15, Alan Mead scribbled these
curious markings:
> Star date: Tue, 14 Dec 2004 17:24:17 -0800, spam1.minus1's log:
That's not a stardate. If you're going to try to make yourself into a
geek, you may as well use a Gregorian->stardate converter. :)
>> 2. solaris, apache, cgi, oracle, perl 5.005, LDAP 3
>
> I would prefer Perl 5.6 or higher.
Apparently you missed the large thread about Solaris and Perl. It was
mentioned numerous times that the 5.005 version of Perl shipped with
Solaris is required for compatability with the Perl scripts that ship
with Solaris.
Best Regards,
Christopher Nehren
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)
iD8DBQFBwGmzk/lo7zvzJioRAnWOAJ0VU+I6Gphm8ygWqehhDgzss2zPKwCfYJTa
ZzwT/mn+73DOpgHo/r9QVsA=
=FAj+
-----END PGP SIGNATURE-----
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Wed, 15 Dec 2004 16:53:24 -0600
From: Alan Mead <amead@comcast.net>
Subject: Re: Session management for cgi, ldap, oracle?
Message-Id: <pan.2004.12.15.22.53.23.748648@comcast.net>
Star date: Wed, 15 Dec 2004 16:43:32 +0000, Christopher Nehren's log:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> On 2004-12-15, Alan Mead scribbled these
> curious markings:
>> Star date: Tue, 14 Dec 2004 17:24:17 -0800, spam1.minus1's log:
>
> That's not a stardate. If you're going to try to make yourself into a
> geek, you may as well use a Gregorian->stardate converter. :)
I don't think Pan will do that but now I'm curious :)
>>> 2. solaris, apache, cgi, oracle, perl 5.005, LDAP 3
>>
>> I would prefer Perl 5.6 or higher.
>
> Apparently you missed the large thread about Solaris and Perl. It was
> mentioned numerous times that the 5.005 version of Perl shipped with
> Solaris is required for compatability with the Perl scripts that ship
> with Solaris.
I'm glad you chimed in, I know nothing about Solaris.
Hmm. But I think I would still recommended 5.6+... The inescapable
conclusion then being "Don't use Solaris if you don't have to."
-Alan
------------------------------
Date: Wed, 15 Dec 2004 21:04:03 GMT
From: Larry <dontmewithme@got.it>
Subject: Re: socket script dies
Message-Id: <dontmewithme-EC38E1.22030515122004@twister1.tin.it>
eureka!
it seems like i've sorted it out!
at first, I tried this:
#!/perl
@nomi = keys(%SIG);
for my $nomesig (@nomi) {$SIG{$nomesig} = 'IGNORE';}
but i found that this would be better:
#!/perl
sub handleruniversale
{
print "\ngot a signal $_[0]\n";
$SIG{$_[0]} = \&handleruniversale;
}
@nomi = keys(%SIG);
for my $nomesig (@nomi) {$SIG{$nomesig} = \&handleruniversale;}
so i discovered that i gotta put this on my script:
local $SIG{NUM13} = 'IGNORE';
what the hell is $SIG{NUM13} ???
see you guys!
Gaetano
------------------------------
Date: 15 Dec 2004 09:33:51 -0800
From: "dede" <abrey@gmx.net>
Subject: use external files as "HERE-docs" (and avoid the undefined substitions)
Message-Id: <1103132031.904486.14360@z14g2000cwz.googlegroups.com>
Hello friends of the community,
find below the solution I am currently using to load external
text-files that
are seamlessly interpolated to behave like the useful HERE-docs:
echo <<"EOT";
Hello $strWorld ...
EOT
SNIPPET:
while (<$handle>) {
$_ =~ s/(\$\S+)/defined eval($1) ? eval($1) : $1/gsxe;
#interpolate all $vars or $self->vars etc.
#note that this "old test"...
#$_ =~ s/(\$\w+)/defined $1 ? $1 : "undefined"/gsxee;
#produced the notorious "undefined substitution errors"
#here might be some extra cleanup-work of the file
push @lines, $_;
} #each line;
close $handle;
A.
Note that you can substitute ANY var or OO-pseudo hash-var (ie.
inst-var)
from the namespace of the context (function/method) that this snippet
resides in.
B.
You might also be more specific and include some static text in the
search
pattern and then add some .. eval('whatever'.$1.'foo') .. stuff.
C.
Note that the defined eval (...) is necessary in order to return values
that
Perls likes to interpret as FALSE (eg. '' or 0).
Any comments / immprovements are welcome.
Share and Enjoy :)
dede, Paris / France
------------------------------
Date: Wed, 15 Dec 2004 17:51:22 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: use external files as "HERE-docs" (and avoid the undefined substitions)
Message-Id: <uQ_vd.5673$eO5.3804@trndny08>
"dede" <abrey@gmx.net> wrote in message
news:1103132031.904486.14360@z14g2000cwz.googlegroups.com...
> $_ =~ s/(\$\S+)/defined eval($1) ? eval($1) : $1/gsxe;
my $str = 'line';
$_ = 'What about ${str}s like this?';
Paul Lalli
------------------------------
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 7522
***************************************