[25696] in Perl-Users-Digest
Perl-Users Digest, Issue: 7937 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 3 06:06:39 2005
Date: Sun, 3 Apr 2005 03:05:09 -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 Sun, 3 Apr 2005 Volume: 10 Number: 7937
Today's topics:
Re: accessing arrays in a different sub-routine <joe@inwap.com>
Re: Can perl do this? <joe@inwap.com>
Re: Can perl do this? <nobull@mail.com>
Re: Can perl do this? <nobull@mail.com>
Re: Can perl do this? <nobull@mail.com>
Re: CGI::UploadEasy - request for comments <noreply@gunnar.cc>
Re: difference between two files xhoster@gmail.com
Re: How to get an external return value? <see_sig@invalid>
Re: How to get an external return value? <mrmnews@the-meissners.org>
Re: How to get an external return value? <Juha.Laiho@iki.fi>
Newbie. Use of uninitialized value in print?? (Jon Anderson)
Stat devfs and SCSI optical drives <effigies@gmail.com>
Re: Stat devfs and SCSI optical drives axel@white-eagle.invalid.uk
Re: Stat devfs and SCSI optical drives <joe@inwap.com>
Re: Stings - textareas in Perl... <joe@inwap.com>
Re: Stings - textareas in Perl... <joe@inwap.com>
Re: To change the time stamp format... <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 03 Apr 2005 01:49:00 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: accessing arrays in a different sub-routine
Message-Id: <KuWdnZVv17WSIdLfRVn-vQ@comcast.com>
erik wrote:
> I just read that, thanks. That sheds some light. So basically with my
> example above, and due to it's dynamic nature, the only way I can get
> this working is a sub-function within a subfunction.
No, not at all.
Use 'my' or 'our' to declare variables.
Do not re-declare an already declared variable.
This does not work:
my @array; # File scoped (global) variable
sub set_it {
my @array = (1,2,3); # A new, different variable
}
sub print_it {
my @array; # Yet another different variable
print "@array";
}
set_it; print_it;
But if you get rid of the 2nd and 3rd 'my', it will work.
Better yet, use 'our' instead of 'my':
sub set_it {
our @array; # Lexical access to long-lived variable
@array = (1,2,3);
}
sub print_it {
our @array; # Access to same long-lived variable
}
set_it; print_it;
> I liked this line from the coping with scope.
>
> When to Use my and When to Use local
> Always use my; never use local.
I say "Always use my or our; never use local unless forced to."
-Joe
------------------------------
Date: Sat, 02 Apr 2005 23:03:25 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Can perl do this?
Message-Id: <a8adnTQA-PLfCNLfRVn-gw@comcast.com>
Big and Blue wrote:
> 2) Don't use a system call to "ls -l" to look for changes.
> i) stat the directory. Has the mtime changed since last time you
> stat()ed it? If not, then no new file has arrived.
> ii) If something has, the use readdir() to get the entries.
But that won't catch the case where a currently existing file
is modified. The stat() value of that file will have changed
but the value from stat() on the directory will not.
>>> * Whenever the contents of a directory change (filesize, date
>>> modified, new file, anything)
That's going to require doing a stat() on every file in the directory.
-Joe
------------------------------
Date: Sun, 03 Apr 2005 08:59:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Can perl do this?
Message-Id: <d2o7dn$4c7$1@sun3.bham.ac.uk>
rublind@gmail.com wrote:
> Subject: Re: Can perl do this?
Please put the subject of your post in the Subject of your post.
> Okay, I don't know perl yet, but I have a book to be read when I get
> some time. But there is something I need soon and I'd like to know if
> perl can do it.
> Here's what I need:
> * Whenever the contents of a directory chnage (filesize, date
> modified, new file, anything) the script needs to call a system
> command,
Perl has all the normal filesystem functions and is good at comparing
things so you could poll.
There is no portable standard for automatic notification of directory
updates but if you look in these newsgroups you'll find many discussions
of interfacing to the
> * The system command will require a password, so the STDIN and STDOUT
> need to be played with so the password can be sent by the file
This sounds like you want something like Expect. Perl has an
implementation of Expect.
> * after the command, the script needs to monitor the folder again, and
> repeat after a change.
Perl is a general purpose programming language. You can do loops and
conditions.
>
> Is this possible?
Yes is it possible.
> If it is, would it be that complicated of a script?
Nothing you've said is all that complex.
> Or can I do it in five minutes after I learned the language?
There's more to reading a language than just reading a book.
Let me turn it round.
This problem is suffiently simple that, if your lack of skills
specifically in the Perl language were the factor preventing you from
solving this problem in Perl then you would not be able to say you had
"learned the language".
There's nothing specific to Perl here - the same could be said of any
programming language that has an implementation of Expect or something
similar.
How many languages do you know?
How many languages could you already solve this in?
There's a big difference between learning a programming language and
learning to program.
------------------------------
Date: Sun, 03 Apr 2005 09:10:26 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Can perl do this?
Message-Id: <d2o82l$4li$1@sun3.bham.ac.uk>
rublind@gmail.com wrote:
> The command I wanted to run was either an SVN update or a CVS update,
Most such commands are designed to be scriptable to provide ways to
avoid the need to enter a password interactively. This makes your
problem (already not too complex) a _lot_ simpler. No need to use
anything Expect-like or manipuate both the the VC program's STDIN and
STDOUT at the same time. You can run it with a simple qx() or open().
------------------------------
Date: Sun, 03 Apr 2005 10:51:25 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Can perl do this?
Message-Id: <d2oe00$7fh$1@sun3.bham.ac.uk>
A. Sinan Unur wrote:
> Humbly, I think it is better for humans to decide when it is a good time
> to check sources in to a version control repository than having every
> change you make be checked in regardless of what that change is, but
> that's just me.
There are places for both. Obviously in a perfect world you have manual
check-in where the VC respository is the prime truth.
But where this has not been achieved there's still value in having a VC
repository that holds a snapshot of something else.
For example I have a project that uses a Microsoft SQL database.
Ideally all the table schemas, views, functions, static table content
etc should be imported from scripts in some sort of VC repository that
is the prime truth. They are not.
In this situation there is still value in having a Perl script that
periodically dumps all this information from the database into a VC
respository so at least I have a way to roll back changes and a reliable
record of what was changed when even if it's not properly tied up with
by whom and why.
> It might be useful to do this on a schedule, in which case the OS
> dependent scheduling facilities (cron, at) ought to be used.
Indeed.
> On the other hand, Windows has a directory change notification callback
> API. Using that would avoid the busy loop.
I wouldn't trust this 100% - I often find I have to hit F5 in Windows
Explorer. Directory change notification _will_ help you to get timely
updates but to be on the safe side I'd still poll occasionally as a
fallback.
------------------------------
Date: Sun, 03 Apr 2005 11:27:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI::UploadEasy - request for comments
Message-Id: <3b9rbhF6ha22gU1@individual.net>
At March 31 Gunnar Hjalmarsson wrote:
>
> CGI::UploadEasy is an attempt to help prevent possible hazzle with
> upload scripts.
>
> CGI::UploadEasy is a wrapper around, and relies heavily on, CGI.pm.
> Its purpose is to provide a simple interface to the upload
> functionality of CGI.pm.
I found a bug, so a new version (0.11) has been uploaded to CPAN.
> Any kind of comments on the module would be much appreciated.
> ...
> to make it easy to acquaint oneself with it, I wrote this script:
> http://www.gunnar.cc/programs/upload.pl.txt
After the bug fix, and if nobody tells me otherwise, I take it that I
wrote TPPM (The Perfect Perl Module). ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.
HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html
------------------------------
Date: 03 Apr 2005 03:58:43 GMT
From: xhoster@gmail.com
Subject: Re: difference between two files
Message-Id: <20050402225843.942$Iy@newsreader.com>
peter pilsl <pilsl@goldfisch.at> wrote:
> Hendrik Maryns wrote:
> >>
> >> perl -MText::Diff -e "print diff @ARGV" file1.xml file2.xml
> >
> > Thanks fot this one. I really have to learn to write oneliners. All
> > these four-line scripts aren't very useful & handy anyway.
> >
>
> oneliners are fast-written and often-written, cause I never save them to
> disk and when I need em again I've to think them over again.
> So on the longer term fourliners are maybe better ;)
On the other hand, if every one-liner I have ever written was saved to
disk as a four-liner, there would be so stinking many of them I would never
be able to find the one I wanted when I wanted it again.
>
> best,
> peter
cheers,
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Sat, 02 Apr 2005 21:56:58 -0500
From: Bob Walton <see_sig@invalid>
Subject: Re: How to get an external return value?
Message-Id: <424f5c32$1_1@127.0.0.1>
topple wrote:
...
> Perl is a whole lot different. I really like it so far, but I am
> still in the learning segment where some of the differences don't make a
> whole lot of sense. I realise that the embedded Perl docs have a ton of
> info, but many times, if not most, I don't know what I am trying to find.
> Just the backtick method of calling something took hours of searching
> before I even knew it existed.
>
> Topple
One suggestion: Read all the FAQ's to start with:
perldoc perlfaq
They aren't really all that long, and there is an absolute wealth
of information about Perl in them -- including mention of the
backticks or qx// feature. The basic docs aren't so bad to grok
where things are at, either:
perldoc perl
is a pretty good starting place. Granted, learning Perl can be a
daunting task. If you're into books (sounds like you are), set
the rest of them aside (maybe some of them permanently if they
really say what you indicated they say) and read "Learning Perl",
current edition.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: 02 Apr 2005 22:55:25 -0500
From: Michael Meissner <mrmnews@the-meissners.org>
Subject: Re: How to get an external return value?
Message-Id: <m3ekdszf82.fsf@tiktok.the-meissners.org>
"Jürgen Exner" <jurgenex@hotmail.com> writes:
> topple wrote:
> > My books don't address the question. Lots of stuff about using
> > backticks to call system functions and getting return values,
>
> Dump those books immediately. backticks don't provide return values, they
> merely capture the output of the external program.
> If your books don't mention that, then they are not worth the paper they are
> printed on.
Well if you need the exit value of the external program, it is in $?.
--
Michael Meissner
email: mrmnews@the-meissners.org
http://www.the-meissners.org
------------------------------
Date: Sun, 3 Apr 2005 07:58:54 +0000 (UTC)
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: How to get an external return value?
Message-Id: <d2o7nu$gng$1@ichaos.ichaos-int>
topple <nope@nowhere.com> said:
>I have no problem calling a subroutine within the same script.
>
>However, in this case...
>
>caller.pl is a perl script that calls dice.pl.
>dice.pl is another standalone perl script.
With perl, it'd be more elegant to model the dice as a perl module;
this is a simplified version of your dice routine (just a single dice),
but should give the essentials for building a module routine:
Dice.pm:
package Dice;
use strict;
sub roll {
return 1+int rand $_[1];
}
1;
caller.pl:
#! /usr/bin/perl
use strict;
use warnings;
use Dice;
print Dice->roll(5),"\n";
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
------------------------------
Date: 3 Apr 2005 01:36:15 -0800
From: five421@fastmail.fm (Jon Anderson)
Subject: Newbie. Use of uninitialized value in print??
Message-Id: <71322843.0504030136.2e4d01e1@posting.google.com>
Hi,
Im having problems getting some Perl code to work (im a programming
newbie). The aim of the code is to read certain text from a file,
print it to screen then allow the user to make a choice based on that
output. Well, that's the aim so far anyway (im about half way through
the code). Ive been stuck on this however. Im getting the error "Use
of uninitialized value in print at... line 26, <STDIN> line 1."
Ive spent most of the day trying to work out what's wrong, but have
come up empty handed. The code is,
$lnum = 0;
open (INPUT, "file.txt") or die "Error, can't find file\n";
@raw_data=<INPUT>;
close(INPUT);
#Print to screen the pricelist in the text file
foreach $price (@raw_data)
{
@pricelist = split (/:/, $price);
print "$lnum" . " " . "$pricelist[1]\n" if @pricelist != 1;
$lnum ++;
}
print "\n";
$prices2 = @raw_data;
@prices1to5 = split (/:/, $prices2);
print "Please enter the item to be purchased..\n\n";
chomp($selectitem = <STDIN>);
if($selectitem == 1)
{
print "\n";
print "You selected item 1, which sells for\n";
print $prices1to5[1];
$item = 1;
}
elsif($selectitem == 2)
{
print "\n";
print "You selected item 2, which sells for\n";
print $prices1to5[2];
$item = 2;
}
elsif($selectitem == 3)
{
print "\n";
print "You selected item 3, which sells for\n";
print $prices1to5[3];
$item = 3;
}
elsif($selectitem == 4)
{
print "\n";
print "You selected item 4, which sells for\n";
print $prices1to5[4];
$item = 4;
}
elsif($selectitem == 5)
{
print "\n";
print "You selected item 5, which sells for\n";
print $prices1to5[5];
$item = 5;
}
else
{
print "\n";
print "Invalid item selection! No such item\n";
}
---
The code at line 26 is
18 $prices2 = @raw_data;
19 @prices1to5 = split (/:/, $prices2);
20 print "Please enter the item to be purchased..\n\n";
21 chomp($selectitem = <STDIN>);
22 if($selectitem == 1)
23 {
24 print "\n";
25 print "You selected item 1, which sells for\n";
26 print $prices1to5[1];
---
I cant pick up the error despite going over it many times & trying a
number of things after looking for answers online. Any help would be
greatly appreciated :)
------------------------------
Date: 2 Apr 2005 18:28:09 -0800
From: "Chris Johnson" <effigies@gmail.com>
Subject: Stat devfs and SCSI optical drives
Message-Id: <1112495289.419394.251080@g14g2000cwa.googlegroups.com>
I'm working on a program that needs to stat devices and pick out
optical drives. I've run the following code on my computer and my
roommates:
opendir DEV, "/dev";
for(readdir(DEV)){
my @stats = stat "/dev/$_";
print "$_: $stats[5]\n";
}
closedir DEV;
And I found that all optical drives have a $gid ($stats[5]) of 93.
However, we both have IDE optical drives and udev, so rather than write
a program with the same configuration, I'd appreciate it if I could get
some confirmation from people with SCSI optical drives and/or devfs.
Thanks,
Chris
------------------------------
Date: Sat, 02 Apr 2005 21:03:49 -0600
From: axel@white-eagle.invalid.uk
Subject: Re: Stat devfs and SCSI optical drives
Message-Id: <BI-dnUviFOSIwNLfRVn-og@adelphia.com>
Chris Johnson <effigies@gmail.com> wrote:
> I'm working on a program that needs to stat devices and pick out
> optical drives. I've run the following code on my computer and my
> roommates:
> And I found that all optical drives have a $gid ($stats[5]) of 93.
> However, we both have IDE optical drives and udev, so rather than write
> a program with the same configuration, I'd appreciate it if I could get
> some confirmation from people with SCSI optical drives and/or devfs.
It's not a relevent question to this newsgroup.
Also any answers that you receive will be a bit pointless unless
they concern the same OS that you are using, which you do not specify.
Axel
------------------------------
Date: Sat, 02 Apr 2005 23:13:31 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Stat devfs and SCSI optical drives
Message-Id: <D9GdnYRjjsA9CtLfRVn-gg@comcast.com>
Chris Johnson wrote:
> And I found that all optical drives have a $gid ($stats[5]) of 93.
I expect that you will get more reliable results by using $stats[6].
my $major = $stats[6] >> 8;
my $minor = $stats[6] & 0xFF;
print "$_: $major,$minor\n";
The bits stored in $stats[6] is operating system dependent.
-Joe
------------------------------
Date: Sun, 03 Apr 2005 01:52:22 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <KuWdnZRv17VLIdLfRVn-vQ@comcast.com>
joesplink wrote:
> Check... see that I must insert <br>s in the HTML.
If you want to preserve newlines and multiple spaces, use <pre>.
------------------------------
Date: Sun, 03 Apr 2005 01:57:47 -0800
From: Joe Smith <joe@inwap.com>
Subject: Re: Stings - textareas in Perl...
Message-Id: <VsednYGFIZ6DI9LfRVn-pg@comcast.com>
joesplink wrote:
> Even if I set my $Field="A\r\l\r\l" I still get back only "A"......
Don't blame perl for that: the behavior is browser specific.
And it's "\r\n" not "\r\l".
> So, (at least part of) the problem is I don't know exactly what string
> Perl is sending to the browser in the above instances.
You mean you've never used the brower's View Source feature?
------------------------------
Date: Sun, 03 Apr 2005 10:29:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: To change the time stamp format...
Message-Id: <d2ocmf$6tk$1@sun3.bham.ac.uk>
A. Sinan Unur wrote:
> "John W. Krahn" <someone@example.com> wrote in news:EEG3e.127836$ZO2.94802
> @edtnps84:
>
>>A. Sinan Unur wrote:
>>
>>>Ooops! How about that Y2.1K bug?!
>>
>>Is that thing still around? :-)
>
> Yeah, it seems like a new version is released every century :)
Indeed, I always wondered why people insisted on calling the centuary
bug 'the millenium bug' or the 'Y2K bug'.
But it's really more often than that. There are all sort of ways that
various software encodes dates internally. Each of these can introduce
its own problems.
There was one on 9th September 2001. (10**9 seconds since 1970).
Of course there's the famous 'Unix' one on 19th January 2038 (2**31
seconds since 1970).
There's a lesser known one one a couple of years earlier (2**32 seconds
since 1900).
There's even one in 2010 that some users of systems written in the MUMPS
programing language may hit.
------------------------------
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 7937
***************************************