[10274] in Perl-Users-Digest
Perl-Users Digest, Issue: 3867 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 1 15:16:15 1998
Date: Thu, 1 Oct 98 12:08:56 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 1 Oct 1998 Volume: 8 Number: 3867
Today's topics:
Re: Clarification of $_ please <jdporter@min.net>
Re: DEL in PERL <jim.michael@gecm.com>
Difference between =~ and =* operators? (Erik Huelsmann)
Re: Difference between =~ and =* operators? <uri@camel.fastserv.com>
Re: Does die close files (when caught) ? <perlguy@inlink.com>
Re: Does die close files (when caught) ? (Mark-Jason Dominus)
forwarding web-based email to mail server? <kin@omni.c-cube.com>
Re: How to know if I deal with a file or a directory (dwc)
IDE for Perl <mkolbuszewski@mail.cebra.com>
Re: Ignore multiple input record seperators (Ilya Zakharevich)
Re: Ignore multiple input record seperators <jdporter@min.net>
Re: Ignore multiple input record seperators (Larry Rosler)
Meeting of Cincinnati.pm - October 7, 1998 patrick@cre8tivegroup.com
Multiple Form Results (Abe Davison)
Re: new term for illogical <upsetter@ziplink.net>
OO question: class data (Phil Tomson)
Re: Passing variable from form to form (Shambo Pfaff)
Re: PERL and Win32 TIME (Larry Rosler)
Perl tutorial <harman@omsi14.omsi.com>
Re: Problems Using a Compare Subroutine with Sort <uri@camel.fastserv.com>
Re: Problems Using a Compare Subroutine with Sort <jdporter@min.net>
Question about getopt.pl subroutine <stevehar@newbridge.com>
readdir in what order? <yong@shell.com>
Re: readdir in what order? (Sean McAfee)
Re: readdir in what order? <uri@camel.fastserv.com>
Re: Rotating an array. (Larry Rosler)
Re: scope question (David Alan Black)
Re: Simple database recommendation needed <hallgren+-no-spam-+@fdn.org>
Re: Some kind of 'real' user interface? (Tad McClellan)
Re: Stock paging, anyone seen this script? (Clinton Pierce)
Re: Stock paging, anyone seen this script? <merlyn@stonehenge.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 01 Oct 1998 14:10:45 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Clarification of $_ please
Message-Id: <3613C5A5.430D50C@min.net>
Last time, I wrote:
>
> From the context, I'm guessing you meant to say
> my $_ = "hello world!";
Of course, that's not legal perl. Omit the 'my'.
--
John "Many Jars" Porter
------------------------------
Date: Thu, 01 Oct 1998 14:45:49 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: DEL in PERL
Message-Id: <3613CDDD.388@gecm.com>
"Computer Guru" <computerguru@mailexcite.com> writes:
> I am trying to find all files on the HD which end in *.bak and then
delete
> them. I was tring to do this as a DOS batch script but noticed DOS
does not
> have this capability...I checked my manuals but could not find out
how to do
> this..would I need a grep statement or something? Thanx
> Computer Guru Consulting
>From the dos man page: ;-)
X:\>del /?
Deletes one or more files.
DEL [/P] [/F] [/S] [/Q] [/A[[:]attributes]] [[drive:][path]filename
ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] [[drive:][path]filename
[drive:][path]filename
Specifies the file(s) to delete. Specify multiple
files by using wildcards.
/P Prompts for confirmation before deleting each file.
/F Force deleting of read-only files.
/S Delete specified files from all subdirectories.
/Q Quiet mode, do not ask if ok to delete on global
wildcard
/A Selects files to delete based on attributes
attributes R Read-only files S System files
H Hidden files A Files ready for
archiving
- Prefix meaning not
If Command Extensions are enabled DEL and ERASE change as follows:
The display semantics of the /S switch are reversed in that it shows
you only the files that are deleted, not the ones it could not find.
------------------------------
Date: 1 Oct 1998 18:38:17 GMT
From: ErikH@Bitsmart.com (Erik Huelsmann)
Subject: Difference between =~ and =* operators?
Message-Id: <wzgSQd1pdrdd-pn2-WcJVqr4Zt48h@localhost>
I am fairly new to perl, but I have extensively read the perlop pod
and have not come to a conclusion about most of the regex operators.
What are the differences?
More specificly: what is the difference between the =3D~ operator and
the =3D* operator? Both are said to influence the behavior of the s///
operator, but how?
Thanks for the answer...
bye, Erik
--
Want to link your Psion to OS/2? Check out
http://www.bitsmart.com/erikh/PSI.html currently relayed to
http://www.oprit.rug.nl/hulsmann/PSI.html
[Don't mail posts, I will see them here just fine]
------------------------------
Date: 01 Oct 1998 14:43:27 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Difference between =~ and =* operators?
Message-Id: <sarogrwruls.fsf@camel.fastserv.com>
>>>>> "EH" == Erik Huelsmann <ErikH@Bitsmart.com> writes:
EH> I am fairly new to perl, but I have extensively read the perlop
EH> pod and have not come to a conclusion about most of the regex
EH> operators. What are the differences?
EH> More specificly: what is the difference between the =3D~ operator
EH> and the =3D* operator? Both are said to influence the behavior of
EH> the s/// operator, but how?
i never heard of =3D~ or =3D* in perl.
:-)
funky newsreader.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Thu, 1 Oct 1998 16:02:19 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: Does die close files (when caught) ?
Message-Id: <3613A78B.1A733F5@inlink.com>
Sorry,
I really reesed that one!
Next time I'll READ THE QUESTION more carefully before putting my foot
in my mouth. I had the exact same problem on tests in school. :-)
Brent
--
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Brent Michalski $
$ -- Perl Evangelist -- $
$ E-Mail: perlguy@technologist.com $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
------------------------------
Date: 1 Oct 1998 14:49:48 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Does die close files (when caught) ?
Message-Id: <6v0isc$1a5$1@monet.op.net>
In article <36137235.66CDB1C9@cnam.fr>,
Paul Preziosi <preziosi@cnam.fr> wrote:
>sub play_with_file {
> open F, '<fname' or die "can't open";
> seek F, $doubtful_offset, O or die "bad offset";
> # ...
> =A0close F;
>}
>
>eval { play_with_file(); }
>handle( $@ ) if $@;
>
> ... and trust that F will be closed anyway,
In email, Tom Christiansen pointed out a really nifty solution, better
in many ways than the others I posted:
sub play_with_file {
local *F;
open F, '<fname' or die "can't open";
seek F, $doubtful_offset, O or die "bad offset";
# ...
}
eval { play_with_file(); }
handle( $@ ) if $@;
It turns out that if the filehandle F is localized to the block, then
the file is *automatically* closed whenever control returns from the
scope of the block, whether the return is a normal one or as a result
of an exception thrown by `die'.
I hadn't been aware oNNTP-Article: 169160 of comp.lang.perl.misc
Path: news.nero.net!logbridge.uoregon.edu!feed1.news.rcn.net!rcn!news-xfer.netaxs.com!newsread.com!not-for-mail
Message-ID: <3613C570.D482A6B1@min.net>
From: John Porter <jdporter@min.net>
X-Mailer: Mozilla 4.04 [en] (WinNT; U)
MIME-Version: 1.0
Newsgroups: comp.lang.perl.misc
Subject: Re: elements of an array passed as args to embedded expect.
References: <6uu282$7t7$1@nnrp1.dejanews.com> <36129560.A34F095B@min.net> <6v010r$dcm$1@nnrp1.dejanews.com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 40
Date: Thu, 01 Oct 1998 14:09:52 -0400
NNTP-Posting-Host: 137.51.206.37
X-Complaints-To: Abuse Role <abuse@min.net>, We Care <abuse@newsread.com>
X-Trace: newsread.com 907265212 137.51.206.37 (Thu, 01 Oct 1998 14:06:52 EDT)
NNTP-Posting-Date: Thu, 01 Oct 1998 14:06:52 EDT
Organization: MetroNet Internet Services (min.net)
Xref: news.nero.net comp.lang.perl.misc:169160
mmurphy@infomedics.com wrote:
>
> #!/usr/local/bin/perl -w
> $thisHost = `hostname`; chop($thisHost);
You should prefer chomp() to chop(). It's safer.
> $hostname = shift; $key = $hostname;
> $host = $hostname;
$host = $key = $hostname = shift;
> $user = 'yourusername'; $ex = '';
> $passwd = 'yourpasswd';
I assume these are the hard-coded values that you
would like to read from a file?
> open (SCRIPT, ">$scriptFileName");
Always, *always*, *ALWAYS* check the result of open().
There is never, NEVER a situation in which you should
neglect checking the result of open().
How long have you been reading this newsgroup, anyway?
> END_SCRIPT close SCRIPT; chmod 0755, $scriptFileName; 7 4vterm (88%)07 7
> system "$scriptFileName $host $thisHost $user $passwd $file"; system "rm
> $scriptFileName";
What happened to the formatting?
Did DejaNews do this?
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: 01 Oct 1998 09:34:09 -0700
From: Kin Cho <kin@omni.c-cube.com>
Subject: forwarding web-based email to mail server?
Message-Id: <coh90j09r7i.fsf@omni.c-cube.com>
I got one of those free email accounts from some ISP.
I'm getting tied of bringing up the browser, login in,
and clicking around to read messages.
I'd like to run some Perl script to:
1) automatically login to the freemail web site,
2) read and parse out the email content,
3) and send the mail to my work email
To me, the "hard" part appears to be 1), cause I don't
know what the browser sends back to the site when I type in
username and password and click on the login button.
-kin
------------------------------
Date: Thu, 01 Oct 1998 17:29:50 GMT
From: dwc@davewc.mv.com (dwc)
Subject: Re: How to know if I deal with a file or a directory
Message-Id: <3619bb37.85459804@news.ultranet.com>
Use the -d file test. The file tests are listed in the O'Reilly books...
example:
if( -d $FNAME )
{
# This is directory.
}
if( -f $FNAME )
{
# This is a plain file.
}
-dwc
On Thu, 01 Oct 1998 13:25:23 +0100, patrick Scotto <sertim@imaginet.fr> wrote:
>I want my perl program to explore my disk (full of files and
>directories) and to create a list of all the filenames.
>
>For this, it opens the top most directory and takes the name of all
>files... ignoring whether the name it reads is related to a file or a
>directory.
>
>How can I check that the name I deal with is related to a file or a
>diretory ?
>Is there a function that returns the type of a file ?
>
>
>Thanks for your help.
>
------------------------------
Date: Thu, 01 Oct 1998 13:32:40 -0400
From: Marcin Kolbuszewski <mkolbuszewski@mail.cebra.com>
Subject: IDE for Perl
Message-Id: <3613BCB8.E18CDF20@mail.cebra.com>
Perl is a mature OO language now and would benefit (at least in my
opinion) from some sort of GUI driven environment to do development.
Although it may be contrary to the spirit of the language and many
purists
will call me names, I think a simple class browser would help
development of
applications.
For example we've just started modelling and prototyping a quite large
OO
system in Perl. We feel just like C++ people in late 80s or Smalltalk
people before
PARC times...
Have you seen anything even remotely resembling an IDE for Perl?
Marcin Kolbuszewski
------------------------------
Date: 1 Oct 1998 18:07:31 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Ignore multiple input record seperators
Message-Id: <6v0gd3$qsn$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<aonghus.onia@ucg.ie>],
who wrote in article <6v04e6$i83$1@nnrp1.dejanews.com>:
> Is it possible to Ignore multiple input record seperators eg multiple spaces
> when reading input. (the no. of spaces is not constant). I know I could test
> for repeated spaces but I am reading in from an extremly large file an I want
> it to be as efficient as possible.+
If you mean "Can IFS be a REx" then not yet.
Ilya
------------------------------
Date: Thu, 01 Oct 1998 14:28:36 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Ignore multiple input record seperators
Message-Id: <3613C9D4.53CD210F@min.net>
aonghus.onia@ucg.ie wrote:
>
> Is it possible to Ignore multiple input record seperators eg multiple spaces
> when reading input. (the no. of spaces is not constant). I know I could test
> for repeated spaces but I am reading in from an extremly large file an I want
> it to be as efficient as possible.+
Ignore empty records:
> $/=" ";
> while(<>){
next if /^$/;
> print;
> print "\n"
> }
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: Thu, 1 Oct 1998 11:38:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Ignore multiple input record seperators
Message-Id: <MPG.107d6becba80f55e9897cf@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <6v04e6$i83$1@nnrp1.dejanews.com> on Thu, 01 Oct 1998 14:43:18
GMT, aonghus.onia@ucg.ie <aonghus.onia@ucg.ie> says...
> Is it possible to Ignore multiple input record seperators eg multiple spaces
> when reading input. (the no. of spaces is not constant). I know I could test
> for repeated spaces but I am reading in from an extremly large file an I want
> it to be as efficient as possible.+
while (<>) {
tr/ //s; # Replace sequences of spaces by single spaces.
print "$_\n";
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 01 Oct 1998 18:23:20 GMT
From: patrick@cre8tivegroup.com
Subject: Meeting of Cincinnati.pm - October 7, 1998
Message-Id: <6v0hao$ajc$1@nnrp1.dejanews.com>
The first meeting of the Cincinnati Perl Mongers will be next Wednesday
evening (October 7, 1998) at 6 PM. The meeting place is a place called "Holy
Grail" in Correyville, Cincinnati OH (near Univ. of Cincinnati).
Any Perl people in Cincinnati, we'd love to see you there!
Patrick Gardella
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Thu, 01 Oct 1998 17:16:42 GMT
From: 331@allied.demon.co.uk (Abe Davison)
Subject: Multiple Form Results
Message-Id: <3613b7d1.446199@news.demon.co.uk>
With an html form generated by a perl script in the lower frame (main)
what form action=? could be used to display one set of results in the
main frame and a second set of results in the top frame.
This means two form actions and two targets from one form submit
button.
Thanks
------------------------------
Date: Thu, 01 Oct 1998 18:30:02 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: new term for illogical
Message-Id: <KSPQ1.3$q5.1560@news.shore.net>
Uri Guttman <uri@sysarch.com> wrote:
:>>>>> "A" == Abigail <abigail@fnx.com> writes:
: A> *plonk*
: poor abby couldn't handle some acerbic comments back at he/r!
She's the sensitive type, you know.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Thu, 01 Oct 1998 18:20:00 GMT
From: ptkwt@user2.teleport.com (Phil Tomson)
Subject: OO question: class data
Message-Id: <6v0h4e$5tn$1@user2.teleport.com>
I've been looking through the perltoot document (Tom's OO perl tutorial)
and there is a section on Class Data. In the example they say to put the
class data at the beginning of the file such as:
my $Census = 0;
package Person;
sub new {
.
.
$Census++; #everytime you create a new person increment the Census
.
.
}
I tried this, but I get the following error:
Can't declare constant item in my at Person.pl line 2, near "Census ="
I tried moving the 'my Census = 0' declaration to just after the package
statement and got the same error message.
I tried this on perl version 5.004_04 for Linux and 5.002 on Solaris and
get the same error.
Am I misreading perltoot?
Phil
--
Phil Tomson
FreeHDL Project
http://www.freehdl.seul.org/
------------------------------
Date: Thu, 01 Oct 1998 13:52:42 -0400
From: shambop@bacon-and-spam.timeoutny.com (Shambo Pfaff)
Subject: Re: Passing variable from form to form
Message-Id: <shambop-0110981352420001@www.timeoutny.com>
What if you want to pass the original FROM variables to another cgi script
based on user input? For example, one of the variables passed is actually
the name of the second cgi script to run, with the other variables going
to that second cgi script. How do you triger another script from within
the original script?
Feel free to e-mail direct.
Thanks,
Shambo Pfaff
In article <6up7c8$svv$1@shell2.ba.best.com>, kirbyk@best.com (Rufus
Xavier Sarsaparilla) wrote:
> In article <36101CBB.3F28EF33@labyrinth.net.au>,
> Reiner <slug@labyrinth.net.au> wrote:
> >Once you get the user's name, print it back in subsequent forms as a
hiddn field.
> >Each new request you will need to read the user name from the input.
> >
> >print "<INPUT TYPE=\"HIDDEN\" NAME=\"user\" VALUE=\"$user\">";
> >
> >
> A small code fragment I find useful:
>
> foreach ($query->param()) {
> print $query->hidden(-name=>$_, -default=>$query->param($_)); }
>
> This preserves all the cgi parameters nicely. Be careful to remove any that
> you don't want duplicated before you get to this spot - particularly
> watch out for things you'll want to change, so they don't end up in getting
> passed on twice, with the old and the new values. But, this definitely
> did the trick in my code.
>
> --
> Kirby Krueger O- kirbyk@best.com
> <*> "Most .sigs this small can't open their own jump gate."
------------------------------
Date: Thu, 1 Oct 1998 11:15:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: PERL and Win32 TIME
Message-Id: <MPG.107d669cf6c82c4f9897ce@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36129D36.9BC98D65@sprintparanet.com> on Wed, 30 Sep 1998
16:05:58 -0500, Sam Woolsey <swwoolse@sprintparanet.com> says...
> How do convert a time/date stamp in a unix PERl file to an NT Perl file?
> I need to include the date and time but it is not working on an NT box.
You need to be much more specific if anyone is to answer.
What do you mean by a 'time/date stamp'?
What is a 'Unix Perl file' and an 'NT Perl file'?
What 'date and time' to you need to include in what?
What is not working on an NT box?
What does it do when it is not working?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 01 Oct 1998 10:17:52 -0700
From: Harmanjit Singh <harman@omsi14.omsi.com>
Subject: Perl tutorial
Message-Id: <xfgpvccurpb.fsf_-_@omsi14.omsi.com>
Eric-Goforth@csi.com writes:
> | I learned basic perl from a freely available 10k tutorial on the web and
> | later referred to perlfunc, perlop and perlsyn manpages whenever I
> | wanted to learn.
>
> Any idea where I could find this, or a similar, tutorial?
You can check out http://odur.let.rug.nl/~koeling/AI/Perl/start.html
I think I learned from a smaller version of the same.
--
With Warm Regards,
Harmanjit Singh.
http://harman.home.ml.org
------------------------------
Date: 01 Oct 1998 13:45:11 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <sarvhm4rxaw.fsf@camel.fastserv.com>
>>>>> "MR" == Michal Rutka <erhmiru@erh.ericsson.se> writes:
MR> "Joe Williams" <willliams@clark.net> writes:
>> I need to sort array strings by the IP address that each string
>> contains. John Porter posted a clever routine to covert the dotted
>> quad address into an integer. The normal Perl sort permits calling
>> a subroutine to do the comparison. So, I can just use index and
>> substr to lift the IP addresses out of the strings being compared,
>> which sort passes to the subroutine by reference in the variables
>> $a and $b, convert them into integers, compare the integers and
>> return 0, -1, or 1 to the sort routine. In principal, $a and $b
>> arn't changed.
>>
>> However, I'm not getting good results, possibly because of scope
>> problems with the way sort passes arguments in the global variables
>> $a and $b by reference.
MR> Hymm, just tell what results you are getting and why do you think
MR> they are wrong. Then I tell you why John's clever routine is not
MR> so clever.
yes, tell us what is so unclever. you don't understand the schwartian
transform so it must not be good. well, benchmark against it in a real
world situation.
MR> Hint - you are loohing for bug in a wrong place. After you spot a
MR> bug, you can tell John how much time did it cost you. He should be
MR> proud.
and you should feel shame for spouting such nonsense. you have never
tried his fixed code or anything to do with the ST. you don't even
understand what it is trying to do and how it saves both development and
cpu time.
MR> Yes. Just try this:
MR> @ips_sorted = sort {pack("C4",split(/\./,$a)) cmp
MR> pack("C4",split(/\./,$b))} @ips;
brilliant. but where does it extract the IP from the string and how does
it return the original string in sorted order?
he asked this:
>> I need to sort array strings by the IP address that each string
do you have a quick answer? i am waiting! the ST is for sorting on a
component of a larger structure while saving all the conversion calls
inside of sort. do you understand what O() means in a algorithm? or
why it is important to keep the compare fast?
please keep you snide comments to your self, unless you actually answer
the problem as stated. john porter has been a long respected contributor
to this group. you are a new interloper with no proven understanding of
perl and software issues.
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Thu, 01 Oct 1998 14:18:03 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <3613C75B.E0302FE2@min.net>
Michal Rutka wrote:
>
> Hymm, just tell what results you are getting and why do you think
> they are wrong. Then I tell you why John's clever routine is not so
> clever.
Hey, I never made any claims about how clever my code was.
But I'll tell you this: my dotted_to_int() subroutine is more
correct -- although a lot slower -- than your pack/split method.
> Hint - you are loohing for bug in a wrong place. After you spot a
> bug, you can tell John how much time did it cost you. He should be
> proud.
You've got a monstrous chip on your shoulder, droog.
> Yes. Just try this:
>
> @ips_sorted = sort {
> pack("C4",split(/\./,$a)) cmp pack("C4",split(/\./,$b))
> } @ips;
Or try this, which is more correct:
@ips_sorted = sort {
inet_aton($a) cmp inet_aton($b)
} @ips;
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: Thu, 01 Oct 1998 14:50:30 -0400
From: Steve Harrison <stevehar@newbridge.com>
Subject: Question about getopt.pl subroutine
Message-Id: <3613CEF6.6B8C7F46@newbridge.com>
According to the Camel book, when the &Getopt subroutine is called with
a switch, but no
argument, the variable $opt_x (where x is the switch name) should take
the value 1 (pg 404).
In my small test program below, this isn't the case. The variable
$opt_f is unassigned when
the program is executed as prog_name -f
----- start of program ---------
#!/usr/local/bin/perl -w
require "getopt.pl";
# Init the variable
$opt_f = 'idle';
&Getopt('f');
if ( $opt_f eq 'idle')
{
print "Pass! $opt_f\n";
}
else
{
print "Fail! $opt_f\n";
}
------ end of program ------------
The result that I get is shown below...
Use of uninitialized value at prog_name line 10.
Use of uninitialized value at prog_name line 10.
Fail!
Question: Shouldn't $opt_f = 1 in this case?
Thanks,
Steven
email: stevehar@newbridge.com
------------------------------
Date: Thu, 01 Oct 1998 12:34:44 -0500
From: yong <yong@shell.com>
Subject: readdir in what order?
Message-Id: <3613BD34.B1BBB3C@shell.com>
If I have both "a.txt" and "b.txt" in my current directory, what does
the following script print?
----------------------------------------
#!perl -w
opendir TMP, "." or die "Can't open: $!";
($myfile)=grep /.*?\.txt/, readdir TMP;
close TMP;
print "The file is: $myfile.\n";
----------------------------------------
Here's the output before and after I renamed the files:
----------------------------------------
C:\Perl\test>perl q.pl
The file is: a.txt.
C:\Perl\test>ren a.txt c.txt
C:\Perl\test>perl q.pl
The file is: b.txt.
C:\Perl\test>ren b.txt v.txt
C:\Perl\test>perl q.pl
The file is: v.txt.
--------------------------------------
Initially I thought readdir picks the first file according to "sort by
name", but it doesn't look like so. I searched the newsgroup and found
somebody has the same problem (his message reported a problem at
http://midifest.com/MIDIFest/PopRock/).
Thanks for any help.
Yong Huang
Email:yong@shell.com
------------------------------
Date: Thu, 01 Oct 1998 17:55:46 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: readdir in what order?
Message-Id: <CmPQ1.5659$F7.20901774@news.itd.umich.edu>
In article <3613BD34.B1BBB3C@shell.com>, yong <yong@shell.com> wrote:
>If I have both "a.txt" and "b.txt" in my current directory, what does
>the following script print?
>----------------------------------------
>#!perl -w
>
>opendir TMP, "." or die "Can't open: $!";
>($myfile)=grep /.*?\.txt/, readdir TMP;
>close TMP;
>print "The file is: $myfile.\n";
>----------------------------------------
>Here's the output before and after I renamed the files:
>----------------------------------------
[snip]
>Initially I thought readdir picks the first file according to "sort by
>name", but it doesn't look like so.
readdir returns file names in whatever order the underlying file system
supplies them (which is typically no order at all). If you want a sorted
list, you have to do it yourself:
opendir(DIRECTORY, ".") || die "Can't open directory: $!\n";
@textfiles = sort grep { /\.txt$/ } readdir DIRECTORY;
closedir(DIRECTORY);
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: 01 Oct 1998 13:55:03 -0400
From: Uri Guttman <uri@camel.fastserv.com>
To: yong <yong@shell.com>
Subject: Re: readdir in what order?
Message-Id: <saru31orwug.fsf@camel.fastserv.com>
>>>>> "y" == yong <yong@shell.com> writes:
y> If I have both "a.txt" and "b.txt" in my current directory, what
y> does the following script print?
y> ---------------------------------------- #!perl -w
y> -------------------------------------- Initially I thought readdir
y> picks the first file according to "sort by name", but it doesn't
y> look like so. I searched the newsgroup and found somebody has the
y> same problem (his message reported a problem at
y> http://midifest.com/MIDIFest/PopRock/).
readdir does not sort the files it reads from the dir. you have to call
sort yourself to to that. file globbing <*.txt> generally does sort
files since it uses csh to to the file matching and that sorts its
results.
hth,
uri
--
Uri Guttman Fast Engines -- The Leader in Fast CGI Technology
uri@fastengines.com http://www.fastengines.com
------------------------------
Date: Thu, 1 Oct 1998 09:18:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Rotating an array.
Message-Id: <MPG.107d4b1bb2e5a69798988f@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <x3yu31omjbp.fsf@tigre.matrox.com> on 01 Oct 1998 10:46:02 -
0400, Ala Qumsieh <aqumsieh@tigre.matrox.com> says...
...
> > >The problem is this: Given an array A of n elements, how do you most
> > >efficiently construct a new array B containing the same elements, but
> > >rotated so that B[0] = A[n-m], B[1] = A[n-m+1] ... B[m] = A[n]?
...
> how about
>
> @B = reverse @A;
You are the first one who has found a 'reverse' in this problem. For all
values of n and m, B[1] is the value in A[] *after* the element whose
value goes into B[0], etc.
As has been demonstrated, the appropriate tool if 'splice'.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 1 Oct 1998 12:11:10 -0400
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: scope question
Message-Id: <6v09iu$8eu$1@pilot.njin.net>
Hello -
Ian Lowe <Ian_Lowe@fanniemae.com> writes:
>Are variables in Perl, by default local to a loop? The following piece
No.
>of code that I have been working on has been confusing me to no end!
>open(DF,"/usr/ucb/df -Fufs | grep -v Filesystem |");
> while (<DF>) {
> chop;
> ($size,$capacity) = (split(/\s+/))[1,4];
> $size = "$size" / 1000;
> %FSSIZE = ("$size","$capacity");
>}
>foreach $key (keys (%FSSIZE)) {
> print "at $key we have $FSSIZE{$key}\n";
>}
>This will NOT print out the hash keys and value correctly. However, if
>I nest the foreach loop within the while loop, it does. Why is this?
>Do I need to predeclare the variables as globals somehow? If so, how?
Here's what's happening:
Each time through the while loop, you are assigning new values to the
entire hash, clobbering whatever was in the hash before. (And what's
with those quotation marks?)
Therefore, once you reach the foreach, %FSSIZE contains one key/value
pair (and maybe not a terribly useful one, even, if there's an extra
newline at the end of your input file).
You need to store key/value pairs in the hash as you go along.
my %FSSIZE = ();
while (<DF>) {
chomp;
my ($size,$capacity) = (split(/\s+/))[1,4];
$size = $size / 1000;
$FSSIZE{$size} = $capacity;
}
foreach my $key (keys (%FSSIZE)) {
print "at $key we have $FSSIZE{$key}\n";
}
(Could be further refined, but that should help.)
David Black
dblack@pilot.njin.net
------------------------------
Date: Thu, 01 Oct 1998 20:14:11 +0200
From: Michael Hallgren <hallgren+-no-spam-+@fdn.org>
To: Aahz Maruch <aahz@netcom.com>
Subject: Re: Simple database recommendation needed
Message-Id: <3613C673.4549A05C@fdn.org>
Aahz Maruch wrote:
> In article <36116018.38991FDC@harris.com>,
> Charlie Davies <cdavies@harris.com> wrote:
> >
> >I am working on an UNIX based application where I need a simple
> >database. I was looking for a recommendation from this group.
> >
> >The database will be fairly small 20K-40K records. Each record would
> >have 3 text fields, each containing 50-60 characters. During a normal
> >session, I will have to open the DB, find a given record, update its
> >content, and close the DB.
>
> I remember seeing a recent announcement for a SQL database implemented
> entirely in Perl, but I can't find it again. Anyone else remember it?
Yes, search for Sprite.
Cheers
Michael
>
>
>
> --
> --- Aahz (@netcom.com)
>
> Hugs and backrubs -- I break Rule 6 <*> -=> http://www.rahul.net/aahz
> Androgynous poly kinky vanilla queer het
>
> Zippergate: if they can get you asking the wrong questions, they don't
> need to worry about the answers. Shut up, already!
>
------------------------------
Date: Thu, 1 Oct 1998 06:55:46 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Some kind of 'real' user interface?
Message-Id: <2kqvu6.h1a.ln@flash.net>
David (david@nospam.port80.com) wrote:
: I'm trying to work out how I can add some kind of 'graphical
: interface' to my Perl programs running under NT.
: Does anyone have any advice as to what modules to use for
: this kind of thing?
use Tk;
: thanks for any help
Also use www.dejanews.com or similar to check out the postings
to comp.lang.perl.tk
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 1 Oct 1998 17:19:04 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
Subject: Re: Stock paging, anyone seen this script?
Message-Id: <6v0di8$cmr4@eccws1.dearborn.ford.com>
In article <8cyar08der.fsf@gadget.cscaper.com>,
Randal Schwartz <merlyn@stonehenge.com> writes:
>>>>>> "Michal" == Michal Rutka <erhmiru@erh.ericsson.se> writes:
>
>Michal> perl -ne 's/<.*?>//g;print;'
>
>Or
>
> perl -pe 's/<.*>//'
>
>unless you feel like typing a lot. :)
This should probably be:
perl -pe 's/<.*?>//g'
Leaving out the '?' makes it a little TOO agressive.
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: Thu, 01 Oct 1998 18:44:30 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Stock paging, anyone seen this script?
Message-Id: <8cbtnw86lu.fsf@gadget.cscaper.com>
>>>>> "Michal" == Michal Rutka <erhmiru@erh.ericsson.se> writes:
Michal> perl -ne 's/<.*?>//g;print;'
Or
perl -pe 's/<.*?>//'
unless you feel like typing a lot. :)
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3867
**************************************