[19743] in Perl-Users-Digest
Perl-Users Digest, Issue: 1938 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 16 11:05:34 2001
Date: Tue, 16 Oct 2001 08:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1003244711-v10-i1938@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 16 Oct 2001 Volume: 10 Number: 1938
Today's topics:
A bug in s///e? <bart.lateur@skynet.be>
Re: A bug in s///e? <bart.lateur@skynet.be>
ANSI Color under WIN NT 4.0 <Landeck.c@zdf.de>
Re: Checking if a file exists <tony_curtis32@yahoo.com>
Re: counting substrings in strings <none@none.none>
Re: Don't want to invent the wheel <Thomas@Baetzler.de>
Re: Help on wait and get process ids.. (Martien Verbruggen)
Re: HELP: cropping lines? <bart.lateur@skynet.be>
Re: how to logout from icewm or oroborus ?? <jurgenex@hotmail.com>
Re: Need cgi script jh123@nc.rr.com
Re: Need cgi script <bernard.el-hagin@lido-tech.net>
Re: Need cgi script <james@zephyr.org.uk>
Re: Need cgi script <bart.lateur@skynet.be>
Net::FTP Problem in ascii mode <dump@the-core.net>
Re: Net::FTP Problem in ascii mode <Thomas@Baetzler.de>
Re: Net::FTP Problem in ascii mode <kai@jendrian.de>
Re: Net::FTP Problem in ascii mode <dump@the-core.net>
Re: problem in getting directory list and filelist thro <bart.lateur@skynet.be>
problems with autoloader <paule.p-deleteme-@gmx.de>
put more simply: putting $1..$9 into a replacement stri (=?ISO-8859-1?Q?sh=F2wd=F6g?=)
Re: put more simply: putting $1..$9 into a replacement <bart.lateur@skynet.be>
Re: put more simply: putting $1..$9 into a replacement <sguazt@infodrome.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Oct 2001 14:38:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: A bug in s///e?
Message-Id: <mbhost4c2cii756ghfu2dgcj889ptpdndg@4ax.com>
Can anybody please explain why, when I do this:
my $repl='this is $1. hi there.';
my $search='(foo)';
my $s="X foo Y\n";
$_ = $s; s/$search/"$repl"/gi; print;
$_ = $s; s/$search/'"'.$repl.'"'/gie; print;
I get the same result for both:
X "this is $1. hi there." Y
X "this is $1. hi there." Y
but when I add an e to the modifiers, they behave differently:
my $repl='this is $1. hi there.';
my $search='(foo)';
my $s="X foo Y\n";
$_ = $s; s/$search/"$repl"/gie; print;
$_ = $s; s/$search/'"'.$repl.'"'/giee; print;
->
X this is $1. hi there. Y
X this is foo. hi there. Y
This is 5.6.1 (IndigoPerl, Win32)
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 14:52:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: A bug in s///e?
Message-Id: <m6iost4di59ps80abtunr3qc8euvboaaue@4ax.com>
Bart Lateur wrote:
>Can anybody please explain why,...
>when I add an e to the modifiers, they behave differently:
>
> my $repl='this is $1. hi there.';
> my $search='(foo)';
> my $s="X foo Y\n";
> $_ = $s; s/$search/"$repl"/gie; print;
> $_ = $s; s/$search/'"'.$repl.'"'/giee; print;
>->
> X this is $1. hi there. Y
> X this is foo. hi there. Y
>
>This is 5.6.1 (IndigoPerl, Win32)
It begins to make some sense. Not much, but...
It looks like the former executes the code snippet
"$repl"
and not, as I expected, firtst replace $repl and THEN eval it. Likely,
with one "e", eval() doesn't even come into play. I suppose the RHS is
compiled at startup, and the compiler sees the above snippet. Executed
as a plain string, this returns $repl as a string.
DWIM doesn't always do what you intend. :-/ I don't think this
behaviour makes a difference, most of the time.
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 15:12:08 +0200
From: "Carsten Landeck" <Landeck.c@zdf.de>
Subject: ANSI Color under WIN NT 4.0
Message-Id: <3bcc322c$0$227$4d4ebb8e@businessnews.de.uu.net>
I can't get colors on my screen with Term::ANSIcolor, altough I used
ansi.com or ansi.sys in config.nt. Does anybody has an example how it works
?
Thanks Carsten
------------------------------
Date: Tue, 16 Oct 2001 09:15:22 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Checking if a file exists
Message-Id: <87n12ry8lh.fsf@limey.hpcc.uh.edu>
[ top-posting rearranged ]
>> On Tue, 16 Oct 2001 09:46:59 +0100,
>> "Simon Pearce" <simonp@NOSPAM.dircon.co.uk> said:
> "Simon Pearce" <simonp@NOSPAM.dircon.co.uk> wrote in
> message news:9qgq4r$8d1$1@news6.svr.pol.co.uk...
>> Hi everyone :)
>>
>> I have a CGI perl script that opens a particular
>> document to read info
> from
>> it.
>>
>> What I would like to do is be able to check if that
>> file actually exists first - something like:
>>
>> if (file.txt does not exist) { &file_error; }
>>
> Thanks guys! That works great! Simon
I assume you then want to go and read from the file. Note
however that it is possible something could happen between
checking the file's existence and opening it for read.
The safer way would be simply to open the file for read.
If it's there, good, you now have a handle for reading its
contents. If not, you can see why you were unable to open
it ($!).
hth
t
--
Oh! I've said too much. Smithers, use the amnesia ray.
------------------------------
Date: Tue, 16 Oct 2001 16:45:06 +0200
From: "toti" <none@none.none>
Subject: Re: counting substrings in strings
Message-Id: <3bcc482f$1@news.barak.net.il>
I hope this will help:
$_ = "this is is a very strange sentense, is it?";
my $substring = "is";
my $count;
while (/\b$substring\b/ig)
{
$count++;
}
print "$substring = $count";
"shaz" <ssa1701@yahoo.co.uk> wrote in message
news:23e71812.0110111316.33ad8f63@posting.google.com...
> I want to count the number of times that a substring appears within a
> longer string.
>
> The following was suggested, but it does not work the way I would like
> it to.
>
> $check = grep { index($_, $substring) != -1 } keys %longstrings;
>
>
> This is being used in the following code: -
>
> foreach $substring (keys %substrings)
> {
> $check = grep { index($_, $substring) != -1 } keys %longstrings;
>
> if ($check != 0)
> {
> print "$substring found in longer strings";
> }
> }
>
> The problem with the code is:-
>
> If $substring = "the" it should find "the end" and "end the" etc
> BUT at the moment it also finds "there is" and "then" amongst others.
> This is not correct.
>
> NOTE: The substring will change as the foreach loop continues,
> therfore, it must be declared as a variable and not something like
> /^the/
>
> How can I can find the frequency of occurance of a substring within
> longer strings?
>
> I would perfer a method similar to that shown above (if possible),
> since I only need to make changes on that particular line of code.
------------------------------
Date: Tue, 16 Oct 2001 12:09:31 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Don't want to invent the wheel
Message-Id: <qp1ostok4qglkpbdu081c17ku2oh3v6oar@4ax.com>
On Tue, 16 Oct 2001, Remco van Veenendaal <remco@polderland.nl> wrote:
[looking for a particular CGI]
Wrong newsgroup. Try http://www.cgi-resources.com/
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Tue, 16 Oct 2001 20:36:44 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Help on wait and get process ids..
Message-Id: <slrn9so3dr.di2.mgjv@martien.heliotrope.home>
On 15 Oct 2001 23:56:37 -0700,
Rashyid <rra@excite.com> wrote:
> hi there again...
Hiya,
next time, please leave a bit of context in your posts. I only realised
that this was a response to me because of my scoring system. otherwise I
wouldn't have noticed it at all.
> well, actually i didn't make myslef clear... heres what i need to do
>
> A------------>B-------------->C-------------->D--......
>| | | |
>| | | |
> E F G H
>| | | |
>| | | |
> J L M N
This is a bit of a bad diagram. It looks as if A fires off B and E, and
E fires off J, and B fires off F and C, etc.
> from the diagram above, A,B,C....are *sub-procedures* that i need to
> call.
>
> each line shows a wait.. where, for eg once A finishes, E and B starts
> and then when B finishes running, C and F starts and so on.. the
> subprocedures basically are system calls that pass through variables
> and process the results..
>
> is there a syntax such like..
>
> run A
>
> if A finishes{run B; (run E and then J;)}
> if B finishes{run C; (run G and then M;)}
> if C finishes{run D; (run H and then N;)}
The answer was in the post that I sent to you.
# perldoc -f fork
# perldoc -f wait
# perldoc -f waitpid
Also read the perlipc documentaiton
# perldoc perlipc
You get the pid(s) from a(some) fork(s), you follow it with an exec of
the program you need to exec. Then the parent waits for either all
processes (wait, most likely), or for one process it is interested in
(waitpid). When waitpid returns, you can be certain the child process
has gone away.
Something like (pseudo code)
$pid = fork_and_exec A;
waitpid $pid;
fork_and_exec E
$pid = fork_and_exec B
waitpid $pid
fork_and_exec F
$pid = fork_and_exec C
etc..
You have not made it very clear what fires off J, L, M and N.
Oh.... wait... did you mean that J should be started as soon as E
finishes? Then you either need to install a signal handler (which isn't
always reliable), or you'll need more than one process managing this.
Or, if you don't really need to start J immediately after E finishes,
but just some time after, you could do something like:
$pid = fork_and_exec A;
waitpid $pid;
$pid_e = fork_and_exec E
$pid_b = fork_and_exec B
waitpid $pid_e;
waitpid $pid_b;
If, however, those branches drawn above need to be independent, then
maybe you could do something like:
$pid = fork_and_exec A;
waitpid $pid;
fork_and_run (E followed by J)
$pid = fork_and_exec B
waitpid $pid;
fork_and_run (F followed by L)
$pid = fork_and_exec C
waitpid $pid;
BTW, if all of these 'subprocesses' are perl, you might not need to
exec, but you could maybe just run them directly.
> and it goes on and on..
>
> Sorry if this is a trivial question, but i am a newbie here..
It doesn't at all sound trivial to me, and I am not even sure that
you've thought this through correctly. Depending on how long these
processes run, you could end up with a large number of them running.
Depending on what fires off J, L, M and N, you might end up with some
geometric progression (Does every process fire off two children and wait
for only one?) You haven't specified what you want to do with all the
children that you are not waiting for. In principle you _should_ wait
for them, or you'll end up with zombies, or you might need to do a
double-fork trick to completely dissociate them, or something like that.
Depending on that, you may need to install a signal handler for
SIG_CHLD. You haven't specified at all whether there is a need for any
communication of information between the processes either.
Maybe if you gave us a bit more of an idea of what those processes are
supposed to be doing, we could be of more help. I've given you some
outlines, but since your spec is so vague and underspecified, it is
impossible to say what would be useful.
Martien
--
Martien Verbruggen |
Interactive Media Division | System Administration is a dirty job,
Commercial Dynamics Pty. Ltd. | but someone said I had to do it.
NSW, Australia |
------------------------------
Date: Tue, 16 Oct 2001 11:09:51 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: HELP: cropping lines?
Message-Id: <l35ost8nfm7b4o2goc6jqfuvki0s83p3dl@4ax.com>
Bruno Boettcher wrote:
> $i =~ s/^\s+(.*)$/$1/;
> $i =~ s/^(.*)\s+$/$1/;
>
>but still there are leading and ending whitespaces that leak through...
>how can this be? and how can i crop them with absolute certainty?
In the first line, it can be embedded newlines that trip you up, as ".*"
doesn't match those; but in the second line, it most definitely is the
greediness of the ".*" that leaves not much for the \s+ to match.
There's no need to match the entire string either. Just do this:
$i =~ s/^\s+//;
$i =~ s/\s+$//;
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 06:53:31 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: how to logout from icewm or oroborus ??
Message-Id: <3bcc3bdf@news.microsoft.com>
"Qiang" <home@home.com> wrote in message
news:HXPy7.270240$j65.69905578@news4.rdc1.on.home.com...
> I have tried these two windows managers. Both i found no way to logout(
back
> to the login window again).need some help please.
>
> for icewm
[...]
> for oroborus
[...]
And your Perl question is?
jue
------------------------------
Date: Tue, 16 Oct 2001 11:30:45 GMT
From: jh123@nc.rr.com
Subject: Re: Need cgi script
Message-Id: <3bcc1bb2.554385@news-server>
On 15 Oct 2001 23:20:58 -0400, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
>jh123@nc.rr.com writes:
>
>> I need a cgi script to do the following:
>
>Your post is off-topic for this newsgroup.
>
>--
>Joe Schaefer "When the gods choose to punish us, they merely answer our
> prayers."
> -- Oscar Wilde
>
Sorry if I posted off-topic... but how is this question off-topic?
I'm looking for a perl application (cgi script).
Jay
------------------------------
Date: 16 Oct 2001 12:14:01 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Need cgi script
Message-Id: <slrn9so8o8.85e.bernard.el-hagin@gdndev25.lido-tech>
On Tue, 16 Oct 2001 11:30:45 GMT, jh123@nc.rr.com <jh123@nc.rr.com> wrote:
> On 15 Oct 2001 23:20:58 -0400, Joe Schaefer
><joe+usenet@sunstarsys.com> wrote:
>
>>jh123@nc.rr.com writes:
>>
>>> I need a cgi script to do the following:
>>
>>Your post is off-topic for this newsgroup.
[snipped sig]
> Sorry if I posted off-topic... but how is this question off-topic?
> I'm looking for a perl application (cgi script).
You're looking for a CGI script. CGI scripts *aren't* language specific.
This newsgroup, on the other hand, *is*. If you have a CGI script written
in Perl and are having problems with then you can ask here. Otherwise
it's a CGI question and belongs elsewhere.
Cheers,
Bernard
------------------------------
Date: Tue, 16 Oct 2001 13:06:36 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Need cgi script
Message-Id: <Z94my9LMLCz7EwNe@gratiano.zephyr.org.uk>
In message <3bcc1bb2.554385@news-server>, jh123@nc.rr.com writes
>Sorry if I posted off-topic... but how is this question off-topic?
Soliciting for programmers you wish to write a script for you is best
conducted in "jobs" groups.
>I'm looking for a perl application (cgi script).
Those two terms are not interchangeable.
--
James Coupe PGP Key: 0x5D623D5D
And if it's all right, I'd kind've like to be your lover EBD690ECD7A1F
'Cause when you're with me I can't help but be B457CA213D7E6
So desperately, uncontrollably happy 68C3695D623D5D
------------------------------
Date: Tue, 16 Oct 2001 13:23:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Need cgi script
Message-Id: <g0dost4r1n71dp2gm8dv0be35hltl4hfeq@4ax.com>
jh123@nc.rr.com wrote:
>Sorry if I posted off-topic... but how is this question off-topic?
>I'm looking for a perl application (cgi script).
On-topic here is technical questions, like "how do you do this better?".
You want a prepackaged script. You don't seem to care how it works. That
is off-topic. If you're looking for free scripts, search the web for
"free cgi scripts". Like, uh, here :<http://cgi.resourceindex.com/>
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 15:07:50 +0200
From: Lars Oeschey <dump@the-core.net>
Subject: Net::FTP Problem in ascii mode
Message-Id: <hfbostg9gqclemstnrhjmee4pt6erpdodq@4ax.com>
Hi,
I have a problem with the ascii mode of Net::FTP. I use the following
code to fetch files with Activestate perl 5.6.1 build 629 from a linux
box:
----------------------------------------------------------
$ftp = Net::FTP->new($Host, Debug => $debug) or print LOG "ftptrans:
Could not connect: $@\n";
$ftp->login($User,$Pass) or print LOG "ftptrans: Could not Login
$User\n";
$ftp->cwd($hostdir) or print LOG "ftptrans: Could not change to
$hostdir on Server\n";
$ftp->ascii();
foreach $file (@filenames) {
unless ($ftp->get ("$hostdir$file", "$localdir$file")) {
print LOG "ftptrans: Could not get $hostdir$file or
could not write $localdir$file\n";
} else {
print LOG "ftptrans: File fetched and written:
$localdir$file. Original file will be deleted now!\n";
$ftp->delete ("$hostdir$file") or print LOG "could not
delete $hostdir$file";
*******this section is only needed because of the problem described
below********
#linefeed reparieren
open (IN, "$localdir$file") or print LOG "could not
open $localdir$file for conversion\n";
open (OUT, ">$localdir$datestring-$file") or print LOG
"could not open $localdir$datestring-$file for writing\n";
while (<IN>) {
chop $_;
chop $_;
print OUT "$_\n";
}
close (IN);
close (OUT);
unlink $localdir$file;
print LOG "file converted\n";
}
}
-------------------------------------------------------
without the "conversion" part I don't get correct linefeeds/carriage
returns. At the end of each line is an additional character. Until now
I could only make it visible with DOS edit, there it looks like a
musical note. Notepad and UltraEdit on windows don't show it, but in
the filesize its also visible.
The Net::FTP is the standard one built in Activestate Perl.
My fear now is, since the conversion part is only a workaround, if
something changes, and the files are *correctly* transferred, the last
character of each line would be chop'ed.
So I'm looking for a solution for the "type ascii" problem.
Btw: I first tried the ftp->type("ascii") command for mode switch, but
the server then just returns "TYPE ascii: unknown command". The
ftp->ascii() works, and my guess would be that somewhere there is the
problem.
Lars
Lars
--
GPZ900R xxMm+2,5Mm http://www.oeschey.de
GS400 xxMm+1,5Mm http://www.the-core.net
------------------------------
Date: Tue, 16 Oct 2001 15:39:13 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Net::FTP Problem in ascii mode
Message-Id: <9scostcpepr9j9u0693ldffgjv28jslt27@4ax.com>
On Tue, 16 Oct 2001, Lars Oeschey <dump@the-core.net> wrote:
>I have a problem with the ascii mode of Net::FTP. I use the following
>code to fetch files with Activestate perl 5.6.1 build 629 from a linux
>box:
ASCII mode is evil (see rfc 959):
The sender converts the data from an internal character
representation to the standard 8-bit NVT-ASCII
representation (see the Telnet specification). The receiver
will convert the data from the standard form to his own
internal form.
Have you verified with a different client that your server does the
Right Thing?
If you only need LF <=> CRLF-Conversion, you should do that manually.
>$ftp = Net::FTP->new($Host, Debug => $debug) or print LOG "ftptrans:
>Could not connect: $@\n";
You're missing an error exit here - if you log an error, it doesn't
really make sense to continue beyond this point. If you don't want to
die(), consider:
if( my $ftp = Net::FTP ... ){
if( $ftp->login ... ){
} else {
print LOG ...
}
} else {
print LOG "ftptrans: Could not connect: $@\n";
}
>Btw: I first tried the ftp->type("ascii") command for mode switch, but
>the server then just returns "TYPE ascii: unknown command". The
>ftp->ascii() works, and my guess would be that somewhere there is the
>problem.
Not necessarily. Net::FTP->ascii() calls Net::FTP->type('A') internally.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: Tue, 16 Oct 2001 16:06:46 +0200
From: Kai Jendrian <kai@jendrian.de>
Subject: Re: Net::FTP Problem in ascii mode
Message-Id: <cueost8uicl12pfe0o7bfvdvvgbbk7jl99@4ax.com>
Hello,
what happens if you set $debug = 1; ?
Can you paste a useful part of this output?
.kai
>I have a problem with the ascii mode of Net::FTP. I use the following
>code to fetch files with Activestate perl 5.6.1 build 629 from a linux
>box:
>
>----------------------------------------------------------
>$ftp = Net::FTP->new($Host, Debug => $debug) or print LOG "ftptrans:
>Could not connect: $@\n";
------------------------------
Date: Tue, 16 Oct 2001 16:18:14 +0200
From: Lars Oeschey <dump@the-core.net>
Subject: Re: Net::FTP Problem in ascii mode
Message-Id: <q7gosto48aso1vdkr4ud4eknnia8js5dbd@4ax.com>
On Tue, 16 Oct 2001 15:39:13 +0200, Thomas Bätzler
<Thomas@Baetzler.de> wrote:
>Have you verified with a different client that your server does the
>Right Thing?
I made a pure ftp transfer from the DOS Box, there it was ok.
>You're missing an error exit here - if you log an error, it doesn't
>really make sense to continue beyond this point. If you don't want to
>die(), consider:
I needed the LOG entry, therefore I didn't wan't to "die", cause I'd
have to redirect STDERR then.
>if( my $ftp = Net::FTP ... ){
> if( $ftp->login ... ){
> } else {
> print LOG ...
> }
>} else {
> print LOG "ftptrans: Could not connect: $@\n";
>}
ah, I'll try that.
>Not necessarily. Net::FTP->ascii() calls Net::FTP->type('A') internally.
hm, seems I should have used "$ftp->type('A')" instread of
"$ftp->type('ascii').
>HTH,
thanks, Lars
Lars
--
GPZ900R xxMm+2,5Mm http://www.oeschey.de
GS400 xxMm+1,5Mm http://www.the-core.net
------------------------------
Date: Tue, 16 Oct 2001 10:59:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: problem in getting directory list and filelist through perl
Message-Id: <1m4ostgrfga9as566ir01nkbilr47ql1i6@4ax.com>
Raja sekhar wrote:
> I have some problem in getting directory list through perl.my
>requirement is 1.to get all directory names.
>2.enter into each directory and get all the file list in that
>directory.
>3. and to perform some operation on each and every file.
>
>I am using File::Find module
That's an excellent idea.
> but it returns path of the
>directory.which is not desirable. I want to get only direcroty names.
Oh. Perhaps you should check out the value of $_ inside that sub,
instead of using $File::Find::name.
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 15:13:18 +0200
From: Falk P. <paule.p-deleteme-@gmx.de>
Subject: problems with autoloader
Message-Id: <7obostcrh2fo79f3mo6c4038rhevrbth3u@4ax.com>
hi,
i dont know why this code behaves different from the source out of a
book -> i get the error:
"String found where operator expected at Administration/User.pm line
19, near "croak "No such method: $AUTOLOAD"" (Do you need to
predeclare croak?) syntax error at Administration/User.pm line 19,
near "croak "No such method: $AU
TOLOAD"" Compilation failed in require at D:\Eigene
Dateien\HTML\freelancer\cgi\login.pl line 4.
BEGIN failed--compilation aborted at D:\Eigene
Dateien\HTML\freelancer\cgi\login.pl line 4."
its about the User.pm, and i dont know why croak is'nt working,
perhaps you know?
thanks,
falk
----- test.pl --------------------------------------
#!d:/perl/bin/perl.exe -w
use strict;
use lib "D:/Eigene Dateien/HTML/freelancer/cgi/Administration";
use Administration::User;
my $user = Administration::User -> new("testname");
print $user->get_vorname();
----- User.pm --------------------------------------
package Administration::User;
$VERSION = "0.01";
use strict;
use Diagnostics;
use vars '$AUTOLOAD';
sub new {
my ($class) = @_;
$class -> _inc_count();
bless {_vorname => $_[1],},$class;
}
sub AUTOLOAD {
my ($self) = @_;
$AUTOLOAD =~ /.*::get(_\w+)/
or croak "No such method: $AUTOLOAD";
#exists $self->{$1}
# or croak "No such attribute: $1";
#return $self->{$1};
}
#sub get_vorname { $_[0] -> {_vorname} }
1;
------------------------------
Date: 16 Oct 2001 05:54:28 -0700
From: showdog@my-deja.com (=?ISO-8859-1?Q?sh=F2wd=F6g?=)
Subject: put more simply: putting $1..$9 into a replacement string such as $repl="=csinfo$1$2^$3"
Message-Id: <187c116b.0110160454.1b5e7974@posting.google.com>
There was a ton of possibly irrelevant code in my last question. I've
narrowed my question down this time in hopes of getting an answer ;-)
use warnings;
use strict;
my $repl='this is $1. hi there.';
my $search='(foo)';
my $strText="foo foo";
$strText =~ s/$search/$repl/gi;
# what I want the above line to evaluate to is:
# $strText =~ s/(foo)/this is $1. hi there./gi;
print $strText;
__END__
this is $1. hi there. this is $1. hi there.
how do I get $strText to contain "foo" instead of $1?
------------------------------
Date: Tue, 16 Oct 2001 13:59:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: put more simply: putting $1..$9 into a replacement string such as $repl="=csinfo$1$2^$3"
Message-Id: <rheost08qb0k9d0hj1s1hk779lsgmdqbni@4ax.com>
shòwdög wrote:
>There was a ton of possibly irrelevant code in my last question. I've
>narrowed my question down this time in hopes of getting an answer ;-)
Yeah, we all got sidetracked, including me.
>use warnings;
>use strict;
>my $repl='this is $1. hi there.';
>my $search='(foo)';
>my $strText="foo foo";
>
>$strText =~ s/$search/$repl/gi;
># what I want the above line to evaluate to is:
># $strText =~ s/(foo)/this is $1. hi there./gi;
>
>print $strText;
>__END__
>this is $1. hi there. this is $1. hi there.
>
>how do I get $strText to contain "foo" instead of $1?
That's an interesting question. It's a problem that I came up with years
ago, and I still haven't seen a 100% satisfactory solution. What you
want, is have the interpolation of the variables also happen to your own
strings, not just to strings embedded in the original source. Well...
One solution would be to put your string between quotes, and eval the
RHS. Or use the /e modifier. Like this:
$strText =~ s/$search/'"'.$repl.'"'/giee;
You might already guess what can go wrong with this... first of all:
what happens with embedded quotes? Backslashes? What about likely unsafe
occurrences of "@{[...]}", "${\(...)}", or even "$foo{code()}" and
"$foo[code()]"?
Alternatively: you could forget about all this, and use a template
library instead. Comes up the problem is: how do you pass $1, $2 etc. to
your sub? How do you even know how many of those submatches there are?
Well: @+ and @- provide a crude means to extract the submatches from the
original string. The code won't be pretty...
Am I missing another option?
--
Bart.
------------------------------
Date: Tue, 16 Oct 2001 15:57:16 +0200
From: "Marco Guazzone" <sguazt@infodrome.net>
Subject: Re: put more simply: putting $1..$9 into a replacement string such as $repl="=csinfo$1$2^$3"
Message-Id: <9qhddo$p4d$1@serv1.iunet.it>
Try with:
use strict;
my $search = '(foo)';
my $repl = '"this is $1. hi there."';
my $strText = 'foo foo';
$strText =~ s/$search/$repl/giee;
print $strText, "\n";
__END__
"shòwdög" <showdog@my-deja.com> wrote in message
news:187c116b.0110160454.1b5e7974@posting.google.com...
> There was a ton of possibly irrelevant code in my last question. I've
> narrowed my question down this time in hopes of getting an answer ;-)
>
> use warnings;
> use strict;
> my $repl='this is $1. hi there.';
> my $search='(foo)';
> my $strText="foo foo";
>
> $strText =~ s/$search/$repl/gi;
> # what I want the above line to evaluate to is:
> # $strText =~ s/(foo)/this is $1. hi there./gi;
>
> print $strText;
> __END__
> this is $1. hi there. this is $1. hi there.
>
> how do I get $strText to contain "foo" instead of $1?
------------------------------
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 1938
***************************************