[22061] in Perl-Users-Digest
Perl-Users Digest, Issue: 4283 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 18 18:05:52 2002
Date: Wed, 18 Dec 2002 15:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 18 Dec 2002 Volume: 10 Number: 4283
Today's topics:
Arguing about the advantage of Perl <pierre.rolin@soredi-group.com>
Re: Arguing about the advantage of Perl <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Arguing about the advantage of Perl <noone@nowhere.com>
Re: comment on 2 or 4 spaces indentation <camerond@mail.uca.edu>
Date Difference <christopher.naugle@fmr.com>
Re: FTPing without Net::FTP (krakle)
Re: FTPing without Net::FTP <uri@stemsystems.com>
Is this a bug? (5.6.1 and 5.005.04) <ndronen@io.frii.com>
Re: Is this a bug? (5.6.1 and 5.005.04) <joe+usenet@sunstarsys.com>
List of perl error numbers?? <bhoppe@ti.com>
Re: List of perl error numbers?? <rgarciasuarez@free.fr>
perl regexp to extract table out of HTML <nospam@spamfrustrator.invalid.tla>
Re: perl regexp to extract table out of HTML (Tad McClellan)
Re: PerlCE on PocketPC (brian)
Re: RESIZE IMAGES PERL MODULES? <bart.lateur@pandora.be>
Strange behaviour with windows task scheduler <s.patterson@freeuk.com>
Tracking User's OS type? <johnthompson1@hotmail.com>
Re: Tracking User's OS type? <s.patterson@freeuk.com>
Re: Tracking User's OS type? <johnthompson1@hotmail.com>
Re: Tracking User's OS type? <flavell@mail.cern.ch>
Re: Tracking User's OS type? (Tad McClellan)
Re: What means sh: ^P: not found (Walter Roberson)
Re: What means sh: ^P: not found <krahnj@acm.org>
Re: Why do beginners read files into an array? <me@privacy.net>
Re: Why do beginners read files into an array? <me@privacy.net>
Re: Why do beginners read files into an array? <me@privacy.net>
Re: Why do beginners read files into an array? <me@privacy.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Dec 2002 21:19:29 +0100
From: "news.dial.oleane.com" <pierre.rolin@soredi-group.com>
Subject: Arguing about the advantage of Perl
Message-Id: <atqldj$9ld$1@s1.read.news.oleane.net>
As i must convert programs from JCL
I have to argue about the avantage of using PERL instead of vb scripts.
could anyone help me on that way.
thanks a lot.
Yours
Pierre
------------------------------
Date: Wed, 18 Dec 2002 22:08:04 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Arguing about the advantage of Perl
Message-Id: <newscache$gp2c7h$crl$1@news.emea.compuware.com>
news.dial.oleane.com wrote:
> As i must convert programs from JCL
> I have to argue about the avantage of using PERL instead of vb scripts.
>
> could anyone help me on that way.
> thanks a lot.
That would be unappopriate. Depending on the requirements either one could
be more fit. If *you* are the one to convert the scripts, then *you* of all
people are best in determining which and why is the best.
"Go figure..." (pun intended)
--
KP
------------------------------
Date: Wed, 18 Dec 2002 21:38:28 GMT
From: "gibbering poster" <noone@nowhere.com>
Subject: Re: Arguing about the advantage of Perl
Message-Id: <oV5M9.730$Gb5.71712878@newssvr14.news.prodigy.com>
"news.dial.oleane.com" <pierre.rolin@soredi-group.com> wrote in message
news:atqldj$9ld$1@s1.read.news.oleane.net...
> As i must convert programs from JCL
> I have to argue about the avantage of using PERL instead of vb scripts.
>
Without knowing anything else about your environment and circumstances, it's hard
to say... here are a couple advantages of perl over VB:
1) Portability and platform independance
2) Speed and efficiency
------------------------------
Date: Wed, 18 Dec 2002 14:10:02 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: comment on 2 or 4 spaces indentation
Message-Id: <3E00D61A.9090506@mail.uca.edu>
Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<arlgj2$t4d$1@korweta.task.gda.pl>...
>
>In article <3DDE42CB.415D34CD@saicmodis.com>, Gary Fu wrote:
>
>>Hi,
>>
>>My colleague uses emacs and had hard time to modify Perl program with 2 spaces
>>indentation. He told me that 4 spaces indentation is standard for Perl and the
>>
>
>In that case your colleague is an idiot. You can quote me on that.
>
>
>
>>tab in
>>emacs will do that automatically. However, I'm a vi user, don't use tab (may be
>>expanded
>>to different number of spaces on different editors), prefer with 2 spaces
>>indentation
>>(to save stroke and line spaces).
>>Any comment why 4 spaces indentation is standard or better than 2 spaces for
>>Perl ?
>>
>
>There is no such standard.
From perlstyle (copied from ActivePerl 5.6 HTML docs):
"Regarding aesthetics of code lay out, about the only thing Larry cares
strongly about is that the closing curly bracket of a multi-line BLOCK
should line up with the keyword that started the construct. Beyond that,
he has other preferences that aren't so strong:
* 4-column indent.
*[other stuff listed here]"
So, maybe there isn't anything carved in stone, but, paraphrasing the
old saw, "When Larry ain't happy, ain't NOBODY happy." So 4 became the
de facto standard.
Cameron
--
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu
------------------------------
Date: Wed, 18 Dec 2002 16:44:03 -0500
From: "Chris" <christopher.naugle@fmr.com>
Subject: Date Difference
Message-Id: <rV5M9.115$O3.18@news-srv1.fmr.com>
Hi,
I was wondering if someone could help me. I'm somewhat new to Perl
and am having a small coding problem.
I have this program that I'm writing. One of the things that it needs to
do
is take a string that represents a date in the format "YYYYMMDD" and
figure out if this date is N number of days old where N is some arbitrary
number.
I know that there are a bunch of date modules for working with dates
but the ones I've come across seemed overly complicated for what
I need to do and lacked clear code examples. I was hoping someone
might be able to post a small code snippet as I would think this problem
is very common.
Any help at all would be really appreciated. Thanks.
Chris
------------------------------
Date: 18 Dec 2002 13:34:41 -0800
From: krakle@visto.com (krakle)
Subject: Re: FTPing without Net::FTP
Message-Id: <237aaff8.0212181334.796a9de3@posting.google.com>
"Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message news:<atq65p$pmq$1@pheidippides.axion.bt.co.uk>...
> I wonder why it is that on this newsgroup, when someone asks a question to
> solve a particular problem they have, and someone else gives them a possible
> solution, there are always a couple of "regulars" who pedantically state
> that this is not the correct way of doing it in Perl and is therefore WRONG.
Must expect this from a newsgroup full of dorks. I once posted a
rather simple question pertaining to using mySQL with Perl and was
told it wasn't a perl question even though it would make no sense to
ask a Perl coding question in a mySQL group.
I was also once told that this isn't the place to ask questions. Last
I checked 97% of these postings have questions.
> In this case, the original poster was writing a perl script that does a
> rather simple task, and wanted to know how to do an FTP transfer without
> using the Net::FTP module.
Like I said this newsgroup is full of morons. He asked how to do a FTP
task WITH OUT Net::Ftp and the majority of answers were "Install Net
ftp".
------------------------------
Date: Wed, 18 Dec 2002 21:43:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FTPing without Net::FTP
Message-Id: <x7r8cfq9z0.fsf@mail.sysarch.com>
>>>>> "k" == krakle <krakle@visto.com> writes:
k> "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk> wrote in message news:<atq65p$pmq$1@pheidippides.axion.bt.co.uk>...
>> I wonder why it is that on this newsgroup, when someone asks a
>> question to solve a particular problem they have, and someone else
>> gives them a possible solution, there are always a couple of
>> "regulars" who pedantically state that this is not the correct way
>> of doing it in Perl and is therefore WRONG.
because it has been solved correctly already and it is a difficult
problem. ever wonder WHY there are all those modules on CPAN? they are
SOLUTIONS to known, common and in many cases HARD problems. do you know
how to code ALL of cpan on your own and quickly? if so, then you should
answer all such questions here with your superb, fast, tested and well
documented code. until then expect such good answers.
k> Must expect this from a newsgroup full of dorks. I once posted a
k> rather simple question pertaining to using mySQL with Perl and was
k> told it wasn't a perl question even though it would make no sense
k> to ask a Perl coding question in a mySQL group.
are you including yourself? i would hope so.
k> Like I said this newsgroup is full of morons. He asked how to do a FTP
k> task WITH OUT Net::Ftp and the majority of answers were "Install Net
k> ftp".
the OP can install a module if he wants to without admin help. and ftp
is not a trivial protocol to work with directly. do you expect someone
of his (or your) skill to do so?
you and moronzilla should write your own ftp module. now go away as you
obviously know nothing about the ftp protocol or about code reuse. try
reading an rfc or two and watch your pea-sized brain explode. oops, i
don't expect you to know what rfc's are or where to find them.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 18 Dec 2002 22:04:33 GMT
From: Nicholas Dronen <ndronen@io.frii.com>
Subject: Is this a bug? (5.6.1 and 5.005.04)
Message-Id: <3e00f0f1$0$16014$75868355@news.frii.net>
Hi:
Before I begin I should note that this program has
been eviscerated in order to narrow down the problem,
so some of the code is contrived -- opening a pipe from
cut, for example.
Here we go.
I'm using 5.6.1 and 5.005.04 on AIX 4.3.3 (bos.mp and
bos.rte.libc 4.3.3.84, in case you're wondering) and
this program:
1 #!/home/ndronen/arch/ibm/bin/perl -w
2
3 use strict;
4 use Destroyer;
5
6 my $destroyer = new Destroyer();
7
8 $destroyer->load_running_users() or die;
dies with:
Died at Destroyer.pm line 32, <LLQ> line 1545.
unless I comment out lines 16, 17, 19 and 20 in the
Destroyer module. That is, removing the for(scalar)
switch-like statement and simply invoking line 18
doesn't result in $self->{os} becoming undefined (!)
after the closing brace of the while loop beginning
on line 29.
1 package Destroyer;
2
3 use strict;
4
5 sub new {
6 my $class = shift;
7 my $self = {};
8 $self->{os} = "AIX";
9 bless($self, $class);
10 return $self;
11 }
12
13 sub load_running_users {
14 my $self = shift;
15
16 for ($self->{os}) {
17 /AIX/i && do {
18 return $self->load_running_users_aix;
19 };
20 }
21 }
22
23 sub load_running_users_aix {
24 my $self = shift;
25
26 open(LLQ, "cut -d: -f1 /etc/passwd |") or die;
27
28 die unless defined $self->{os};
29 while (<LLQ>) {
30 die unless defined $self->{os};
31 }
32 die unless defined $self->{os};
33
34 close(LLQ);
35 }
36
37 1;
If I rearrange lines 32-34 to:
32 close(LLQ) or die $!;
33
34 die unless defined $self->{os};
it dies on line 34, which leads me to believe that the
child process is still alive, meaning in turn that
it's unlikely any signal handlers have been invoked
in the parent perl, which event can easily corrupt
a program.
Anyway, am I missing something howlingly obvious?
I just tried the program with 5.005_03. The behavior
is the same.
Regards,
Nicholas
------------------------------
Date: 18 Dec 2002 17:19:20 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Is this a bug? (5.6.1 and 5.005.04)
Message-Id: <m3k7i7nf6f.fsf@mumonkan.sunstarsys.com>
Nicholas Dronen <ndronen@io.frii.com> writes:
[...]
> 16 for ($self->{os}) {
[...]
> 29 while (<LLQ>) {
while() does not auto-localize $_. Since your
for() loop binds $_ to $self->{os}, you're
actually assigning each line of LLQ to $self->{os}.
Once you've exhausted the file, the while() loop
exits, with $self->{os} now undefined. Your
program dies soon afterwards.
HTH
--
Joe Schaefer "The only thing that interferes with my learning is my
education."
--Albert Einstein
------------------------------
Date: Wed, 18 Dec 2002 14:49:59 -0600
From: Brandon Hoppe <bhoppe@ti.com>
Subject: List of perl error numbers??
Message-Id: <atqn1o$93r$1@tilde.itg.ti.com>
What are all the possible error numbers and error codes returned by perl? Is
there a list of them all?
------------------------------
Date: 18 Dec 2002 21:19:00 GMT
From: Rafael Garcia-Suarez <rgarciasuarez@free.fr>
Subject: Re: List of perl error numbers??
Message-Id: <slrnb01pmd.qs.rgarciasuarez@dat.local>
Brandon Hoppe wrote in comp.lang.perl.misc :
>
> What are all the possible error numbers and error codes returned by perl? Is
> there a list of them all?
You mean the error status returned by the exit(3) call ?
They're undocumented, unsupported, subject to change and to vary among
OSes. Don't rely on them. If you want to force and exit(3) value, use
the exit() function.
------------------------------
Date: Wed, 18 Dec 2002 20:12:11 +0000
From: Dave Pimlott <nospam@spamfrustrator.invalid.tla>
Subject: perl regexp to extract table out of HTML
Message-Id: <atqkqq$q44$1$8302bc10@news.demon.co.uk>
Hi,
if you can help me sort out this problem I would appreciate it. I am no
perl/regexp guru and so far I have managed to spend a day reading docs
and trying things without sucess
I have a HTML page with 4 tables in it (amongst other things), I want to
extract the HTML code for the first table only.
For example the page might render the page as follows just as an example...:
CPU 0 Alpha EV4033
what I want is to copy from the first <TABLE> tag to the first </TABLE>
tag (inclusive of regexp matches) to another file. So far I have
managed to get this far (without success I might add). For reference
I'm using an old version of perl 5 IIRC.
perl -0777 -pe 'print "$1\n" while /(\<TABLE.*?\<\/TABLE\>)/s'
somefile.htm > myOutputFile
Any pointers for me to get this to work?
TIA.
Dave Pimlott.
------------------------------
Date: Wed, 18 Dec 2002 16:05:43 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl regexp to extract table out of HTML
Message-Id: <slrnb01s9n.3d6.tadmc@magna.augustmail.com>
Dave Pimlott <nospam@spamfrustrator.invalid.tla> wrote:
> if you can help me sort out this problem I would appreciate it. I am no
> perl/regexp guru and so far I have managed to spend a day reading docs
> and trying things without sucess
So you realize that using a regex to "parse" HTML is Not So Good then?
Once you get a regex that "works", try it with this:
<TABLE>
table one data
<!--
what the heck is a </TABLE> doing in this comment?
-->
</TABLE>
If you need your code to be robust, then use a module that
understand HTML for processing HTML.
> I have a HTML page with 4 tables in it (amongst other things), I want to
> extract the HTML code for the first table only.
> perl -0777 -pe 'print "$1\n" while /(\<TABLE.*?\<\/TABLE\>)/s'
> somefile.htm > myOutputFile
>
> Any pointers for me to get this to work?
You are print()ing *twice*, use -n instead of -p.
You have a while but no m//g, so it is going to loop for
a "long time" if the match succeeds once. :-)
Angle brackets are not special in regexes, no need to backslash them.
If you use an alternate delimiter for your m// then you
won't need to backslash the slash either.
perl -0777 -ne 'print "$1\n" if m#(<TABLE.*?</TABLE>)#s'
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Dec 2002 13:25:35 -0800
From: briantac@hotmail.com (brian)
Subject: Re: PerlCE on PocketPC
Message-Id: <6b52e5a7.0212181325.49fa91b6@posting.google.com>
here is the link to the registry editor, it was omitted in my post above.
http://www.phm.lu/products/PocketPC/devmgmt.asp
------------------------------
Date: Wed, 18 Dec 2002 19:05:20 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: RESIZE IMAGES PERL MODULES?
Message-Id: <olh10vckkcgbud0kkjahd6ggohjhipvkga@4ax.com>
Jim Melanson wrote:
>--
...
>"Do be do be do" - Sinatra
Blimey: a 40 line signature! Wouldn't you think that's a bit much?
--
Bart.
------------------------------
Date: 18 Dec 2002 20:57:38 GMT
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Strange behaviour with windows task scheduler
Message-Id: <slrnb01olf.pi.s.patterson@bloodnok.localdomain>
I have a couple of scripts which are invoked by the task scheduler on
windows 2000, and which occasionally fail to run for no apparent reason
(i.e. it works fine if I run it myself).
I've adjusted the scripts to create log files, from which I can tell that
when the scripts fail, the task scheduler is not executing them.
Any ideas? The scripts are on a network drive, could this be affecting
things?
--
Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
steve@SPAM.lexx.uklinux.net remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Last one down the pub's an MCSE
------------------------------
Date: Wed, 18 Dec 2002 14:28:18 -0500
From: "John" <johnthompson1@hotmail.com>
Subject: Tracking User's OS type?
Message-Id: <3e00cc4b$1@news.xetron.com>
Hello,
I recently created a website and I am able to do the following:
Track IP Address, browser, etc.
However, I can't seem to find how to track what OS the user is using. Is
there a simple line of perl code that will accomplish this?
Thank you,
John
------------------------------
Date: 18 Dec 2002 20:38:22 GMT
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: Tracking User's OS type?
Message-Id: <slrnb01nha.pi.s.patterson@bloodnok.localdomain>
On Wed, 18 Dec 2002 14:28:18 -0500, John wrote:
> Hello,
>
> I recently created a website and I am able to do the following:
>
> Track IP Address, browser, etc.
>
> However, I can't seem to find how to track what OS the user is using. Is
> there a simple line of perl code that will accomplish this?
There's $ENV{HTTP_USER_AGENT} which (for linux, galeon) at least holds the
browser type and operating system among other things.
--
Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
steve@SPAM.lexx.uklinux.net remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Last one down the pub's an MCSE
------------------------------
Date: Wed, 18 Dec 2002 15:42:08 -0500
From: "John" <johnthompson1@hotmail.com>
Subject: Re: Tracking User's OS type?
Message-Id: <3e00dd98$1@news.xetron.com>
"Stephen Patterson" <s.patterson@freeuk.com> wrote in message
news:slrnb01nha.pi.s.patterson@bloodnok.localdomain...
> On Wed, 18 Dec 2002 14:28:18 -0500, John wrote:
> > Hello,
> >
> > I recently created a website and I am able to do the following:
> >
> > Track IP Address, browser, etc.
> >
> > However, I can't seem to find how to track what OS the user is using.
Is
> > there a simple line of perl code that will accomplish this?
>
> There's $ENV{HTTP_USER_AGENT} which (for linux, galeon) at least holds the
> browser type and operating system among other things.
It's times like these when I feel stupid. Thank you Steve.
>
>
> --
> Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
> steve@SPAM.lexx.uklinux.net remove SPAM to reply
> Linux Counter No: 142831 GPG Public key: 252B8B37
> Last one down the pub's an MCSE
------------------------------
Date: Wed, 18 Dec 2002 22:26:27 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Tracking User's OS type?
Message-Id: <Pine.LNX.4.40.0212182213270.31478-100000@lxplus065.cern.ch>
On Dec 18, Stephen Patterson inscribed on the eternal scroll:
> There's $ENV{HTTP_USER_AGENT} which (for linux, galeon) at least holds the
> browser type and operating system among other things.
They could hold whatever the user configured their client agent to
send. The HTTP/1.1 spec suggests a format, but it's only advisory.
I.e they are trivial to manipulate, if one has a mind to do so.
So don't take them _too_ earnestly. A check of our server log shows
for example occasional visits by
Mozilla/6.5a1 (compatible; NoYdb v.42; NextOS)
I've also seen "Nutscrape" and "Notzilla"...
and http://www.akintermedia.co.nz/seo/other-user-agents.htm lists
some creative examples too:
Nintendo64/1.0 (SuperMarioOS with Cray-II Y-MP Emulation)
Notepad ENHANCED/0.041 [MS] (Win00;S; Bloatware)
and finally
You-Do-Neither-Want-Nor-Need-To-Know-This-In-Order-To-Send-Out-Some-Stupid-Web-Pages/12345678901234567891234567890.1234567890
[en]
(OkayNowLetsSeeHowLongICanMakeThisStringSoThatYourStupidLittleScriptThatShouldNotLookAtThisHeaderFieldAnywayDiesBecauseSomeb
So take care with your parsing! (that's the only Perl-topic part of
this posting, really)
------------------------------
Date: Wed, 18 Dec 2002 16:10:19 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tracking User's OS type?
Message-Id: <slrnb01sib.3d6.tadmc@magna.augustmail.com>
John <johnthompson1@hotmail.com> wrote:
> "Stephen Patterson" <s.patterson@freeuk.com> wrote in message
> news:slrnb01nha.pi.s.patterson@bloodnok.localdomain...
>> On Wed, 18 Dec 2002 14:28:18 -0500, John wrote:
>> > However, I can't seem to find how to track what OS the user is using.
You could ask them...
>> There's $ENV{HTTP_USER_AGENT} which (for linux, galeon) at least holds the
>> browser type and operating system among other things.
>
> It's times like these when I feel stupid. Thank you Steve.
It is ridiculously easy to spoof that.
ie. It is unwise to rely on that.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 18 Dec 2002 19:19:15 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: What means sh: ^P: not found
Message-Id: <atqhnj$32g$1@canopus.cc.umanitoba.ca>
In article <3E00C661.8010705@consultant.com>,
Alexander Stremitzer <stremitz@consultant.com> wrote:
:system ("\\\cp ./xxx1 ./yyy1") == 0 || die ("Can not copy xxx1 to yyy1\n");
:sh: ^P: not found
In a quoted string, \c followed by a letter stands for taking the
"control" of the following letter.
Remove one of those 3 \'s and you should be okay.
--
Beware of bugs in the above code; I have only proved it correct,
not tried it. -- Donald Knuth
------------------------------
Date: Wed, 18 Dec 2002 22:03:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: What means sh: ^P: not found
Message-Id: <3E00F051.4BFB4FD9@acm.org>
Alexander Stremitzer wrote:
>
> I am trying to copy a file from one location to another utilizing the
> non aliased version of Solaris cp.
>
> When doing the command in the shell itself, it works.
> $ \cp xxx1 yyy1
>
> When doing it through system in Perl, it fails. Does anybody know what
> goes on here ?
>
> I know I could replace "\\\cp ./xxx1 ./yyy1" with "unalias cp; cp ./xxx1
> ./yyy1" and make it work. But I am curious what is wrong here.
>
> Thanks for your help,
> Alex
>
> pds:/db0_d/_alex/hup/pmc> cat yyy
> #!/usr/local/bin/perl
>
> use diagnostics;
>
> system ("\\\cp ./xxx1 ./yyy1") == 0 || die ("Can not copy xxx1 to yyy1\n");
> pds:/db0_d/_alex/hup/pmc> yyy
> sh: ^P: not found
> Uncaught exception from user code:
> Can not copy xxx1 to yyy1
Use the File::Copy module:
use File::Copy;
copy( 'xxx1', 'yyy1' ) or die "Can not copy xxx1 to yyy1: $!\n"
Or use system() with a list so that the shell isn't involved:
system( 'cp', './xxx1', './yyy1' ) == 0 or die "Can not copy xxx1 to
yyy1: $?\n";
Or use the absolute path to cp:
system( '/bin/cp ./xxx1 ./yyy1' ) == 0 or die "Can not copy xxx1 to
yyy1: $?\n";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 19 Dec 2002 08:29:28 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Why do beginners read files into an array?
Message-Id: <atqpbq$1tkm9$1@ID-172104.news.dfncis.de>
"Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote in message
news:newscache$rpdb7h$2nl$1@news.emea.compuware.com...
> Tintin wrote:
>
> > Can anyone come up with a plausible reason why so many beginners write
> > code like:
> >
> > open FILE, "data.txt";
> > @var=<FILE>;
> > close FILE;
> >
> > foreach $line (@var) {
> > print $line;
> > }
> >
> > Where does this logic come from?
> >
> > The only reason I can come up with is that the newbies are learning from
> > bad examples.
>
>
> Keeping open links to system files as minimal or as short as possible
> (NFS!), does not seem silly to me.
That might be so, but would only be the case in a *very* small percentage of
usage.
------------------------------
Date: Thu, 19 Dec 2002 08:34:52 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Why do beginners read files into an array?
Message-Id: <atqpuo$1su85$1@ID-172104.news.dfncis.de>
"Jim Melanson" <jim@jimmelanson.ca> wrote in message
news:DQ_L9.11718$i%.2235983@localhost...
[Please don't top post]
[PLEASE reduce your signature size to something sensible]
>
> "Tintin" <me@privacy.net> wrote in message
> news:atpnn4$1cv63$2@ID-172104.news.dfncis.de...
> > Can anyone come up with a plausible reason why so many beginners write
> code
> > like:
> >
> > open FILE, "data.txt";
> > @var=<FILE>;
> > close FILE;
> >
> > foreach $line (@var) {
> > print $line;
> > }
> >
> > Where does this logic come from?
> >
> > The only reason I can come up with is that the newbies are learning from
> bad
> > examples.
>
> The "newbies" are learning from the experienced web application
developers.
> Dump the file into an array and close the dang file as quickly as you can.
> When you are on a busy site with thousands of hits per hour, you want that
> file open as little as possible. Dumping the contents to an array will
allow
> you to extract the data and manipulate the content.
Entirely depends on what you are doing with it. I see so many examples of
newbies opening a small file for reading. The looping through the data to
print out the contents.
> When I was a "newbie" i had too many experiences of a file being wiped out
> becuase there was too much reading and writing going on at the same time.
If that was the case, you obviously didn't implement file locking correct
(or at all) or use an alternative data structure like DBM.
------------------------------
Date: Thu, 19 Dec 2002 08:39:34 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Why do beginners read files into an array?
Message-Id: <atqpuq$1su85$2@ID-172104.news.dfncis.de>
<ctcgag@hotmail.com> wrote in message
news:20021218111051.776$Ez@newsreader.com...
> "Tintin" <me@privacy.net> wrote:
> > Can anyone come up with a plausible reason why so many beginners write
> > code like:
>
> I'm not a beginner anymore, and I still write code like that.
>
> >
> > open FILE, "data.txt";
> > @var=<FILE>;
> > close FILE;
>
> After this point, if data.txt become unavailable because, say, the NFS
> mounted drive it is a symlinked into goes MIA, this program is fine.
All well and good, but the vast majority of people don't use NFS.
>
>
> > foreach $line (@var) {
> > print $line;
> > }
>
>
> If all I wanted to do was print each line of a file, I wouldn't use Perl
> to do it in the first place.
Obviously this is a code snippet. Typically, you see this type of construct
in Perl/CGI scripts.
> So the chances are good that code like this
> is a prelude to something else. Say I now want to print the lines
> backward. All I have to do is add a strategically placed 'reverse'
> statement. If I originally wrote this as a while loop, I would have to
> rewrite it as a slurp with a for loop, and then add a reverse statement.
> That's definately more work.
I'm not saying that reading a file into an array is bad. All I'm trying to
understand is why people do it when they don't need to. I'm sure a search
of the Google archives will reveal a number of posts where people are
running out of memory by trying to slurp a file into an array when they
really don't need to.
>
> > Where does this logic come from?
>
> Arrays are easier to pass around. Arrays are easier to 'unread' from.
> Arrays are easier look up historical lines from. Arrays are easier to
> copy. Arrays are just easier to work with in general.
Agreed, when they are required.
------------------------------
Date: Thu, 19 Dec 2002 08:43:07 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: Why do beginners read files into an array?
Message-Id: <atqq5d$1ok1l$1@ID-172104.news.dfncis.de>
"brian d foy" <comdog@panix.com> wrote in message
news:181220021244372619%comdog@panix.com...
> In article <atpnn4$1cv63$2@ID-172104.news.dfncis.de>, Tintin
> <me@privacy.net> wrote:
>
> > Can anyone come up with a plausible reason why so many beginners write
code
> > like:
>
> > open FILE, "data.txt";
> > @var=<FILE>;
> > close FILE;
>
> > foreach $line (@var) {
> > print $line;
> > }
> >
> > Where does this logic come from?
>
> it works, and for someone learning a language, i am not surprised
> that they would do something one step at a time (i get data, now i got
> data, now i process data).
>
> remember, they are beginners :)
I am remembering that, but to me (and it's a little hard to remember back to
my first programming experiences), my logic would have been.
open file, do something with each line of the file, close file.
Maybe that's just because I came up through the ranks of BASIC, Pascal,
Fortran, C, shell scripts etc.
------------------------------
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 4283
***************************************