[19430] in Perl-Users-Digest
Perl-Users Digest, Issue: 1624 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 27 06:40:56 2001
Date: Mon, 27 Aug 2001 03:05:08 -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: <998906707-v10-i1624@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 27 Aug 2001 Volume: 10 Number: 1624
Today's topics:
Re: $1 as subroutine parameter - problems (Abigail)
Re: $1 as subroutine parameter - problems <bart.lateur@skynet.be>
Re: CGI redirect <godzilla@stomp.stomp.tokyo>
Re: CGI redirect <mbudash@sonic.net>
Re: CGI redirect <flavell@mail.cern.ch>
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: Error: "BEGIN not safe after errors" <news@N.O.--.S.P.A.M.andrew.dabsol.co.uk>
Re: File::Find not recursing on Win32 Perl 5.001 <goldbb2@earthlink.net>
Re: Grep Question <goldbb2@earthlink.net>
Re: How replace <goldbb2@earthlink.net>
Re: Multi-part HTML <goldbb2@earthlink.net>
Re: Newbie. Searching a text file and replacing text. <Rainer.Klier@erl.sbs.de>
Re: Problems with fixed-length random access databases. <dscarlett@optushome.com.au>
Re: Sex or Perl? Which is better? <qvyht@removejippii.fi>
SNMP ( Printer MIB ) <petek.external@infineon.com>
Re: Text::Wrap/ANSI proplem <goldbb2@earthlink.net>
Re: Warning Question <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Aug 2001 07:10:24 GMT
From: abigail@foad.org (Abigail)
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <slrn9ojsj5.p7l.abigail@alexandra.xs4all.nl>
ctcgag@hotmail.com (ctcgag@hotmail.com) wrote on MMCMXVII September
MCMXCIII in <URL:news:20010826183219.628$gz@newsreader.com>:
^^ abigail@foad.org (Abigail) wrote:
^^ > Markus Laire (markus.laire@usa.net) wrote on MMCMXVI September MCMXCIII
^^ > in <URL:news:Xns9109A5A7BF1markuslaire@192.89.123.233>:
^^ > -:
^^ > -: When I use $1 as parameter to subroutine, which does some regexp for
^^ > that -: parameter and then tries to use parameter again, it is changed by
^^ > that -: regexp because $_[0] seems to reference $1 which was given as
^^ > parameter.
^^ >
^^ > That's because Perl passes arguments by reference. You pass $1 as $_ [0],
^^ > which will be passed as a reference, then your regex will set $1 -
^^ > modifying $_ [0] too.
^^
^^ But, if you print $1 again after the subroutine, it will have the same
^^ value it did before the subroutine. So $_[0] wasn't really acting as an
^^ alias for the passed $1.
Oh, sure it does. Except that for each block, there's an implied local()
for $1 and friends. Hence the "restoration".
Abigail
--
perl -le 's[$,][join$,,(split$,,($!=85))[(q[0006143730380126152532042307].
q[41342211132019313505])=~m[..]g]]e and y[yIbp][HJkP] and print'
------------------------------
Date: Mon, 27 Aug 2001 07:41:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: $1 as subroutine parameter - problems
Message-Id: <0aujot02cpsas26e1nquhninho24c56ser@4ax.com>
ctcgag@hotmail.com wrote:
>The original poster said the code has illustrative of the behavior under
>discussion. I guess he could use substr, but then it would no longer
>illustrate the behavior it was intended to. Is there some reason you think
>he was lying, and that he actually plans to use the code as given in
>some application?
He obviously wants to do *some* regex matching on the matched result of
another pattern match. What regexes, that isn't part of the discusssion.
--
Bart.
------------------------------
Date: Mon, 27 Aug 2001 00:37:45 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: CGI redirect
Message-Id: <3B89F8C9.249C5D7E@stomp.stomp.tokyo>
Guy wrote:
(snipped)
> How can I redirect to a url, using POST, and pass it some parameters?
> and I would like to redirect to a url as if the user submitted a form (the
> parameters from the saved query) to the new url:
> but using POST.
I have noticed some rather interesting responses to this article.
You certainly don't need CGI.poopmaker to bloat memory usage and
to slow your script to a pace of a snail on ice.
Although LWP is an excellent and efficient module, it is not needed.
Lots of stuff suggested in stereotypical Perl 5 Cargo Cult vain,
are mondo beyondo wasteful and inefficient.
You want a post action redirection, easy as snapping your fingers.
* snaps her fingers *
Below my signature, you will logically discover two test scripts.
Name them according to the name given in each, under my Perl
locale line. This is the only critical point; test1.pl test2.pl
This is a very pretty method and, will impress your visitors
via providing any feedback or comments you like, before sending
your visitors off to another site. Just a simple matter of adding
whatever you like, whatever strokes your ego.
What strokes my ego is this. My methodology is stylish, affords
an ability to showcase, uses no modules and is exceptionally
quick and efficient along with being highly configurable.
Obviously you know what input variables are needed for a remote
site. You wouldn't be trying a post redirect if you didn't.
Load these scripts with correct names, point your browser at
either one, doesn't matter, my style is, as always, ingenious.
You will kick yourself on your butt for not taking this simple
and highly logical approach. This one is way easy.
This will teach you a lesson about taking Perl 5 Cargo Cultists
way too seriously.
Godzilla!
--
#!perl
#### TEST ONE SCRIPT - test1.pl
&Akostininchi_Ithana;
sub Akostininchi_Ithana
{
local (*in) = @_ if @_;
local ($i, $key, $val);
read (STDIN, $in, $ENV{'CONTENT_LENGTH'});
@in = split (/&/, $in);
foreach $i (0 .. $#in)
{
$in[$i] =~ s/\+/ /g;
($key, $val) = split (/=/, $in[$i], 2);
($val eq "") && next;
$key =~ s/%(..)/pack ("c",hex($1))/ge;
$val =~ s/%(..)/pack ("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val;
}
}
print "Content-type: text/html\n\n
<HTML><BR><BR>";
if (!($in{Control}))
{
print "
<FORM ACTION=\"test1.pl\" METHOD=\"POST\">
<INPUT TYPE=\"submit\" NAME=\"chat\" VALUE=\"Anumpa\">
<INPUT TYPE=\"hidden\" NAME=\"Control\" VALUE=\"Godzilla Rocks!\">
</FORM><P></HTML>";
}
else
{
print "
<FORM ACTION=\"test2.pl\" METHOD=\"POST\">
<INPUT TYPE=\"submit\" NAME=\"chat\" VALUE=\"Anumpa\">
<INPUT TYPE=\"hidden\" NAME=\"Control\" VALUE=\"Godzilla Rocks And Rolls!\">
</FORM><P>Input Received: $in{Control}<P>
You Are At Location One.<P>Click For Location Two.</HTML>";
}
exit;
#!perl
#### TEST 2 SCRIPT - test2.pl
&Akostininchi_Ithana;
sub Akostininchi_Ithana
{
local (*in) = @_ if @_;
local ($i, $key, $val);
read (STDIN, $in, $ENV{'CONTENT_LENGTH'});
@in = split (/&/, $in);
foreach $i (0 .. $#in)
{
$in[$i] =~ s/\+/ /g;
($key, $val) = split (/=/, $in[$i], 2);
($val eq "") && next;
$key =~ s/%(..)/pack ("c",hex($1))/ge;
$val =~ s/%(..)/pack ("c",hex($1))/ge;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $val;
}
}
print "Content-type: text/html\n\n
<HTML><BR><BR>";
if (!($in{Control}))
{
print "
<FORM ACTION=\"test2.pl\" METHOD=\"POST\">
<INPUT TYPE=\"submit\" NAME=\"chat\" VALUE=\"Anumpa\">
<INPUT TYPE=\"hidden\" NAME=\"Control\" VALUE=\"Godzilla Rocks And Rolls!\">
</FORM><P></HTML>";
}
else
{
print "
<FORM ACTION=\"test1.pl\" METHOD=\"POST\">
<INPUT TYPE=\"submit\" NAME=\"chat\" VALUE=\"Anumpa\">
<INPUT TYPE=\"hidden\" NAME=\"Control\" VALUE=\"Godzilla Rocks!\">
</FORM><P>Input Received: $in{Control}<P>
You Are At Location Two.<P>Click For Location One.</HTML>";
}
exit;
------------------------------
Date: Mon, 27 Aug 2001 08:13:51 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: CGI redirect
Message-Id: <mbudash-7EA3AF.01135127082001@news.sonic.net>
In article <3b889cc3@news.barak.net.il>, "Guy"
<guymal@__NOSPAM__hotmail.com> wrote:
> "Michael Budash" <mbudash@sonic.net> wrote in message
> news:mbudash-D8C354.00423925082001@news.sonic.net...
> > In article <9m6oo5$alt$1@news.netvision.net.il>, "Guy"
> > <guymal@__NOSPAM_hotmail.com> wrote:
> >
> > > "Michael Budash" <mbudash@sonic.net> wrote in message
> > > news:mbudash-C673C4.23485221082001@news.sonic.net...
> > > > In article <3b832ff4@news.barak.net.il>, "Guy"
> > > > <guymal@__NOSPAM__hotmail.com> wrote:
> > > >
> > > > > How can I redirect to a url, using POST, and pass it some
> parameters?
> > > > >
> > > > > I'm using CGI.pm to open a saved query:
> > > > > open(OLD_Q,"$saved_query_path")|| die "Error: $! in file:
> > > > > ".__FILE__."
> > > > > line:
> > > > > ".__LINE__."Cannot open saved query $saved_query_path \n";
> > > > > my $old_query=new CGI(OLD_Q);
> > > > > close(OLD_Q);
> > > > >
> > > > > and I would like to redirect to a url as if the user submitted a
> form
> > > > > (the
> > > > > parameters from the saved query) to the new url:
> > > > >
> > > > > print
> > > > > $old_query->redirect("http://my-server.com/cgi-bin/a-script.pl");
> > > > > #but
> > > > > I need to pass all saved parameters using POST
> > > > >
> > > > > What I basically need is how to do something like this:
> > > > > my $one=$old_query->param('param_1');
> > > > > my $two=$old_query->param('param_2');
> > > > > print
> > > > >
> > >
> $old_query->redirect("http://my-server.com/cgi-bin/a-script.pl?param_1=$on
> > > > > e&
> > > > > param_2=$two....");
> > > > >
> > > > > but using POST.
> > > >
> > > > use the LWP perl module (which can be found at
> > > > http://www.perl.com/CPAN-local/modules/by-module/LWP/ as
> > > > libwww-perl)
> > > >
> > >
> > > LWP would be used to open a connection from the web server to another
> > > url.
> > > What I need is to redirect the USER to another url (just like the
> > > CGI.pm
> > > redirect function).
> >
> > trust me, you want LWP in a POST scenario. i do it all the time... read
> > the LWP docs (type: perldoc lwpcook)... or not, it's your choice...
> >
>
> I've read the LWP documentation several times and used the module many
> times.
> Let me explain what I'm trying to achieve:
> The user goes to a script at a certain url (doesn't matter if the user's
> request is post or get).
> The script on the server opens a saved query, sends the contents of the
> saved query back to the client, and "tells" the client to open a
> connection
> to a different url/script and post the saved query it received there.
>
> Is this even possible?
> I read the excellent article that Alan wrote
> (http://ppewww.ph.gla.ac.uk/~flavell/www/post-redirect.html) but it
> didn't
> address anything similar to what I need (where the client gets the query
> from the server and then posts it somewhere else).
ok, what have you tried so far? what of that worked? what didn't?
in essence, since it's very difficult to do a post-redirect, what you
will do is impersonate a browser that's doing a post, and simply push
the received results back to the real browser.
just use the portion of lwpcook dealing with POSTs:
use LWP::UserAgent;
$ua = new LWP::UserAgent;
my $req = new HTTP::Request
'POST','http://my-server.com/cgi-bin/a-script.pl';
$req->content_type('application/x-www-form-urlencoded');
my $content;
foreach ($old_query->param()) {
$content .= "$_=" . CGI::escape($old_query->param($_)) . '&';
}
chop $content; # remove last '&'
$req->content($content);
my $res = $ua->request($req);
print $res->as_string;
hth (really)-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Mon, 27 Aug 2001 10:51:12 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI redirect
Message-Id: <Pine.LNX.4.30.0108271040050.3471-100000@lxplus023.cern.ch>
On Aug 26, Guy inscribed on the eternal scroll:
> Let me explain what I'm trying to achieve:
That's always a good plan...
> The user goes to a script at a certain url (doesn't matter if the user's
> request is post or get).
> The script on the server opens a saved query, sends the contents of the
> saved query back to the client, and "tells" the client to open a connection
> to a different url/script and post the saved query it received there.
Well, possibly this is how you aimed to implement it, but it doesn't
seem to me to be a description of what you're really trying to
achieve. It's often useful to take a bigger step back and look at the
overall aim, rather than getting bogged down in details of what at
first seemed a reasonable solution but then turns out to be sticky.
In any case, at the planning stage this question should be on
comp.infosystems.www.authoring.cgi; only when you've reached a point
where you have a problem with the Perl implementation would it be
properly on-topic here (or c.l.p.modules as the case may be).
You're trying to command a client to do something. But clients on the
WWW don't work like that. I see a number of possible approaches: -
1. write them a pre-filled form and invite the user to submit it.
(to get a POST request, you really have to submit the form, it's no
use just giving them a URL).
2. As 1, but with Javascript that auto submits the form. But they
might have Javascript disabled or filtered out, so you need to have
a fallback solution prepared as in 1.
3. Don't do it from the client at all, but from the initial server,
as other postings have already been suggesting to you.
a) by using LWP to issue the request from the initial server, and
return the results to the client as if from the initial server.
b) by configuring the server as a proxy [details would have to be
deferred to the appropriate servers' group - see Apache mod_rewrite
for example]
good luck
------------------------------
Date: 27 Aug 2001 08:33:04 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_998901127@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Windows
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/emacs-elisp.html
Emacs Perl Modules
Cperl -- Perl programming mode
.ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
.<olson@mcs.anl.gov> Bob Olson (started 1991)
.<ilya@math.ohio-state.edu> Ilya Zakharevich
Major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
.http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Load source code into Emacs, like Devel::DProf.pm
o Grep through all Perl manpages (.pod)
o Follow POD manpage references to next pod page with TinyUrl
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o TinyUrl is used to jump to URLs (other pod pages, man pages etc)
mentioned in POD pages. (It's a general URL minor mode)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in the Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up datatbases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to run the find for you, You can adjust
recursive grep options, ignored case, add user grep options.
You can get `igrep.el' module from <kevinr@ihs.com>. Ask for copy.
Check also ftp://ftp.ihs.com/pub/kevinr/
TinyCompile -- Browsing grep results in Emacs *compile* buffer
TinyCompile is minor mode for *compile* buffer from where
you can collapse unwanted lines, shorten the file URLs
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Mon, 27 Aug 2001 10:24:55 +0100
From: "Andrew Smith" <news@N.O.--.S.P.A.M.andrew.dabsol.co.uk>
Subject: Re: Error: "BEGIN not safe after errors"
Message-Id: <20010827092911.6437F34C.NOFFLE@tau.andrewsmith.plus.com>
Hi
The README said the script needed 5.0 or higher, although I upgraded to 5.6
and all works fine now.
Thanks :o)
Andrew
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9oi4dm.lu5.tadmc@tadmc26.august.net...
> Andrew Smith <news@N.O.--.S.P.A.M.andrew.dabsol.co.uk> wrote:
>
> No. It is a perl-version problem (I'd guess).
>
> our() was introduced in perl 5.6 you appear to have an earlier version
> of perl.
>
> One way to fix it would be to upgrade your perl.
>
> Another way would be to change our() to the "old way" of
> declaring dynamic variables, "use vars".
>
> perldoc vars
>
------------------------------
Date: Mon, 27 Aug 2001 04:08:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: File::Find not recursing on Win32 Perl 5.001
Message-Id: <3B89FFF8.FCBFE1DD@earthlink.net>
Phil Hibbs wrote:
>
> I tried this from the cookbook:
>
> @ARGV = qw(.) unless @ARGV;
> use File::Find;
> find sub { print $File::Find::name, -d && '/', "\n" }, @ARGV;
>
> It doesn't recurse into subdirectories. Ideas why not? I can't upgrade
> my perl, as this has to function on other machines with standard
> installs.
Try looking into find() via perl's debugger.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Mon, 27 Aug 2001 04:14:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Grep Question
Message-Id: <3B8A014A.D3CE13D0@earthlink.net>
Tad McClellan wrote:
>
> meadows_p <meadows_p@yahoo.com> wrote:
>
> > my @foundfiles = grep($bmCode, @$files);
>
> >I'm passing a directory listing and trying to filter out the files
> >who's names contain the what's in $bmCode.
> ^^^^^^^^^^^^^^^^^
>
> Well, we need to know what is in $bmCode then.
>
> >It displays the list of files correctly, but after my grep,
> >@foundfiles seems to contain exactly the same as @files.
>
> Then evaluating "$bmCode" must be coming up "true" for every
> list element.
>
> >Can anyone help me as to why my grep isn't working?
>
> perldoc -f grep
>
> Shows the first argument is an EXPR. If, for instance, $bmCode =
> 'foo', then Perl sees
>
> my @foundfiles = grep('foo', @$files);
>
> The EXPR 'foo' (a string) always evaluates to "true" so grep()
> always selects it for the output list.
>
> You need to make it be a real EXPR, but what kind of EXPR we
> cannot tell because you have not given us enough information.
>
> Maybe one of these:
>
> grep /$bmCode/, ... # EXPR is a pattern match
>
> grep /\Q$bmCode/, ... # might contain regex metachars
>
> grep /\.$bmCode$/, ... # $bmCode is a filename extension
>
> You want $_ involved in the EXPR somehow, 'cause that is where
> grep() puts each list element.
Other possibilities are:
grep $bmCode->(), ... # assumes it's a coderef looking at $_
grep $bmCode->($_), ... # assumes it's a coderef looking at @_
grep index($_,$bmCode) != -1, ... # like /\Q$bmCode/ but faster.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Mon, 27 Aug 2001 04:18:35 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How replace
Message-Id: <3B8A025B.F7D40108@earthlink.net>
Dmitry wrote:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:9lgeun$kle$3@mamenchi.zrz.TU-Berlin.DE...
> > According to Dmitry <sda999@mail.ru>:
> > > Source string: "abcebsasaanrart"
> > > I want transform in "abcebsasaanraart"
> > > i.e. replace last "a" in "aa" (count "a" - arbitrary)
> >
> > Replace the last "a" in a string with "aa"?
> >
> > s/a([^a]*)$/aa$1/;
> >
> > Anno, wondering what that operation might be good for
>
> Tankx.
>
> Real strange situation :|
> I send .uue file at Unix host mailbox (created win32 application)
> there it uudecoded and put in dir. All good, but...
> Rarely, but uudecoded with errors - defacement 2 symbols
> ("`" and "." ) in last string uue-code ("."->"..", "`"->"``")
> in ONE places!
> Here i investigate in this bugs ;(
> If you known with this things - advise me pls.
Hmm. Either the win32 programs is defacing it, or the mail hosts in
between are defacing it, or the unix machine is defacing it on
reception. How about you base64 encode it instead of uuencoding it?
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Mon, 27 Aug 2001 05:21:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multi-part HTML
Message-Id: <3B8A1136.358D406F@earthlink.net>
Bob wrote:
>
> I have a perl program which sends:
>
[snip]
That should probably be multipart/mixed-replace, not multipart/mixed.
> Now Netscape does exactly what I expected. It shows the first html,
> asks for a destination for the zip, and when the download is
> completed, it shows the second html.
>
> IE, on the other hand, seems brain dead. It reads the first
> content-type spec, but ignores "multipart". It displays everything
> following, including the subsequent boundaries and content types and
> the zip file, as though it were a single html.
>
> I've read through RFC-2045 and RFC-2046 to see if there's something
> I'm missing, but haven't found anything. Any idea how to get IE to
> properly handle multi-part content?
I think you might consider looking at the CGI::Push module.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Mon, 27 Aug 2001 08:53:11 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: Re: Newbie. Searching a text file and replacing text.
Message-Id: <3B8A1887.F8A79B8C@erl.sbs.de>
Rainer Klier wrote:
>
> Andrew Paul Gorton wrote:
> >
> > I need to find say the ChkDisk and replace this line with the updated
> > line from another program.
> > How is this done.
> ------------------- untested ---------------------
> #!/usr/bin/perl -w
> use Fcntl qw/:DEFAULT :flock :seek/;
>
> my $file = "/path/to/file";
> sysopen(FH,$file,O_RDWR) or die("Cannot open file $file for writing.
> $!.");
> flock(FH,LOCK_EX) or die("Cannot get exclusive lock for $file. $!.");
> my @lines = <FH>;
> seek(FH,0,SEEK_SET);
> truncate(FH,0);
> foreach (@lines) {
> $_ = "ChkDisk:\t$newvalue\n" if(/^ChkDisk:/);
> print FH;
> }
> close(FH);
> ------------------- untested ---------------------
>
> Provides Filelocking, in case you have
> more progs accessing the file concurrently.
> If not, skip the flock line.
What I wonder is, wether this is a common way to
update textfiles. Is there another possibility?
I do not like the idea so much to load the whole
file into memory.
Rainer
------------------------------
Date: Mon, 27 Aug 2001 07:41:45 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <ZQmi7.23256$A5.71534@news1.eburwd1.vic.optushome.com.au>
"Eric Bohlman" <ebohlman@omsdev.com> wrote in message
news:9mbrqc$8kv$3@bob.news.rcn.net...
> David Scarlett <dscarlett@optushome.com.au> wrote:
> > if (@_[0,1] == (unpack($pstring,$buf))[0,1]) { # Record
found.
>
> You can't compare lists like this.
I beg to differ. Have a look at the following script and it's output.
----------------
#!/usr/bin/perl
use strict;
my($i,$j);
my(@array) = (1,2,3,4,5,1,2,3,4,5);
foreach $i (0,1,2,3) {
foreach $j (5,6,7,8) {
if (@array[$i,$i+1] == @array[$j,$j+1]) {
print "True\n";
} else {
print "False\n";
}
}
}
---------------
True
False
False
False
False
True
False
False
False
False
True
False
False
False
False
True
---------------
--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/
"If you have a thing for parentheses, then LISP is the programming language
for you!"
-My Computing Fundamentals lecturer
------------------------------
Date: Mon, 27 Aug 2001 08:08:14 GMT
From: Hessu <qvyht@removejippii.fi>
Subject: Re: Sex or Perl? Which is better?
Message-Id: <3B89FE24.6BF2092A@removejippii.fi>
None wrote:
>"none"
I'm doing perl all night long to my Girl!
So did I miss something here?
YAPF
------------------------------
Date: Mon, 27 Aug 2001 11:50:36 +0200
From: "Suko Paul" <petek.external@infineon.com>
Subject: SNMP ( Printer MIB )
Message-Id: <9md55d$i3j$1@mosquito.HL.Siemens.DE>
Hi !
Does anyone have experience with the SNMP Package ( Net-SNMP -
www.net-snmp.org )?
1) First Problem: I added the Printer-MIB to the MIBS. But when i start a
snmp-request i always get the warning ( unlinked OID in Printer-MIB - 43 ).
Does anyone knows how to solve this ?
2) I want to determine the Trays of a printer, but i didnīt find a oid,
which descripbes this. Does anyone knows, how to determine the trays of a
printer ( a clean way ).
thanks
HP
------------------------------
Date: Mon, 27 Aug 2001 05:18:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Text::Wrap/ANSI proplem
Message-Id: <3B8A106C.D194FF10@earthlink.net>
Philip Taylor wrote:
>
> I've got some text which needs to be wrapped at 50 columns, and
> Text::Wrap does this fine.
>
> However, there is a problem when the text contains ANSI codes, e.g.
> "\e[31mThis line of text should appear in the colour red\e[0m".
>
> When displayed, the ANSI codes don't take up any space (i.e. the
> user sees just "This line [...] colour red", which is 49 characters),
> but Text::Wrap doesn't know this and counts the ANSI codes as
> displayed characters, making it 58 characters long and wrapping it
> incorrectly.
>
> Is there an easy way to make Text::Wrap ignore the codes when
> calculating the wrapping, but still include them in the printed
> output?
Hmm, not quite ignore them, but here's a way to make them get counted as
single characters, which produces results which are closer to correct.
my $text = "\e[31m".
"This line of text should appear in the colour red".
"\e[0m";
my @ansi;
$text =~ s/((?:
\e \[ [\d;?]* [^\d;?] |
\e \( . |
\e \] \d+ [^\cG\n]* \cG |
\e [^](] # this is a kind of fallthough.
)+)/push(@ansi, $1), "\01"/gsex;
$text = wrap("\t","",$text);
$text =~ s/\01/pop @ansi/ge;
You might want to change the regex for matching ansi a bit... There are
surely other patterns which can represent escape sequences.
My favorite escape sequence is "\e]2;stuff here\cG" (yes, that is a "]"
not a "["), and where I have "stuff here", you can put any string which
doesn't have a control-g. What this sequence does is an exercise for
the reader. Using 1 instead of 2 has a similar, but slightly different
[and possibly less noticable] effect. Using 3 has the effect of doing
both the 1 effect and the 2 effect at the same time. This particular
escape sequence doesn't work on MS telnet, though, and *might* [i'm not
sure] only work with xterm and clones of it.
I believe that higher numbers for this type of escape sequence are used
for setting the text and background to *named* colors -- though I forget
which numbers are needed.
Anyway, you want the regex to match any kind of ansi sequence which
could conievably occur.
--
I'm not a programmer but I play one on TV...
------------------------------
Date: Mon, 27 Aug 2001 04:06:09 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Warning Question
Message-Id: <3B89FF71.1CADCE7D@earthlink.net>
Mark Riehl wrote:
>
> All - I'm reading from a CSV file, using strict and diagnostics. I'm
> getting a warning on the input that I can't seem to resolve:
>
> $_ = 591347,097 20:15:56.311,8453756,1000896,R,-116.575062,35.350251
> Use of uninitialized value in numeric ne (!=) at new_kpp_jev2.pl line
> 401,
> <INPUT> line 2 (#1)
>
> I'm printing out the current line of my input file ($_) and my input
> file is named INPUT. I'm tracking down the uninitialized warning, but
> what is the <INPUT> line 2 (#1)?
It means that the most recent filehandle which you've read from is named
INPUT, and that two lines have been read from it (ie, $. == 2).
However, I'm not sure what the (#1) means.
--
I'm not a programmer but I play one on TV...
------------------------------
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 1624
***************************************