[18496] in Perl-Users-Digest
Perl-Users Digest, Issue: 664 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 10 03:05:44 2001
Date: Tue, 10 Apr 2001 00:05:16 -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: <986886315-v10-i664@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 10 Apr 2001 Volume: 10 Number: 664
Today's topics:
Re: #!/usr/bin/perl -w vs. use diagnostics nobull@mail.com
Re: ? The best Perl book ? <uri@sysarch.com>
Re: dir problem <nlp0421@gz.cngb.com>
file input output problems <lupey@imap.pitt.edu>
Re: file input output problems <krahnj@acm.org>
Filehandle question <bmccann@naisp.net>
Re: Filehandle question <krahnj@acm.org>
Re: Including Perl code in documents <cave@pertus.com.pl>
Re: inheritance within one file? <wayne.keenan@ntlworld.com>
Multiple map,grep,while,foreach g.sands@auckland.ac.nz
Re: Multiple map,grep,while,foreach <uri@sysarch.com>
Re: Perl as an email client <waltman@netaxs.com>
Poblem with Windows ME and Perl? <cernava@itexas.net>
Re: registration script <amazingkgb@earthlink.net>
Re: registration script (Steven Smolinski)
Re: Regular Expression as a variable? (Tad McClellan)
RE: Return code for % operator <huem@MailAndNews.com>
Re: save a value of a variable between subroutines run. <NO_SPAM_klubbheads@home.com>
Re: save a value of a variable between subroutines run. <NO_SPAM_klubbheads@home.com>
Re: save a value of a variable between subroutines run. (Gwyn Judd)
Re: save a value of a variable between subroutines run. <NO_SPAM_klubbheads@home.com>
Re: save a value of a variable between subroutines run. <joe+usenet@sunstarsys.com>
Re: There is a problem with this code containing tell a (Tad McClellan)
Re: To run perl in the backround <bowman@montana.com>
Re: using dup() (Andrew J. Perrin)
Re: Want Lisp-like state machine impl. dave@cadet.i-did-not-set--mail-host-address--so-shoot-me
Re: Want Lisp-like state machine impl. (Logan Shaw)
We have 'use strict' and 'my', and now 'our', but no 'u <pvoris@nekophile.com>
Re: Why Perl? (GrapeApe)
wordsearcher-please help with my script <armin.nolte@aktion-mensch.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 09 Apr 2001 17:50:34 +0100
From: nobull@mail.com
Subject: Re: #!/usr/bin/perl -w vs. use diagnostics
Message-Id: <u9wv8u9fvp.fsf@wcl-l.bham.ac.uk>
"Kevin B" <kbass1@nc-rr.com> writes:
> Is there a difference in using
>
> #!/usr/bin/perl -w
>
> as opposed to using
>
> use diagnostics
Verbosity.
For details 'perldoc diagnostics'.
See also 'perldoc perllexwarn'.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 10 Apr 2001 03:40:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: ? The best Perl book ?
Message-Id: <x78zl9pglv.fsf@home.sysarch.com>
>>>>> "CL" == Cameron Laird <claird@starbase.neosoft.com> writes:
CL> In article <9aqh0a$l05$1@plutonium.btinternet.com>,
CL> Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>> In comp.lang.perl.misc Ciaran McCreesh <keesh@users.pleaseremovethisbit.sourceforge.net> wrote:
CL> .
CL> .
CL> .
>> If Uri is still maintaining his book list I would suggest you refer to that.
CL> .
CL> .
CL> .
CL> And if Uri's not, I would suggest showing ones appreciation
CL> for all the help here by taking on the chore of maintaining
CL> the book list.
if anyone does want to work on maintaining the list i will be glad to
give you the code and data. it could be rehosted to a pm.org site. bdf
has started book review page there and this could be merged with it.
i just don't have the time to focus on it but if someone else drives it,
i can help.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Mon, 9 Apr 2001 09:24:08 +0800
From: "J.A.W" <nlp0421@gz.cngb.com>
Subject: Re: dir problem
Message-Id: <9ar32h$ep6$1@news.cz.js.cn>
"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn9d1l3m.k95.tjla@thislove.dyndns.org...
> I was shocked! How could J.A.W <nlp0421@gz.cngb.com>
> say such a terrible thing:
>
> >to ignore the subdirs, but is there an efficient way to do this?
>
> You want the '-d' file-test operator.
Thanks, I rewrote the lines like this:
foreach $file (@FILES) {
$f=$file;
next if -d $f;
}
but some subdirs still fails to be left out, particularly those ".files"
ones. Why does this happen?
J.A.W.
------------------------------
Date: Mon, 09 Apr 2001 23:53:08 -0400
From: Paul Cantalupo <lupey@imap.pitt.edu>
Subject: file input output problems
Message-Id: <3AD283A4.67D03DAE@imap.pitt.edu>
Hello,
I am having some trouble getting my file handling down straight. Here
is my code for testing the functions of seek, open, read and print
<program>
#!/opt/bin/perl
$filename = "seekproblems.txt";
open(FILE, "+<".$filename); #
read/write access
print "Current position of file is " . tell(FILE) . "\n"; # shows
that I am pointed to beginning of file
seek FILE, 19, 0; # should be letter 'o';
$numread = read FILE, $line, 3; # read the string "of\n"
print "numread is=$numread\n";
print "Current position of file after read is " . tell(FILE) . "\n"; #
file pointer is pointing to the 'u' in "using"
print FILE "X"; # replace 'u' (of the word using) with X
print "Current position of file after print is " . tell(FILE) . "\n";
# file pointer has moved one position
close (FILE);
<end or program>
Here is the text file "seekproblems.txt"
this
is
an
example
of
using
seek
Here is the what the text file looks like after script runs>>
this
is
an
example
of
using
seek
of
X
Here is the output of the program:
Current position of file is 0
numread is=3
Current position of file after read is 22
Current position of file after print is 23
My question is this, "Why does printing to the file cause the addition
of the string "of\nX"?! I only told it to print the letter 'X' not
"of\nX" After looking at the output, the character 'X' should have
replaced the 'u' of the word 'using'. The output shows that the file
pointer is located within the word "using" and not at the end of the
file so no output should have occurred at the end.
What gives? What am I missing? Is it because of the function "read"?
Because if I comment out the "read" line, the program works as I expect
it to.
Thank you for your help
Paul
------------------------------
Date: Tue, 10 Apr 2001 04:37:09 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: file input output problems
Message-Id: <3AD28DA2.DF6C614A@acm.org>
Paul Cantalupo wrote:
>
> [snip]
>
> Here is the what the text file looks like after script runs>>
> this
> is
> an
> example
> of
> using
> seek
>
> of
> X
>
> Here is the output of the program:
> Current position of file is 0
> numread is=3
> Current position of file after read is 22
> Current position of file after print is 23
>
> My question is this, "Why does printing to the file cause the addition
> of the string "of\nX"?! I only told it to print the letter 'X' not
> "of\nX" After looking at the output, the character 'X' should have
> replaced the 'u' of the word 'using'. The output shows that the file
> pointer is located within the word "using" and not at the end of the
> file so no output should have occurred at the end.
>
> What gives? What am I missing? Is it because of the function "read"?
> Because if I comment out the "read" line, the program works as I expect
> it to.
This is what I get when I run your program:
this
is
an
example
of
Xsing
seek
What OS and version of Perl are you using?
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 10 Apr 2001 09:56:27 -0700
From: "Brian McCann" <bmccann@naisp.net>
Subject: Filehandle question
Message-Id: <td4qb2nt3li719@corp.supernews.com>
Hi,
When I run this script without the open OUT lines
the script will replace the string "tag" with the string "PCS-1-0-0-Build94"
in the dos
window, but if I add those lines in nothing happens. the line that perl
complains about is:
#rename $filename, "$filename.bak" or die "Cannot rename: $!";
I get this error on the command line: Cannot rename: No such file or
directory at C:\Perl\scripts\whatrn.plx line 23.
any help would be greatly appreciated
Thanks,
Brian
use warnings;
use strict;
my $dir = "AppsTagBuild";
my $tag = "PCS-1-0-0-Build94";
my $filename = "WhatLabel.java";
open IN,
"<C:\\$dir\\$tag\\source\\Applications\\InternalProduct\\Java\\Utils\\$filen
ame.bak" or die "Cannot open: $!";
open OUT,
">C:\\$dir\\$tag\\source\\Applications\\InternalProduct\\Java\\Utils\\$filen
ame" or die "Cannot create: $!";
while (<IN>) {
s/tag/$tag/;
#print OUT $_;
print $_;
}
close IN;
close OUT;
#rename $filename, "$filename.bak" or die "Cannot rename: $!";
------------------------------
Date: Tue, 10 Apr 2001 02:54:27 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Filehandle question
Message-Id: <3AD275D2.C67D0657@acm.org>
Brian McCann wrote:
>
> Hi,
> When I run this script without the open OUT lines
> the script will replace the string "tag" with the string "PCS-1-0-0-Build94"
> in the dos
> window, but if I add those lines in nothing happens. the line that perl
> complains about is:
> #rename $filename, "$filename.bak" or die "Cannot rename: $!";
>
> I get this error on the command line: Cannot rename: No such file or
> directory at C:\Perl\scripts\whatrn.plx line 23.
Either chdir to the directory where all these files are or include the
complete path every time.
> use warnings;
> use strict;
>
> my $dir = "AppsTagBuild";
> my $tag = "PCS-1-0-0-Build94";
> my $filename = "WhatLabel.java";
>
> open IN,
> "<C:\\$dir\\$tag\\source\\Applications\\InternalProduct\\Java\\Utils\\$filen
> ame.bak" or die "Cannot open: $!";
> open OUT,
> ">C:\\$dir\\$tag\\source\\Applications\\InternalProduct\\Java\\Utils\\$filen
> ame" or die "Cannot create: $!";
> while (<IN>) {
> s/tag/$tag/;
> #print OUT $_;
> print $_;
> }
> close IN;
> close OUT;
> #rename $filename, "$filename.bak" or die "Cannot rename: $!";
chdir
"C:\\$dir\\$tag\\source\\Applications\\InternalProduct\\Java\\Utils";
open IN, "<$filename.bak" or die "Cannot open: $!";
open OUT, ">$filename" or die "Cannot create: $!";
while ( <IN> ) {
...
}
rename $filename, "$filename.bak" or die "Cannot rename: $!";
# The full path version is left as an exercise for the OP. :-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 10 Apr 2001 07:42:11 +0200
From: Mirek Rewak <cave@pertus.com.pl>
Subject: Re: Including Perl code in documents
Message-Id: <ev55dtkkj9f30rsopocg0gt43ujqihkl1f@4ax.com>
On Mon, 09 Apr 2001 08:41:41 +0100, "wayne.keenan"
<wayne.keenan@ntlworld.com> wrote:
>http://www.palfrader.org/code2html/
>
>&paste
Thanks. It's nice but too many colors - I will need to hack it.
Pozdrowienia
Mirek Rewak
cave@pertus.com.pl
------------------------------
Date: Tue, 10 Apr 2001 07:54:23 +0100
From: "wayne.keenan" <wayne.keenan@ntlworld.com>
Subject: Re: inheritance within one file?
Message-Id: <3AD2AE1F.E302CB27@ntlworld.com>
Bart Lateur wrote:
> Phil R Lawrence wrote:
>
> >While hacking together a set of 2 modules and a script to test out
> >some inheritance issues, I thought, "Why not stick this all into one
> >file for convenience?">use A;
>
>
> Loose that line.
>
> For a start: you don't need to "use" a module for OO only purposes.
> "require" is good enough. Since you're already loading the A package,
> there's no need to load it again.
>
> HTH,
> Bart.
unless , for some reason, you use the module in a BEGIN block, the require
will only get executed at runtime, not compile time. also, you would
manually have to call import using require.
REgards
Wayne
------------------------------
Date: 10 Apr 2001 05:26:58 GMT
From: g.sands@auckland.ac.nz
Subject: Multiple map,grep,while,foreach
Message-Id: <9au5j2$f12$1@news.netmar.com>
Can anyone see a way to simplify the code below? I'm taking a list of
process names that match 'name', extracting the first word of the line,
following symbolic links, and then removing everything up to the final '/'.
At present this requires 2 maps, 1 grep, 1 while and 1 foreach. It works,
but it's a bit ugly :-) Any improvements?
@processes =
map { $_ = readlink while -l; $_ }
map { (split)[0] }
grep { /name/ }
`ps -o args=`;
s/\S*\/// foreach @processes;
Thanks,
Greg
----- Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web -----
http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
NewsOne.Net prohibits users from posting spam. If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net
------------------------------
Date: Tue, 10 Apr 2001 06:17:26 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Multiple map,grep,while,foreach
Message-Id: <x766gdp9c9.fsf@home.sysarch.com>
>>>>> "gs" == g sands <g.sands@auckland.ac.nz> writes:
gs> Can anyone see a way to simplify the code below? I'm taking a
gs> list of process names that match 'name', extracting the first word
gs> of the line, following symbolic links, and then removing
gs> everything up to the final '/'. At present this requires 2 maps,
gs> 1 grep, 1 while and 1 foreach. It works, but it's a bit ugly :-)
gs> Any improvements?
gs> @processes =
gs> map { $_ = readlink while -l; $_ }
gs> map { (split)[0] }
gs> grep { /name/ }
you can probably merge that grep and map into a sigle map of m//g. you
just need to grab the path out of each line that has name. not to hard
to do.
gs> `ps -o args=`;
gs> s/\S*\/// foreach @processes;
that can be merged in the first map:
map { $_ = readlink while -l; s{\S*/}{} ; $_ }
if you were crazier you could merge the last two maps into one. by then
it becomes a large block of code for a map
@processes = map {
/^.*name.*(\S+)$/m && do {
$_ = $1 ;
$_ = readlink while -l ;
s{\S*/}{} ;
$_
} || () ;
} `ps -o args=`;
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 09 Apr 2001 22:40:15 -0400
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: Perl as an email client
Message-Id: <87n19pbhps.fsf@netaxs.com>
Dionte S Wilson <dsw4@lucent.com> writes:
> Has anyone ever used perl to simulate an email client? If so, was it alot of
> effort. I'm thinking about writing a generic email client using PERL.
If you just want to send email from inside a Perl script, several
simple methods are outlined in one of Perl's FAQ's. Run
perldoc -q 'send mail'
Walt
------------------------------
Date: Tue, 10 Apr 2001 01:10:20 -0500
From: "Itexas" <cernava@itexas.net>
Subject: Poblem with Windows ME and Perl?
Message-Id: <9au8490jtt@enews3.newsguy.com>
Hi,
I've tryed this script with two Windows ME systems and both do not work.
The problem is can_read never returns an array of the pipe that is ready to
read from.
This works good on linux. I don't have windows 98 or 2k to test it with.
use strict;
use IO::Select;
use IO::File;
$| = 1;
my $sel = new IO::Select;
pipe(my $reader,my $writer) or die "Cannot pipe: $!";
my $kid = fork();
if ($kid)
{
close ($writer);
$sel->add($reader);
}
else
{
close ($reader);
$writer->autoflush(1);
while(1)
{
print $writer "I am $$\n";
sleep rand(10); #pause for somthing from 10 sec and down.
}
exit;
}
while(1)
{
foreach my $client ($sel->can_read)
{
my $data = <$client>;
print "Got $data";
}
}
Hope some one can help.
Richard.
------------------------------
Date: Tue, 10 Apr 2001 03:16:57 GMT
From: "Atayarani" <amazingkgb@earthlink.net>
Subject: Re: registration script
Message-Id: <JWuA6.3295$Ak1.307184@newsread2.prod.itd.earthlink.net>
I get an error: 500
the pages are: www.atayarani.com/form.html
and www.atayarani.com/cgi-bin/readinput.pl
"Steven Smolinski" <sjs@linux.ca> wrote in message
news:slrn9d4ic2.1ag.sjs@ragnar.stevens.gulch...
> Atayarani <amazingkgb@earthlink.net> wrote:
> > I am very new to Perl, but hope that I will get some helpful responses.
>
> To get helpful responses, you must help people to understand the problem.
>
> > I am trying to create a script for my page, in which a user can
> > register (for benefits unknown) and all information submitted is sent
> > to a specified email address. I currently am using a script copied
> > from a book, for a start. It did not work, I got an Internal Server
> > Error. The permissions are correct, and the path is correct. I have
> > no idea where it went wrong.
>
> Now, what information in the above paragraph do you think could help
> anyone diagnose your problem? No code, no details, no nothing.
> Seriously, though--what sort of mind-reading did you expect?
>
> There is a FAQ in the subject:
>
> http://www.perl.com/pub/doc/FAQs/cgi/perl-cgi-faq.html
>
> and the unfortunately named checklist:
>
> http://www.perl.com/pub/doc/FAQs/cgi/idiots-guide.html
>
> General information is all you posted, so general pointers is all you
> can really expect.
>
> Steve
> --
> Steven Smolinski => http://www.steven.cx/
>
------------------------------
Date: Tue, 10 Apr 2001 03:36:38 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: registration script
Message-Id: <slrn9d54u9.1o1.sjs@ragnar.stevens.gulch>
[ Please post your comments at the end of the suitably trimmed article
you're replying to. The regulars around here prefer it, and you will
get more help from them that way. Jeopardectomy performed. ]
Atayarani <amazingkgb@earthlink.net> wrote:
> "Steven Smolinski" <sjs@linux.ca> wrote:
> > Atayarani <amazingkgb@earthlink.net> wrote:
> > > I am very new to Perl, but hope that I will get some helpful
> > > responses.
> >
> > To get helpful responses, you must help people to understand the
> > problem.
> >
> > > [... snip CGI program "doesn't work": 500 server error ...]
>
> I get an error: 500
>
> the pages are: www.atayarani.com/form.html
> and www.atayarani.com/cgi-bin/readinput.pl
We can't see the code in that second URL, of course, because the
webserver tries to execute it.
In any case, did you look at the URLs I posted at all? They would have
told you to check lots of things:
- Did you run the script from the command line?
- Did you fix all the warnings/errors from the command line?
- Did you use -w, -T and strict?
In any case, I looked at the form.html quickly. It's non-compliant HTML
by a long shot. Your quoting is all over the place. All the inputs
look like this:
<input type = "text" size = "35 name = "address>
when they should look like this:
<input type="text" size="35" name="address">
If the page even works, it's by magic and all-too-forgiving browser
manufacturers. But that's off-topic here. Fix your HTML, try debugging
the script from the command line and let us know how you did.
HTH.
Steve
--
Steven Smolinski => http://www.steven.cx/
------------------------------
Date: Mon, 9 Apr 2001 20:19:29 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular Expression as a variable?
Message-Id: <slrn9d4kch.2vu.tadmc@tadmc26.august.net>
bob_waltenspiel@agilent.com <bob_waltenspiel@agilent.com> wrote:
>there's no way to modify the regular
>expression.
Yes there is.
>Any suggestions?
perldoc perlre
-----------------------------------------
=item C<(?imsx-imsx)>
One or more embedded pattern-match modifiers. This is particularly
useful for dynamic patterns, such as those read in from a configuration
file, read in as an argument, are specified in a table somewhere,
etc. Consider the case that some of which want to be case sensitive
and some do not. The case insensitive ones need to include merely
C<(?i)> at the front of the pattern. For example:
-----------------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 10 Apr 2001 01:46:08 -0400
From: hue micheal <huem@MailAndNews.com>
Subject: RE: Return code for % operator
Message-Id: <3AD8703E@MailAndNews.com>
Thanks every body, It makes sense now.
I will learn not to have opinions, well will try ;)
HUem
>===== Original Message From Bernie Cosell <bernie@fantasyfarm.com> =====
>tadmc@augustmail.com (Tad McClellan) wrote:
>
>} hue micheal <huem@MailAndNews.com> wrote:
>} >My first thought, the following were correct:
>} >if (100%4) { print "100 is dividible by 4" }
>} >if (!(101%4)) { print "101 is not divisible by 4" }
>} >
>} >results: Nothing is printed !!!
>}
>} >I my opinion, the first case is more acurate ?
>} ^^^^^^^
>}
>} There are no "opinions" in rudimentary mathematics.
>
>Until you get into the question of how 'remainder' should work with
>negative operands..:o)
>
> /Bernie\
>--
>Bernie Cosell Fantasy Farm Fibers
>bernie@fantasyfarm.com Pearisburg, VA
> --> Too many people, too few sheep <--
------------------------------
Date: Tue, 10 Apr 2001 02:55:39 GMT
From: "Roman Filippov" <NO_SPAM_klubbheads@home.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <LCuA6.190791$A6.43309409@news4.rdc1.on.home.com>
Thanx for responce...
That is not exactly what i wanted.
Actually I am talking about the example from Perl Cookbook. It's in section
"Automatization in Web" - "Creating HTML templates" (20.9) - I am not sure
it's called exactly like that, because my book is in Russian.
Here is the code...
### START OF CODE
# creates an hash with fillings
%fields = (
anything => 'whatever to fill...'
);
# send stuff to template to print
print template('template.tpl',\%fields);
sub template {
my ($filename,$fillings) = @_;
my $text;
local $/;
local *F;
open(F,"< $filename") or return;
$text = <F>;
close(F);
$text =~ s{ %% (.*? ) %% }
{ exists( $fillings->{$1} )
? $fillings->{$1}
: ''
}gsex;
return $text;
}
### END OF CODE
When i fetch data from SQL server, I want to display it as HTML, but using
templates. So i this case, i have a template that looks like this:
<tr>
<td>%%something%%</td>
</tr>
and I call this template for each row. If there are 100 rows, it is going to
open file 100 times. And template() could be run from anywhere in the
program... I need the the subrouting to remember the file that has beed
opened...
------------------------------
Date: Tue, 10 Apr 2001 03:00:34 GMT
From: "Roman Filippov" <NO_SPAM_klubbheads@home.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <mHuA6.190855$A6.43319280@news4.rdc1.on.home.com>
"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
news:m3zodp8xdl.fsf@mumonkan.sunstarsys.com...
> "Roman Filippov" <NO_SPAM_klubbheads@home.com> writes:
>
> > I am not sure if it's possible...
> >
> > I need to save the value of a localized variable in the function. By
> > localized I mean - it is not accessable from the rest of the program. It
can
> > be "my" or "local", i don't know... Here is an example and a decription
of a
> > script:
>
> Sounds like you want to Memoize portions of some_sub.
> Did you know there's a package on CPAN that does that for you?
> Also see
>
> http://perl.plover.com/MiniMemoize/
>
I try to avoid using modules as much as I can, if there is a way to have it
done without, then I do it without :)
> The basic gist is something like this:
>
> sub some_sub {
> my $filename = shift;
> my $file; # array_ref to avoid spurious copying
> #...
> }
>
> becomes (untested)
>
> sub some_sub {
> my %cache if 0; # static variable trick
Can u tell me more about that please or just tell me the part of reference
or place where I can read?
And how would %cache get saved in between the sessions?
>
> my $filename = shift;
> my $file = $cache{$filename} || # orcish maneuver
> do {
> local *FILE;
> open FILE, "< $filename" or die $!;
> $cache{$filename} = [<FILE>];
> };
>
> ...
> }
>
>
> HTH
> --
> Joe Schaefer "The worst thing you can do to a man is to tell him he can
have
> what he wants."
> --Mark Twain
------------------------------
Date: Tue, 10 Apr 2001 03:04:46 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <slrn9d4u2c.te8.tjla@thislove.dyndns.org>
I was shocked! How could Roman Filippov <NO_SPAM_klubbheads@home.com>
say such a terrible thing:
>When i fetch data from SQL server, I want to display it as HTML, but using
>templates. So i this case, i have a template that looks like this:
>
><tr>
> <td>%%something%%</td>
></tr>
>
>and I call this template for each row. If there are 100 rows, it is going to
>open file 100 times. And template() could be run from anywhere in the
>program... I need the the subrouting to remember the file that has beed
>opened...
Sounds like you have the priorities inside out. If the function is being
called repeatedly, why not have the calling function load the template
and then pass it to the function as a parameter, rather than trying to
do the static variable trick?
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
BOUNDARY
n. In political geography, an imaginary line between two nations, separating
the imaginary rights of one from the imaginary rights of the other.
------------------------------
Date: Tue, 10 Apr 2001 03:23:22 GMT
From: "Roman Filippov" <NO_SPAM_klubbheads@home.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <K0vA6.191166$A6.43363187@news4.rdc1.on.home.com>
"Gwyn Judd" <tjla@guvfybir.qlaqaf.bet> wrote in message
news:slrn9d4u2c.te8.tjla@thislove.dyndns.org...
> I was shocked! How could Roman Filippov <NO_SPAM_klubbheads@home.com>
> say such a terrible thing:
>
> >When i fetch data from SQL server, I want to display it as HTML, but
using
> >templates. So i this case, i have a template that looks like this:
> >
> ><tr>
> > <td>%%something%%</td>
> ></tr>
> >
> >and I call this template for each row. If there are 100 rows, it is going
to
> >open file 100 times. And template() could be run from anywhere in the
> >program... I need the the subrouting to remember the file that has beed
> >opened...
>
> Sounds like you have the priorities inside out. If the function is being
> called repeatedly, why not have the calling function load the template
> and then pass it to the function as a parameter, rather than trying to
> do the static variable trick?
>
Because my template() function is modified a bit and it is also used in
other places in the code, because the code is big, it's a web application.
It's also used to display normal HTML (by normal i mean not repeated). I
used to do the way you said ( i just had a separate function flyTemplate ),
but i was just thinking of an alternative way to do it.
> --
> Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
> BOUNDARY
>
> n. In political geography, an imaginary line between two nations,
separating
> the imaginary rights of one from the imaginary rights of the other.
------------------------------
Date: 09 Apr 2001 23:58:20 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: save a value of a variable between subroutines run... (++)
Message-Id: <m3n19p8kyr.fsf@mumonkan.sunstarsys.com>
"Roman Filippov" <NO_SPAM_klubbheads@home.com> writes:
> "Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
> news:m3zodp8xdl.fsf@mumonkan.sunstarsys.com...
> > sub some_sub {
> > my %cache if 0; # static variable trick
>
> Can u tell me more about that please or just tell me the part of reference
> or place where I can read?
>
> And how would %cache get saved in between the sessions?
It's a trick(bug?)- I don't think it's documented anywhere. Basically
it has the same effect as writing this
{ my %cache;
sub some_sub {
...
}
}
#!/usr/bin/perl -wl
use strict;
sub foo {
my %cache if 0;
$cache{$_[0]} ||= warn "making cache for $_[0]";
keys %cache;
}
foo($_) for 1..5;
foo($_) for 1..5;
print foo(1);
__END__
Output:
making cache for 1 at /tmp/try.pl line 5.
making cache for 2 at /tmp/try.pl line 5.
making cache for 3 at /tmp/try.pl line 5.
making cache for 4 at /tmp/try.pl line 5.
making cache for 5 at /tmp/try.pl line 5.
12345
It's based on some compile-time/run-time magic that I can't
adequately explain, so I won't try. There was some discussion
of this idiom on p5p some time ago and IIRC the consensus was
that this is not a bug ( i.e. nobody's planning to "fix" it ).
YMMV
--
Joe Schaefer "Technological progress is like an axe in the hands of a
pathological criminal."
--Albert Einstein
------------------------------
Date: Mon, 9 Apr 2001 20:14:29 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: There is a problem with this code containing tell and seek
Message-Id: <slrn9d4k35.2vu.tadmc@tadmc26.august.net>
Jay Tilton <tiltonj@erols.com> wrote:
>On Mon, 9 Apr 2001 22:14:41 +0100, "Milliwave"
><milliwave@rfengineering.freeserve.co.uk> wrote:
>
>Did you have to post this three times within three minutes, each with
>a different subject? Evidently, this is related to a prior thread.
The time I spend maintaining my scorefile pays off yet again.
milliwave got an entry last month when (s)he said:
"I don't have access to the perldoc manuals"
I took the appropriate action.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 9 Apr 2001 21:57:59 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: To run perl in the backround
Message-Id: <irvA6.397$6v3.3627@newsfeed.slurp.net>
"T_Boss" <T_boss75@curanet.com> wrote in message
news:VNlA6.138474$lj4.4243833@news6.giganews.com...
> Is there anyway to let perl run in the backround, so that i can close this
> box??
> I have Active perl 5.6 on Win NT 4.0 Sp 5.0
you could try making it a service. 'srvany perl myscript.pl' is the quick
and dirty way, or you could look at Win32::Daemon.
------------------------------
Date: 09 Apr 2001 21:33:02 -0500
From: andrew_perrin@unc.edu (Andrew J. Perrin)
Subject: Re: using dup()
Message-Id: <87vgodfpr5.fsf@nujoma.perrins>
mjd@plover.com (Mark Jason Dominus) writes:
[snip]
>
> If you don't have 'tee', it's easy to write it:
>
> #!/usr/bin/perl
> # 'tee'
>
> my $file = shift or die "Usage: $0 filename";
> open FILE, "> $file" or die "$0: Couldn't open file $file: $!";
>
> while (read STDIN, my $buf, 8192) {
> print $buf;
> print FILE $buf;
> }
>
>
You can make this more generic, and allow more than two output
streams, by using IO::File:
#!/usr/local/bin/perl -w
use strict;
use IO::File;
my @files;
foreach (@ARGV) {
if ($_ eq 'STDOUT') {
push(@files, \*STDOUT);
} else {
my $fh = new IO::File(">>$_");
push(@files, $fh);
}
}
push(@files, new IO::File(">>/var/log/demogtrak.log"))
unless @files;
push(@files, \*STDERR);
foreach my $file (@files) {
print $file `/bin/date`;
print $file 'Demogtrak Logger starting up, sending log to ', scalar @files,
" files\n";
}
while (<STDIN>) {
foreach my $file (@files) {
print $file $_;
}
}
exit 0;
--
----------------------------------------------------------------------
Andrew J Perrin - Ph.D. Candidate, UC Berkeley, Dept. of Sociology
(Soon: Asst Professor of Sociology, U of North Carolina, Chapel Hill)
andrew_perrin@unc.edu - http://www.unc.edu/~aperrin
------------------------------
Date: Tue, 10 Apr 2001 03:49:19 GMT
From: dave@cadet.i-did-not-set--mail-host-address--so-shoot-me
Subject: Re: Want Lisp-like state machine impl.
Message-Id: <m2k84tz9a8.fsf@cadet.i-did-not-set--mail-host-address--so-shoot-me>
mjd@plover.com (Mark Jason Dominus) writes:
> In article <9armjh$ed4$1@charity.cs.utexas.edu>,
> Logan Shaw <logan@cs.utexas.edu> wrote:
> >I'd just like to point out that, while Lisp may be the lingua franca at
> >MIT, it isn't in comp.lang.perl.misc.
>
> Yes, I agree. Although it seemed to me that there might very well be
> a solution to his problem, I wasn't familiar enough with the CL
> feature that he described to know what the problem was.
>
> David, perhaps a more degtailed functional description would be helpful here.
I expounded a bit. See
Message-ID: <m3n19qgo6s.fsf@alum.mit.edu>
------------------------------
Date: 10 Apr 2001 00:18:45 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Want Lisp-like state machine impl.
Message-Id: <9au53l$lp1$1@charity.cs.utexas.edu>
In article <m3n19qgo6s.fsf@alum.mit.edu>,
David Bakhash <cadet@alum.mit.edu> wrote:
>Anyway, I thought the Lisp stuff was pretty straight-forward. It's
>syntax was:
>
>(defstate <name> (:throws (<list-of-exception-states>)
> :seeks (<list-of-sought-states>))
> <state-description-string>
> (<list-of-parameter-specifiations>)
> <state-implementation>)
>
>I was defining a ``state'' as something with a fixed number of
>(required) parameters, a list of possible next states (some being
>exceptional, some being non-exceptional), and an implementation.
>That's it. No magic.
>
>anyway, thanks for th help. Sorry the post was cryptic. The purpose
>was to eliminate the Perl-iness from the definition,
... definition of the states, right? I wasn't sure if what you
were asking about was implementing the simulator itself or what.
> and making the
>syntax look as custom as possible for the purposes of implementing a
>state machine.
If you want to make a custom syntax, one approach is to go get the
Parse::RecDescent module (or one of the other parser modules), write a
context-free grammar, and parse your files with it. Then you can have
an arbitrarily custom syntax (well, almost -- it has to be context
free), although doing so might actually generate more work.
If you're interested in that, see
http://search.cpan.org/Catalog/Language_Extensions/ .
>It might be as simple as:
>
>define_state("Q1",
> parameters => ["param-1",
> "param-2",
> ["param-3", type => INTEGER]]
> seeks => ["P2", "P3"]
> implementation => sub { ... });
>
>But, of course, that doesn't look as pretty as the Lisp (at least not
>to me). I was counting on a Perl guru to help me make it look nice
>(e.g. getting rid of the "'s if possible,
You can get rid of some of the quotation marks by doing this type
of thing:
parameters => [ qw( param-1 param-2 ) ]
But somehow I don't think you're going to find that prettier.
> perhaps making states
>generate subroutines whose names are the names of the states
>themselves, etc.
Hmm. I'm not sure how that makes it prettier. Maybe I'm
misunderstanding, but how do you protect against using a state
definition picking a subroutine name that's already used?
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Mon, 09 Apr 2001 21:04:30 -0700
From: Phil Voris <pvoris@nekophile.com>
Subject: We have 'use strict' and 'my', and now 'our', but no 'use local-scope' - why?
Message-Id: <3AD2864E.68F8FBCF@nowhere.com>
I've long been baffled that there is no pragma to automatically declare
all variables as default locally-scoped. This way, rather than typing
'my' everywhere, one could just type the ocassional 'our' and assume
everything else is local (er, my'd). I understand that there would be
problems with older code, but it sure would be a nice pragma to invoke
on new code.
Thoughts?
##pvorishatesspam at sega.com##
------------------------------
Date: 10 Apr 2001 06:56:59 GMT
From: grapeape@aol.comjunk (GrapeApe)
Subject: Re: Why Perl?
Message-Id: <20010410025659.29881.00002578@ng-fn1.aol.com>
>>Thats why I ask, why Perl? What can it do for me?
>
>From what I can see, you want MacPerl, and start practicing with
>regexes, s/// for replacing, and sort(). Most definitely check out the
>Schwartzian Transform. (<http://www.5sigma.com/perl/schwtr.html>, I
>think. The server isn't responding right now.)
I'm happy with my schwartz as it is....
Actually yes, that looks handy, from reading some Perlmonk discussion.
Yep have MacPerl, but of course can't think of what to do with it yet. It may
be a matter of looking at the o'reilly books again to scrap up some ideas, or
digging through my old problems that I have worked some other work pattern
around.
Thanks.
------------------------------
Date: Tue, 10 Apr 2001 08:47:32 +0200
From: Armin Nolte <armin.nolte@aktion-mensch.de>
Subject: wordsearcher-please help with my script
Message-Id: <3AD2AC84.E6CFA5F0@aktion-mensch.de>
Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------EE4A0751E2DCE1ACEB1D6DB4
Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353"
Content-Transfer-Encoding: 7bit
my skript 'search.pl' does not finish his work and I don't know why
So heres a summary:
Task:
search in all files / subdirectories for a key - word.
Process:
saves files/directory names in a hash., goes through them and after
work is done, it 'undefs' the hash-values.
Problem:
in large dir-trees not all values are 'undef', debugger says '100
levels deep in subroutine calls'.(???)
Question:
Is there any option which causes this (mis)behavior? Does someone know
this problem? Is there an
existing script which does this work (probably it is but what's it's
name)
Thanks for helping
Armin
e.g.
(I know it's a bit tim-consuming to handle with this scipt-but maybe
someone can give me an advice where
to search or what to do- please feel free to test my scipt)
--------------EE4A0751E2DCE1ACEB1D6DB4
Content-Type: application/x-perl; x-mac-type="54455854"; x-mac-creator="646F7361";
name="SEARCH.PL"
Content-Transfer-Encoding: 8bit
Content-Description: Dokument
Content-Disposition: inline;
filename="SEARCH.PL"
#!usr/bin/perl -w
use Cwd;
############################ Individuell bestimmen
@suchbegriffe = qw( Marketing );
############################ ENDE ################
open(OUT, ">>Treffer.csv") or die "kann datei nicht öffenen $!";
$i = 1;
#sub dateityp_abfragen {
# print "Bitte Dateisuffix eingeben!\n";
# $dateisuffix = <STDIN>;
# chomp $dateisuffix;
# if ($dateisuffix !~ /\w+/) {
# $dateisuffix = "*";
# }
#}
&verzeichnisliste_erstellen;
close(OUT);
print %ref_dave;
sub verzeichnisliste_erstellen {
opendir (CURR, ".") or die "Verzeichis kann nicht geöffnet werden $!";
my @dave;
my $da_ve;
while (defined ($da_ve = readdir(CURR))) {
if (-d $da_ve) { ## Verzeichnis ?
if ($da_ve =~ /^[^.]+$/){ ## -> keine versteckten Verzeichnisse '.' '..' verwenden
push @dave, $da_ve;
print "VERZEICHNIS-\da_ve: $da_ve\n"; #######testdruck
}
}
elsif (-f $da_ve) { ## Datei ?
print "DATEI-\da_ve: $da_ve\n";
push @dave, $da_ve;
}
else { ## sonst was ???
print "ELSE - Sonst was - \da_ve: $da_ve\n"; #######testdruck
}
}
if (defined $dave[0]) { ## gehaltvolles Verzeichnis
$ref_dave{$i} = [ @dave ];
closedir(CURR);
&Dat_Vz_Array_auslesen;
}
else { ## leeres Verzeichnis
closedir(CURR);
print "leeres Verzeichnis\n"; #######testdruck
if ($i > 1) {
&eins_hoeher;
}
}
}
sub Dat_Vz_Array_auslesen {
for ($k =0; $k <= $#{ $ref_dave{$i} }; $k++) {
my $da_ve = ${ $ref_dave{$i} }[$k];
undef ${ $ref_dave{$i} }[$k];
if (defined $da_ve) { # es existiert irgendwas
if (-d $da_ve) {
&eins_tiefer($da_ve) ; # print "Verzeichnis\n";
}
if (-f $da_ve) {
&Datei_einlesen($da_ve); # print "Datei\n";
}
}
}
if (defined $ref_dave{$i-1} ) {
&eins_hoeher;
}
}
sub eins_tiefer {
my $verzeichnis = $_[0];
chdir "$verzeichnis";
$i++;
&verzeichnisliste_erstellen;
}
sub eins_hoeher {
$i--;
chdir "..";
&Dat_Vz_Array_auslesen;
}
sub Datei_einlesen {
$dateiname = $_[0] ;
open(DATEI, "$dateiname" ) or die "kann datei nicht öffenen $!";
&suchen($dateiname, @suchbegriffe);
close DATEI;
}
sub suchen {
my $dateiname = shift @_;
my @suchbegriffe = @_;
my $suchbegriff;
$/ = "";
my $curr;
binmode DATEI;
while ($input = <DATEI>) {
#print $input;
foreach $suchbegriff (@suchbegriffe) {
if ($input =~ /$suchbegriff/gi) {
$curr = cwd();
print "\$curr: ", $curr, ,"\$i: ", $i, "\n" ;
print OUT "$suchbegriff: $curr/$dateiname, \n" ;
}
}
}
}
--------------EE4A0751E2DCE1ACEB1D6DB4
Content-Type: text/x-vcard; charset=us-ascii;
name="armin.nolte.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Visitenkarte fŸr Armin Nolte
Content-Disposition: attachment;
filename="armin.nolte.vcf"
begin:vcard
n:Nolte;Armin
tel;fax:+49-228-2092-281
tel;work:+49-228-2092-233
x-mozilla-html:FALSE
url:http://www.aktion-mensch.de
org:Deutsche Behindertenhilfe Aktion Mensch e.V.;Database Marketing
adr:;;Holbeinstrasse 15;Bonn;NRW;53175;Deutschland
version:2.1
email;internet:Armin.Nolte@aktion-mensch.de
x-mozilla-cpt:;3
fn:Armin Nolte
end:vcard
--------------EE4A0751E2DCE1ACEB1D6DB4--
------------------------------
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 664
**************************************