[22727] in Perl-Users-Digest
Perl-Users Digest, Issue: 4948 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 6 21:06:10 2003
Date: Tue, 6 May 2003 18:05:07 -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 Tue, 6 May 2003 Volume: 10 Number: 4948
Today's topics:
Re: Array::Compare <jkeen@concentric.net>
Re: Array::Compare <sammie@greatergreen.com>
Re: basic doubts.. <pkent77tea@yahoo.com.tea>
Re: clearing stdin (Anno Siegel)
Re: Design Opinions - Dealing with Constants <bigj@kamelfreund.de>
Re: Forcing an rvalue context on a scalar expression <abigail@abigail.nl>
Re: Forcing an rvalue context on a scalar expression <skuo@mtwhitney.nsc.com>
Re: Forcing an rvalue context on a scalar expression (Anno Siegel)
Re: Help: Create Hash On The Fly? (entropy123)
Re: How do you create a biniary file in Perl. <fxn@hashref.com>
Re: Including files in Perl <jkeen@concentric.net>
Re: Including files in Perl <jkeen@concentric.net>
Re: Newbie question Perl Print function using files <REMOVEsdnCAPS@comcast.net>
Re: Open With? <wksmith@optonline.net>
Re: Open With? <dont@want.spam>
Re: Open With? (Tad McClellan)
Re: Open With? <taariqq@yahoo.com>
Re: Open With? <taariqq@yahoo.com>
Re: Open With? <emschwar@pobox.com>
Re: Open With? (Malcolm Dew-Jones)
Re: Passing hash and string to subroutine <jkeen@concentric.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 06 May 2003 23:24:00 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Array::Compare
Message-Id: <b99g6g$s2j@dispatch.concentric.net>
"James E Keenan" <jkeen@concentric.net> wrote in message
news:b978at$d39@dispatch.concentric.net...
>
> But, the plot thickens further. In his inline comments in &full_compare,
> the author says that there is "no point in continuing if the number of
> elements is different." To get what he describes as a meaningful return
> value, he constructs a list with the range operator in which the lower
value
> is the last index number of the shorter array + 1 (equivalent to #
elements
> in shorter) and the upper value is the last index number of the longer
> array. In your example, that would be the range (3+1)..4 ... i.e.,
4..4 --
> which is a list consisting solely of the value '4'. Now, why that is a
> meaningful return value for the case of lists with different numbers of
> elements escapes me.
>
To be fair, as I was drifting off to sleep last night I _think_ I realized
what the author had in mind. He's constructing a list of the indices of
what might be called the 'excess columns'. In the OP's example, the second
list is only one element larger than the first, hence, the return value is a
1-item list.
------------------------------
Date: Wed, 07 May 2003 00:04:09 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Array::Compare
Message-Id: <Z3Yta.760410$F1.96408@sccrnsc04>
Well, List::Compare solved my problems, and did so quite well! Now on to the
next issue...
Thanks,
Brad
"James E Keenan" <jkeen@concentric.net> wrote in message
news:b99g6g$s2j@dispatch.concentric.net...
>
> "James E Keenan" <jkeen@concentric.net> wrote in message
> news:b978at$d39@dispatch.concentric.net...
> >
> > But, the plot thickens further. In his inline comments in
&full_compare,
> > the author says that there is "no point in continuing if the number of
> > elements is different." To get what he describes as a meaningful return
> > value, he constructs a list with the range operator in which the lower
> value
> > is the last index number of the shorter array + 1 (equivalent to #
> elements
> > in shorter) and the upper value is the last index number of the longer
> > array. In your example, that would be the range (3+1)..4 ... i.e.,
> 4..4 --
> > which is a list consisting solely of the value '4'. Now, why that is a
> > meaningful return value for the case of lists with different numbers of
> > elements escapes me.
> >
> To be fair, as I was drifting off to sleep last night I _think_ I realized
> what the author had in mind. He's constructing a list of the indices of
> what might be called the 'excess columns'. In the OP's example, the
second
> list is only one element larger than the first, hence, the return value is
a
> 1-item list.
>
>
------------------------------
Date: Tue, 06 May 2003 22:22:07 GMT
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: basic doubts..
Message-Id: <pkent77tea-77F09B.23104206052003@dev.rsn.selsyn.co.uk>
In article <bf3db5a0.0305030418.668437f3@posting.google.com>,
viijv@rediffmail.com (Rajesh M A) wrote:
> #)Write a program that outputs "Hello World" but using both system()
> and backticks.
an example would be, on a Unix system:
system('echo hello world');
but you can be much more complex if you want.
> Hmm... what is the meaning of 'prepend w'?
'append' means that stick something at the end of another thing.
'prepend' means you stick something at the beginning of another thing.
E.g. if you prepend 'w' to 'ant' you get 'want'.
> What is the meaning of... 'references to arrays as its arguments'?
> i can only pass variables to an subroutine, right? something like
> &my_sub($var1,$var2,$var3);
the usual style (unless you have a good reason to do otherwise) is:
my_sub( $arg1, $arg2, $arg3 );
with no '&' in front.
> &my_sub(@array);
>
> how can i send two arrays? what do they mean by 'reference to arrays'?
> Can some one explain this to me ?
See the 'perlreftut' man page. If I wanted to pass refs to 2 arrays I
could say:
my_sub( \@array1, \@array2 );
> #)Rewrite the following fragment of code to use a dispatch table:
> If ($answer eq "y"){
> Print "Yes";
there is no such operator/keyword/function ar 'If', nor 'Print'.
Somebody who is setting you exercises should be able to spell 'if' and
'print' correctly...
> My doubt is simple...what is a dispatch table? i searched the internet
> a lot, but failed to find any promising information.
See http://shrunk.net/?c=978abe15
It's basically where you make a hash of code refs, where the key is the
value that you're using in the 'if' conditions. Here's a simple example:
http://www.itworld.com/nl/perl/08162001/
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: 6 May 2003 22:11:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: clearing stdin
Message-Id: <b99bv2$2rh$1@mamenchi.zrz.TU-Berlin.DE>
Lee&James <schnozx@hotmail.com> wrote in comp.lang.perl.misc:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:b95cbs$2av$1@mamenchi.zrz.TU-Berlin.DE...
> > Lee&James <schnoz@adelphia.net> wrote in comp.lang.perl.misc:
> > > On a windows platform I want to clear stdin before putting out a message
> > > and then reading stdin. Can someone tell me how to do this?
> >
> > "stdin" is a file handle (well, STDIN is). What do you mean by "clearing
> > stdin"?
[please don't top-post]
> I want to send a message to the screen and then read any input that the user
> has entered after I sent the message. If the user presses enter before I
> send a message to the screen I'll be picking up that data. I want to make
> sure I only get data the user entered after he has seen the message, so I
> want to make sure stdin is empty before I send the message.
What if they keep typing? Or STDIN happens to be a large disk file?
> However, if I
> try to read stdin before sending the message, I'll block waiting for input.
So you want to clear the type-ahead buffer. That's bound to be rather
system-dependent. See "perldoc -f getc" for a hint of what you're up
to, though it won't immediately apply to Windows. The Term::ReadKey
module may do what you want to do.
Anno
------------------------------
Date: Tue, 06 May 2003 21:53:22 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Design Opinions - Dealing with Constants
Message-Id: <pan.2003.05.06.19.49.33.152764@kamelfreund.de>
Kevin Vaughn wrote at Tue, 06 May 2003 08:38:27 -0500:
> I've created a large number of scripts that reference a single file
> containing all of my constants. I named the file environment.pl. The file
> mainly contains paths. I include environment.pl using a "required"
> statement.
>
> Is this good or bad design? I'm particularly interested in the downsides.
That depends. Of course, it's good that you don't double your code.
My prefered way would be to use a real config file.
In such cases, I personally prefer to use the CPAN module
Tie::Config.
In your case the main reason would be,
that you don't need the power (and inconvenience) of a programming language,
only to set some paths.
(Such a config file could also be edited by a non programmer!)
But it also could be necessary,
e.g. setting a major prefix and configuring all the necessary sub
directories or looking in some system files (win registry or something
else).
In these cases,
I would prefer to write a simple module that I could include with a
use MyConfigurationModule;
statetment.
A main advantage is that the namespaces are seperated.
Or are you sure, that you remember in all 30/40,... scripts using these
variables, all names of them.
Thus it's better to avoid name conflicts.
You could also customize the import possibilities, e.g.
use MyConfigModule qw/:standard/;
# or
use MyConfigModule qw/:all/;
# or
use MyConfigModule qw/$HOME_PATH/;
But please read
perldoc perlmod
for details.
> Now a specific question - How do I get perl to stop giving me the error
> "Global symbol $constant_from_environment requires explicit package name at
> $line_number" when I have strict turned on?
Solution for the long run: Write a module
Solution for the short run: Declare the variable via our.
> I'm trying to get my head around the lexical vs. package scope thing, but
> it's not coming easy for some reason. Do I have to go through creating a
> package, or can I use "our"?
Don't be scared.
Creating a package is really simple.
All you need is to write 'package XYZ;'.
For exporting stuff out of it,
you'll need some other lines, too,
but they are explained on the first pages of
perldoc perlmod
Greetings,
Janek
------------------------------
Date: 06 May 2003 22:16:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Forcing an rvalue context on a scalar expression
Message-Id: <slrnbbgd1o.tib.abigail@alexandra.abigail.nl>
Steven Kuo (skuo@mtwhitney.nsc.com) wrote on MMMDXXXV September MCMXCIII
in <URL:news:Pine.GSO.4.21.0305061204110.24147-100000@mtwhitney.nsc.com>:
<>
<> Do you consider this less ugly?
<>
<> foo(${\(defined $q[-1]? $q[-1]: undef)});
Why not:
foo (@q ? $q [-1] : undef)
Abigail
--
BEGIN {$^H {join "" => ("a" .. "z") [8, 13, 19, 4, 6, 4, 17]} = sub
{["", "Just ", "another ", "Perl ", "Hacker\n"] -> [shift]};
$^H = hex join "" => reverse map {int ($_ / 2)} 0 .. 4}
print 1, 2, 3, 4;
------------------------------
Date: Tue, 6 May 2003 15:50:10 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: Forcing an rvalue context on a scalar expression
Message-Id: <Pine.GSO.4.21.0305061540220.24147-100000@mtwhitney.nsc.com>
On 6 May 2003, Abigail wrote:
> Steven Kuo (skuo@mtwhitney.nsc.com) wrote on MMMDXXXV September MCMXCIII
> in <URL:news:Pine.GSO.4.21.0305061204110.24147-100000@mtwhitney.nsc.com>:
> <>
> <> Do you consider this less ugly?
> <>
> <> foo(${\(defined $q[-1]? $q[-1]: undef)});
>
>
> Why not:
>
> foo (@q ? $q [-1] : undef)
>
>
> Abigail
>
Yours is simpler and more easily read.
I seem to have this bad habit of using or writing ${\(...)} or @{[...]}
in an overly ornate fashion. :(
For example,
I tend to write:
my $aref = \@{[bar()]};
when I really should write:
my $aref = [ bar() ];
sub bar {
return qw(0 2 4);
}
... Must rid myself of this habit.
--
Regards,
Steve
------------------------------
Date: 6 May 2003 22:51:44 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Forcing an rvalue context on a scalar expression
Message-Id: <b99ea0$4l3$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>
> AS> Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
> >>
> >> Consider this:
> >>
> >> sub foo {$_ [0] = 1}
> >> my @q;
> >> foo $q [2];
> >> print scalar @q;
> >>
> >> This prints 3 because you created $q [2]. But suppose you had called
> >> 'foo $q [-1]', how large should @q be afterwards? Which element was
> >> created?
>
> AS> All true, but the error shouldn't happen just because foo( $q[ -1]) is
> AS> called, only when foo() actually tries to assign to its argument.
>
> but a sub call creates an alias to that element which doesn't exist. it
> can be undef since there is no slot to create alias to.
...but $q[ 12] doesn't exist either, but is legal in places where $q[ -1]
isn't. The difference would be that (with an empty array) $q[ -1] can
never be allocated.
I don't understand the second sentence.
> this generates the same error so it is not a sub related problem. you
> can't take a ref or make an alias to an unknown slot in the array. the
> -1 index implies you have at least one slot in the array so you can get
> its size and index from the end.
>
> perl -e '$r = \$a[-1]'
> Modification of non-creatable array value attempted, subscript -1 at -e line 1.
Hmm... referencing and aliasing seems to be the key. "1 for $q[ -1]"
also triggers it. Still, the behavior is unexpected, considering that
read-access is usually possible with any array and any index, even
large negatives. Also, how can a prepended "scalar", or a "do{}"
wrapped around heal it? Something is flaky here and needs attention.
> it is the -1 index which is causing the problem and i don't feel it is a
> bug. you can't index from the end when you have no elements - there is
> no end to use.
Ah, c'mon, 0 is a respectable end too. Emptiness has nothing to do
with it, the same happens with a non-empty array for large negative
indices, once they point past (err, before) the beginning of the array.
I still think there's a bug involved, but the solution may be less
straight-forward than I was hoping for.
Anno
------------------------------
Date: 6 May 2003 18:01:47 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Re: Help: Create Hash On The Fly?
Message-Id: <90cdce37.0305061701.7914aa6c@posting.google.com>
\> >
> You want a hash of hashes:
>
> my %hoh = ();
>
> $hoh{A0} = {B1=>2, A0=>1, A3=>3};
>
> To get the values out:
>
> my $val = $hoh{A0}{B1};
>
This is pretty damned great. One question:
How would I do this -
while ( ($key, $value) = each %hash) {
print "$key = $value\n";
}
in the hash of hashes?
Thanks,
ent
------------------------------
Date: Tue, 6 May 2003 22:39:00 +0000 (UTC)
From: Xavier Noria <fxn@hashref.com>
Subject: Re: How do you create a biniary file in Perl.
Message-Id: <b99di4$3a8$1@news.ya.com>
In article <b98s0e$gqb$1@nets3.rz.RWTH-Aachen.DE>, Tassilo v. Parseval wrote:
: I think you don't even need binmode() if you are writing the characters
: implicitely by providing their octal or hexadecimal value.
What do you mean here?
-- fxn
------------------------------
Date: 06 May 2003 23:09:13 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Including files in Perl
Message-Id: <b99fap$d37@dispatch.concentric.net>
"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:b97ulv$nep$1@news.dtag.de...
> James E Keenan wrote:
>
> > $SERVER = 'foo';
> >
> > Hence, no 'our' in the included file ... only in the script.
>
> Why not? It makes the required file strict safe.
>
Why should we worry whether the required file is strict-safe or not? The
required file is merely a file holding some text that, while it looks like
code for Perl variables, only _really_ becomes code for Perl variables once
the file is required into a real Perl script.
As I noted in another posting in this thread, to call the required file
'require.pl' is arbitrary. In fact, it's more than arbitrary, it's
misleading. Better to call it 'require.txt' or 'require.conf'.
Consider this: Suppose that we altered the main package by commenting out
the declaration of $SERVER with 'our'. Suppose we put an 'our' in front of
$SERVER in the required file. Does the main package compile? No.
------------------------------
Date: 06 May 2003 23:13:21 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Including files in Perl
Message-Id: <b99fih$d3c@dispatch.concentric.net>
"PropART" <temp1_NO_SPAM_@williamc.com> wrote in message
news:3EB79F63.A20F1BA6@williamc.com...
>
>
> So, if I'm understanding everything that's being said in this thread
> correctly, the situation is this:
>
> if I want to put a bunch of scalar variable in an include file AND use
> strict in the including files, I'll need to declare the variables with
> our in the including file. Which also implies that if I change the
> include file I'll need to change the declaration in all of the including
> files.
>
Yes.
> However, your suggestion of putting the values into a hash could work
> around the problem at the expense of a little extra code to get the
> value out of the hash. Thanks for the help.
>
Yes, good point. I was just mentioning arrays and hashes to be inclusive.
I wasn't even thinking that that would lead to greater flexibility down the
road ... though I should have, because a hash in an included file is
precisely how I've been using an included file in a script I've run every
day for nearly 3 years!
------------------------------
Date: Tue, 06 May 2003 17:07:40 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Newbie question Perl Print function using files
Message-Id: <Xns9373B85D9B13Bsdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
repsg@btclick.com (Reps) wrote in
news:cf9445fa.0305060423.2bbf2a16@posting.google.com:
> Hi there,
> I have a small problem. I aiming to open a file and write to the
file
> on one line>
>
> I have my variables such as:
>
> $firstname , $lastname , $gender etc.
>
> I use the print function
>
> open(CSVFILE, "contacts.csv");
> print CSVFILE "${firstname} , ${lastname} , ${gender}";
> close(CSVFILE);
Please do not re-type code that you want help with. Copy and paste
it. The above code cannot produce the output that you are seeing
(nor the output that you want). Help others to help you.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uDIbY96i4h5M0egRAlTKAKC6MQqOFNEpvUfhsC/sgtQ/207JeQCg3ZvQ
0+qtNwqJ4E9pOku6OPUf1ao=
=F2Rp
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 22:45:08 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Open With?
Message-Id: <UVWta.15270$kV3.2846181@news4.srv.hcvlny.cv.net>
"Tariq" <taariqq@yahoo.com> wrote in message
news:b997rt02km4@enews2.newsguy.com...
> Hello all,
>
> I am trying to learn a little Perl, and I was going thru the book
'Teach
> yourself Perl in 21 days'. Unfortunately the book is written for the
Unix
> OS, and I am trying the code on win2k.
>
> I have installed Apache and Perl successfully, using the package
> 'indigoperl', and have run a program successfully, using the tutorial
on
> perl.about.com.
>
> However, when I try the following interactive listing from the Perl
book,
> the application asks me to 'Open With', and displays a list of
applications!
>
> I know the shebang line has to be changed to "#!perl". Which I have
done,
> but I just can't figure out how to run this interactive program ... it
won't
> ask for input on the command line, as I had thought.
>
There are several ways to run a perl script under WIN32 Ref:
"What is the equivalent of the shebang ("#!") syntax for win32" in
perlwin32faq4.
You did not say how you tried to run it. I think that you clicked on
the icon
for your script. The message was from WIN32. It did not know what
program (perl) to run to process your script. This would happen if your
script file did not have the extension ".pl" or if the association was
not set up
during installation.
I prefer to work from the DOS command line. Open a DOS window and
use the syntax "perl myscript.pl". Both STDOUT and STDERR will be
written
to the DOS window. Other methods have advantages for production code,
but this is the best way to be sure of getting your error messages.
Good Luck,
Bill
------------------------------
Date: Tue, 06 May 2003 23:58:58 +0100
From: Chris Lowth <dont@want.spam>
Subject: Re: Open With?
Message-Id: <X6Xta.4663$Yc2.1452@newsfep4-winn.server.ntli.net>
Tariq wrote:
> Hello all,
>
> I am trying to learn a little Perl, and I was going thru the book 'Teach
> yourself Perl in 21 days'. Unfortunately the book is written for the Unix
> OS, and I am trying the code on win2k.
>
> I have installed Apache and Perl successfully, using the package
> 'indigoperl', and have run a program successfully, using the tutorial on
> perl.about.com.
>
> However, when I try the following interactive listing from the Perl book,
> the application asks me to 'Open With', and displays a list of
> applications!
>
> I know the shebang line has to be changed to "#!perl". Which I have done,
> but I just can't figure out how to run this interactive program ... it
> won't ask for input on the command line, as I had thought.
>
> Any help would be greatly appreciated, and here is the listing.
>
>
>
>
>
> 1: #!/usr/local/bin/perl
>
> 2: $inputline = <STDIN>;
>
> 3: print( $inputline );
>
>
>
> Sincerely,
>
> Tariq
I assume you are not trying to run this script as an Apache CGI script? It
wont work as it stands.
However - assuming that you are trying to run by clicking on the script
name, then I think this is probably a windows "association" issue. Have you
given your new script a ".pl" extension? If yes - then is the ".pl"
extension "associated" with the perl interpreter?
Try running it from the Windows command prompt..
perl yourprog.pl
This should work even if the association hasnt been set up.
Chris
--
Real address: chris at lowth dot sea oh em.
GPL e-mail anti-virus: http://protector.sourceforge.net
IPTables wizzards: http://www.lowth.com/LinWiz
------------------------------
Date: Tue, 6 May 2003 17:56:32 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Open With?
Message-Id: <slrnbbgfd0.6g7.tadmc@magna.augustmail.com>
Tariq <taariqq@yahoo.com> wrote:
> I am trying to learn a little Perl,
You do not have a Perl problem though.
You have a Windows problem.
> and I was going thru the book 'Teach
> yourself Perl in 21 days'. Unfortunately the book is written for the Unix
> OS, and I am trying the code on win2k.
>
> I have installed Apache
You do not need apache to learn Perl.
You need apache to learn CGI programming using Perl.
> and Perl successfully, using the package
> 'indigoperl', and have run a program successfully, using the tutorial on
> perl.about.com.
How was the program run? From the command line? As a CGI program?
> However, when I try the following interactive listing from the Perl book,
> the application asks me to 'Open With', and displays a list of applications!
How did you invoke the program?
Did it have a filename extension?
Did the indigoperl install make a Registry entry for Perl?
> I know the shebang line has to be changed to "#!perl".
^^^^^^^^^
No it doesn't.
It _should_ be changed, but you don't _have to_ change it.
> Which I have done,
> but I just can't figure out how to run this interactive program
perl myprog
or
myprog.pl (assuming .pl is in the Registry)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 6 May 2003 19:12:21 -0400
From: "Tariq" <taariqq@yahoo.com>
Subject: Re: Open With?
Message-Id: <b99fdm026i@enews2.newsguy.com>
Both Bill and Chris,
Thanks for the tip. I was using the dos prompt, but the word "perl" was
missing from in-front ... it works now!
This had prompted me to install Linux on my laptop, but for now I guess I
can continue using my windows station.
Thanks,
Sincerely,
Tariq
"Chris Lowth" <dont@want.spam> wrote in message
news:X6Xta.4663$Yc2.1452@newsfep4-winn.server.ntli.net...
> Tariq wrote:
>
> > Hello all,
> >
> > I am trying to learn a little Perl, and I was going thru the book 'Teach
> > yourself Perl in 21 days'. Unfortunately the book is written for the
Unix
> > OS, and I am trying the code on win2k.
> >
> > I have installed Apache and Perl successfully, using the package
> > 'indigoperl', and have run a program successfully, using the tutorial on
> > perl.about.com.
> >
> > However, when I try the following interactive listing from the Perl
book,
> > the application asks me to 'Open With', and displays a list of
> > applications!
> >
> > I know the shebang line has to be changed to "#!perl". Which I have
done,
> > but I just can't figure out how to run this interactive program ... it
> > won't ask for input on the command line, as I had thought.
> >
> > Any help would be greatly appreciated, and here is the listing.
> >
> >
> >
> >
> >
> > 1: #!/usr/local/bin/perl
> >
> > 2: $inputline = <STDIN>;
> >
> > 3: print( $inputline );
> >
> >
> >
> > Sincerely,
> >
> > Tariq
>
> I assume you are not trying to run this script as an Apache CGI script? It
> wont work as it stands.
>
> However - assuming that you are trying to run by clicking on the script
> name, then I think this is probably a windows "association" issue. Have
you
> given your new script a ".pl" extension? If yes - then is the ".pl"
> extension "associated" with the perl interpreter?
>
> Try running it from the Windows command prompt..
>
> perl yourprog.pl
>
> This should work even if the association hasnt been set up.
>
> Chris
>
> --
> Real address: chris at lowth dot sea oh em.
> GPL e-mail anti-virus: http://protector.sourceforge.net
> IPTables wizzards: http://www.lowth.com/LinWiz
------------------------------
Date: Tue, 6 May 2003 19:33:38 -0400
From: "Tariq" <taariqq@yahoo.com>
Subject: Re: Open With?
Message-Id: <b99glp03tv@enews2.newsguy.com>
Tad,
Thank you for the detailed answers. Now I do have one more question ... the
answer to which is also probably become clear, as I learn more, but still I
thought I would try ... answer if you like, or I will read on.
My feeble understanding is that CGI is a server side scripting language, and
so is PHP. So, can one use a combination of Perl/PHP, instead of Perl/CGI?
I asked the question from the about.com guide, but haven't gotten the answer
in about 24 hours ... guess that says something about the question :-)
Reason behind all of this is that I am trying to learn some buzz-word
technologies that I hear are somehow related to the field of Bioinformatics.
Database programming is one, Knowledge of Unix/Linux is another, and Perl
and different XML derivatives are talked about as the necessary tools. Since
PHP is famous for server side scripting with MySQL, I thought if I could
eliminate CGI from the mix, that would be one less technology to learn :-)
Tariq
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbbgfd0.6g7.tadmc@magna.augustmail.com...
> Tariq <taariqq@yahoo.com> wrote:
>
> > I am trying to learn a little Perl,
>
>
> You do not have a Perl problem though.
>
> You have a Windows problem.
>
>
> > and I was going thru the book 'Teach
> > yourself Perl in 21 days'. Unfortunately the book is written for the
Unix
> > OS, and I am trying the code on win2k.
> >
> > I have installed Apache
>
>
> You do not need apache to learn Perl.
>
> You need apache to learn CGI programming using Perl.
>
>
> > and Perl successfully, using the package
> > 'indigoperl', and have run a program successfully, using the tutorial on
> > perl.about.com.
>
>
> How was the program run? From the command line? As a CGI program?
>
>
> > However, when I try the following interactive listing from the Perl
book,
> > the application asks me to 'Open With', and displays a list of
applications!
>
>
> How did you invoke the program?
>
> Did it have a filename extension?
>
> Did the indigoperl install make a Registry entry for Perl?
>
>
> > I know the shebang line has to be changed to "#!perl".
> ^^^^^^^^^
>
> No it doesn't.
>
> It _should_ be changed, but you don't _have to_ change it.
>
>
> > Which I have done,
> > but I just can't figure out how to run this interactive program
>
>
> perl myprog
> or
> myprog.pl (assuming .pl is in the Registry)
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: 06 May 2003 18:16:24 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Open With?
Message-Id: <etod6ivy5k7.fsf@wormtongue.emschwar>
"Tariq" <taariqq@yahoo.com> writes:
> My feeble understanding is that CGI is a server side scripting language, and
> so is PHP.
No. CGI is an interface, an API. CGI defines the way a webserver
calls a program, what environment the server will set up for the
program, and how the program is to return output to the server. For
more information, read the c.i.w.a.cgi FAQ.
> So, can one use a combination of Perl/PHP, instead of Perl/CGI?
See above. That question doesn't make sense, as you ask it.
> I asked the question from the about.com guide, but haven't gotten the answer
> in about 24 hours ... guess that says something about the question :-)
Or the guide.
> Reason behind all of this is that I am trying to learn some buzz-word
> technologies that I hear are somehow related to the field of
> Bioinformatics.
I understand the impulse-- believe me, I do. It's nice to have a
fully buzzword-compliant resume. But you have to look past the
buzzwords to what you want to do with them, or else you have no focus
when you're learning them.
> Database programming is one,
There's a reason they have graduate-level courses in this. Database
programming is easy; database design is very hard. I can't remember
offhand who it was (Dijkstra? Knuth?), but someone very seminal in
computer science said, "Show me your data structures, and I'll show
you your code". This is doubly (trebly?) true for databases.
> Knowledge of Unix/Linux is another,
Your best solution here is to download a copy of your favourite Linux
distribution of choice, and break a lot of things. You'll learn more
by fixing your mistakes than any other way, IME.
> and Perl
Of all the things you mentioned, this is the only one relevant to this
group. There is a book on Bioinformatics with Perl, put out by
O'Reilly, but I can't recall more. You can google for reviews.
You'll also want "Learning Perl", and "Programming Perl", also
published by O'Reilly. In addition, a healthy supply of patience and
willingness to look things up and try stuff out instead of just
getting 'stuck' will go a long way.
> and different XML derivatives
Perl does XML quite well.
> are talked about as the necessary tools. Since
> PHP is famous for server side scripting with MySQL, I thought if I could
> eliminate CGI from the mix, that would be one less technology to learn :-)
You'd better ask that in a PHP newgroup, then. I do know there is a
standalone PHP interpreter you can use to write scripts in, but why
you'd want to do that when you have Perl, shell, Ruby-- anything else,
really-- I can't imagine. I'm currently teaching myself PHP, just so
I can put it on my list of "Languages I Know", but I find it
frustrating and difficult to get anything useful done in it.
Also, don't top-post; it's rude, and gets your messages read by
significantly fewer people. Intersperse your comments with the
message you're replying to, like I'm doing, and quote the minimum
required to preserve context.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: 6 May 2003 17:37:46 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Open With?
Message-Id: <3eb8555a@news.victoria.tc.ca>
Tariq (taariqq@yahoo.com) wrote:
: Tad,
: My feeble understanding is that CGI is a server side scripting language, and
No. CGI is the definition of how to pass data from a web server to a
program running on the server. Any program, no matter what language it is
written in, must use the CGI protocol if it wants to be able to run under
the control, so to speak, of a web server. In some languages you must
take explicit action to use the CGI protocols. In other languages it all
happens automatically, you just see the results, such as the magical
existence of a certain variable in your program. Some "languages"
automatically provide additional useful functionality, such as "session
variables", which might be useful to the programmer, but they are not CGI,
just useful extra stuff.
------------------------------
Date: 06 May 2003 22:57:00 GMT
From: "James E Keenan" <jkeen@concentric.net>
Subject: Re: Passing hash and string to subroutine
Message-Id: <b99ejs$s2g@dispatch.concentric.net>
"Rich Pasco" <richp1234@hotmail.com> wrote in message
news:3EB7BEFE.8020605@hotmail.com...
> James E Keenan wrote:
>
> >>
> > Perfectly fine, as is Sara's suggestion from this morning. If you
prefer to
> > see things really explicit within the subroutine, you could dereference
the
> > hashref and assign it to a lexically scoped hash.
> >
> > sub process_events {
> > my($criteria, $body) = @_;
> > my %crit = %$criteria;
> > print "a=$crit{'a'}\n";
> > print "b=$crit{'b'}\n";
> > print "\nbody = $body\n";
> > }
>
> That would not only make it easier to see, it would also incur the
> runtime cost of copying all the data over to a local variable. Of
> course, that same cost was paid in my initial implementation which
> started this thread.
>
True. There are tradeoffs. The benefit of the clarity is obvious. But the
real run-time cost in speed can only be determined by benchmarking it
against the real data you're going to use in your production script.
------------------------------
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 4948
***************************************