[25049] in Perl-Users-Digest
Perl-Users Digest, Issue: 7299 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 25 03:05:49 2004
Date: Mon, 25 Oct 2004 00: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 Mon, 25 Oct 2004 Volume: 10 Number: 7299
Today's topics:
Re: array parameters <jurgenex@hotmail.com>
Re: arrays of arrays question <jurgenex@hotmail.com>
Re: copying files <usa1@llenroc.ude.invalid>
FAQ 4.52: How do I sort an array by (anything)? <comdog@panix.com>
Re: FAQ 4.56: What happens if I add or remove keys from (Peter J. Acklam)
Re: foreach vs. for <jurgenex@hotmail.com>
Re: foreach vs. for (Hae Jin)
how do I call a function from a .so file in UNIX via a <sonet@msa.hinet.net>
MAIL recommendation <nospam@nospam.com>
Re: MAIL recommendation <cwilbur@mithril.chromatico.net>
measure time (hopefully in milliseconds) <takashiyyy@yahoo.com>
Re: measure time (hopefully in milliseconds) <tintin@invalid.invalid>
Re: Practical Extraction Recording Language <matthew.garrish@sympatico.ca>
Re: Practical Extraction Recording Language <uri@stemsystems.com>
Re: Practical Extraction Recording Language <uri@stemsystems.com>
Re: Practical Extraction Recording Language <tintin@invalid.invalid>
Re: Problem with useless use error message (delfuego)
Re: Problem with useless use error message <usa1@llenroc.ude.invalid>
Re: Problem with useless use error message <usa1@llenroc.ude.invalid>
Re: Problem with useless use error message (delfuego)
Re: Problem with useless use error message (delfuego)
Re: where download web application source code examples <nospam@bigpond.com>
Re: where download web application source code examples <sholden@flexal.cs.usyd.edu.au>
Re: where download web application source code examples <nospam@bigpond.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Oct 2004 01:05:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: array parameters
Message-Id: <4jYed.4181$kr4.3916@trnddc01>
Daniel Molina Wegener wrote:
> I have a trouble passing multiple array parameters in
> Perl 5. I handle parameters using @_, but I can't handle
> multiple array parameters using @_.
>
> sub mysub {
> my ($arg1, @arg2, @arg3) = @_;
> # do something with args...
> }
>
> Then I can't handle @arg2 and @arg3, because Perl 5
> does not takes @arg2 and @arg3 as one array.
Actually it does. The argument list is flattened into one single list. And
that is exactly your problem.
> Any other way
> to handle array parameters?
As described in 'perldoc perlsub' you should use references.
> Any way to pass by reference
Sure. The method described in 'perldoc perlsub' normally works great.
jue
> any parameter in subs?.
>
> Regards...
------------------------------
Date: Mon, 25 Oct 2004 01:12:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: arrays of arrays question
Message-Id: <MpYed.4182$kr4.3815@trnddc01>
daniel kaplan wrote:
> ok, i have been thru perlfaq4 (i believe four) and my manuals aren't
> helping me either, and/or it's just 3am...but need some help syntax
> wise.
> in brief, i am going through my database afetr a query.
> so what i am attempting to do, is to make an array of each array.
Granted, references are a more advanced topic an not trivial.
In this particular case you may want to look for the real manual, not the
FAQ.
- "perldoc perlreftut" is an introduction to references in Perl
- "perldoc perlref" is the actual manual (a bit harder to read than the
tutorial).
Keep in mind that strictly speaking there are no arrays of arrays (AoA) in
Perl. The values of arrays and hashes must be scalars.
Therefore AoA is a sloppy term for array of references pointing to arrays.
Once you understand this the whole concept of AoA becomes much easier.
jue
------------------------------
Date: 25 Oct 2004 02:04:56 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: copying files
Message-Id: <Xns958CE09BBACD6asu1cornelledu@132.236.56.8>
Abigail <abigail@abigail.nl> wrote in
news:slrncnofsn.3ac.abigail@alexandra.abigail.nl:
> A. Sinan Unur (usa1@llenroc.ude.invalid) wrote on MMMMLXXII September
> MCMXCIII in <URL:news:Xns958C826FE4F67asu1cornelledu@132.236.56.8>:
Is the date supposed to be wrong above? :)
> !! I think this justifies my preference for not shelling out for
> !! wholesale file operations, but using File::Copy.
> I, OTOH have issues with File::Copy, and never use it, and always
> "shell" out. (Well, I always use "system cp", but that doesn't always
> involve a shell). Issues I have with File::Copy:
[ issues snipped for brevity ]
Thanks, Abigail, for pointing those out. I must have not realized those
limitations for the two simple reasons that I don't do much copying of
files in the kind of stuff I write, and I spend most of my time on Win32.
> File::Copy offers me nothing over 'system cp' (No, I don't care for
> portability to non-POSIX systems - if you can't be POSIX, screw you).
Thanks for the advice.
Sinan.
------------------------------
Date: Mon, 25 Oct 2004 04:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.52: How do I sort an array by (anything)?
Message-Id: <clhttm$a94$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
4.52: How do I sort an array by (anything)?
Supply a comparison function to sort() (described in "sort" in
perlfunc):
@list = sort { $a <=> $b } @list;
The default sort function is cmp, string comparison, which would sort
"(1, 2, 10)" into "(1, 10, 2)". "<=>", used above, is the numerical
comparison operator.
If you have a complicated function needed to pull out the part you want
to sort on, then don't do it inside the sort function. Pull it out
first, because the sort BLOCK can be called many times for the same
element. Here's an example of how to pull out the first word after the
first number on each item, and then sort those words case-insensitively.
@idx = ();
for (@data) {
($item) = /\d+\s*(\S+)/;
push @idx, uc($item);
}
@sorted = @data[ sort { $idx[$a] cmp $idx[$b] } 0 .. $#idx ];
which could also be written this way, using a trick that's come to be
known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
If you need to sort on several fields, the following paradigm is useful.
@sorted = sort { field1($a) <=> field1($b) ||
field2($a) cmp field2($b) ||
field3($a) cmp field3($b)
} @data;
This can be conveniently combined with precalculation of keys as given
above.
See the sort article in the "Far More Than You Ever Wanted To Know"
collection in http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz for more
about this approach.
See also the question below on sorting hashes.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Mon, 25 Oct 2004 08:11:28 +0200
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: FAQ 4.56: What happens if I add or remove keys from a hash while iterating over it?
Message-Id: <hdojjpin.fsf@online.no>
PerlFAQ Server <comdog@panix.com> wrote:
> --------------------------------------------------------------------
>
> 4.56: What happens if I add or remove keys from a hash while iterating over it?
>
> Don't do that. :-)
>
> [lwall] In Perl 4, you were not allowed to modify a hash at all while
> iterating over it. In Perl 5 you can delete from it, but you still can't
> add to it, because that might cause a doubling of the hash table, in
> which half the entries get copied up to the new top half of the table,
> at which point you've totally bamboozled the iterator code. Even if the
> table doesn't double, there's no telling whether your new entry will be
> inserted before or after the current iterator position.
>
> Either treasure up your changes and make them after the iterator
> finishes or use keys to fetch all the old keys at once, and iterate over
> the list of keys.
>
> --------------------------------------------------------------------
According to the docs for delete() it is safe to delete the
key/value pair most recently returned from each().
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Mon, 25 Oct 2004 01:31:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: foreach vs. for
Message-Id: <jIYed.4183$kr4.302@trnddc01>
daniel kaplan wrote:
> and yes i have looked in the dox, but it's more of a low-level
> question
> am trying to find out if there is an essential difference between the
> way the two run that you would chose one over the other. the best
> answer i have found so far (book) was "foreach is longer to type".
You must have missed "perldoc perlsyn":
Foreach Loops
[...]
The "foreach" keyword is actually a synonym for the "for" keyword, so
you can use "foreach" for readability or "for" for brevity. [...]
jue
------------------------------
Date: Sun, 24 Oct 2004 22:39:52 -0700
From: "Austin P. So (Hae Jin)" <who@what.where>
Subject: Re: foreach vs. for
Message-Id: <cli3k5$psb$1@nntp.itservices.ubc.ca>
Sisyphus wrote:
> I mean 'for' and 'foreach' are simply synonymous, irrespective of which
> of the "two distinct meanings" you're referring to.
Hmmm...if I'm not mistaken, the real difference is in how they use memory.
Austin
------------------------------
Date: Mon, 25 Oct 2004 12:17:40 +0800
From: "news.hinet.net" <sonet@msa.hinet.net>
Subject: how do I call a function from a .so file in UNIX via a perl script?
Message-Id: <clhuq6$p1t$1@netnews.hinet.net>
Can perl script create shared object (.so) libraries in a UNIX environment??
and
how do I call a function from a .so file in UNIX via a perl script?
------------------
http://www.program.com.tw/dirModule/index
------------------------------
Date: Mon, 25 Oct 2004 00:10:54 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: MAIL recommendation
Message-Id: <1098677502.746195@nntp.acecape.com>
been doing some email programming, and "sendmail" is simple, easy, quick,
but it seems that there are other modules and am trying to find the most all
around one....
one that let's me get & make attachemtns, easily read headers, etc.
if i just jump into the first i find, i might go down the wrong path....
so i figured i would ask if anyone out there knows of which is the most
used, most raved about type
thanks ahead
------------------------------
Date: Mon, 25 Oct 2004 05:18:22 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: MAIL recommendation
Message-Id: <87ekjnmllc.fsf@mithril.chromatico.net>
>>>>> "dk" == daniel kaplan <nospam@nospam.com> writes:
dk> been doing some email programming, and "sendmail" is simple,
dk> easy, quick, but it seems that there are other modules and am
dk> trying to find the most all around one....
[...]
dk> so i figured i would ask if anyone out there knows of which is
dk> the most used, most raved about type
perldoc -q 'send mail'
Have you *still* not read the Posting Guidelines?
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Sun, 24 Oct 2004 23:39:04 -0500
From: "Takashi Yamauchi" <takashiyyy@yahoo.com>
Subject: measure time (hopefully in milliseconds)
Message-Id: <cli018$674$1@news.tamu.edu>
I am a novice perl learner. If this question is one of FAQ, please direct
me to the web site where I can get an answer.
I use $^T to measure time (e.g., the time that a person spent on reading a
text).
$^T gives me the running time in seconds. This is good. But I want to have
a more accurae measure of timing (hopefully in miliseconds, or 10 or 100
miliseconds).
Could anyone show me how to measure time in miliseconds (or better than
seconds)?
Thank you
Takashi Yamauchi
------------------------------
Date: Mon, 25 Oct 2004 19:06:11 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: measure time (hopefully in milliseconds)
Message-Id: <2u3jcdF26ndf5U1@uni-berlin.de>
"Takashi Yamauchi" <takashiyyy@yahoo.com> wrote in message
news:cli018$674$1@news.tamu.edu...
>I am a novice perl learner. If this question is one of FAQ, please direct
> me to the web site where I can get an answer.
No need to access a website. Type in
perldoc -q "measure time"
from your command prompt.
------------------------------
Date: Sun, 24 Oct 2004 23:53:15 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Practical Extraction Recording Language
Message-Id: <CM_ed.1608$rs5.227208@news20.bellglobal.com>
<el_roachmeister@yahoo.com> wrote in message
news:5d705481.0410241000.649a77e1@posting.google.com...
> "A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message
> news:<Xns958CE837A2D0asu1cornelledu@132.236.56.8>...
>> Just for laughs:
>>
>> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
>>
> As someone who has been programming in perl for several years, I found
> the site useful. It was simple and well organized and I picked up
> several new tips to add to my "arsenal". Yeah, it may not be 100%
> accurate, but perl is about getting the job done, not about splitting
> hairs.
>
Care to elaborate on what you found useful on that site?
>
> Next time you insult someone's work, why dont you post a link of your
> own tutorial? Don't have one, I didnt think so.
>
The people who post here know better than to rewrite the docs, but if you
really like links:
www.perldoc.com
Starting people off with false information and bad coding practices in the
interest of not "splitting hairs" is not justification for writing a bad
tutorial. It's harder to break a bad habit than to learn something right the
first time. Worse, someone who believes information like that is
authoritative may not discover for a long time just how uninformed they are.
Matt
------------------------------
Date: Mon, 25 Oct 2004 04:57:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Practical Extraction Recording Language
Message-Id: <x7y8hv9z26.fsf@mail.sysarch.com>
>>>>> "ASU" == A Sinan Unur <usa1@llenroc.ude.invalid> writes:
ASU> Tad McClellan <tadmc@augustmail.com> wrote in
ASU> news:slrncnnucu.fpi.tadmc@magna.augustmail.com:
>> Thanks for posting the link Sinan, it was a real hoot!
ASU> You are welcome. I had googled for something and it came up
ASU> second or third so I decided to follow the link. It took a while
ASU> for my initial reaction to subside and then I realized it might
ASU> be appreciated over here.
thanx from me too. i enjoy shredding pages like that. i do code review
for work when i can and doc review is similar. i wouldn't have the
energy to write a proper tute/book (and there are good ones out there)
but it is much easier to do critiques. this was the easiest critique i
have ever done. i was having trouble finding stuff that didn't have
blatant errors or stupidities.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 25 Oct 2004 04:59:47 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Practical Extraction Recording Language
Message-Id: <x7vfcz9yxn.fsf@mail.sysarch.com>
>>>>> "er" == el roachmeister <el_roachmeister@yahoo.com> writes:
er> As someone who has been programming in perl for several years, I found
er> the site useful. It was simple and well organized and I picked up
er> several new tips to add to my "arsenal". Yeah, it may not be 100%
er> accurate, but perl is about getting the job done, not about splitting
er> hairs.
100%?? more like it was right about 20%. the mistakes and errors and
misstatements were legion. the organization made no sense (like i said,
context was never mentioned).
er> Next time you insult someone's work, why dont you post a link of
er> your own tutorial? Don't have one, I didnt think so.
why? there are several good ones out amongst the dozens of bad ones. it
would be better to point newbies to the good ones (and ridiculing the
bad ones) rather than writing one.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 25 Oct 2004 19:29:31 +1300
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Practical Extraction Recording Language
Message-Id: <2u3ko5F26rcaaU1@uni-berlin.de>
<el_roachmeister@yahoo.com> wrote in message
news:5d705481.0410241000.649a77e1@posting.google.com...
> As someone who has been programming in perl for several years, I found
> the site useful. It was simple and well organized and I picked up
> several new tips to add to my "arsenal". Yeah, it may not be 100%
> accurate, but perl is about getting the job done, not about splitting
> hairs.
Virtually all programming languages are precise in their syntax. You just
can't use random stuff and expect it to work.
What happens when a novice Perl programmer comes along a read a tutorial
that's full of errors, misinformation and misleading statements. That's
hardly going to enable them to "gettting the job done".
------------------------------
Date: 24 Oct 2004 19:00:14 -0700
From: djcameron60616@yahoo.com (delfuego)
Subject: Re: Problem with useless use error message
Message-Id: <6b28e43f.0410241800.2aaf14d2@posting.google.com>
"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message news:<Xns958C982C1C1F7asu1cornelledu@132.236.56.8>...
> djcameron60616@yahoo.com (delfuego) wrote in
> news:6b28e43f.0410241021.3ba24178@posting.google.com:
>
> > Hello,
> >
> > I am trying to write a simple Perl program to do the following:
> > Open /etc/passwd for read, create an output file in cwd for append,
> > cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
> > the output file password, then close the two file handles for the
> > input and output files.
> >
> > Here is the code:
> >
> > #!/usr/bin/perl -w
>
> use strict;
> use warnings;
>
> If you haven't done so already, please read the posting guidelines posted
> here regularly.
>
> > my $FIN;
> > my $FOUT;
>
> > open ($FIN, "</etc/passwd") or die "Cannot open input file.\n";
> > open ($FOUT, ">>password") or die "Cannot open output file.\n";
>
> I recommend using the 3 argument form of open. You also don't need to
> declare $FIN and $FOUT separately. Finally, it is useful to report the
> actual reason open failed:
>
> open my $FIN, '<', '/etc/passwd'
> or die "Cannot open '/etc/passwd': $!";
>
> open my $FOUT, '>>', 'password'
> or die "Cannot open 'password': $!";
>
> > while ($myline = <$FIN>) {
>
> while(my $myline = <$FIN>) {
>
> OK, so you have read a line from $FIN.
>
> > readline($FIN);
>
> Now, you read another line and discard it.
>
> > $myline=$printable;
>
> But this is the best. You now replace the contents of the line you had
> earlier managed to read and store in $myline with the contents of
> $printable. However, $printable is undef at this point. If you had used
> strict, you would have caught this error.
>
> > print($FOUT,$printable,"\n");
>
> Now that you have nuked $myline you attempt to output $printable to $FOUT.
> You might want to check
>
> perldoc -f print
>
> because this will never output aything to $FOUT.
>
> > i $myline = chop($myline = `cut -d: -f1,3-4,6`);
>
> Ahem, what is that 'i' up there. Oh, I see, you did not actually post the
> code you ran on your system. Don't do that.
>
> So, now you are over-writing the line you had stored in $myline with the
> return value of the chop call. Do you know what chop returns? I have a
> feeling you don't. You can look it up:
>
> perldoc -f chop
>
>
> > [root@localhost james]# ./program.pl
> > Use of uninitialized value in print at ./program.pl line 12, <$FIN>
> > line 2.
> > GLOB(0x804ca88)
>
> perl has just told you everything I said above.
>
> > [root@localhost james]#
>
> Are you sure you want to mess with your system's crucial files while you
> are logged in as root?
>
> > Thank you for your help.
>
> You are welcome.
>
> Sinan.
Hi Sinan,
Thanks again for the response, as embarrassing as it may have been to
me. But I apparently seem to be a glutton for punishment. After some
cleanup (the i was supposed to be a #) and reso (according to your
suggestions), here is the code, errors (new this time requiring
packages) and whatnot:
[root@localhost james]# ./program.pl
Global symbol "$printable" requires explicit package name at
./program.pl line 1
1.
Global symbol "$printable" requires explicit package name at
./program.pl line 1
2.
Execution of ./program.pl aborted due to compilation errors.
[root@localhost james]# cat program.pl
#!/usr/bin/perl -w
use strict;
use warnings;
#
open my $FIN, '<', '/etc/passwd'
or die "Cannot open '/etc/passwd': $!";
open my $FOUT, '>>', 'password'
or die "Cannot open 'password': $!";
#
while (my $myline = <$FIN>) {
$printable = chop ($myline = `cut -d: -f1,3-4,6`);
print($FOUT, $printable, "\n");
}
#
close ($FIN);
close ($FOUT);
#
[root@localhost james]#
Thanks again --
James
------------------------------
Date: 25 Oct 2004 02:16:35 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Problem with useless use error message
Message-Id: <Xns958CE2954328Easu1cornelledu@132.236.56.8>
djcameron60616@yahoo.com (delfuego) wrote in
news:6b28e43f.0410241800.2aaf14d2@posting.google.com:
[ snipped previous exchange for brevity ]
> Hi Sinan,
>
> Thanks again for the response, as embarrassing as it may have been to
> me. But I apparently seem to be a glutton for punishment.
I don't think of this as punishment.
> After some cleanup (the i was supposed to be a #)
Yeah, you have too many of those '#' symbols all over the place. If there
is a good reason to do that, fine, but I find them distracting.
> and reso (according to your suggestions),
reso?
> here is the code, errors (new this time requiring packages)
> and whatnot:
No, it is not requiring packages. See below.
> [root@localhost james]# ./program.pl
> Global symbol "$printable" requires explicit package name at
> ./program.pl line 1
> 1.
> Global symbol "$printable" requires explicit package name at
> ./program.pl line 1
> 2.
> Execution of ./program.pl aborted due to compilation errors.
Really, don't mess with your system files while you are logged in as root.
> [root@localhost james]# cat program.pl
> #!/usr/bin/perl -w
No need for -w now that you are using warnings.
> use strict;
> use warnings;
> open my $FIN, '<', '/etc/passwd'
> or die "Cannot open '/etc/passwd': $!";
> open my $FOUT, '>>', 'password'
> or die "Cannot open 'password': $!";
> while (my $myline = <$FIN>) {
> $printable = chop ($myline = `cut -d: -f1,3-4,6`);
You haven't checked the return value of chop, yet, have you? It is not what
you think it is:
perldoc -f chop
$printable is not declared anywhere and you are running under strict. You
need to declare your variables before using them under strict (so that
variables don't magically come to life when you misspell the name of a real
variable).
The declaration is normally made at the point the variable is first used,
that is:
my $printable = chop ($myline = `cut -d: -f1,3-4,6`);
But I don't think you really want to do that (hint: look up what chop
returns).
> print($FOUT, $printable, "\n");
> }
As I mentioned, you need to also look up the syntax for print:
perldoc -f print
> close ($FIN);
> close ($FOUT);
As for
($myline = `cut -d: -f1,3-4,6`);
I don't know what you think that line is doing.
See also Tad's response.
Sinan.
------------------------------
Date: 25 Oct 2004 02:18:37 GMT
From: "A. Sinan Unur" <usa1@llenroc.ude.invalid>
Subject: Re: Problem with useless use error message
Message-Id: <Xns958CE2ED373D7asu1cornelledu@132.236.56.8>
"A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in
news:Xns958CE2954328Easu1cornelledu@132.236.56.8:
>> and reso (according to your suggestions),
>
> reso?
Argh! You must have meant 'redo', right. Please ignore that comment.
Sinan.
------------------------------
Date: 24 Oct 2004 23:17:23 -0700
From: djcameron60616@yahoo.com (delfuego)
Subject: Re: Problem with useless use error message
Message-Id: <6b28e43f.0410242217.3fdb0d60@posting.google.com>
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncnodsa.g1i.tadmc@magna.augustmail.com>...
> delfuego <djcameron60616@yahoo.com> wrote:
>
> > I am trying to write a simple Perl program to do the following:
> > Open /etc/passwd for read, create an output file in cwd for append,
> > cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
> > the output file password, then close the two file handles for the
> > input and output files.
>
>
> Here is a complete Perl program that does that:
>
> perl -lne 'print join ":", (split /:/)[0,2,3,5]' /etc/passwd >>password
>
>
> > [root@localhost james]# ./program.pl
>
>
> Yikes!
>
> You shouldn't do things as root unless the thing *requires* that
> you be root.
>
> You do not need to be root to do what you describe above, so don't
> be root when you are doing the above.
Thanks guys for the answers .. yes, reso was supposed to be redo, and
I did back up the system file before working on this program. I will
look up the perl docs for the commands I was trying to use as well,
not that I was trying to incurr your wrath(s), but it was frustrating
that I know I could do the same intent in just a bash script, in
Pascal or C as well .. but it was an exercise simple enough in theory
-- declare/open file handles, set the mode and declare the actual
files for I/O; loop while next line in file is not null, read a line
and format the output, write that output; and close the files.
Anyway, I will try your suggestions guys, thanks again.
*grin*
That grin was just that this is supposed to be an exercise for me to
learn basic file handling of Perl .. I have bigger and better projects
I want to work on that will require this basic knowledge.
Thanks -- James
------------------------------
Date: 24 Oct 2004 23:25:43 -0700
From: djcameron60616@yahoo.com (delfuego)
Subject: Re: Problem with useless use error message
Message-Id: <6b28e43f.0410242225.47d226f2@posting.google.com>
Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrncnodsa.g1i.tadmc@magna.augustmail.com>...
> delfuego <djcameron60616@yahoo.com> wrote:
>
> > I am trying to write a simple Perl program to do the following:
> > Open /etc/passwd for read, create an output file in cwd for append,
> > cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
> > the output file password, then close the two file handles for the
> > input and output files.
>
>
> Here is a complete Perl program that does that:
>
> perl -lne 'print join ":", (split /:/)[0,2,3,5]' /etc/passwd >>password
>
>
> > [root@localhost james]# ./program.pl
>
>
> Yikes!
>
> You shouldn't do things as root unless the thing *requires* that
> you be root.
>
> You do not need to be root to do what you describe above, so don't
> be root when you are doing the above.
Tad -- thanks! It worked.
I still need to learn a lot more Perl and scour your brain as well as
Sinan's in the futuer for answers probably.
Thanks again -- James
------------------------------
Date: Mon, 25 Oct 2004 15:45:45 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: where download web application source code examples ?
Message-Id: <2u3i8cF253oinU1@uni-berlin.de>
Jasper wrote:
> Hi building an ecommerce website here, is there anywhere on the web
> one can download the perl source for a basic one ? Its probably a
> search problem but I cant find any..
>
> thanks !
>
> Jasper
Most are in php but you can try
http://www.google.com/search?ie=UTF8&q=perl%20shopping%20cart
I'm writing a shopping cart of my own at the moment, & you get lots of
flexibility with Perl. For example, I've got a C program that prints the
html headers/logo/sidebar menu to stdout in about 1 msec (I want a speedy
site like www.eyo.com.au ), and them Perl generates the rest of the html.
While this may be possible with php, its easy & logical in Perl.
gtoomey
------------------------------
Date: 25 Oct 2004 05:54:34 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: where download web application source code examples ?
Message-Id: <slrncnp58q.m9s.sholden@flexal.cs.usyd.edu.au>
On Mon, 25 Oct 2004 15:45:45 +1000, Gregory Toomey <nospam@bigpond.com> wrote:
> Jasper wrote:
>
>> Hi building an ecommerce website here, is there anywhere on the web
>> one can download the perl source for a basic one ? Its probably a
>> search problem but I cant find any..
>>
>> thanks !
>>
>> Jasper
>
> Most are in php but you can try
> http://www.google.com/search?ie=UTF8&q=perl%20shopping%20cart
>
> I'm writing a shopping cart of my own at the moment, & you get lots of
> flexibility with Perl. For example, I've got a C program that prints the
> html headers/logo/sidebar menu to stdout in about 1 msec (I want a speedy
> site like www.eyo.com.au ), and them Perl generates the rest of the html.
> While this may be possible with php, its easy & logical in Perl.
And the time taken to fork a process doesn't swamp any speed
benefit the C program might bring?
--
Sam Holden
------------------------------
Date: Mon, 25 Oct 2004 16:35:16 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: where download web application source code examples ?
Message-Id: <2u3l5bF23e2dpU1@uni-berlin.de>
Sam Holden wrote:
> On Mon, 25 Oct 2004 15:45:45 +1000, Gregory Toomey <nospam@bigpond.com>
> wrote:
>> Jasper wrote:
>>
>>> Hi building an ecommerce website here, is there anywhere on the web
>>> one can download the perl source for a basic one ? Its probably a
>>> search problem but I cant find any..
>>>
>>> thanks !
>>>
>>> Jasper
>>
>> Most are in php but you can try
>> http://www.google.com/search?ie=UTF8&q=perl%20shopping%20cart
>>
>> I'm writing a shopping cart of my own at the moment, & you get lots of
>> flexibility with Perl. For example, I've got a C program that prints the
>> html headers/logo/sidebar menu to stdout in about 1 msec (I want a speedy
>> site like www.eyo.com.au ), and them Perl generates the rest of the html.
>> While this may be possible with php, its easy & logical in Perl.
>
> And the time taken to fork a process doesn't swamp any speed
> benefit the C program might bring?
>
- The Perl part takes around 160 msec (140 msec for compilation, 20 msec
writing to stdout) & includes html whitespace removal
- fork on modern Linux/unix is < 1 msec
- logon to mysql from C is 3 msec, though I dont do that (yet).
- the C program is optimised (-O2 in gcc) & staticly linked
- Also some versions of Apache insist on generating a "Content Length" in
the header (eg Apache in Redhat 9) which means they run the cgi & buffer
stdout, calculate the content length, then send everything back to the
browser. Recent versions of Apache send content back to the browser as soon
as the cgi generates to stdout.
This whole process is designed to start sending content back to the browser
a few milliseconds after it hits the server.
I've written about related issues at:
http://gregorytoomey.com/index.php?option=content&task=view&id=2&Itemid=2
gtoomey
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7299
***************************************