[17994] in Perl-Users-Digest
Perl-Users Digest, Issue: 154 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 21:05:55 2001
Date: Fri, 26 Jan 2001 18:05:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980561114-v10-i154@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 26 Jan 2001 Volume: 10 Number: 154
Today's topics:
Re: 'apply' function in perl? (Abigail)
Re: Basic string question <godzilla@stomp.stomp.tokyo>
Re: Calling rsync with "system" does not work <ddunham@redwood.taos.com>
Re: Calling rsync with "system" does not work (Martien Verbruggen)
Re: Counting elements in an array (foreach) lc1178@my-deja.com
Re: Counting elements in an array (foreach) <uri@sysarch.com>
Re: Does DBI support Oracle long data type? rereidy@my-deja.com
Re: Finding unused variables ? <sumus@aut.dk>
Re: Finding unused variables ? (Abigail)
Re: Finding unused variables ? (Martien Verbruggen)
Re: Finding unused variables ? (James Kufrovich)
Re: forms and security (Paul Delahunta)
Re: hash question (Abigail)
How to connect/disconnect a PPPoE DSL connection w. Per <nmarino@home.com>
Re: Internal Server Error- Newbie Question. (JCDixon)
MS Access <jtjohnston@courrier.usherb.ca>
naming array with a variable? <todda@xmission.com>
Re: naming array with a variable? <uri@sysarch.com>
Re: naming array with a variable? <sumus@aut.dk>
Re: perl editors (Tim Hammerquist)
Re: Perl Style Guide - uncuddled elses <elijah@workspot.net>
Re: Perl Style Guide - uncuddled elses <uri@sysarch.com>
Re: Problem with Tie::StdHash / FETCH ?? nexus6_kills@yahoo.com
Re: right place for a mod_perl question? (Martien Verbruggen)
Re: Script to "rotate" the chars in a string. (Martien Verbruggen)
Simple Random Number Problem <whataman@home.com>
Re: Simple Random Number Problem <kstep@pepsdesign.com>
Re: Simple Random Number Problem <joe+usenet@sunstarsys.com>
Re: Simple Random Number Problem <uri@sysarch.com>
sorting a hash of anon. arrays <gopalan@cs.sc.edu>
Re: sorting a hash of anon. arrays <kstep@pepsdesign.com>
Re: Split losing UTF-8 flag on UTF-8 scalars <dan@tuatha.sidhe.org>
Re: Very newbie question (Rob - Rock13.com)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jan 2001 23:46:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: 'apply' function in perl?
Message-Id: <slrn97433h.aeq.abigail@tsathoggua.rlyeh.net>
Greg Bacon (gbacon@HiWAAY.net) wrote on MMDCCV September MCMXCIII in
<URL:news:t73mn8ubgc3f3@corp.supernews.com>:
-- In article <94sim6$87p$1@nnrp1.deja.com>,
-- <tcblue@my-deja.com> wrote:
--
-- : Maybe there is a way to do it w/o this fuction, but i haven't figured
-- : out how... basically what i'm trying to do is something like this:
-- :
-- : $sum = apply(+, @list_of_numbers);
-- :
-- : where it takes a function and applies it to a list, and returns a scalar.
--
-- Perl won't let you refer to the addition operator like many functional
-- languages will.
--
-- : I know there's gotta be some eligant 1 liner that will do this (pref w/o
-- : a loop of somesort)... Please let me... Thanks!
--
-- What are you? Some kinda anti-loopite? :-) mjd wrote[*] a Perl
-- version of reduce, and you could use that:
--
-- my @nums = (1, 5, 14, 17, 7, -2);
-- my $sum = reduce { $a + $b } 0, @nums;
--
-- If only Perl had curried functions... :-)
Alternatively:
my $sum = do {local $" = "+"; eval "@nums"};
And extended to averages, that gives:
my $avg = do {local $" = "+"; eval "@nums" / @nums};
Abigail
--
@_=map{[$!++=>$_^$/]}split$²=>"\@\x7Fy~*kde~box*Zoxf*Bkiaox";$\="\r";
$|=++$*;do{($#=>$=)=(rand@_=>rand@_);@_[$#,$=]=@_[$=,$#]}for($*..@_);
for$:($|..@_-$|){for($|..@_-$:){@_[$_-$|,$_]=@_[$_=>$_-$*]if$_[$_][$¼
]<$_[$_-$*][$®];print+map{$_->[$|]}@_;select$·,$°,$½,"$[.$|"}}print$/
------------------------------
Date: Fri, 26 Jan 2001 15:12:41 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Basic string question
Message-Id: <3A720469.23D0D888@stomp.stomp.tokyo>
James Kufrovich wrote:
> Godzilla! wrote:
> [snip]
(more snippage)
> after setting $string = "something ";
> >@Array = split (//, $string);
> >print "@Array";
> >This will print:
> >s o m e t h i n g <-- two trailing spaces
> >A print command for an array without
> >quotes will not have spaces, unless
> >spaces are included in your elements:
> >print @Array;
> >This will print:
> >something <-- one trailing space
> Erf. Can somebody explain why this is, or point me toward
> documentation that would explain it
Look for references to "interpolation" or "array interpolation"
in your reference books or online resources.
Perl performs a trick, interpolation, which means,
as a word, to alter, insert, enlarge or corrupt
written material; to change text somehow.
When an array is enclosed in double quotes and printed,
each element is treated as a double quoted string. So,
logically, you don't want individual strings to be joined
together or ran together; they are uniquely individual
much like words in this article. Perl automatically
prints each element, inserting a space after each,
to keep them sorted, keep them separated so as not
to create one long string, erroneously.
There are many hidden default variables within Perl,
scary little critters few wish to discuss lest
one of those crafty creatures be invoked and wreak
havoc upon your data. In this example, this masked
and hidden default variable is, $" * shudders *
one of the more nefarious entities of Perl bringing
critical mass confusion to citizens of Perl Perl Land.
Blah! Don't worry about this. Just remember what
quotes or lack of quotes, will do when printing
an array. This worry will drive you crazy; there
are other hidden variables of great nonsense
written into Perl as a joke by Mr. Wall.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Sat, 27 Jan 2001 00:54:03 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Calling rsync with "system" does not work
Message-Id: <L_oc6.429$U22.130772@news.pacbell.net>
Otto Wyss <otto.wyss@bluewin.ch> wrote:
> I have written 2 allmost identical scripts (actually just one) which
> mirrors a debian server using rsync through the system function. While
> the following statement in script "mirrorcheck" works
> @args=("rsync", "-aPv", "$serverdir", "$workfile");
> print "@args\n";
> system (@args);
> the following statement in script "mirrorsync"
> @args=("rsync", "-aPv --include-from .listfile", "$serverdir",
> "$workdir");
Without actually testing, I don't like the above.
There are really two different ways to call system.
1 arg
>1 arg
With 1 arg, the argument is broken up into multiple command line
arguments and executed.
With >1 arg, it assumes *you* have already broken everything up.
I'm assuming that you want "-aPv" and "--include-from" to be separate
arguments. By placing them within the same scalar and passing multiple
arguments to system, they are not. They are a single argument with a
space inside.
Either break up all your arguments, or join them all together and just
pass a scalar to system.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Sat, 27 Jan 2001 12:38:06 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Calling rsync with "system" does not work
Message-Id: <slrn9749ju.tip.mgjv@martien.heliotrope.home>
On Fri, 26 Jan 2001 21:23:26 +0100,
Otto Wyss <otto.wyss@bluewin.ch> wrote:
> @args=("rsync", "-aPv --include-from .listfile", "$serverdir",
> "$workdir");
Either use a single string (without shell metacharacters), or split the
list up correctly. In your case, the whole string "-aPv --include-from
.listfile" gets passed to rsync as a single argument, instead of the
three separate ones that it should get.
@args = (qw(-aPv --include-from .listfile), $serverdir, $workdir);
my $rc = system("rsync", @args);
If you use a single string, and there are no shell metacharacters, the
splitting up on whitespace will happen automatically for you.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Fri, 26 Jan 2001 23:41:48 GMT
From: lc1178@my-deja.com
Subject: Re: Counting elements in an array (foreach)
Message-Id: <94t1vr$moq$1@nnrp1.deja.com>
Excuse me if this is too obvious, but I'd do it this way:
my @words = qw(fizz buzz foo bar flurp frap);
foreach my $i (0..$#words) {
print "3rd Word is $words[$i]\n" if $i == 2;
}
-Lalit Chhabra
In article <94gl8k$sgo$1@plutonium.btinternet.com>,
"Jerry Pank" <me@jp1.co.uk> wrote:
>
> Jim Monty <monty@primenet.com> wrote in message
> news:94bbe5$sqq$1@nnrp2.phx.gblx.net...
> > Jerry Pank <me@jp1.co.uk> wrote:
> > > Perl special variable for counting elements in an array (foreach
etc)
> > >
> > > If I wish to count elements whilst looping through an array, I
resort to
> $i
> > > as below.
> > >
> > > I would have thought perl would have had a `special' variable for
this.
> > > There probably is but I can't find one in my reference material.
> >
> > There's no need for a 'special' loop counter variable in Perl. The
> > number of elements in the array @array is given by @array in a
scalar
> > context. For example:
> >
> > my $number_of_elements = @array;
> >
> > You can force a scalar context using the scalar function. For
> > example:
> >
> > print scalar @array; # print number of elements of @array
> >
> > And the last index of the array @array is given by $#array.
> >
> > So...
> >
> > > #!bin/perl5 -w
> >
> > Shouldn't that be '#!/bin/perl5 -w'?
> >
> > > use strict;
> > > my @array=(1..100);
> > > my $i;
> > > foreach my $element(@array) {
> > > $i++;
> > > # do stuff
> > > print "Done element $i\n";
> > > }
> >
> > You're simply using the wrong idiom.
> >
> > foreach (0 .. $#array) {
> > # $_ is index of @array, $array[$_] is corresponding element
> > }
> >
> > foreach my $i (0 .. $#array) {
> > # $i is index of @array, $array[$i] is corresponding element
> > }
> >
> > for (my $i = 0; $i <= $#array; $i++) {
> > # $i is index of @array, $array[$i] is corresponding element
> > }
> >
> > foreach (@array) {
> > # $_ is element of @array, index is unknown
> > }
> >
> > foreach my $element (@array) {
> > # $element is element of @array, index is unknown
> > }
> >
> > Any of those foreach's can be (and often are) abbreviated to for.
> > "for" example:
> >
> > for (0 .. $#array) { ... }
> >
> > --
> > Jim Monty
> Thanks for your time on this Jim. Maybe I should have given a better
> example (without numbers in the array) eg:
>
> my @words = qw(fizz buzz foo bar flurp frap);
> my $i=0;
> foreach my $word (@words) {
> print "3rd Word is $word\n" if $i == 2;
> $i++;
> }
>
> My point is that I expected perl to have a `special' variable that I
could
> use without having to resort to $i every time.
>
> --
> j
> me@jp1.co.uk
>
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 27 Jan 2001 00:53:25 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Counting elements in an array (foreach)
Message-Id: <x7zogdu86y.fsf@home.sysarch.com>
>>>>> "l" == lc1178 <lc1178@my-deja.com> writes:
l> Excuse me if this is too obvious, but I'd do it this way:
excuse me but you should read the rest of the thread before jumping in
with a silly answer.
l> my @words = qw(fizz buzz foo bar flurp frap);
l> foreach my $i (0..$#words) {
l> print "3rd Word is $words[$i]\n" if $i == 2;
l> }
huh? if you have an array and you just want the 3rd element, just index
into it. why loop for no reason?
print "3rd Word is $words[2]\n" ;
and you jeopardy posted as well. not a good sign.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 26 Jan 2001 23:14:55 GMT
From: rereidy@my-deja.com
Subject: Re: Does DBI support Oracle long data type?
Message-Id: <94t0d8$l7j$1@nnrp1.deja.com>
Look at the DBI and DBD::Oracle docs concerning longs (LongReadLen() and
LongTruncOk()).
Ron Reidy
Oracle DBA
In article <94qd9l$dkg$1@nnrp1.deja.com>,
henry00@my-deja.com wrote:
> I use DBI to make a selection statement. When my selected columns have
> long type (in Oracle table), it returned nothing. I knew there are
> records. my code like this:
> $sth = $dbh->prepare("select id, long_seq from my_seq_table where
> id=?");
> while(<IN>) { # id list
> chomp;
> $sth->execute($_);
> @fields = $sth->fetchrow_array;
>
> Why there is no record with long_seq (datatye of long), but w/o it
> everything OK.
>
> Help please
>
> Sent via Deja.com
> http://www.deja.com/
>
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 27 Jan 2001 00:18:13 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Finding unused variables ?
Message-Id: <snm5kimi.fsf@macforce.sumus.dk>
eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich) writes:
> On 26 Jan 2001 17:05:41 +0100, Jan Willamowius <jan@willamowius.de> wrote:
> >I'm looking for a tool that finds unused variables.
> [snip]
> >Is there a tool that can detect any of those 2 categories ?
>
> Put '-w' (sans quotes, of course) on the shebang line, which you
> should do for every script you write, as well as using the "strict"
> pragma, which wont necessarily (I don't think so, anyway) detect unused
> variables, but it's a Good Idea anyway. </runon_sentence>
None of those detect the kinds of unused variable that bother the OP.
-w warns you of namespace variables (non-my) which are only used once and
of uselessnesses such as statements of the form $swweeeeee;
The below code snippet however produces nothing but the sound of tomatoes
smashing :-)
But you're absolutely right about the inevitability of -w and strict. They're
a great help.
I've no help for the OP. I'd search the files in my editor or with a custom
script.
-------------------------
#!/usr/bin/perl -w
use strict;
my $haha;
my $puma = 25;
$::gnii = 100;
$::gnii = 101;
$::gnii = 102;
print "The sound of tomatoes smashing\n";
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: 27 Jan 2001 00:27:27 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Finding unused variables ?
Message-Id: <slrn9745ff.aeq.abigail@tsathoggua.rlyeh.net>
James Kufrovich (eggie@REMOVE_TO_REPLYsunlink.net) wrote on MMDCCV
September MCMXCIII in <URL:news:slrn973umn.26h.eggie@melody.mephit.com>:
^^ On 26 Jan 2001 17:05:41 +0100, Jan Willamowius <jan@willamowius.de> wrote:
^^ >I'm looking for a tool that finds unused variables.
^^ [snip]
^^ >Is there a tool that can detect any of those 2 categories ?
^^
^^ Put '-w' (sans quotes, of course) on the shebang line, which you
^^ should do for every script you write, as well as using the "strict"
^^ pragma, which wont necessarily (I don't think so, anyway) detect unused
^^ variables, but it's a Good Idea anyway. </runon_sentence>
That's wrong. -w *might* warn you for unused variables; but not for
my()ed variables. Witness:
$ perl -wle '$foo = 1'
Name "main::foo" used only once: possible typo at -e line 1.
$ perl -wle 'my $foo = 1'
$
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Sat, 27 Jan 2001 12:22:37 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Finding unused variables ?
Message-Id: <slrn9748mt.tip.mgjv@martien.heliotrope.home>
On 26 Jan 2001 17:05:41 +0100,
Jan Willamowius <jan@willamowius.de> wrote:
> I'm looking for a tool that finds unused variables.
>
> I have to maintain some old code where sombody put in
> a number of variables that are only used in my declarations
> and others that are only written to, but never read from.
>
> Is there a tool that can detect any of those 2 categories ?
Use deja.com, and read the newsgroup before you post questions like
this.
A thread with the subject /How to find unused variables?/ started on 7
Sep 2000, with message id <_HPt5.252$pz5.129366@news.bahnhof.se>.
A thread with subject /Lint for perl?/ started here 22 Jan 2001 (less
than a week ago), with message id <94hme6$bo3$1@panix6.panix.com>.
If you had gone to http://www.deja.com/home_ps.shtlm, and you had
searched for 'unused variables' in the group comp.lang.perl.misc, you
would have foiund these, and other articles.
Go there now, and find them. hey explain that it is impossible to do
this reliably. Only Perl can parse Perl. Besides that, a variable may be
used at runtime, and you can only find that out by running the program.
Even Perl's -w gets these things 'wrong' at times:
$ perl -wl
$banana = 42;
$first_half = "ban";
$second_half = "ana";
print ${$first_half . $second_half};
print eval "\$$first_half$second_half";
__END__
Name "main::banana" used only once: possible typo at - line 1.
42
42
Martien
--
Martien Verbruggen |
Interactive Media Division | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd. | make up 3/4 of the population.
NSW, Australia |
------------------------------
Date: Sat, 27 Jan 2001 01:50:36 GMT
From: eggie@REMOVE_TO_REPLYsunlink.net (James Kufrovich)
Subject: Re: Finding unused variables ?
Message-Id: <slrn974ag4.2si.eggie@melody.mephit.com>
On 27 Jan 2001 00:27:27 GMT, Abigail <abigail@foad.org> wrote:
>James Kufrovich (eggie@REMOVE_TO_REPLYsunlink.net) wrote on MMDCCV
>^^ Put '-w' (sans quotes, of course) on the shebang line, which you
>^^ should do for every script you write, as well as using the "strict"
>^^ pragma, which wont necessarily (I don't think so, anyway) detect unused
>^^ variables, but it's a Good Idea anyway. </runon_sentence>
>
>
>That's wrong. -w *might* warn you for unused variables; but not for
>my()ed variables. Witness:
>
> $ perl -wle '$foo = 1'
> Name "main::foo" used only once: possible typo at -e line 1.
> $ perl -wle 'my $foo = 1'
> $
*bows* And so I'm enlightened. Thanks. Shows how much I have to
learn yet. I guess I thought -w would work in all cases because I thought
I remembered getting the "$var only used once" error a few times, and I
always use strict, hence always use my() variables. *shrug* I could be
mistaken, though. Oh, well. Post and learn, ne?
Jamie
"THERE ARE FOUR POSTS!"
--
Egg, eggie@REMOVE_TO_REPLYsunlink.net
FMSp3a/MS3a A- C D H+ M+ P+++ R+ T W Z+
Sp++/p# RLCT a+ cl++ d? e++ f h* i+ j p+ sm+
------------------------------
Date: Fri, 26 Jan 2001 23:12:02 GMT
From: mustbe@pdelahunta.cjb.com (Paul Delahunta)
Subject: Re: forms and security
Message-Id: <3a7202c0.22606910@news.planet.nl>
On Sat, 27 Jan 2001 00:54:18 +0100, Per Kistler <kistler@gmx.net>
wrote in message <3A720E2A.2857E150@gmx.net>:
>Hi Paul
>
>I would make it save, even if I would not know in what way
>it could be critical. Define what the user is allowed to
>do and restrict it the rest.
>You may want to quote all metacharacters with: quotemeta()
>and then maybe reallow "*" by $a=~s/\\\*/*/g;
>
Thanks for the tip Per, I didn't know of the quotemeta() function.
Shouldn't the regexp be:
$a=~s/\\\*/\*/g; (backslash before the second '*')?
Paul
------------------------------
Date: 26 Jan 2001 23:50:04 GMT
From: abigail@foad.org (Abigail)
Subject: Re: hash question
Message-Id: <slrn97439c.aeq.abigail@tsathoggua.rlyeh.net>
Todd Ahlstrom (todda@xmission.com) wrote on MMDCCV September MCMXCIII in
<URL:news:3A71CA9B.FFE9FD38@xmission.com>:
-- I am new to perl, and I am having a problem getting something to work.
-- I have reread the hash section in the book I am using, but I cannot
-- figure this out. I have a hash that contains item, color, and qty
-- values. The keys are named item1...item6 color1...color6 qty1...qty6.
-- What I want to happen is if the value of a qty key is zero, to delete
-- the corresponding item and color keys. Example: qty4's value is 0 then
-- I would want to delete item4 and color4. I figured I could do this with
-- some simple loops, but I can't get it to actually work. I can get it to
-- compile and run, but it never deletes the keys I want deleted. this is
-- a sample of code I have tried:
--
-- for($i=1; $i<7; $i++){
-- if ($hash{qty$i}==0){
-- delete $hash{item$i, color$i}; }
-- }
delete @hash {grep {/^qty/ && !$hash {$_}} keys %hash};
Abigail
--
sub camel (^#87=i@J&&&#]u'^^s]#'#={123{#}7890t[0.9]9@+*`"'***}A&&&}n2o}00}t324i;
h[{e **###{r{+P={**{e^^^#'#i@{r'^=^{l+{#}H***i[0.9]&@a5`"':&^;&^,*&^$43##@@####;
c}^^^&&&k}&&&}#=e*****[]}'r####'`=437*{#};::'1[0.9]2@43`"'*#==[[.{{],,,1278@#@);
print+((($llama=prototype'camel')=~y|+{#}$=^*&[0-9]i@:;`"',.| |d)&&$llama."\n");
------------------------------
Date: Sat, 27 Jan 2001 00:36:59 GMT
From: "Nicholas Marino" <nmarino@home.com>
Subject: How to connect/disconnect a PPPoE DSL connection w. Perl
Message-Id: <LKoc6.8150$49.1085719@news1.rdc2.pa.home.com>
Is there a way to use Perl to connect and disconnect a Dial-up Networking
connection for a PPPoE DSL line?
I'm rewriting a WinBatch (anyone heard of it?) script in Perl. Winbatch has
nice dunconnect() and dundisconnect() functions, but I can't find a way to
do it in Perl.
BTW - My DSL is from Verizon. It sucks. Besides using a byzantine virtual
adaptor/RAS/PPPoE/Dialer arrangement, it actually times out after about 24
hrs, even if the connection is kept in constant use, but doesn't disconnect!
So the internet connection just looks dead, but the connection is still
there. I verified this with Verizon. They don't seem to have a problem with
it. My computer sends a short "I'm alive" message to a central server every
5 minutes, so you would think that the connection would either stay active,
or of they choose to drop it, that it would disconnect.
------------------------------
Date: 27 Jan 2001 00:09:13 GMT
From: jcdixon@aol.com (JCDixon)
Subject: Re: Internal Server Error- Newbie Question.
Message-Id: <20010126190913.03811.00002566@ng-md1.aol.com>
I am having trouble with a Perl script that is returning the same error; i.e.
"premature end of script headers" - an error for which there is no
documentation at www.perl.com. And here's the really wild thing: the error is
only generated when I access the script from home or work. The guys at the
company hosting my site _can't_ get it to throw the error (they now believe I
am crazy). And if that isn't enough, the script (which opens a template file
and a data file, and merges data into the template file) only throws the error
with a particular set of data - it works fine with all other template and data
files. The script was created with Programmers File Editor, which allows
saving in UNIX format, and I have checked the "shebang" line with the web
hoster. Ideas, anyone?
------------------------------
Date: Fri, 26 Jan 2001 19:36:32 -0500
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: MS Access
Message-Id: <3A721810.828E89B6@courrier.usherb.ca>
Intermediate User question :)
I need enough code to be able to open and display a couple of
lines in a Microsoft Access file called db1.mdb, in a table called
QuizData, that looks a bit like this:
No Questions A IsACorr AnsA B IsBCorr AnsB C IsCCorr AnsC D IsDCorr AnsD
Timer SoundFile
1 How ____ you? A 0 Am B 0 Is C 1 Are D 0 20 clip1.rpm
Before, I used a simple text file delimited by ||
1||How ____ you?||A||0||Am||B||0||Is||C||1||Are||D||0||||20||clip1.rpm||
and used this code below. What will I have to do differently with MS
Access?
Can I specify a specific line number in my Access table?
For that matter, how could I improve the code below?
I'd really appreciate some help and/or some code.
Thanks,
John
###################################################################
###################################################################
open(QUESTIONSFILE, "$datafile") || die "I can't open $datafile\n";
@Questions = <QUESTIONSFILE>;
close QUESTIONSFILE;
$QMax=0;
foreach $ThisQuestion (@Questions)
{
$QMax++;
}
if ($QNum > $QMax)
{
foreach $ThisQuestion (@Questions)
{
@TempData = split (/\|\|/, $ThisQuestion);
if($TempData[0] eq $QNum)
{
print "<TR>\n";
print "<TD><B>$TempData[0]</B></TD><TD
COLSPAN=2><B>$TempData[1]</B></TD>";
print "</TR>\n";
#etc.
}
}
------------------------------
Date: Fri, 26 Jan 2001 16:12:47 -0700
From: Todd Ahlstrom <todda@xmission.com>
Subject: naming array with a variable?
Message-Id: <3A72046F.AF129AA1@xmission.com>
Is it possible to name an array with a variable?
What I want are arrays named @array1 @array2 @array3 etc... I was
hoping to name and fill them with a for loop. So I would need the array
to be something like:
(for loop){
@array$x=(some stuff);
}
obviously this doesn't work, I have been banging my head against my
keyboard trying all different ways to make this naming possible. Either
I have missed it, or it can't be done. Thank you for any help.
Todd
------------------------------
Date: Fri, 26 Jan 2001 23:23:04 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: naming array with a variable?
Message-Id: <x766j1vqxz.fsf@home.sysarch.com>
>>>>> "TA" == Todd Ahlstrom <todda@xmission.com> writes:
TA> Is it possible to name an array with a variable?
for you, no.
TA> What I want are arrays named @array1 @array2 @array3 etc... I was
TA> hoping to name and fill them with a for loop. So I would need the array
TA> to be something like:
TA> (for loop){
TA> @array$x=(some stuff);
TA> }
don't try to do that. use a hash of arrays. read perllol and perldsc for
more on this.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 27 Jan 2001 00:28:07 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: naming array with a variable?
Message-Id: <r91pki60.fsf@macforce.sumus.dk>
Todd Ahlstrom <todda@xmission.com> writes:
> Is it possible to name an array with a variable?
Yes but it's bad practice.
> What I want are arrays named @array1 @array2 @array3 etc...
No you don't ........ :-)
> I was
> hoping to name and fill them with a for loop. So I would need the array
> to be something like:
> (for loop){
> @array$x=(some stuff);
> }
I think @{ "array$x" } would do what you think you want. But stop and do
the right thing in stead.
You want an array of arrays.
check man perllol (and perlref and perldsc).
for ( 1..100 ) {
$array[ $_ ] = [ 'some', 'stuff' ];
...
}
You won't regret it in the long run.
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Sat, 27 Jan 2001 01:37:59 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: perl editors
Message-Id: <slrn9749s0.eav.tim@degree.ath.cx>
Kent Perrier <kperrier@blkbox.com> wrote:
> hanja <hanja@my-deja.com> writes:
>
> > Out of curiousity, what editor do you use to write your scripts?
>
> echo "<perlcode>" > filename
>
> Of course editing the script to debug it is a bit hard....
I've been known to use
$cat >> filename
on many occasions, and have used
C:\ > copy con filename
when I was using MS-DOS 3 and 5.
No doubt, if I'd had Vim back then, I'd me a much better man today. ;)
--
-Tim Hammerquist <timmy@cpan.org>
A liar should have a good memory.
-- Quintilian
------------------------------
Date: 26 Jan 2001 23:38:50 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Perl Style Guide - uncuddled elses
Message-Id: <eli$0101261835@qz.little-neck.ny.us>
In comp.lang.perl.misc, Uri Guttman <uri@sysarch.com> wrote:
> [] are usually called brackets (or redundantly square brackets).
That is not /so/ redundant when one thinks of <> as 'angle brackets'.
Elijah
------
print qq<Just another perl hacker,\n>;
------------------------------
Date: Sat, 27 Jan 2001 00:50:42 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl Style Guide - uncuddled elses
Message-Id: <x73de5vmvx.fsf@home.sysarch.com>
>>>>> "EtB" == Eli the Bearded <elijah@workspot.net> writes:
EtB> In comp.lang.perl.misc, Uri Guttman <uri@sysarch.com> wrote:
>> [] are usually called brackets (or redundantly square brackets).
EtB> That is not /so/ redundant when one thinks of <> as 'angle brackets'.
but those are never referred as just brackets, whereas [] are commonly
called that. and if you want to continue the short names, <> are called
angles.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 26 Jan 2001 23:51:44 GMT
From: nexus6_kills@yahoo.com
Subject: Re: Problem with Tie::StdHash / FETCH ??
Message-Id: <94t2id$n9b$1@nnrp1.deja.com>
> You are lucky that some of your cases work, because what your code is
> doing is really strange !
>
> > sub new
> > {
> > my %retHash;
> > tie %retHash, $className, $self;
> > return bless \%retHash, $className;
>
> This part of your code is probably the source of your problems. When
you
> tie() a variable, it is bound to an instance of the specified class.
The
> class instance manages the internal state and behaviour of the tied
> variable. As this is a case of tied hash, you tried to mix them, and
the
> same variable is both the tied variable and blessed with the same
class
> as its implementation counterpart. So, depending on the way you call a
> member method (on the tied one or just on the blessed one), a member
> value acces is redirected or not through the tie methods.
>
> The behaviour of such a construction is probably not defined in the
> Perl5 language, and you should not use it. I think you are right when
> you say it's a bug, but I think the correct fix is to issue an error
> when a tied hash is trying to be blessed.
Thanks for your reply. I removed the blessing of the reference to
the hash, but the same problem persists. The blessing of the hash
reference is done so that I can identify the returned object in
the code. In my new trial (which is still failing), I have blessed
the underlying object to be different class than the hash reference
(lines marked with '# <====' don't have any effect on the bug) --
see the included code:
BTW, all I am trying to do, is have a FETCH method to be called
for a package. In this case when the user writes $pkg_1->{key_1},
I want the FETCH method to be called. May be there is a better
way to do this ... Oh and the only requirement on the user is that
they say '$pkg_1 = new MyPackage1;'
----------------------------------------------------------------
package MyHash;
use Tie::Hash;
@ISA = (Tie::StdHash);
sub TIEHASH
{
my ($className, $obj) = @_;
return bless $obj, $className;
}
sub FETCH
{
my ($self, $key) = @_;
my ($rhs) = $self->{$key};
$rhs = &$rhs if (ref($rhs) eq "CODE");
return $rhs;
}
#===============================================================================
package MyPackage_1;
sub new
{
my ($className) = shift;
my $self = {};
my %retHash;
tie %retHash, "MyHash", $self;
bless \%retHash, $className; # <====
$self->{key_1} = "val_1";
$self->{key_2} = "val_2";
return \%retHash;
}
#===============================================================================
package MyPackage_2;
sub new
{
my ($className, $pkg_1) = @_;
my $self = {};
my %retHash;
tie %retHash, "MyHash", $self;
bless \%retHash, $className; # <====
$self->{DEPS}{pkg_1} = $pkg_1;
$self->{the_keys} = sub { return [$self->{DEPS}{pkg_1}->{key_1},
$self->{DEPS}{pkg_1}->{key_2}]; };
$self->{the_keys_2} = sub { return ["foo", "bar"]; };
return \%retHash;
}
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Sat, 27 Jan 2001 12:32:46 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: right place for a mod_perl question?
Message-Id: <slrn97499u.tip.mgjv@martien.heliotrope.home>
On 26 Jan 2001 13:45:16 GMT,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Daniel W. Burke <dwb1@home.com> wrote in comp.lang.perl.misc:
>
> [snip Gary E. Ansok's good advice]
>
>>It seems weird that mod_perl is passing the apache object to each script in
>>@_, but if each script is called like a function inside the interpreter, I
>>guess it makes sense...
>
> Well, @_ a truly global variable, and everyone has access to it.
> Consequently it is a mistake to assume anything about its contents
> unless you have assigned it yourself.
What I'm going to say is only tangentially related to the problem, but I
felt I had to add a bit to your statement here.
@_ does get localised appropriately and automatically when a sub is called.
#!/usr/local/bin/perl -wl
use strict;
sub changer { @_ = (2, 3, 4) }
@_ = (4, 3, 2);
print "@_";
changer;
print "@_";
But I do agree that a sub that passes on @_ though the & calling syntax
should really know what its doing. I tend to avoid that syntax (I only
use it for goto &sub constructions), and pass @_ explicitly when that's
what I mean. It's also more clear for other people wo need to read my
code, but don't know the subtle differences between the five ways a sub
can get called.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: Sat, 27 Jan 2001 12:10:19 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <slrn9747vr.tip.mgjv@martien.heliotrope.home>
On Fri, 26 Jan 2001 18:59:29 GMT,
Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "MV" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
>
> MV> $r = reverse $s = shift;
> MV> print $s and $s .= substr $s, 0, 1, "" for 1 .. length $s;
> MV> print $r and $r .= substr $r, 0, 1, "" for 1 .. length $r;
>
> perl -le '$_ = shift ; print and substr( $_, 0, 0, chop ) while $i++ <
> length' qwert
That only solves half the problem, though :)
Martien
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results
Commercial Dynamics Pty. Ltd. | were negative.
NSW, Australia |
------------------------------
Date: Sat, 27 Jan 2001 00:09:02 GMT
From: "What A Man !" <whataman@home.com>
Subject: Simple Random Number Problem
Message-Id: <3A721209.E246BD44@home.com>
Why am I getting 2 numbers for $td in the coding below?
Most of the time $td turns out to be 3 numbers, but
occasionally I get 2 numbers, such as 44 or 78 (and they
are even lower numbers than what I have specified).
### random number for temp directories
$td = rand(@num = 100 .. 1000);
@td = split ( /\./, $td );
$td = $td[0];
$tmpdir = "$dir/$td";
Thanks,
Dennis
------------------------------
Date: Fri, 26 Jan 2001 19:39:50 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Simple Random Number Problem
Message-Id: <94t5bc$njf$1@slb3.atl.mindspring.net>
"What A Man !" <whataman@home.com> wrote in message
news:3A721209.E246BD44@home.com...
> Why am I getting 2 numbers for $td in the coding below?
> Most of the time $td turns out to be 3 numbers, but
> occasionally I get 2 numbers, such as 44 or 78 (and they
> are even lower numbers than what I have specified).
>
> ### random number for temp directories
> $td = rand(@num = 100 .. 1000);
> @td = split ( /\./, $td );
> $td = $td[0];
> $tmpdir = "$dir/$td";
That's an odd way to do what you're trying to do. Let's look at what it
actually does.
> $td = rand(@num = 100 .. 1000);
Assigns a list containing the numbers 100 through 1000 to the array variable
@num. (@num now contains 901 elements). The rand() function uses @num in a
scalar context, producing a random floating point value greater than or
equal to zero and less than 901. See the problem here?
> @td = split ( /\./, $td );
> $td = $td[0];
> $tmpdir = "$dir/$td";
You're going through a lot of work converting the floating point value to a
string containing the integer part. The int() function does what you want.
The code above could be re-written as:
my $tmpdir = "$dir/" . int(rand(900) + 100);
HTH
Kurt Stephens
------------------------------
Date: 26 Jan 2001 19:42:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Simple Random Number Problem
Message-Id: <m3g0i5omey.fsf@mumonkan.sunstarsys.com>
"What A Man !" <whataman@home.com> writes:
> Why am I getting 2 numbers for $td in the coding below?
> Most of the time $td turns out to be 3 numbers, but
> occasionally I get 2 numbers, such as 44 or 78 (and they
> are even lower numbers than what I have specified).
s/numbers/digits/ ?
>
> ### random number for temp directories
> $td = rand(@num = 100 .. 1000);
same as
@num = 100 .. 1000;
$_ = 1000 - 99; # num elts in @num
$td = rand($_);
see
% perldoc -f rand
for proper usage, and try
$td = int rand(@num) + 100;
to get random whole numbers between 100 and 1000.
HTH
--
Joe Schaefer
------------------------------
Date: Sat, 27 Jan 2001 00:57:48 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Simple Random Number Problem
Message-Id: <x7wvbhu7zn.fsf@home.sysarch.com>
>>>>> "JS" == Joe Schaefer <joe+usenet@sunstarsys.com> writes:
JS> for proper usage, and try
JS> $td = int rand(@num) + 100;
JS> to get random whole numbers between 100 and 1000.
or use the standard idiom to pick a random element from an array:
$td = $num[ rand @num ] ;
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 26 Jan 2001 18:16:22 -0500
From: Gopi Sundaram <gopalan@cs.sc.edu>
Subject: sorting a hash of anon. arrays
Message-Id: <Pine.GSO.4.31.0101261813500.15862-100000@mum.cs.sc.edu>
Hello all,
I generate a hash called %data based on SSNs containing student data
like so in a loop:
$data{$ssn} = [$name, $login, $class, $section];
Later I want to process it in two separate orders: sorted by name,
and sorted by class. Is there a way to use "sort" to do this?
--
Gopi Sundaram
gopi@cse.sc.edu
------------------------------
Date: Fri, 26 Jan 2001 20:01:08 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: sorting a hash of anon. arrays
Message-Id: <94t6jc$r8k$1@slb7.atl.mindspring.net>
"Gopi Sundaram" <gopalan@cs.sc.edu> wrote in message
news:Pine.GSO.4.31.0101261813500.15862-100000@mum.cs.sc.edu...
> Hello all,
>
> I generate a hash called %data based on SSNs containing student data
> like so in a loop:
>
> $data{$ssn} = [$name, $login, $class, $section];
>
> Later I want to process it in two separate orders: sorted by name,
> and sorted by class. Is there a way to use "sort" to do this?
Read the following in perlfaq4:
How do I sort an array by (anything)?
How do I sort a hash (optionally by value instead of key)?
# Sort by name
print join(', ', $_, @{$data{$_}}, "\n") foreach
sort { $data{$a}->[0] cmp $data{$b}->[0] } keys %data;
# Sort by class
print join(', ', $_, @{$data{$_}}, "\n") foreach
sort { $data{$a}->[2] cmp $data{$b}->[2] } keys %data;
HTH
Kurt Stephens
------------------------------
Date: Sat, 27 Jan 2001 00:18:31 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Split losing UTF-8 flag on UTF-8 scalars
Message-Id: <rtoc6.157124$P82.19061894@news1.rdc1.ct.home.com>
Nate Edel <edel@best.com> wrote:
> Finally, my question:
> Is split supposed to lose the UTF-8 flag, or is this a bug?
Bug. UTF-8 support in 5.6.0 is whacked. If you need it, snag one of the
development releases, where things are enourmously better.
Dan
------------------------------
Date: 26 Jan 2001 23:41:59 GMT
From: rob_13@excite.com (Rob - Rock13.com)
Subject: Re: Very newbie question
Message-Id: <9035B478Drock13com@207.91.5.10>
Ross McLoughlin <ross@technipoint.ie>:
>I want to install ActivePerl on Windows98, and run them locally
>before adding them to the website. For example, is it possible to
>run a form validation script separate from the web server?
Always a good idea to run scripts locally before putting your server
at risk:-) If you haven't done it already this article may help:
http://www.egovision.org/htmlresources/articles/apache_win32.html
--
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/
------------------------------
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 V10 Issue 154
**************************************