[23322] in Perl-Users-Digest
Perl-Users Digest, Issue: 5542 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 22 14:06:03 2003
Date: Mon, 22 Sep 2003 11:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 22 Sep 2003 Volume: 10 Number: 5542
Today's topics:
Re: "my" declarations, only matter of taste? <peter@semantico.com>
Re: "my" declarations, only matter of taste? (Chris Richmond - MD6-FDC ~)
Re: "my" declarations, only matter of taste? (Chris Richmond - MD6-FDC ~)
Re: "my" declarations, only matter of taste? (Chris Richmond - MD6-FDC ~)
Re: "my" declarations, only matter of taste? (Chris Richmond - MD6-FDC ~)
Re: () questions <mpapec@yahoo.com>
Re: () questions <mpapec@yahoo.com>
Re: () questions <mpapec@yahoo.com>
Re: Can Filehandles Be Shared Between Threads? <mooseshoes@gmx.net>
Re: Can Filehandles Be Shared Between Threads? <syscjm@gwu.edu>
Re: Can Filehandles Be Shared Between Threads? <mooseshoes@gmx.net>
Capturing a data squirt. <spikey-wan@bigfoot.com>
CGI.pm <notavailable@nospamplease.com>
Re: CGI.pm <pinyaj@rpi.edu>
Re: CGI.pm <notavailable@nospamplease.com>
Re: CGI.pm <notavailable@nospamplease.com>
Re: CGI.pm (Helgi Briem)
Re: CGI.pm <pilsl_usenet@goldfisch.at>
fixed width fields (Jim)
Re: fixed width fields <pilsl_usenet@goldfisch.at>
Re: fixed width fields <minceme@start.no>
Re: Form problems, post method yeilds 0 at end of value <notavailable@nospamplease.com>
Re: Form problems, post method yeilds 0 at end of value <mills_nospam_@free.fr>
Re: killing zombie file lock <ryantate@OCF.Berkeley.EDU>
Re: killing zombie file lock <ryantate@OCF.Berkeley.EDU>
Re: killing zombie file lock <ddunham@redwood.taos.com>
Re: length of the longest $_ in @_ <pinyaj@rpi.edu>
Re: length of the longest $_ in @_ <minceme@start.no>
Re: Operator Precedence (Jeff Mott)
Re: regexp help - match on two backslashes <shondell@cis.ohio-state.edu>
splitting lines <bobsmith@jippii.fi>
Re: splitting lines <bigus_34@yahoo.co.uk>
Re: string length? <someone@microsoft.com>
Re: string length? <raisin@delete-this-trash.mts.net>
Re: string length? <abigail@abigail.nl>
Re: string length? <syscjm@gwu.edu>
Re: string length? <uri@stemsystems.com>
Re: string length? <jurgenex@hotmail.com>
Re: What are you allowed to share? <mooseshoes@gmx.net>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Sep 2003 16:26:24 +0100
From: Peter Hickman <peter@semantico.com>
Subject: Re: "my" declarations, only matter of taste?
Message-Id: <3f6f14a0$0$24109$afc38c87@news.easynet.co.uk>
Abigail wrote:
> Peter Hickman (peter@semantico.com) wrote on MMMDCLXXIV September
> MCMXCIII in <URL:news:3f6ed7d7$0$24108$afc38c87@news.easynet.co.uk>:
> !! Abigail wrote:
> !! >
> !! > Actually, for a small loop that you run many times, it may matter:
> !! >
> !! > #!/usr/bin/perl
> !! >
> !! > use strict;
> !! > use warnings;
> !! >
> !! > use Benchmark qw /cmpthese/;
> !! >
> !! > our $loop = 1000;
> !! >
> !! > cmpthese -2 => {
> !! > inner => ' for (1 .. $::loop) {my $m = $_ % 3}',
> !! > outer => 'my $m; for (1 .. $::loop) { $m = $_ % 3}',
> !! > };
> !! >
> !! > __END__
> !! > Benchmark: running inner, outer for at least 2 CPU seconds...
> !! > inner: 2 wallclock secs ( 2.04 usr + 0.00 sys = 2.04 CPU)
> !! > @ 1982.35/s (n=4044)
> !! > outer: 2 wallclock secs ( 2.11 usr + 0.00 sys = 2.11 CPU)
> !! > @ 2858.77/s (n=6032)
> !! > Rate inner outer
> !! > inner 1982/s -- -31%
> !! > outer 2859/s 44% --
> !! >
> !! >
> !! > Abigail
> !!
> !! Just for completeness there is also
> !!
> !! middle => ' for my $m (1 .. $::loop) { $m = $_ % 3}',
> !!
> !! Which I favour which lies between the two.
>
>
> Well, that's something different. In both inner and outer, $_ iterates
> from 1 to $::loop, and $m is derivated from that. If you make $m the
> loop variable, and then do something like $m = $m % 3; in the loop,
> you don't have the original value anymore.
>
>
> Abigail
Oops. Should have read it slower.
"That just went on your permanent record" as they say.
------------------------------
Date: Mon, 22 Sep 2003 15:44:25 +0000 (UTC)
From: crichmon@filc8533.fm.intel.com (Chris Richmond - MD6-FDC ~)
Subject: Re: "my" declarations, only matter of taste?
Message-Id: <bkn5cp$qmi$1@news01.intel.com>
In article <bkl1vu$pl3$1@nets3.rz.RWTH-Aachen.DE>,
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> writes:
>Also sprach Chris Richmond - MD6-FDC ~:
>Whereas with strictures:
>
> ethan@ethan:~$ perl -Mstrict
> my $variable = "foobar";
> print $varaible;
> __END__
> Global symbol "$varaible" requires explicit package name at - line
> Execution of - aborted due to compilation errors.>
>So I don't need this warning any longer. It would serve no purpose and
>given that the lower code wont even compile, emitting an additional
>warning would be rather pointless.
Point taken. My secondary complaint is that with strict you
have to put 'my' or some global scope on every variable you
use. Its more typing and just that much more line noise.
thx, Chris
--
Chris Richmond | I don't speak for Intel & vise versa
------------------------------
Date: Mon, 22 Sep 2003 15:48:34 +0000 (UTC)
From: crichmon@filc8533.fm.intel.com (Chris Richmond - MD6-FDC ~)
Subject: Re: "my" declarations, only matter of taste?
Message-Id: <bkn5ki$qmi$2@news01.intel.com>
In article <vms31gnatp959e@corp.supernews.com>,
Steve May <drumspoorly@reachone.net> writes:
>Chris Richmond - MD6-FDC ~ wrote:
>Ah... I would say you are setting yourself up for other
>problems by refusing to use 'my'.
I'm not refusing, I just don't like it that well. We've
developed this environment over maybe 5 years, and its quite
robust. Whatever pitfalls with/without 'my' have been
dealt with. Actually, one of the several developers does
use strict and my in his stuff. It works. I find the occational
laziness related to 'my' variables.
>You might think about building a little routine to take advantage of
>the argument form of the function 'caller'. I trap errors and feed
>them to a caller trace routine I wrote that tells me exactly what
>happened, where it happened and how it got there.
We've got something similar.
Thx, Chris
--
Chris Richmond | I don't speak for Intel & vise versa
------------------------------
Date: Mon, 22 Sep 2003 15:54:44 +0000 (UTC)
From: crichmon@filc8533.fm.intel.com (Chris Richmond - MD6-FDC ~)
Subject: Re: "my" declarations, only matter of taste?
Message-Id: <bkn604$qmi$3@news01.intel.com>
In article <slrnbms9km.1rs.tadmc@magna.augustmail.com>,
tadmc@augustmail.com (Tad McClellan) writes:
>Chris Richmond - MD6-FDC ~ <crichmon@filc8533.fm.intel.com> wrote:
>It is not that lexical variables are so great.
>It is that global variables (the alternative) are so bad.
Right. For better or worse, all the subroutines are
packaged such that un-my'd variables act more like auto
variables in a C program. we treat them as local to
the routine.
>You catch typos on a fairly regular basis because every variable
>in your program is a global variable.
They "aren't." I realize that packages are just more globals
with an alternate name space.
>That will cause you great pain at some point in time.
Its all been worked through.
>You can have both (lexicals and typo detection) if you "use strict"
>which you should be already doing anyway.
As I said in a previous followup, with the packaged subs, I can
treat unmarked variables local to the sub without having to
type 'my' in front of everything. Reduces typing and line noise.
my still disables 'used only once' detection, and strict doesn't
catch it either.
Thx, Chris
--
Chris Richmond | I don't speak for Intel & vise versa
------------------------------
Date: Mon, 22 Sep 2003 15:56:07 +0000 (UTC)
From: crichmon@filc8533.fm.intel.com (Chris Richmond - MD6-FDC ~)
Subject: Re: "my" declarations, only matter of taste?
Message-Id: <bkn62n$qmi$4@news01.intel.com>
In article <3F6E2AC0.9000406@gwu.edu>,
Chris Mattern <syscjm@gwu.edu> writes:
>Chris Richmond - MD6-FDC ~ wrote:
>> If 'my' is so great, why does it disable the 'used only once'
>> warning from perl -w? I catch typos on a fairly regular basis
>> because I don't use 'my'.
>
>If you'd use "use strict", you'd catch even more. The idea
>is to us "my" *and* "use strict". That way every variable
>you didn't declare rings the bell.
I know. my and strict still don't catch unused variables
(used only once).
Thx, Chris
--
Chris Richmond | I don't speak for Intel & vise versa
------------------------------
Date: Mon, 22 Sep 2003 19:31:31 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <d68umv4a6l4ebcp3b6r4bqppqphouddi8i@4ax.com>
X-Ftn-To: Eric J. Roode
>> 1) () stands afaik for "empty list", so why it doesn't pass a map
>> function? Is such behavior accidental or intentional?
>>
>> print join ',', map $_%2 ? () : $_, 1..20;
>
>I do not understand what you mean by "pass a map function". The above
"Passing a map" is what happens to $_ when it gets transformed by map (from
right to left).
>statement prints "2,4,6,8,10,12,14,16,18,20", which makes perfect sense
>to me. What is puzzling you about it?
Well, map is a function which transforms list of values, so one could
expect[1] at least one value on the left side of map, for each element
coming from right. In case of empty list, () nothing gets through..?
>> 2) how to grok this expression, what exactly perl does here?
>>
>> my $count = () = $data =~ /match/g;
>
>This is a semi-cheesy way of getting a list context on the right side of
>the expression and a scalar context on the left side. In a list context,
>m//g gives a list of all matching substrings. The left side, $count, is
>in scalar context, which yields the number of substrings.
This forcing of list context looks easier then @{[]} but who can tell if
newer perls will support it?
[1] at least on the 'do what I mean' basis :)
--
Matija
------------------------------
Date: Mon, 22 Sep 2003 19:31:33 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <8eaumvsup9d5rjfdcj89jcp38815pjeafn@4ax.com>
X-Ftn-To: Abigail
Abigail <abigail@abigail.nl> wrote:
>][ 2) how to grok this expression, what exactly perl does here?
>][
>][ my $count = () = $data =~ /match/g;
>
>Perl does a little strange here. It matches /match/ against $data,
>repeatedly, and, because it's in list context, it returns a list
>of the matches (since there are no parens in /match/).
>
>But the list itself is in scalar context. Now, we all like to chant
>that there are no lists in scalar context, but this one is. And
>apparently, a list in scalar context returns the number of elements
>in the list.
>
>However, I doubt this is documented.
Really don't have a clue, I didn't saw it till recently..
>][ is this /on the perl side/ same as,
>][ my $count = @{[ $data =~ /match/g ]};
>
>Sort of. Except that instead of a list, we have an array in scalar
>context. And that behaviour is well defined.
Err, any suggestion for perldoc RTFM? :)
--
Matija
------------------------------
Date: Mon, 22 Sep 2003 19:31:33 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: () questions
Message-Id: <f5bumvsas5pfo23t5bhik50422pj49f5t6@4ax.com>
X-Ftn-To: John W. Krahn
"John W. Krahn" <krahnj@acm.org> wrote:
>> Is such behavior accidental or intentional?
>>
>> print join ',', map $_%2 ? () : $_, 1..20;
>
>$ perl -le'print join ",", map $_%2 ? () : $_, 1..20;'
>2,4,6,8,10,12,14,16,18,20
>
>It works fine here. What problems are you having?
See my post to Eric.
>> 2) how to grok this expression, what exactly perl does here?
>>
>> my $count = () = $data =~ /match/g;
>>
>> is this /on the perl side/ same as,
>> my $count = @{[ $data =~ /match/g ]};
>
>The first one uses a list to get the count and the second one uses an
>array. I would assume, but I don't know for sure, that populating and
>dereferencing an array would be less efficient then using a list.
Tnx, I'll try benchmark.
--
Matija
------------------------------
Date: Mon, 22 Sep 2003 15:34:56 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: Can Filehandles Be Shared Between Threads?
Message-Id: <AEEbb.9913$Om4.168118445@newssvr13.news.prodigy.com>
I figured it out...
------------------------------
Date: Mon, 22 Sep 2003 11:57:22 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Can Filehandles Be Shared Between Threads?
Message-Id: <3F6F1BE2.8040606@gwu.edu>
mooseshoes wrote:
> I figured it out...
>
>
Care to share it with the rest of the class? :-)
Seriously, searching old threads is a valuable research
tool; when you find an answer to a question you asked,
post it, so that other people can find that answer later.
chris Mattern
------------------------------
Date: Mon, 22 Sep 2003 16:31:47 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: Can Filehandles Be Shared Between Threads?
Message-Id: <TtFbb.18$ew7.7643237@newssvr21.news.prodigy.com>
<snip>
> Care to share it with the rest of the class? :-)
>
> Seriously, searching old threads is a valuable research
> tool; when you find an answer to a question you asked,
> post it, so that other people can find that answer later.
<<< I actually did with a response to David Morel's "What Are You Allowed To
Share?" thread from yesterday. My response was:
"<<< After a lengthy evening of continued research I was able to make this
work. As far as I can tell you should avoid using any filehandle creation
method that creates objects (FileHandle, IO::Handle), because threads
(perlthrtut) prefer simple scalars. You can create filehandles rather
simply with several different methods. I am using typeglob filehandles
which can be passed around quite readily. Check out perldata on how to do
this. I have implemented it and it works."
Moose
------------------------------
Date: Mon, 22 Sep 2003 16:42:19 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Capturing a data squirt.
Message-Id: <bkn5be$f84$1@newshost.mot.com>
Guys,
The infra red port on my laptop is com4. When I point my palm pilot at it,
and send a file it works just fine, and the file is transferred. (Running
w32)
I want to capture this data squirt, and store it in a file, so I tried
this...
use strict;
use warnings;
use Win32::SerialPort;
open( PORT, "+>COM4" ) or die "Can't open COM4: $!";
open (FILE, ">file.txt");
while (1) {
my $input = <PORT>;
print FILE "$input\n";
}
However all I get is a file containing nothing at all.
Can anyone help me, please?
Thanks.
--
R.
GPLRank +79.699
------------------------------
Date: Mon, 22 Sep 2003 16:53:15 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: CGI.pm
Message-Id: <4WEbb.734$xr.21@newsfep1-gui.server.ntli.net>
Hi folks,
How do i go about get a parameter list from a form, without having to use
CGI.pm?
I was going to use this, but it's just a waste of time learning how to use
it correctly - i mean if i wanted to read, read, read and read i would have
just got a job in a library. It's something that i have been finding with
perl more and more. I finished reading the Llama about a week ago, and have
since been horrified by sheer mass of perl bits and bobs. The TMTOWTDI
motto, is all well and fine but it also helps to badly confuse a beginner in
language, you read a peice of text from one person and later you read
another telling you that what you just read, isn't the best or safest way to
do it, then later on you read that, that people don't like it that way
either, but prefer to do this. Then there's all the modules, soom seem to
have tried to re-create a sub-language within perl as some of the syntax for
some modules i have seen. Then there's the book on every kind of subject
that you can think of with perl - (i ain't rich and can't afford these, so
perl's free but learning it's not? as the only other alternative to outdated
or badly coded tutorials by the odd perl programmer) To be quite honest the
only reason i chose perl over PHP was because i believe(d) that PHP was just
a hype and when when perl6 is released everyone would come flooding back to
perl, et cetera, but somehow i'm starting to think i chose wrong :( Maybe
PHP was the better choice.
Well that's a little bit of the stress perl has given me gone... sigh
Dagmar
------------------------------
Date: Mon, 22 Sep 2003 12:14:50 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: CGI.pm
Message-Id: <Pine.SGI.3.96.1030922121236.774837A-100000@vcmr-64.server.rpi.edu>
On Mon, 22 Sep 2003, D Borland wrote:
>How do i go about get a parameter list from a form, without having to use
>CGI.pm?
It's not easy. CGI.pm makes it easy.
use CGI 'param';
my @form_fields = param();
Ta da!
>I was going to use this, but it's just a waste of time learning how to use
>it correctly - i mean if i wanted to read, read, read and read i would have
>just got a job in a library.
Heh. It's an important module, it does a lot, and it needs documentation.
But the part you need isn't very hidden or difficult to find.
>Maybe PHP was the better choice.
If what you need is web-based stuff, by all means, use PHP. That's what
it's there for.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 22 Sep 2003 17:28:14 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: CGI.pm
Message-Id: <XrFbb.6722$Ne.2732660@newsfep2-win.server.ntli.net>
I know, your right! I guess i'm just getting stressed out a bit and needed
to let off a bit of steam, so perl got it :)
i understand that PHP is built for web-scripting but it's then learn PHP
aswell, and as you can see i'm most likely gonna lose the plot trying. I'll
stick to perl and try to agree with the docs rather than argue with them.
"What was that?", "Did you hear that?"...
Cheers
"Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
news:Pine.SGI.3.96.1030922121236.774837A-100000@vcmr-64.server.rpi.edu...
> On Mon, 22 Sep 2003, D Borland wrote:
>
> >How do i go about get a parameter list from a form, without having to use
> >CGI.pm?
>
> It's not easy. CGI.pm makes it easy.
>
> use CGI 'param';
>
> my @form_fields = param();
>
> Ta da!
>
> >I was going to use this, but it's just a waste of time learning how to
use
> >it correctly - i mean if i wanted to read, read, read and read i would
have
> >just got a job in a library.
>
> Heh. It's an important module, it does a lot, and it needs documentation.
> But the part you need isn't very hidden or difficult to find.
>
> >Maybe PHP was the better choice.
>
> If what you need is web-based stuff, by all means, use PHP. That's what
> it's there for.
>
> --
> Jeff Pinyan RPI Acacia Brother #734 2003 Rush
Chairman
> "And I vos head of Gestapo for ten | Michael Palin (as Heinrich
Bimmler)
> years. Ah! Five years! Nein! No! | in: The North Minehead
Bye-Election
> Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
>
------------------------------
Date: Mon, 22 Sep 2003 17:28:14 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: CGI.pm
Message-Id: <zqFbb.754$xr.65@newsfep1-gui.server.ntli.net>
I know, your right! I guess i'm just getting stressed out a bit and needed
to let off a bit of steam, so perl got it :)
i understand that PHP is built for web-scripting but it's then learn PHP
aswell, and as you can see i'm most likely gonna lose the plot trying. I'll
stick to perl and try to agree with the docs rather than argue with them.
"What was that?", "Did you hear that?"...
Cheers
"Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
news:Pine.SGI.3.96.1030922121236.774837A-100000@vcmr-64.server.rpi.edu...
> On Mon, 22 Sep 2003, D Borland wrote:
>
> >How do i go about get a parameter list from a form, without having to use
> >CGI.pm?
>
> It's not easy. CGI.pm makes it easy.
>
> use CGI 'param';
>
> my @form_fields = param();
>
> Ta da!
>
> >I was going to use this, but it's just a waste of time learning how to
use
> >it correctly - i mean if i wanted to read, read, read and read i would
have
> >just got a job in a library.
>
> Heh. It's an important module, it does a lot, and it needs documentation.
> But the part you need isn't very hidden or difficult to find.
>
> >Maybe PHP was the better choice.
>
> If what you need is web-based stuff, by all means, use PHP. That's what
> it's there for.
>
> --
> Jeff Pinyan RPI Acacia Brother #734 2003 Rush
Chairman
> "And I vos head of Gestapo for ten | Michael Palin (as Heinrich
Bimmler)
> years. Ah! Five years! Nein! No! | in: The North Minehead
Bye-Election
> Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
>
------------------------------
Date: Mon, 22 Sep 2003 16:34:02 GMT
From: f_baggins80@hotmail.com (Helgi Briem)
Subject: Re: CGI.pm
Message-Id: <3f6f2320.606259995@News.CIS.DFN.DE>
On Mon, 22 Sep 2003 16:53:15 +0100, "D Borland"
<notavailable@nospamplease.com> wrote:
>How do i go about get a parameter list from a form, without having to use
>CGI.pm?
Well, it's pretty hard. On the other hand, using the module,
it's amazingly easy:
use CGI qw(param);
my @params = param();
>I was going to use this, but it's just a waste of time learning how to use
>it correctly - i mean if i wanted to read, read, read and read i would have
>just got a job in a library.
Perl requires less reading than any other programming language.
What you *do* have to read is well organised and easily
accessible.
> It's something that i have been finding with
>perl more and more. I finished reading the Llama about a week ago, and have
>since been horrified by sheer mass of perl bits and bobs.
It's a big language.
>The TMTOWTDI
>motto, is all well and fine but it also helps to badly confuse a beginner in
>language, you read a peice of text from one person and later you read
>another telling you that what you just read, isn't the best or safest way to
>do it, then later on you read that, that people don't like it that way
>either, but prefer to do this.
Well, read the documentation then and not some random crap
from all over the place.
>Then there's all the modules, soom seem to
>have tried to re-create a sub-language within perl as some of the syntax for
>some modules i have seen. Then there's the book on every kind of subject
>that you can think of with perl
People write books that they hope they can sell. Shrug. So what?
>- (i ain't rich and can't afford these, so perl's free but learning it's not?
Yes, read the Perl documentation that comes bundled with every
Perl distribution.
--
Helgi Briem hbriem AT simnet DOT is
Excuse the munged address. My last
e-mail address was killed by spammers.
------------------------------
Date: Mon, 22 Sep 2003 19:03:38 +0200
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: Re: CGI.pm
Message-Id: <3f6f2c32$1@e-post.inode.at>
D Borland wrote:
> it correctly - i mean if i wanted to read, read, read and read i would
> have just got a job in a library.
Its never too late ;)
peter
--
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: 22 Sep 2003 08:36:01 -0700
From: jg_x30@iwon.com (Jim)
Subject: fixed width fields
Message-Id: <b15b026d.0309220736.571cbaae@posting.google.com>
This should be an easy one but I'm having a brain cramp.
I have a string: 2-s1.0-49FR-WSJ0-TWC1-XXXX-12345-00. I want to
replace the 12345 with $i. When $i equals "1" how can I make it
"00001"?
------------------------------
Date: Mon, 22 Sep 2003 17:47:26 +0200
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: Re: fixed width fields
Message-Id: <3f6f1a55$1@e-post.inode.at>
Jim wrote:
> This should be an easy one but I'm having a brain cramp.
>
> I have a string: 2-s1.0-49FR-WSJ0-TWC1-XXXX-12345-00. I want to
> replace the 12345 with $i. When $i equals "1" how can I make it
> "00001"?
>
perldoc -f sprintf
example:
$a="2-s1.0-49FR-WSJ0-TWC1-XXXX-12345-00";
$i=234;
$b=sprintf("%05i",$i);
$a=~s/-\d{5}-/-$b-/;
print $a,"\n"
peter
--
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Mon, 22 Sep 2003 15:53:15 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: fixed width fields
Message-Id: <bkn5ta$4pq$1@troll.powertech.no>
Jim <jg_x30@iwon.com> wrote:
> This should be an easy one but I'm having a brain cramp.
>
> I have a string: 2-s1.0-49FR-WSJ0-TWC1-XXXX-12345-00. I want to
> replace the 12345 with $i. When $i equals "1" how can I make it
> "00001"?
$str =~ s/12345/sprintf "%05d", $i/e;
--
Vlad
------------------------------
Date: Mon, 22 Sep 2003 16:06:00 +0100
From: "D Borland" <notavailable@nospamplease.com>
Subject: Re: Form problems, post method yeilds 0 at end of values
Message-Id: <wdEbb.6163$Ne.2670977@newsfep2-win.server.ntli.net>
I'm sure that the 0 is the end of string notififer (or something like that)
that c/c++ need/put at the end of the fields. I'm sure that you can just
chop it off when you don't want it, and put it back on when you do (isn't it
/0 anyhow?)
Dagmar
"David Mills" <mills_nospam_@free.fr> wrote in message
news:pan.2003.09.22.14.40.29.44104@free.fr...
> First of all hello to the group
>
> I'm relativly new to perl, so if this is a stupid question, I'll accept my
> due flaming.
>
> I've written a small script to take user information and insert it into a
> database, before creating an account for the user (this is obviously for
> internal use only, and has the relevant .htaccess to prevent unorthorised
> use).
>
> The problem is that when the form is submitted, I get 0 at the end of each
> value field (and by this I mean a hex 0 in the field, I've checked this
> with a hex editor).
>
> My question is how to remove these zeros, since they muck up the user
> creation and the insertion into the database.
>
> Google has shown up nothing relating to this
>
> I've quoted part of the script below which shows these symptomes
>
>
> Thanks in advance for your time
>
> David Mills
>
> #!/usr/bin/perl -w
> use DBI;
>
> print "Content-type: text/html\n\n";
>
> #get info from form, lifted from http://www.cgi101.com, great site
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
> print "$buffer\n";
> print "\n";
> @pairs = split(/\n/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> $FORM{$name} =~ s/\0//eg;
> print "$name = $FORM{$name}t<br>";#Puts a 0 between the variable and the t
> }
>
------------------------------
Date: Mon, 22 Sep 2003 17:09:21 +0200
From: "David Mills" <mills_nospam_@free.fr>
Subject: Re: Form problems, post method yeilds 0 at end of values
Message-Id: <pan.2003.09.22.15.09.21.53900@free.fr>
On Mon, 22 Sep 2003 16:06:00 +0100, D Borland wrote:
> I'm sure that the 0 is the end of string notififer (or something like that)
> that c/c++ need/put at the end of the fields. I'm sure that you can just
> chop it off when you don't want it, and put it back on when you do (isn't it
> /0 anyhow?)
>
> Dagmar
>
Already tried, useing regexp on the values doesn't work.
------------------------------
Date: Mon, 22 Sep 2003 15:40:24 +0000 (UTC)
From: Ryan Travis Tate <ryantate@OCF.Berkeley.EDU>
Subject: Re: killing zombie file lock
Message-Id: <bkn558$bbt$1@agate.berkeley.edu>
news@roaima.freeserve.co.uk wrote:
| A non-blocking attempt to get an exclusive lock, which aborts the program
| if it fails. Unusual (especially given that your introduction implies
| read-only access to the log file), but if that's what you want...
Yes, I did perhaps phrase things badly. My script reads a custom
access log (for a specific CGI script), looks up domain names for IP
addresses (nslookup) and writes the domain names in place of the IP
addresses where possible. (It also moves a text marker to the end of
the file, and echoes the processed file to STDOUT.)
| Ah. UNIX. Depending on the complexity of your web server, this may give
| you a process id:
| ps -ef | grep YOUR_CGI_PROGRAM_NAME
I haven't had luck with this yet but I appreciate the tip.
Thanks again for your time.
Cheers
ryan
------------------------------
Date: Mon, 22 Sep 2003 15:48:10 +0000 (UTC)
From: Ryan Travis Tate <ryantate@OCF.Berkeley.EDU>
Subject: Re: killing zombie file lock
Message-Id: <bkn5jq$bcv$1@agate.berkeley.edu>
Ryan Travis Tate <ryantate@ocf.berkeley.edu> wrote:
| I haven't had luck with this yet but I appreciate the tip.
The solution was to copy the file to a new name, delete the original
file, and then rename the new copy to the original name.
Thanks Anno and Chris for your help. Sorry for what turns out to be a
non-Perl question.
Cheers
r
------------------------------
Date: Mon, 22 Sep 2003 16:18:58 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: killing zombie file lock
Message-Id: <ShFbb.5327$A5.2842@newssvr27.news.prodigy.com>
Ryan Travis Tate <ryantate@ocf.berkeley.edu> wrote:
> Ryan Travis Tate <ryantate@ocf.berkeley.edu> wrote:
> | I haven't had luck with this yet but I appreciate the tip.
> The solution was to copy the file to a new name, delete the original
> file, and then rename the new copy to the original name.
Prior to doing that, I would have run 'fuser <filename>' to see what
processes it identified as holding a lock on the file.
If you had just 'mv'd it rather than deleting it, you could still do
that...
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Mon, 22 Sep 2003 12:16:07 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: length of the longest $_ in @_
Message-Id: <Pine.SGI.3.96.1030922121506.774837C-100000@vcmr-64.server.rpi.edu>
On Mon, 22 Sep 2003, Vlad Tepes wrote:
> sub amax(@;\$) { # prototype to make it work like built-in (no parens)
What exactly is that prototype doing? And you don't need a prototype to
get the function to work without parens -- it merely must be declared (or
defined) before it's used.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 22 Sep 2003 16:53:09 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: length of the longest $_ in @_
Message-Id: <bkn9dl$67d$1@troll.powertech.no>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> On Mon, 22 Sep 2003, Vlad Tepes wrote:
>
>> sub amax(\@;@) { # prototype to make it work like built-in (no parens)
>
> What exactly is that prototype doing? And you don't need a prototype to
> get the function to work without parens -- it merely must be declared (or
> defined) before it's used.
I wanted to make the sub accept either an array reference or an array.
A quick look at perlsub suggest that it doesn't work this way.
I have to take a closer look at perlsub again. I haven't got time right
now, though.
--
Vlad
------------------------------
Date: 22 Sep 2003 08:18:04 -0700
From: mjeff1@twcny.rr.com (Jeff Mott)
Subject: Re: Operator Precedence
Message-Id: <970676ed.0309220718.485e891e@posting.google.com>
> To assign to $s, the right hand side must be evaluated. You
> have a call to substr() there (uses at most four arguments), so
> the zero and the one will be interpreted as the second and third
> argument of that function call.
I know what it does do, I was referring to what it seemed like it
should do. But Abigail answered it so we're good here.
------------------------------
Date: 22 Sep 2003 11:41:56 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: regexp help - match on two backslashes
Message-Id: <xcwoexcrfsr.fsf@psi.cis.ohio-state.edu>
Abigail <abigail@abigail.nl> writes:
> Ryan Shondell (shondell@cis.ohio-state.edu) wrote on MMMDCLXXI September
> MCMXCIII in <URL:news:xcwznh0r8st.fsf@psi.cis.ohio-state.edu>:
> :: danielems@myfastmail.com (Daniel Ems) writes:
> ::
> :: > Hello,
> :: >
> :: > Apologies if this is the wrong place to post this question...
> :: >
> :: > What regular expression can I use to match two backslashes?
> ::
> :: /\Q\\/
>
> That's incorrect:
>
> $ perl -wle '$_ = "\\\\"; print; print "Nope" unless /^\Q\\$/'
> \\
> Nope
Well, since you didn't use \E before your $, doesn't that make the
pattern match '\\$' ?
If you need to anchor the pattern (though the OP never mentioned that),
/^\Q\\\E$/
> Use /\\\\/ instead:
>
> $ perl -wle '$_ = "\\\\"; print; print "Yes" if /^\\\\$/'
> \\
> Yes
TMTOWTDI
--
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'
------------------------------
Date: Mon, 22 Sep 2003 19:41:09 +0300
From: Bob Smith <bobsmith@jippii.fi>
Subject: splitting lines
Message-Id: <3F6F2625.B949AE9@jippii.fi>
hi
how to split text into lines?
I have in a db whitespace delimited words forming chapters in one field,
and I want to nicely put it on the page with max 30 or so characters per
paragraph, after that line breaks should occur,
but I can't figure out the regexp for doing it,
any help much appreciated. Thank you
/G
------------------------------
Date: Mon, 22 Sep 2003 18:20:48 +0100
From: "Bigus" <bigus_34@yahoo.co.uk>
Subject: Re: splitting lines
Message-Id: <QbGbb.1792$jJ3.27457@newsfep4-glfd.server.ntli.net>
"Bob Smith" <bobsmith@jippii.fi> wrote in message
news:3F6F2625.B949AE9@jippii.fi...
> hi
> how to split text into lines?
> I have in a db whitespace delimited words forming chapters in one field,
> and I want to nicely put it on the page with max 30 or so characters per
> paragraph, after that line breaks should occur,
I take it you mean 30 characters per line rather than paragraph?
If so, try something like this:
@lines = $dbtext =~ /(.{30}\S*)/g;
foreach(@lines)
{
$_ =~ s/^\s+//;
print "$_\n";
}
Bigus
------------------------------
Date: Mon, 22 Sep 2003 15:06:12 GMT
From: "John Smith" <someone@microsoft.com>
Subject: Re: string length?
Message-Id: <EdEbb.13782$Ej.1998102@ursa-nb00s0.nbnet.nb.ca>
I'm sorta new so I don't imagine you mean:
$a="12345"
print("length of a = length($a) \n";
"Bob Smith" <bobsmith@jippii.fi> wrote in message
news:3F6F0C2D.20514EE8@jippii.fi...
> how do I get the string length of a string?
> /B
>
------------------------------
Date: Mon, 22 Sep 2003 10:25:06 -0500
From: Barry Kimelman <raisin@delete-this-trash.mts.net>
Subject: Re: string length?
Message-Id: <MPG.19d8d0485e51148098968c@news.mts.net>
[This followup was posted to comp.lang.perl.misc]
In article <3F6F0C2D.20514EE8@jippii.fi>, bobsmith@jippii.fi says...
> how do I get the string length of a string?
> /B
>
>
$length = length $string;
Note : you can use the perldoc command to get a lot of info on perl
features.
------------------------------
Date: 22 Sep 2003 15:30:53 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: string length?
Message-Id: <slrnbmu5dd.lsa.abigail@alexandra.abigail.nl>
Bob Smith (bobsmith@jippii.fi) wrote on MMMDCLXXIV September MCMXCIII in
<URL:news:3F6F0C2D.20514EE8@jippii.fi>:
'' how do I get the string length of a string?
That's why Perl has the handy chop function!
$str = "I want to know the length";
$length = 0;
while ($str ne "") {
$tmp = $length + 1;
chop $str;
$length = $tmp;
}
Abigail
--
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-
------------------------------
Date: Mon, 22 Sep 2003 12:01:14 -0400
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: string length?
Message-Id: <3F6F1CCA.4040702@gwu.edu>
Abigail wrote:
> Bob Smith (bobsmith@jippii.fi) wrote on MMMDCLXXIV September MCMXCIII in
> <URL:news:3F6F0C2D.20514EE8@jippii.fi>:
> '' how do I get the string length of a string?
>
>
> That's why Perl has the handy chop function!
>
> $str = "I want to know the length";
> $length = 0;
> while ($str ne "") {
> $tmp = $length + 1;
> chop $str;
> $length = $tmp;
> }
>
>
Now, is that a nice thing to do to a newbie, Abigail?
Chris Mattern
------------------------------
Date: Mon, 22 Sep 2003 16:03:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: string length?
Message-Id: <x7isnklsji.fsf@mail.sysarch.com>
>>>>> "JS" == John Smith <someone@microsoft.com> writes:
JS> I'm sorta new so I don't imagine you mean:
JS> $a="12345"
JS> print("length of a = length($a) \n";
if you are new here, you should test your code before posting here. that
one has a nice bug.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Mon, 22 Sep 2003 16:25:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: string length?
Message-Id: <YnFbb.14186$zA2.13275@nwrddc02.gnilink.net>
Bob Smith wrote:
> how do I get the string length of a string?
Finally!!
It has been months and months since we had this self-answering question the
last time.
jue
------------------------------
Date: Mon, 22 Sep 2003 15:33:09 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: What are you allowed to share?
Message-Id: <VCEbb.9912$Om4.168118445@newssvr13.news.prodigy.com>
<snip>
> I'm trying to do some threads programming, and I need to share a
> filehandle. Perl won't let me do that. I get the error: "Cannot share
> globs yet..." when I try to share a filehandle. Perl won't even let me
> share a pointer to a filehandle, as I get the error: "Invalid value
> for shared scalar..."
<<< After a lengthy evening of continued research I was able to make this
work. As far as I can tell you should avoid using any filehandle creation
method that creates objects (FileHandle, IO::Handle), because threads
(perlthrtut) prefer simple scalars. You can create filehandles rather
simply with several different methods. I am using typeglob filehandles
which can be passed around quite readily. Check out perldata on how to do
this. I have implemented it and it works.
Good luck!
Moose
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5542
***************************************