[22776] in Perl-Users-Digest
Perl-Users Digest, Issue: 4997 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 17 00:05:46 2003
Date: Fri, 16 May 2003 21:05:10 -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 Fri, 16 May 2003 Volume: 10 Number: 4997
Today's topics:
Re: A script that can (conditionally) return 3 differen <michael.p.broida@boeing.com>
Re: A script that can (conditionally) return 3 differen <jurgenex@hotmail.com>
Re: concise code competition (Sara)
Re: Exporter not doing what I expect <michael.p.broida@boeing.com>
Re: Exporter not doing what I expect <noreply@gunnar.cc>
Re: fchown and fchmod (Jason McManus)
Re: fchown and fchmod (Sara)
Re: fchown and fchmod <rick.delaney@rogers.com>
Re: Help!: Hash or Array in this Situation? <bkennedy@hmsonline.com>
Re: Help!: Hash or Array in this Situation? (entropy123)
Re: Memory problem ctcgag@hotmail.com
Re: multiple sorts on an array ctcgag@hotmail.com
Re: No data entering @array from open(DATA...) <sammie@greatergreen.com>
OK, poll-time who is going to OSCON?? (Sara)
Re: possible bug in m// ? <stevenm@bogus.blackwater-pacific.com>
Re: possible bug in m// ? <abigail@abigail.nl>
Re: possible bug in m// ? <jurgenex@hotmail.com>
Re: Splitting, Sorting, then Rebuilding an Array <sammie@greatergreen.com>
Re: strange behaviour of Tk::getOpenFile (Zhao Wu)
Visual Basic Conversion to Perl.... Thunder9_NOSPAM@dsemail.net
Re: Visual Basic Conversion to Perl.... <krahnj@acm.org>
Re: Why do I get double line feeds ctcgag@hotmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 16 May 2003 22:13:19 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: A script that can (conditionally) return 3 different exit codes
Message-Id: <3EC5627F.E17BC1EB@boeing.com>
A Epstein wrote:
>
> Brian McCauley <nobull@mail.com> wrote in message news:<u93cjeg6md.fsf@wcl-l.bham.ac.uk>...
> > epstein_asaf@emc.com (A Epstein) writes:
> >
> > > I have to write a script that exists with exit code 0 on success, exit
> > > code 1 on a user interactivity error (such as misspelling a word), and
> > > exit code 2 if there is a system error that causes the script to fail.
> > > The first two codes (0, 1) are easy. I just check if the user makes a
> > > mistake and exit with 1. Otherwise it will exit with 0. But what
> > > about the exiting with code 2 if there is a system problem?
> >
> > I'm not sure I understand what you are asking. If indeed you are
> > asking anything.
> >
> > The exit code from perl in the event of abnornal termination is as
> > described in 'perldoc -f die'.
>
> Wow you guys! That was indeed humiliating. I am perfectly aware of
> how to write 'exit 2' and of the die function, the $! $? special
> variables and much more. all i wanted to know is how to determine of
> indeed i am in a situation were 'exit 2' is needed. In other words,
> has there been an error that would require me to exit with this code.
> I mean do I just have to go through my code and add a bunch of 'or die
> "..."' statements to every place I can concieve a failure might
> happen?
> Maybe this is all silly but the fact remains:
> I need to:
> exit 0 if all goes well,
> exit 1 if user makes a mistake,
> exit 2 if something is wrong, system-wise, that causes a failure.
Hmm, maybe what you're looking for could be dealt with in some
kind of "sig handler"?? That might catch a few "system" errors.
Look up "signals" or related terms.
Other than that, your code (meaning "YOU") is what has to decide
which value to return. You have to write code that will identify
the various situations and return the correct value. If your
code can't "see" the problem, it can't return any value indicating
the problem.
At the point in your code where YOU have determined that, yes,
"something is wrong, system-wise, that causes a failure", put
in an "exit 2" or setup a value of "2" in a flag to return
later via an exit statement. You don't -have- to use "die"
to get out of error situations. I usually print out my own
error message (perhaps including $!) and do whatever cleanup
I have to do (final writes to some file?) before I exit with
an appropriate error code.
If the "something is wrong" is not catchable by your Perl code,
Perl may already have crashed out and can't return ANY error
code, anyway. :)
It didn't look to me like the other responders were really
putting you down; it's just that your question didn't seem
to make sense. <grin> It sounded like you wanted them to
tell you what the conditions were that would make you return
a value of "2".
Mike
------------------------------
Date: Sat, 17 May 2003 03:12:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: A script that can (conditionally) return 3 different exit codes
Message-Id: <sMhxa.35149$Ur1.25183@nwrddc03.gnilink.net>
A Epstein wrote:
> Maybe this is all silly but the fact remains:
> I need to:
> exit 0 if all goes well,
> exit 1 if user makes a mistake,
> exit 2 if something is wrong, system-wise, that causes a failure.
Well, the problem is what exactly do you mean by
"something is wrong, system-wise, that causes a failure".
This you have to define, we can't help you with that because it depends on
your program and its expected behaviour.
Example 1: If a configuration file that is required for your program to work
cannot be found arguably this would qualify a system error.
Example 2: If the user enters a file name and this file cannot be found is
this a user error or do you consider this a system error?
Example 3: What about if the same file cannot be written because the user
removed the write permission. User or system error?
Example 4: Some file cannot be downloaded from the web because the user is
not connected to the Internet. Is that a user error or a system error for
your application? What about if he doesn't even have a modem (or
LAN/DSL/....)?
Those question you have to ask and then to answer yourself. We cannot know
what your (or your bosses) concept of system error versus user error is.
jue
------------------------------
Date: 16 May 2003 19:46:18 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: concise code competition
Message-Id: <776e0325.0305161846.41c0ff0f@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<ba385i$853$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Sara:
>
> > "joeri" <jvandervloet@hotmail.com> wrote in message news:<CD2xa.4452$1u5.337@afrodite.telenet-ops.be>...
>
> >> opendir(DIR, $dir="c:/dir") or die "$!";
> >> mkdir("$dir/output");
> >>
> >> for(grep(/\.txt$/, readdir(DIR))) {
> >> open(FILE, "$dir/$_") or die "$!";
> >> $out = "$dir/output/$_";
> >> open(OUT, ">$out") if !-e $out || -z $out;
> >> for(@strings=<FILE>) {
> >> $_ =~ s/=/\n/g;
> >> print OUT;
> >> }
> >> close OUT;
> >> close FILE;
>
> > Reconsider your use it quotes. Anytime you see
> >
> > "$var"
> >
> > an alarm should go off in your, better written of course as
> >
> > $var
>
> True.
>
> > Also, parens are nearly always optional, and it makes the program LESS
> > readable.
> >
> > mkdir("$dir/output");
> >
> > better written as mkdir $dir.'/output';
>
> And even better written as
>
> mkdir "$dir/output";
>
> Implicit concatenation through interpolation within strings is more
> readable, IMO. And it could be further improved yet:
>
> mkdir "$dir/output" or error_handling($!);
>
> :-)
>
> > perhaps? Another idiom that should set off alarms?
> >
> > if (!something);
> >
> > better written as
> >
> > unless $something;
>
> Debatable. This is not necessary more readable for everyone. For me,
> being a non-native speaker of English, it is not so I'd always prefer
> the first. I'd leave such things up to personal preferences.
>
> Tassilo
Hello Tassilio:
Understood- probably injected too much of my personal preferences.
-Gx
------------------------------
Date: Fri, 16 May 2003 21:56:31 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Exporter not doing what I expect
Message-Id: <3EC55E8F.EB6DB193@boeing.com>
Gunnar Hjalmarsson wrote:
>
> Michael P. Broida wrote:
> > Jay Tilton wrote:
> >> "Michael P. Broida" <michael.p.broida@boeing.com> wrote:
> >>
> >> : use vars qw($VarONE, $VarTWO); # Next line didn't work
> >> without this one
> >>
> >> Is there a reason to prefer "use vars" over "our"?
> >
> > Nope. I did this before I heard of "our". And it wouldn't let me
> > add the variables to EXPORT_OK or EXPORT until I added the "use
> > vars" line first. If "our" is better (and another poster indicated
> > so), then I'll try changing that.
>
> "our" is _shorter_ than "use vars"...
>
> If you want your program to be able to be run with Perl versions older
> than 5.6.0, you _must_ use "use vars". I always use "use vars" as soon
> as portability is an issue.
I'm on Perl 5.6.0 here, and I don't think this tool will
ever go to an OLDER Perl. But ya just never know...
As long as "shorter" is the only real advantage (assuming
you mean only "fewer characters to type"), I will probably
just stick with "use vars" for that particular item.
I think I do need to use "our" for the Exporter variables,
though. It works with that combination, anyway. :)
Thanks!
Mike
------------------------------
Date: Sat, 17 May 2003 00:39:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Exporter not doing what I expect
Message-Id: <ba3pbj$ob2um$1@ID-184292.news.dfncis.de>
Michael P. Broida wrote:
> Gunnar Hjalmarsson wrote:
>> "our" is _shorter_ than "use vars"...
>>
>> If you want your program to be able to be run with Perl versions
>> older than 5.6.0, you _must_ use "use vars". I always use "use
>> vars" as soon as portability is an issue.
>
> I'm on Perl 5.6.0 here, and I don't think this tool will ever go to
> an OLDER Perl. But ya just never know...
>
> As long as "shorter" is the only real advantage (assuming you mean
> only "fewer characters to type"), I will probably just stick with
> "use vars" for that particular item.
Well, that is what I mean, and that is the only difference I'm aware
of (which doesn't guarantee that there isn't anything else...). Maybe
somebody can fill in here.
> I think I do need to use "our" for the Exporter variables, though.
No, you don't. You can do
use vars qw($VarONE $VarTWO);
or
use vars '$VarONE', '$VarTWO';
Actually, if you want to take into consideration the portability
aspect I mentioned, you need to ensure that "our" isn't used anywhere
in your program, or else it won't compile in Perl versions < 5.6.0.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 16 May 2003 18:02:48 -0700
From: google@sleepdep.net (Jason McManus)
Subject: Re: fchown and fchmod
Message-Id: <50481f2e.0305161702.2ce6d254@posting.google.com>
Rick Delaney <rick.delaney@rogers.com> wrote in message news:<m34r3umtuw.fsf@biff.bort.ca>...
> google@sleepdep.net (Jason McManus) writes:
>
> > Greetings all,
> >
> > I am really disturbed by the lack of existence of fchmod and fchown in
> > perl.
>
> perldoc -f syscall
That's great and all, and that's exactly how I implemented it, but
that does not address the lack of portability issue that I was
referring to. The fact that one has to write several dozen lines of
code to make their program portable (i.e. checking the syscall number,
using file descriptor pointers, etc.), whereas it could be easily
implemented directly in the chown()/chmod() functions (mirroring the
behaviour of perl's stat() by accepting filenames OR filehandles) is
the problem.
------------------------------
Date: 16 May 2003 19:54:55 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: fchown and fchmod
Message-Id: <776e0325.0305161854.78e749c9@posting.google.com>
Rick Delaney <rick.delaney@rogers.com> wrote in message news:<m34r3umtuw.fsf@biff.bort.ca>...
> google@sleepdep.net (Jason McManus) writes:
>
> > Greetings all,
> >
> > I am really disturbed by the lack of existence of fchmod and fchown in
> > perl.
>
> perldoc -f syscall
That's a copout, and poor advice. We all know that syscalls are
discouraged and basically a last resort. I can't recall the last time
I used one - maybe 5 years ago (1,000,000 lines ago?)....
I suggest you check CPAN?
File PINYAN File-chmod-0.31.tar.gz 8k 27 Jul
1999
-Gx
------------------------------
Date: Sat, 17 May 2003 03:46:17 GMT
From: Rick Delaney <rick.delaney@rogers.com>
Subject: Re: fchown and fchmod
Message-Id: <m3znlmkzg7.fsf@biff.bort.ca>
google@sleepdep.net (Jason McManus) writes:
> Rick Delaney <rick.delaney@rogers.com> wrote in message news:<m34r3umtuw.fsf@biff.bort.ca>...
> > google@sleepdep.net (Jason McManus) writes:
> >
> > > Greetings all,
> > >
> > > I am really disturbed by the lack of existence of fchmod and fchown in
> > > perl.
> >
> > perldoc -f syscall
>
> That's great and all, and that's exactly how I implemented it, but
> that does not address the lack of portability issue that I was
> referring to. The fact that one has to write several dozen lines of
> code to make their program portable (i.e. checking the syscall number,
> using file descriptor pointers, etc.), whereas it could be easily
> implemented directly in the chown()/chmod() functions (mirroring the
> behaviour of perl's stat() by accepting filenames OR filehandles) is
> the problem.
I don't understand what you mean by "portability" here. Either an OS has
fchown or it doesn't. Still, I agree it would be nice if
chown $uid, $gid, $fh;
called fchown when $fh is a filehandle. But I only see it using fchown
if you have it so it will be no more portable than the syscall. Unless
you're suggesting the perl porters write their own fchown that works
everywhere.
Patches welcome either way.
Not sure where "several dozen lines of code" comes from either.
require 'syscall.ph';
syscall(&SYS_fchown, fileno($fh), $uid, $gid) == 0
or die "chown: $file: $!";
versus
chown($uid, $gid, $fh) or die "chown: $file: $!";
--
Rick Delaney
rick.delaney@rogers.com
------------------------------
Date: Fri, 16 May 2003 18:42:10 -0400
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Help!: Hash or Array in this Situation?
Message-Id: <WnKdnWjYC5ni9FijXTWcpg@giganews.com>
"entropy123" <email_entropy123@yahoo.com> wrote in message
news:90cdce37.0305151926.6fc3bbfc@posting.google.com...
> Any suggestions as to good bookeeping? I'm thinking I need to generate
> a list of arrays to iterate - push through a compare subroutine -
> through and compare each array to every other array (not too good with
> the logical statements yet...)
>
> My array names are something like name123 name122 name231 and so
> on...its very hard to keep track... :) At least I figured out how to
> make arrays on the fly...
>
> ...
>
> $angel = $first . $through . $pass . $pass2;
> # print "angel: $angel\n";
> push (@{ $angel}, $first);
> push (@{ $angel}, $second);
> push (@{ $angel}, $third);
> push (@{ $angel}, $four);
This is called using soft references. Nearly every time you want to use
soft references, you are better off using a hash.
> #my %remem;
> #my ( $first, @memory ) = split; # Split $_ on white space
> #push @{ $remem{ $first}}, @memory; # Just push, it'll spring
> into existence
This is getting closer - however, you are declaring %remem within the
inner-most loop - this initializes it every time only for that block. You
will want to move "my %remem" to before you start iterating. You should
definitely look into using 'strict' which will help debug code like this
(perldoc strict), and check out "perldoc perlref" and "perldoc perldsc" for
some tutorials on building complex data structures using references.
Another thing you could investigate is the "next" flow control operator.
You can reduce the number of indents, e.g.:
for $four ( keys %{ $supha{$third} } ) {
$pass2 +=1;
if ($four ne $second) {
next; # skip to next key
}
# continue processing (one less indent)
print "...\n";
}
--Ben Kennedy
------------------------------
Date: 16 May 2003 20:15:02 -0700
From: email_entropy123@yahoo.com (entropy123)
Subject: Re: Help!: Hash or Array in this Situation?
Message-Id: <90cdce37.0305161915.4125aefa@posting.google.com>
Another question,
How do I get Perl to 'ignore' the fact that the hash has a reference
to the first node
C1-C2-C3 so when I check C3 it finds C2 which is of course bonded to
C1....I'm telling it to do nothing if C2 = C1, so my routine always
finds a ring at C3 even though there is not one....In other words, how
do I make this routine 'directional'?
Thanks ,
entropy
------------------------------
Date: 16 May 2003 23:27:03 GMT
From: ctcgag@hotmail.com
Subject: Re: Memory problem
Message-Id: <20030516192703.847$A9@newsreader.com>
"Allanon" <allanon@hotmail.com> wrote:
>
> foreach(@logdir)
> {
> @logs = <$_/LISTSERV-20030211*>;
> foreach $l(@logs)
> {
> open(LOG,$l); @lines = <LOG>; close(LOG);
> foreach $line(@lines)
> {
> }
> }
> }
>
> I watched the memory usage for perl.exe shoot up to over 200MB and it was
> still increasing before I killed it. So, why one earth does perl.exe
> require that much memory just to slurp a 39MB file into an array?
Magic isn't free.
But it only took 80 MB to do it on my box (perl 5.6.0 on Linux),
which is about what I thought it would.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: 16 May 2003 23:45:32 GMT
From: ctcgag@hotmail.com
Subject: Re: multiple sorts on an array
Message-Id: <20030516194532.380$8V@newsreader.com>
dontsendjunk@mailcity.com wrote:
> I was trying to interactively group the contents of an array based on
> pattern match and sort operation. for eg if the array is
> aabbcc
> aaefgh
> aaghe
> aafftr
> abbef
> abbec
> afgcc
> abcc
>
> the patterns given interactively by me would be something like
> first pattern \baa
> sort
> second pattern \ba.*bb
> sort
> third pattern \ba.*cc
> sort
> and the final expected result is
>
> aabbcc
> aaefgh
> aaghe
> aafftr
> abbef
> abbec
> aabbcc
> afgcc
> abcc
This seems to be an exceptionally poor example. An example should
demonstrate what you are trying to do, not obscure it.
> The actual codefragement use is at the end of this post
> is there a way to retain previously sorted part of the array without
> using a second array? or is grep the only way to go?
I'd probably use a hash:
my %hash; @hash{@things}=();
@things=();
while (my $pattern=<STDIN>) {
foreach (keys %hash) {
if (/$pattern/) {
push @things, $_;
delete $hash{$_};
};
};
};
push @things,keys %hash; # Put non-matchers back at the end.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Sat, 17 May 2003 00:36:28 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: No data entering @array from open(DATA...)
Message-Id: <gufxa.861957$3D1.491670@sccrnsc01>
> my @currplids = (<CPDATA>);
Yes, this is much better, and works fine for what I was trying to do.
Thanks!
Brad
------------------------------
Date: 16 May 2003 19:49:29 -0700
From: genericax@hotmail.com (Sara)
Subject: OK, poll-time who is going to OSCON??
Message-Id: <776e0325.0305161849.17e67d48@posting.google.com>
I haven't missed one in years but guess what- the company is too broke
this year to send me :((( Can't complain they've been very good about
letting me go to Monterray and SD.
Anyhow- who is going and what are your favorite topics?
-Gx
------------------------------
Date: Fri, 16 May 2003 19:40:42 -0700
From: Steve May <stevenm@bogus.blackwater-pacific.com>
Subject: Re: possible bug in m// ?
Message-Id: <ba473d$841$1@quark.scn.rain.com>
dan baker wrote:
> I am attempting to catch illegal formats for zip codes, and think I
> have a bug in the "exact number of times" part of regex. the snippet
> is:
>
> unless ( ($MemberZip =~ m/\d{5}/) or ($MemberZip =~ m/\d{5}\-\d{4}/))
> {
> $FormErrorMsg .= " \n<li> Zip must be either 5 digit, or 5+4 format."
> }
>
> What is happening is that values with more than 5 digits are passing
> right thru without getting caught. Am I doing something wrong with
> regex or is this a bug? Running perl 5.00503 from activestate on
> windows98.
>
>
> D
In addition to the other posts, be aware that some countries include
letters in their postal codes.
Not that that has anything to do with Perl....
s.
------------------------------
Date: 17 May 2003 02:47:22 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: possible bug in m// ?
Message-Id: <slrnbcb8lp.mth.abigail@alexandra.abigail.nl>
dan baker (botfood@yahoo.com) wrote on MMMDXLV September MCMXCIII in
<URL:news:13685ef8.0305161231.2c4bae1d@posting.google.com>:
;; I am attempting to catch illegal formats for zip codes, and think I
;; have a bug in the "exact number of times" part of regex. the snippet
;; is:
;;
;; unless ( ($MemberZip =~ m/\d{5}/) or ($MemberZip =~ m/\d{5}\-\d{4}/))
;; {
;; $FormErrorMsg .= " \n<li> Zip must be either 5 digit, or 5+4 format."
;; }
;;
;; What is happening is that values with more than 5 digits are passing
;; right thru without getting caught. Am I doing something wrong with
;; regex or is this a bug? Running perl 5.00503 from activestate on
;; windows98.
Your perception is wrong. /\d{5}/ will match any string that contains
5 digits in a row. A string consisting of 6 digits will contain 5 in
a row, and hence it matches. If you want to match exactly 5 digits,
use anchors: /^\d{5}$/.
For zip codes, you could also use Regexp::Common:
use Regexp::Common qw /zip/;
unless ($MemberZip =~ /^$RE{zip}{US}$/) {
....
}
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
------------------------------
Date: Sat, 17 May 2003 03:21:36 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: possible bug in m// ?
Message-Id: <4Vhxa.35183$Ur1.22282@nwrddc03.gnilink.net>
dan baker wrote:
> I am attempting to catch illegal formats for zip codes, and think I
> have a bug in the "exact number of times" part of regex. the snippet
> is:
>
> unless ( ($MemberZip =~ m/\d{5}/) or ($MemberZip =~ m/\d{5}\-\d{4}/))
> {
> $FormErrorMsg .= " \n<li> Zip must be either 5 digit, or 5+4 format."
> }
>
> What is happening is that values with more than 5 digits are passing
> right thru without getting caught. Am I doing something wrong with
> regex or is this a bug? Running perl 5.00503 from activestate on
> windows98.
Well, the string "1234567890" contains surely 5 digits, doesn't it? It also
contains 2, 8, 4, or even 10 digits for that matter.
So your RE /\d{5}/ will match the first part "12345" already and happily
return a successful match.
It would also match the part "23456" or "34567" or ... .
If you don't want any additional digits then you need to say so, by e.g.
anchoring the beginning and/or end or by specifying that the next character
should not be digit or similar means.
jue
jue
------------------------------
Date: Sat, 17 May 2003 00:18:57 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: Splitting, Sorting, then Rebuilding an Array
Message-Id: <Rdfxa.861828$3D1.490769@sccrnsc01>
> Now it's already looking like good c-code.
> Now, we only have to make it Perlish,
> so let's shorten again :-)
Works well so far. Still running tests, but I think it's fine.
Severely condensed code:
----
sub update_archive {
#Grab session variables
my (@newsess,$n);
my @currentsess = split /\t/, $adddata;
my @oldsess = split /\t/, $updatedata;
#Increment archive data with new data
@newsess[0..5,7,33] = @currentsess[0..5,7,33];
@newsess[6,8..30,34..36] = map {$oldsess[$_] + $currentsess[$_]}
(6,8..30,34..36);
@newsess[31,32] = map {$currentsess[$_] || $oldsess[$_]} (31,32);
#Format info for return to archive db
push @updatearchive, join "\t", @newsess[0..36];
}
----
Looks real purty now :-) Thanks again! I am amazed at how helpful some of
the people are on this forum. Someday maybe I can be of help too...
Cheers,
Brad
------------------------------
Date: 16 May 2003 15:51:48 -0700
From: zhao_wu@pmc-sierra.com (Zhao Wu)
Subject: Re: strange behaviour of Tk::getOpenFile
Message-Id: <8ec9eeab.0305161451.69f00145@posting.google.com>
Eric Moors <scare.crow@oz.land> wrote in message news:<pan.2003.05.16.16.05.04.613889.26636@oz.land>...
> I have a weird problem when I use Tk::getOpenFile
>
> It's possible to specify a initial directory where the file search
> starts, but I cannot get this option to work correctly. A window pops up,
> starting in the root directory of my machine. If I now press <cancel> and
> press the button that executes getOpenFile() again, it is in the correct
> directory, although the box(?) at the top still displays the wrong path
> (just a plain /). (getSaveFile displays the same erroneous behaviour)
>
> I'll include the code that shows this behaviour on my machine.
> If anyone knows what's wrong, or knows a work-around, please let me know.
>
> Eric
>
> ######### program start #############################
> use strict;
> use warnings;
> use Tk;
>
> my $mw = new MainWindow(-title => "a simple GUI");
>
> rootWindow();
> MainLoop;
>
> sub rootWindow {
> # first we create an input frame
> my $in_frame = $mw->Frame;
> my $in_label = $in_frame->Label(
> -text => "Select an input file: ",
> -anchor => 'e'
> );
> my $in_entry = $in_frame->Entry(
> -width => 20
> );
> my $in_button = $in_frame->Button(
> -text => "Browse ...",
> -command => sub { fileDialog($in_entry) }
> );
> $in_label->pack(-side => 'left');
> $in_entry->pack(-side => 'left',-expand => 'yes', -fill => 'x');
> $in_button->pack(-side => 'left');
> $in_frame->pack(-fill => 'x', -padx => '1c', -pady => 3);
> }
>
> sub fileDialog {
> my $in_entry = shift;
> my @types =
> (["video files", [qw/.mpg .mpeg .avi/]],
> ["All files", '*']
> );
>
> my $file = $mw->getOpenFile(-initialdir => '/mnt/disc2/video',
> -filetypes => \@types,
> -initialdir => '/mnt/disc2/video',
> -title => 'Select an input file');
>
> if (defined $file and $file ne '') {
> $in_entry->delete(0, 'end');
> $in_entry->insert(0, $file);
> $in_entry->xview('end');
> }
> }
>
> __END__
> ######### program end #############################
This seems to be a known bug with perl5.6.1 + Tk800.023 (see my post a
few days ago on getSaveFile(). Slaven said that the bugs have been
fixed in perl5.8 + Tk800.024, but I haven't tried.
------------------------------
Date: Fri, 16 May 2003 23:04:25 GMT
From: Thunder9_NOSPAM@dsemail.net
Subject: Visual Basic Conversion to Perl....
Message-Id: <kkracvso0oapll1rc4tbsa9b62rg0nsgp3@4ax.com>
I need to convert a VB program I just wrote into perl. If you have a
minute could you please look at the section of code below and give me
a pointer on just *one* (or more if you want) item?
The following are the constructs I need to imitate in perl in order to
do my conversion.... the Visual Basic has been dumbed-down a little
so don't rely on any of this for actual working code.
1. Structured Types
Dim MyObject as new MyType
MyObject.value1 = "Fred"
MyObject.value2 = "Barney"
2. Collections Object
A collections object that you can add structured types to, with a hash
value. (All hash values are guaranteed unique so I don't need to
managage collisions). Example
Dim Col as new collection
Dim hashvalue as string
Dim MySecondObject as MyType
hashvalue = MyObject.value1
if Col.exists(hashvalue) then
MySecondObject = Col.Lookup(hashvalue)
else
Col.AddItem(MyObject, hashvalue)
endif
3. File Handling FindFirst and FindNext
Search a single level directory using FindFirst and FindNext as
follows:
hFile = FindFirstFile("C:\*.*", wfd)
While hFile <> INVALID_HANDLE
If IsDirectory(wfd) Then
' Directory Processing
Else
' File Processing
End If
FindNextFile(hFile, wfd)
Wend
4. Other File Handling:
4.1 Get last modified date of a file
4.2 Test if file exists based on full path
5. String Functions:
5.1 Test for Match against Regular Expression
5.2 Emulate Instr, Left$, Right$, and Mid$ functions.
5.3 Concatenate Strings
5.4 Assignment to a variable based on a reg expression match within
another string
5.5 Convert to upper case.
7. Modular Design
7.1 Functions with parameters
7.2 Recursion
7.3 Return Values
7.4 Local Variables
Thanks...
NOSPAM is antispam
------------------------------
Date: Sat, 17 May 2003 03:08:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Visual Basic Conversion to Perl....
Message-Id: <3EC5A765.1C7F8345@acm.org>
Thunder9_NOSPAM@dsemail.net wrote:
>
> I need to convert a VB program I just wrote into perl. If you have a
> minute could you please look at the section of code below and give me
> a pointer on just *one* (or more if you want) item?
>
> The following are the constructs I need to imitate in perl in order to
> do my conversion.... the Visual Basic has been dumbed-down a little
> so don't rely on any of this for actual working code.
>
> 1. Structured Types
>
> Dim MyObject as new MyType
> MyObject.value1 = "Fred"
> MyObject.value2 = "Barney"
>
> 2. Collections Object
>
> A collections object that you can add structured types to, with a hash
> value. (All hash values are guaranteed unique so I don't need to
> managage collisions). Example
>
> Dim Col as new collection
> Dim hashvalue as string
> Dim MySecondObject as MyType
>
> hashvalue = MyObject.value1
> if Col.exists(hashvalue) then
> MySecondObject = Col.Lookup(hashvalue)
> else
> Col.AddItem(MyObject, hashvalue)
> endif
perldoc perldata
perldoc perldsc
perldoc perllol
> 3. File Handling FindFirst and FindNext
>
> Search a single level directory using FindFirst and FindNext as
> follows:
>
> hFile = FindFirstFile("C:\*.*", wfd)
>
> While hFile <> INVALID_HANDLE
> If IsDirectory(wfd) Then
> ' Directory Processing
> Else
> ' File Processing
> End If
>
> FindNextFile(hFile, wfd)
>
> Wend
perldoc -f opendir
perldoc -f readdir
perldoc -f rewinddir
perldoc -f telldir
perldoc -f closedir
perldoc -f glob
> 4. Other File Handling:
> 4.1 Get last modified date of a file
> 4.2 Test if file exists based on full path
perldoc -f stat
perldoc -f lstat
perldoc -f -e
> 5. String Functions:
>
> 5.1 Test for Match against Regular Expression
> 5.2 Emulate Instr, Left$, Right$, and Mid$ functions.
> 5.3 Concatenate Strings
> 5.4 Assignment to a variable based on a reg expression match within
> another string
> 5.5 Convert to upper case.
perldoc perlre
perldoc perlop
perldoc -f index
perldoc -f rindex
perldoc -f substr
perldoc -f uc
> 7. Modular Design
>
> 7.1 Functions with parameters
> 7.2 Recursion
> 7.3 Return Values
> 7.4 Local Variables
perldoc perlsub
John
--
use Perl;
program
fulfillment
------------------------------
Date: 17 May 2003 00:01:29 GMT
From: ctcgag@hotmail.com
Subject: Re: Why do I get double line feeds
Message-Id: <20030516200129.144$W6@newsreader.com>
Bob Walton <bwalton@rochester.rr.com> wrote:
> Travis wrote:
>
> > print MEMCHK "$used_timein[$j]\n";
> >
> > I am writing to file and simply want to get each line with a single
> > line feed.
> >
> > For some reason I get the single line feed when I leave off the \n and
> > I get a double line feed when
> > I leave it in?
> >
> > Any ideas?
>
> Sure. Leave off the \n :-).
>
> You undoubtedly have a newline at the end of array element
> $used_timein[$j]. Perhaps you read it from a file and neglected to
> chomp it?
Well, there is at least a sliver of doubt that the elements have
line feeds on them. Maybe they don't but he's running perl -l.
But yeah, your explanation is the better bet.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
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 4997
***************************************