[16786] in Perl-Users-Digest
Perl-Users Digest, Issue: 4198 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 1 11:05:25 2000
Date: Fri, 1 Sep 2000 08:05:10 -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: <967820710-v9-i4198@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 1 Sep 2000 Volume: 9 Number: 4198
Today's topics:
Re: "Premature end of script headers" reschramz@my-deja.com
Re: Challenge: Cause the "final @" error to occur <aqumsieh@hyperchip.com>
Re: converting text to doc files... <camerond@mail.uca.edu>
Re: converting text to doc files... <elephant@squirrelgroup.com>
Re: dynamic object instantiation using eval (Randal L. Schwartz)
Re: dynamic object instantiation using eval (Mike Stok)
Re: How can I find an images size?? <dturley@pobox.com>
How do you use setuid in perl shobs11@my-deja.com
Re: How get all parameters of cgi-form? <elephant@squirrelgroup.com>
Re: How get all parameters of cgi-form? <elephant@squirrelgroup.com>
Re: interchanging variables <elephant@squirrelgroup.com>
Re: learning perl <nickco3@yahoo.co.uk>
Re: learning perl <samay1NOsaSPAM@hotmail.com.invalid>
Re: learning perl <russ_jones@rac.ray.com>
Re: MAS90, Word, and Perl <elephant@squirrelgroup.com>
Re: My Perl looks like C! <jcook@strobedata.com>
Mysterious vanishing of an array value <mattbee@soup-kitchen.net>
Newbie needs help! (I Hawes)
no $ENV{REMOTE_USER} ? <noemail@nodomain.com>
Re: open web file (Keith Calvert Ivey)
Re: output fun (Keith Calvert Ivey)
Re: output fun (Tony L. Svanstrom)
Re: output fun <yanick@babyl.sympatico.ca>
Re: pack function (Keith Calvert Ivey)
Regular Expression Help <dangerar@my-deja.com>
Re: Regular Expression Help (Jakob Schmidt)
Re: replace some word in text file <elephant@squirrelgroup.com>
Rip apart my code <usenet@dstanek.com>
Re: timelocal() is wrong? <russ_jones@rac.ray.com>
Re: Using SQL_LONGVARCHAR in DBI:ODBC in a INSERT state (Keith Calvert Ivey)
using unix commands within perl script <E.L.Stoten@ncl.ac.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 01 Sep 2000 13:15:34 GMT
From: reschramz@my-deja.com
Subject: Re: "Premature end of script headers"
Message-Id: <8ooa55$fa7$1@nnrp1.deja.com>
In article <slrn8qu76l.ci6.tjla@thislove.dyndns.org>,
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:
> I was shocked! How could Jon Drukman <jsd@cluttered.com>
> say such a terrible thing:
> >On Thu, 31 Aug 2000 18:13:03 GMT,
> > reschramz@my-deja.com <reschramz@my-deja.com> wrote:
> >>What I want to know is how your script manages to work just fine,
when
> >>usually truncated HTTP headers means that the CGI output won't
display
> >>at all.
> >
> >most likely the script works fine some times and outputs errors
> >other times, which come out before the Content-type header.
> >
> >using $|=1 sometimes eliminates this situation. better error
> >checking usually fixes it completely.
>
> *sigh*
Whatever....
>
> #!/usr/bin/perl -w
> use strict;
> use CGI qw/:standard/;
> use CGI::Carp 'fatalsToBrowser';
>
> always eliminates this problem.
>
Do you meant that unbuffering errors doesn't _always_ work? Why?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 01 Sep 2000 15:04:44 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Challenge: Cause the "final @" error to occur
Message-Id: <7aitsgrw4x.fsf@merlin.hyperchip.com>
daniel@chetlin.com (Daniel Chetlin) writes:
> From perldiag.pod:
>
> =item Final @ should be \@ or @name
>
> (F) You must now decide whether the final @ in a string was meant to be
> a literal "at" sign, or was meant to introduce a variable name that
> happens to be missing. So you have to put either the backslash or the
> name.
>
> My challenge to you: using a relatively recent (say, 5.005_03 or later) Perl,
> come up with code that causes this error to occur.
I could get the sister error:
Final $ should be \$ or $name
to show up:
% perl -wle '$x = 1; print "$x$"'
Final $ should be \$ or $name at -e line 1, within string
syntax error at -e line 1, near "print "$x$""
Execution of -e aborted due to compilation errors.
But changing the $ to @ doesn't generate the same error:
% perl -wle '@x = (1); print "@x@"'
1@
Interesting error though ..
--Ala
------------------------------
Date: Fri, 01 Sep 2000 09:35:31 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: converting text to doc files...
Message-Id: <39AFBEB3.776BE6B0@mail.uca.edu>
closetgeekla@my-deja.com wrote:
>
> i need to convert formatted text documents (made from MAS90 reports) to
> *.doc with landscape formatiing and with a courier 8pt font. Anyone have
> any ideas on how to start?
use Win32::OLE to run M$Word to handle the conversion. Write macros in
M$W and then just convert them to Perl. There is information on that in
the AS Perl docs, there was a good article by Jan Dubois on Win32::OLE
in TPJ #10, and when you get stuck, go to the AS mailing list for
Win32-Perl-users for further help (There used to be a web-based
searchable archive of the list, but due to changing mailservers and
other issues, it is not there now, but I hope it'll be back soon).
Or, if you only have one or two to do, it might be easier to just
convert them manually. (TIMTOWTDI)
Actually, if this is all you have to do to them, you might be able to
just use Wordpad, included with Window$, and not have to purchase Word.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: Fri, 01 Sep 2000 14:46:15 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: converting text to doc files...
Message-Id: <MPG.141a5eafc29e6a1d98973f@localhost>
closetgeekla@my-deja.com <closetgeekla@my-deja.com> wrote ..
>i need to convert formatted text documents (made from MAS90 reports) to
>*.doc with landscape formatiing and with a courier 8pt font. Anyone have
>any ideas on how to start?
have a look at the Win32::OLE module which comes with the standard
ActiveState port of Perl
there's even a FAQ "Using OLE with Perl" (at least in 5.6)
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 01 Sep 2000 06:22:13 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: dynamic object instantiation using eval
Message-Id: <m13djk458a.fsf@halfdome.holdit.com>
>>>>> "Paul" == Paul Johnston <johnston.p@worldnet.att.net> writes:
Paul> # This dies with "Can't find method new":
Paul> package Foo;
Paul> my $class = "MyPackage::MyClass";
Paul> my $obj = eval $class . '->new($myargs)';
That's too much work. What's wrong with just:
$class->new($myargs)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Fri, 01 Sep 2000 13:52:33 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: dynamic object instantiation using eval
Message-Id: <BwOr5.29669$K5.463329@typhoon.austin.rr.com>
In article <9jFr5.27665$K5.455094@typhoon.austin.rr.com>,
Mike Stok <mike@stok.co.uk> wrote:
>>my $obj = eval $class . '->new($myargs)';
[...]
>You are aware that $myargs will not interpolate inside single quotes,
>so you may have a problem there.
Mike, you blithering idiot. The eval will see the $myargs and do the
interpolation.
This may be the effect the poster wanted ... but the s at the end of
$myargs triggered a reaction. In the debugger:
DB<1> sub func { print "Arg count: ", scalar( @_ ), "\n" }
DB<2> $myargs = "foo, bar"
DB<3> eval "func($myargs)"
Arg count: 2
DB<4> eval 'func($myargs)'
Arg count: 1
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ |
GPG PGP Key 1024D/059913DA | Fingerprint 0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work) | 75D2 9EC4 C1C0 0599 13DA
------------------------------
Date: Fri, 01 Sep 2000 13:30:13 GMT
From: "David Turley" <dturley@pobox.com>
Subject: Re: How can I find an images size??
Message-Id: <FbOr5.2530$vc.4417@skycache.prestige.net>
In article <8ob6m8$7gp$1@uk21.supernews.com>, "Speed Demon"
<speed.demon9999@virgin.net> wrote:
> I can't open the tar.gz files as im on windows, can someone send the
> files in either a .zip or uncompressed format to me so I can upload to
> my UNIX host?
>
WinZip handles tar.gz
Doesn't every Windoze machine have an unregistered copy of WinZip on it ? :-)
--
David Turley
dturley@pobox.com
------------------------------
Date: Fri, 01 Sep 2000 13:32:16 GMT
From: shobs11@my-deja.com
Subject: How do you use setuid in perl
Message-Id: <8oob50$gko$1@nnrp1.deja.com>
I am trying to run a script, but the user who is to run the script
needs root permissions to do what the script is to do.
setuid should do it, and I can get this working in C/C++ but I would
like to use it within perl.
Can anyone tell me how to do this?
Are there any security problems with using setuid with perl?
Thankyou in advance.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 01 Sep 2000 14:10:51 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: How get all parameters of cgi-form?
Message-Id: <MPG.141a56616e3960b698973c@localhost>
Phill Kahle <mrpkahle@dingoblue.net.au> wrote ..
>yeah sorry. use cgi.pm and the file is called cgi-lib.pl
stop now before you sound any sillier
the statement is
use CGI;
and the file is CGI.pm
cgi-lib.pl is a completely different beast .. and is superceded by
CGI.pm (and various other tools) in modern perls
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 01 Sep 2000 14:14:52 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: How get all parameters of cgi-form?
Message-Id: <MPG.141a57536a762cf398973d@localhost>
Paul Dortman <paul@pco.iis.nsk.su> wrote ..
>It's strange but I could not find the way to do it. I need array of all
>parameters of cgi form.
>I tried $q->param, but it did not work.
that will (assuming you've initialised $q properly) return an array of
all the parameter *names* .. as per the documentation
it's a trivial exercise to iterate over that array and retrieve all the
values - if that's what you want
>I use 'post' method.
irrelevant when using CGI.pm (if not all the CPAN CGI modules)
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 01 Sep 2000 14:20:52 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: interchanging variables
Message-Id: <MPG.141a58bcd014047298973e@localhost>
Ala Qumsieh <aqumsieh@hyperchip.com> wrote ..
>
>Ankur Banerjee <ankban4@indiainfo.com> writes:
>
>> HI,
>> How do i interchange values of three variables $a,$b,$c WITHOUT using
>> this expression:-
>> ($a,$b,$c)=($b,$c,$a);
>
>I wonder why!!!
>
> ($d, $e, $f) = ($a, $b, $c);
> ($a, $b, $c) = ($e, $f, $d);
>
>A silly question deserves a silly answer.
I was thinking the even sillier
($c,$b,$a)=($a,$c,$b);
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 01 Sep 2000 14:28:02 +0100
From: Nick Condon <nickco3@yahoo.co.uk>
Subject: Re: learning perl
Message-Id: <39AFAEE2.9E47F1B9@yahoo.co.uk>
W Kemp wrote:
> Simon Voorwinde wrote in message <39af9495@news1.idx.com.au>...
> >Where's is the best place to learn perl ?
> >
>
> I started learning perl when I was in the south of France. Lovely
> mountains, with a clear river cascading down into a lovely valley full of
> vinyards. Where better?
And the best thing you could find to do was read a Perl book?
------------------------------
Date: Fri, 01 Sep 2000 08:31:05 -0700
From: Samay <samay1NOsaSPAM@hotmail.com.invalid>
Subject: Re: learning perl
Message-Id: <01d1dbc4.22e3750a@usw-ex0106-048.remarq.com>
Very nice..
Did you memrorize before going to the computer?
In article <967812079.29553.0.nnrp-09.c3ad6973@news.demon.co.uk>, "W
Kemp" <bill.kemp@wire2.com> wrote:
> Simon Voorwinde wrote in message <39af9495@news1.idx.com.au>...
> >Where's is the best place to learn perl ?
> >
> I started learning perl when I was in the south of France. Lovely
> mountains, with a clear river cascading down into a lovely valley
> full of
> vinyards. Where better?
* Sent from Novell Discussion Forums http://novell.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 01 Sep 2000 09:45:15 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: learning perl
Message-Id: <39AFC0FB.8C1DB7E5@rac.ray.com>
W Kemp wrote:
>
> Simon Voorwinde wrote in message <39af9495@news1.idx.com.au>...
> >Where's is the best place to learn perl ?
> >
>
> I started learning perl when I was in the south of France. Lovely
> mountains, with a clear river cascading down into a lovely valley full of
> vinyards. Where better?
I learned it during frequent trips to the crapper.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Fri, 01 Sep 2000 14:49:26 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: MAS90, Word, and Perl
Message-Id: <MPG.141a5f71f945d6ac989740@localhost>
closetgeekla@my-deja.com <closetgeekla@my-deja.com> wrote ..
>The accounting department here uses MAS90 and each month or week (or
>whatever it was) they make reports. Several people in the company need
>to see these and print them. They can't simply print them out and give
>them to their intended recipients because everyone gets between 4 and 30
>reports depending on who they are. So as of right now they are being
>e-mailed to the specified people as txt files and recipients must then
>open them in word and manually change the font to Courier 8pt with a
>LANDSCAPE layout so that they can print these reports. MAS90 uses tabs
>and spaces and equal signs to line up all of the rows and columns, so
>courier has been the only font that works and only at 8 pt.
you posted the same question roughly two hours earlier .. check the
answers there
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 01 Sep 2000 07:28:49 -0700
From: Jim Cook <jcook@strobedata.com>
Subject: Re: My Perl looks like C!
Message-Id: <39AFBD21.145C3DA8@strobedata.com>
> >One of my biggest concerns is that my Perl code looks like C code. When I
> >look at what Real Perl Hackers write, it doesn't look like C at all.
> read http://www.perl.org/press/style-guide.html
I thought maybe I could learn something too, but that seems to be just
an opening page with no links. It says to spell "Perl" for the language
and "perl" for the interpreter.
Is there really a style guide to _coding_ Perl, instead of a style guide
for _spelling_ it?
--
jcook@strobedata.com Live Honourably 4/1 - 4/3 + 4/5 - 4/7 + . . .
2000 Tuesdays: Feb/last 4/4 6/6 8/8/ 10/10 12/12 9/5 5/9 7/11 11/7 3/14
Strobe Data Inc. home page http://www.strobedata.com
My home page O- http://jcook.net
------------------------------
Date: Fri, 01 Sep 2000 15:44:04 +0000
From: "Matthew Bloch" <mattbee@soup-kitchen.net>
Subject: Mysterious vanishing of an array value
Message-Id: <JgPr5.4692$WT1.99526@news2-win.server.ntlworld.com>
Hi there; I'm writing a semi-intelligent web mirroring script which has a
very odd problem. I have a list of sites to mirror, some of which will be
different sections of the same site. The program forks every time it
starts to mirror a site in order to maximise the bandwidth, but I didn't
want to hit the same site with more than one robot at a time.
So my program has an outer loop which goes through the list of URLs, and
pushes similarly-hosted ones onto an array called @pile. When it comes
across one that's on a different host, it forks, and one thread proceeds
to the inner loop to do the mirroring, while the other goes to pick off
the next URL.
Just before the mirroring loop is started, I print out the base URL it's
starting to mirror. My problem is that if I try to print the value of
@pile /before/ this print statement, it shows up fine. If I put the print
statement immediately after, the array is empty. And it always seems to
be empty by the time it starts trying to read from it to do the actual
fetching.
So in the best tradition of USENET posts, my question is: what the **** is
going on? :-) I've enclosed the relevant bit of source in case anybody
can help.
--------------------8<----------------------------------------
# Declare variables, read in @urls etc.
foreach (@urls) {
next if !$_; my $u = URI::URL->new($_);
if (scalar(@pile) == 0)
{ $base = $u; $base->path("/"); push @pile, $u; }
elsif ($pile[scalar(@pile)-1]->host eq $u->host)
{ push @pile, $u; next; }
else
{
wait if ($children == $MAX_CHILDREN);
if (my $pid = fork) {
$children++;
@pile = ();
$base = undef;
next;
} elsif ($pid == 0) {
# ATTENTION! Weirdness!
#print scalar @pile;
print "*** Starting to crawl $base\n"; print scalar @pile;
#print scalar @pile;
for (my $d=0; $d!=$MAX_DEPTH; $d++) {
@links_next_depth = ();
foreach (@pile) {
... do the mirroring ...
}
@pile = @links_next_depth;
}
exit(0);
} else {
die "Fork failed for $u: $!\n";
}
}
push @pile, $u;
}
# subroutines here
--------------------8<----------------------------------------
cheers,
--
Matthew > http://www.soup-kitchen.net/
> ICQ 19482073
------------------------------
Date: Fri, 01 Sep 2000 14:57:49 GMT
From: ikh1@cornell.edu (I Hawes)
Subject: Newbie needs help!
Message-Id: <8oog33$qqb$2@news01.cit.cornell.edu>
I need a script that will collect the following information into a file,
moving recursively, for every file in every directory, beginning from the
current directory:
full path name
file name
maximum line length
number of lines
whether the file has a constant or a variable line length
number of carriage returns
number of control characters
number of non-ascii characters
total characters (uncompressed)
total characters (compressed)
To also get file owner and permissions info would be terrific, but is not
necessary.
The files are all compressed with gzip, and reside on a Windows 2000 operating
system. The output for each file should be all on one line, as this will be
used as input for a database. Any help you could give, even small fragments
of code, would be most helpful. Thanks.
------------------------------
Date: Fri, 01 Sep 2000 14:14:47 GMT
From: "Dave A." <noemail@nodomain.com>
Subject: no $ENV{REMOTE_USER} ?
Message-Id: <rROr5.301$Mc.12891@nnrp1.ptd.net>
I have a simple basic html page that uses frames.
One frame source is a perl script.
The html directory contains .htaccess for authentication.
All I want to do, is get $ENV{'REMOTE_USER'}
and display it on the perl script frame.
A simple : Logged In as <b>$ENV{'REMOTE_USER'}</b><br>
does not work.
I have tried every variation, even retrieved the env variables (system("env"); )
and displayed them.
No REMOTE_USER variable is set in the environment.
Is there something I'm missing here ?
REQUEST_METHOD is GET (if that even makes a difference at this point.
Thanks in advance
D.
------------------------------
Date: Fri, 01 Sep 2000 13:03:58 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: open web file
Message-Id: <39b1a8b8.43750224@news.newsguy.com>
"Xin Li" <lxzy@yeah.net> wrote:
>open (READ,"<path>/test.htm");
>@temp=<READ>;
>close (READ);
>
>the "@temp" have some value.
>it is the "test.htm" 's content.
As Tony said:
>> That's nice. What's that got to do with "open"ing URL's
>> over a network?
There's a huge difference between a URL and a file on your
local system that happens to contain HTML.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 12:48:12 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: output fun
Message-Id: <39afa411.42559051@news.newsguy.com>
logan@cs.utexas.edu (Logan Shaw) wrote:
>Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>>ITYM:
>> select(undef, undef, undef, rand() * rand());
>
>O.K. Honest question: why would I need to do that? I mean,
>you see code like this all the time:
>
> while (<>)
> { $l += length; }
>
>So, how is using length() without parenthesis any different from using
>rand() without parenthesis?
It isn't. This is fine:
$l += rand;
This isn't:
$x = length * length;
Whether you can omit the parentheses depends on what's after the
function. You need parentheses in rand * rand; otherwise it's
parsed as rand(*rand). So rand() * rand would work in your
case, or (rand) * rand, but I think Gwyn's rand() * rand() looks
better.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 1 Sep 2000 15:59:52 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: output fun
Message-Id: <1egae2s.ij9fno2sk6jaN%tony@svanstrom.com>
Ren Maddox <ren.maddox@tivoli.com> wrote:
> kcivey@cpcug.org (Keith Calvert Ivey) writes:
>
> > Uri Guttman <uri@sysarch.com> wrote:
> >
> > >$_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/.( +)\S/ $1 /g;
> >
> > $_="ABCDEFGFEDCBA\n";print,s/G|(?<= ).|.(?= )/ /g while/\S/;
> >
> > Four strokes shorter, and avoids printing the extra blank line.
>
> $_="ABCDEFGFEDCBA\n";print,s/.( +)./ $1 /,s/G/ /while/\S/;
>
> Two strokes shorter.
$_="ABCDEFGFEDCBA\n";$c=9;while($c--){s/\10$c/ /g;print}
Not really a good solution, but, hey, it's one character less. :)
/Tony
--
/\___/\ Who would you like to read your messages today? /\___/\
\_@ @_/ Protect your privacy: <http://www.pgpi.com/> \_@ @_/
--oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
on the verge of frenzy - i think my mask of sanity is about to slip
---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
\O/ \O/ ©99-00 <http://www.svanstrom.com/?ref=news> \O/ \O/
------------------------------
Date: Fri, 01 Sep 2000 14:59:04 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: output fun
Message-Id: <YuPr5.209716$Gh.4206684@news20.bellglobal.com>
Tony L. Svanstrom <tony@svanstrom.com> wrote:
: Ren Maddox <ren.maddox@tivoli.com> wrote:
:> kcivey@cpcug.org (Keith Calvert Ivey) writes:
:>
:> > Uri Guttman <uri@sysarch.com> wrote:
:> >
:> > >$_="ABCDEFGFEDCBA\n";print;print while y/G/ /||s/.( +)\S/ $1 /g;
:> >
:> > $_="ABCDEFGFEDCBA\n";print,s/G|(?<= ).|.(?= )/ /g while/\S/;
:> >
:> > Four strokes shorter, and avoids printing the extra blank line.
:>
:> $_="ABCDEFGFEDCBA\n";print,s/.( +)./ $1 /,s/G/ /while/\S/;
:>
:> Two strokes shorter.
: $_="ABCDEFGFEDCBA\n";$c=9;while($c--){s/\10$c/ /g;print}
: Not really a good solution, but, hey, it's one character less. :)
If dubious solutions are fair play, then I suggest
$_="ABCDEFGFEDCBA\n";print&&s/$2/ /gwhile/(F| )(\S)/
which save no less than 4 strokes. :)
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
Date: Fri, 01 Sep 2000 12:57:48 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: pack function
Message-Id: <39b0a754.43394088@news.newsguy.com>
mgopi@csa.iisc.ernet.in wrote:
>can i use a unpack function to split a string into its constituent characters
>"hello" -> h,e,l,l,o
>i used unpack "c*","hello", when i printed its o/p it gave the ascii values of
>the
>constituent chars instead.
>i know that split func could be used .but i'm just experimenting with
>pack/unpack
You could use unpack('a' x 5, 'hello').
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 13:54:00 GMT
From: dangerous dan <dangerar@my-deja.com>
Subject: Regular Expression Help
Message-Id: <8oocdh$hv0$1@nnrp1.deja.com>
OK, guys I've R'd TFM till blue, but can't figure this out.
Following is a working perl program (5_004 on OS/390 USS).
---------------------------------------------------
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0;
# testpl.pl - perl test case
$_ = "/aaaa/bbbb/cccc/dddd.snork";
$lev = 2;
for ($i = $lev; $i >= 0; $i--) {
s#(.*)/.*?#$1#;
print "DIR: $_\n";
print "DL1: $1\n";
}
---------------------------------------------------
>testpl.pl
DIR: /aaaa/bbbb/ccccdddd.snork
DL1: /aaaa/bbbb/cccc
DIR: /aaaa/bbbbccccdddd.snork
DL1: /aaaa/bbbb
DIR: /aaaabbbbccccdddd.snork
DL1: /aaaa
>
From reading, I expected $_ and $1 to contain the same value.
$1 is as expected, but $_ is not.
What am I missing?
Thanks,
dangerous dan
----------------------------------------------------------------------
". . . but your enemies only win when you hate them back. . .
and then you destroy yourself." - Richard M. Nixon
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 1 Sep 2000 16:24:19 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: Regular Expression Help
Message-Id: <1egag50.1qbx2zi1r0brzsN@[192.168.88.117]>
dangerous dan <dangerar@my-deja.com> wrote:
> for ($i = $lev; $i >= 0; $i--) {
> s#(.*)/.*?#$1#;
> print "DIR: $_\n";
> print "DL1: $1\n";
> }
the problem is that .*? matches as few chars as possible. In this case
zero.
using s#(.*)/.*?$#$1#; or s#(.*)/.*?\z#$1#; should change things.
Jakob
--
$_="rka rPrhoatuJs nte elHce\n";0while[$s=-int.5
-.5*length]&&s&(.{$s})(.)(.{$s})&$1$3&s&&print$2
------------------------------
Date: Fri, 01 Sep 2000 14:08:31 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: replace some word in text file
Message-Id: <MPG.141a55dc169e393298973b@localhost>
Larry Rosler <lr@hpl.hp.com> wrote ..
>In article <MPG.1418c1a8ed309c2a989739@localhost> on Thu, 31 Aug 2000
>09:24:01 GMT, jason <elephant@squirrelgroup.com> says...
>> Keith Calvert Ivey <kcivey@cpcug.org> wrote ..
>
>...
>
>> >But the normal Perl idiom for slurping a whole file would be
>> >
>> > { local $/; $File = <FILE>; }
>>
>> someone showed me a neater WTDI that - for some reason - I'd never
>> thought of before .. I like it because it saves the separate 'my'
>> declaration which always looks clumsy
>>
>> my $file = do { local $/; <FILE> };
>>
>> syntactic sugar .. yummy
>
>Extra calories are bad for you. As demonstrated by bookmarking some
>time ago, this causes an extra copy of the string from within the block
>to outside it. An implementation deficiency, no doubt; AKA an
>optimization opportunity.
thanks for the information .. I still like it - where's the source gone
(yeah right ;)
>The fastest way turned out to be (as posted by Anno Siegel):
>
> read FILE, $File, -s FILE;
don't know that I can give up my diamonds
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 1 Sep 2000 09:28:15 -0400
From: "David Stanek" <usenet@dstanek.com>
Subject: Rip apart my code
Message-Id: <8ooan6$os0$1@news.chatlink.com>
I read a post last night in the "My Perl looks like C!" thread that got me
thinking. The code below is an excerp from a CGI script I wrote recently.
It is a little lengthy, but relitively simple. Please, if you could spare
the time, rip this code to shreads and explain where things could be better
and more perl like.
Thank you for your time!
David Stanek
# CODE STARTS HERE
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use CGI qw/:standard/;
################################################################
# configuration
my $CGI = '1';
################################################################
# start application flow
my $Isbn;
if ($CGI) # we are running through CGI
{
$Isbn = param('isbn');
unless (defined $Isbn)
{
print header,
start_html,
start_form({-method=>'GET', -action=>'BookFinder.pl'}),
textfield({-name=>'isbn', -size=>'13', -maxlength=>'13'}),
submit,
end_form,
end_html;
exit;
}
}
else # we are using the command-line
{
$Isbn = $ARGV[0];
unless (defined $Isbn)
{
print "Please enter an ISBN number: ";
chomp($Isbn = <STDIN>);
}
}
my ($Browser, $Response);
$Browser = new LWP::UserAgent;
$Browser->agent('Mozilla/4.0');
my ($Title, %Amazon, %Barnes, %Borders, %Buy, %Fatbrain);
$Response = &amazonSearch($Isbn);
%Amazon = &parseAmazonHTML($Response->content);
print header,
start_html($Amazon{'title'}), # use the title from Amazon
h2($Amazon{'title'}),
&formatStoreResults(%Amazon),
end_html;
sub formatStoreResults
{
my (%hash) = @_;
return b($hash{'store'}) . ' - ' .$hash{'price'} . "<br>\n";
}
################################################################
# amazonSearch: retrieve book information by ISBN
# Params: ISBN
# Returns: an HTTP::Response object
sub amazonSearch
{
my ($isbn) = @_;
return &doRequest(GET "http://www.amazon.com/exec/obidos/ASIN/$isbn");
}
################################################################
# parseAmazonHTML:
# Params: html string
# Returns: a book hash; SEE PAGE COMMENTS FOR DETAILS
sub parseAmazonHTML
{
my ($html) = @_;
my (%hash);
$hash{'store'} = 'Amazon.com';
# parse price
$html =~ /<b>Our Price:.*\$(\d*\.\d*)<\/font>\s*<\/b>/i;
$hash{'price'} = $1;
# parse title
$html =~ /<title>Amazon.com:\s*buying\s*info:\s*(.*)<\/title>/i;
$hash{'title'} = $1;
return %hash;
}
sub doRequest {
my ($request) = @_;
my ($response, $nextrequest);
$response = $Browser->request($request);
while ($response->headers->header("Location")) {
$nextrequest = $request->clone;
$nextrequest->method("GET");
$nextrequest->content("");
$nextrequest->content_length(0);
$nextrequest->content_type("text/html");
$nextrequest->uri($response->headers->header("Location"));
$response = $Browser->request($nextrequest);
}
return $response;
}
------------------------------
Date: Fri, 01 Sep 2000 09:35:53 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: timelocal() is wrong?
Message-Id: <39AFBEC9.4C6B5558@rac.ray.com>
Martien Verbruggen wrote:
>
> According to the documentation (perldoc Time::Local):
>
> [snip]
> BUGS
> The whole scheme for interpreting two-digit years can be
> considered a bug.
>
> Note that the cache currently handles only years from 1900
> through 2155.
> [snip]
>
Yeah, I saw all of that. But the cache is just a memory area where
Time::Local keeps dates that it's already calculated, so it doesn't
have to calculate it again. To me, timelocal_nocheck() implied that
you could work outside that range. I'm gonna look at datecalc today.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Fri, 01 Sep 2000 13:32:45 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Using SQL_LONGVARCHAR in DBI:ODBC in a INSERT statement
Message-Id: <39b6ae4b.45177417@news.newsguy.com>
"Etienne Laverdiere" <info@digitaltango.com> wrote:
>I need to explicitly defined all the Bind
>DataType to SQL_LONGVARCHAR. I am saying ALL because I need a generic
>function.
>So, everything will be sql_longvarchar.
That won't work if you have numeric fields (among other things).
You have to bind data types that are compatible with the types
you actually have.
>So I use this SQL statement :
>
>INSERT INTO products (IDMag, IDMapping, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
>VALUES (125, 42, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
You have 1 .. 10 as field names? I think you want the real
field names (which hopefully match /^[a-z][a-z0-9_]*$/i) there.
>Plus these bind_param :
>
>handle->bind_param(1, '074299229916', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(2, 'Barbie Ocean Discovery', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(3, '0.0', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(4, 'Gameboy', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(5, 'Adventure', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(6, 'Help Barbie search for sunken treasure with Sandy the
>dolphin and her ocean friends! Save the undersea animals when you and Barbie
>find the treasure hidden deep in the ocean. Play games to uncover clues and
>pieces of the treasure map. ', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(7, '39.99', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(8, 'Mattel', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(9, '50.0', { TYPE => SQL_LONGVARCHAR })
>handle->bind_param(10, '074299229916.jpg', { TYPE => SQL_LONGVARCHAR })
It looks suspiciously like parameters 3, 7, and 9 are numeric,
so you'll get an error when single quotes get put around the
values substituted for the placeholders.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 01 Sep 2000 15:44:29 +0100
From: Emma Stoten <E.L.Stoten@ncl.ac.uk>
Subject: using unix commands within perl script
Message-Id: <39AFC0CD.4243F90@ncl.ac.uk>
I'm trying to use a unix command within a perl script:
system(`COMMAND`);
I've tried using all three types of quotes, and still it doesn't work
when executed. The command works at the command line and -c and -w
options don't shed any light.
I've exhausted all other lines of enquiry and hope someone can offer
some advice.
Cheers,
Emma Stoten
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4198
**************************************