[18563] in Perl-Users-Digest
Perl-Users Digest, Issue: 731 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 20 18:10:45 2001
Date: Fri, 20 Apr 2001 15:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <987804615-v10-i731@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 20 Apr 2001 Volume: 10 Number: 731
Today's topics:
Perl Calendaring software -WWWsched <vrdoljak@uclink.berkeley.edu>
Re: PERL Code Generator <gellyfish@gellyfish.com>
Re: PERL Code Generator <mischief@velma.motion.net>
Re: Problem with associative array--what am I doing wro <krahnj@acm.org>
Re: regexp matching with optional part <ocschwar@mit.edu>
Re: Returning 2 arrays from a sub <mischief@velma.motion.net>
Searching a File for a string, displaying the reults <js@hotmail.com>
Re: Secure key generator/Algorithum <mischief@velma.motion.net>
Re: server timeout <mdt27@email.byu.edu>
Storable question alex@hoopsie2.com
Re: Things I'm just not getting in Perl <jesse@uchicago.edu>
Re: Things I'm just not getting in Perl (Damian Conway)
US$50 prize for hash failure from 'delete' inside an 'e <mjd@plover.com>
use of Perl, Was Re: Can't open file, dies gls@byu.edu
Re: use strict & require... <mnm@mnm.com>
Re: Why Perl? <gellyfish@gellyfish.com>
Win32::OLE problem -- command line vs. CGI <murthy@cox-internet.com>
YARQ (Yet another regex question) <nospam@hotmail.com>
Re: YARQ (Yet another regex question) <nospam@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 20 Apr 2001 14:09:40 -0700
From: Gordon Vrdoljak <vrdoljak@uclink.berkeley.edu>
Subject: Perl Calendaring software -WWWsched
Message-Id: <3AE0A594.55EC73A8@uclink.berkeley.edu>
Hello Everyone,
I've written some weekly calendaring software in Perl that may be of use in
laboratory facilities. We use it to schedule and monitor usage of our TEM. It
simulates the old sign up sheet on the wall idea, but on the web. It has
a modest amount of security to control which users can sign up onto the
schedule. It also keeps a searchable archive of your past schedules for
history and billing information.
I've tried to make the installation as automated as possible. You'll need
to have an account on a server where you can run cgi scripts, or your own
linux/sun/irix/windows nt server. You'll also need to have Perl installed
where you want the software to run. Please send me comments if you have
any difficulties with setting up or running the software. I'm at version
1.2 which hopefully shouldn't have too many bugs.
The link for the software is at:
http://wilfred.berkeley.edu/~gordon/www-sched
I ask for a small fee for our lab for the software which is explained on
the web page. I appreciate any comments on my programming - how it can be
improved, etc.
Gordon Vrdoljak.
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Gordon Ante Vrdoljak Electron Microscope Lab
ICQ 23243541 http://nature.berkeley.edu/~gvrdolja 26 Giannini Hall
gvrdolja@nature.berkeley.edu UC Berkeley
phone (510) 642-2085 Berkeley CA 94720-3330
fax (510) 643-6207 cell (510) 290-6793
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Gordon Ante Vrdoljak Electron Microscope Lab
ICQ 23243541 http://nature.berkeley.edu/~gvrdolja 26 Giannini Hall
vrdoljak@uclink.berkeley.edu UC Berkeley
phone (510) 642-2085 Berkeley CA 94720-3330
fax (510) 643-6207 cell (510) 290-6793
------------------------------
Date: 20 Apr 2001 21:01:03 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: PERL Code Generator
Message-Id: <9bq82f$sgo$2@uranium.btinternet.com>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> dynamic spam in many spammish languages such as
> Usenet, Email, Web Forums, Fax, Pager, and cellphone spam."
>
I'm sorry but if it can't do good old plain paper junk mail then I'm not
having anything to do with it - you're losing the old fire Randal ... :)
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Fri, 20 Apr 2001 22:01:23 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: PERL Code Generator
Message-Id: <te1cdjnm8tjd51@corp.supernews.com>
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Michael" == Michael Wenzelmaier <michaelw@elkhart.net> writes:
> Michael> "CodeCharge is a powerful code generator that helps web
> Michael> developers and non-programmers create database-driven web
> Michael> applications in a matter of hours. You may use it to easily
> Michael> create any types of web forms and grids, such us User
> Michael> Registration Form for the web site or an Event List, or you
> Michael> may generate full featured Employee Directories, Forums and
> Michael> Task Management Systems up to advanced Online Auctions,
> Michael> Stores, Portals and Intranets. In fact, CodeCharge comes with
> Michael> many of such solutions already pre-built and you may easily
> Michael> customize them to your needs. CodeCharge works by letting you
> Michael> select database fields to be included on each web page and
> Michael> specifying how they should interact. It then generates
> Michael> database-driven, dynamic websites in many server-programming
> Michael> languages such as ASP, ColdFusion, JSP, PHP and Perl."
> Michael> http://www.[deleted]/codecharge
> "SpamForCodeCharge is a powerful spam generator that helps
> WebProCenter and their marketeers create spam-driven Usenet postings
> in a matter of minutes. You may use it to easily create any types of
> Spam and Usenet Postings, such us [sic] Cash Diverter Form for the
> Usenet post or a rented Mailing List, or you may generate full
> featured Spam Lists, Forum Autoinserts, and Spamhauses. In fact
> SpamForCodeCharge comes with many of such mailing lists and newsgroups
> already prebuilt and you can easily customize them to your needs.
> SpamForCodeCharge works by letting you select names for database
> fields to be included in each spam page and specifying how you want
> the victim, er, customer to interact. It then generates
> database-driven, dynamic spam in many spammish languages such as
> Usenet, Email, Web Forums, Fax, Pager, and cellphone spam."
It even auto-generates and spams out excuses for you when you
bogart the potato salad, which is about as acceptable as spamming
anyway.
http://www.get.a.clue.com/bogart/potato-salad for details on this
wonderful new feature.
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Fri, 20 Apr 2001 20:47:00 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Problem with associative array--what am I doing wrong here?
Message-Id: <3AE0A052.7575B2D4@acm.org>
Bill Weissborn wrote:
>
> Let me start out by saying it has been awhile since I've used perl.....
>
> For the life of me, I can't figure out why this code is not working. I have
> an associative array and I want to see if a value, passed on the command
> line, is in the array. If found, then I want to do more processing based on
> that fact. However, it doesn't work UNLESS, I enter the value, via the
> debugger, manually into the variable $pooltouse. Is there something going
> on with the getopt() function?
>
> What am I doing wrong? Any thoughts, better-ways of doing this, etc would
> be greatly appreciated.
>
> Bill W.
>
> **** tape-pool file *****
> #...First field is 15chars in length, spaces used to pad string
> sybaseA ,004,003,007,001,002,0001
> sybaseB ,004,003,007,001,002,0001
> wcw ,001,999,999,001,002,0000
> dumps ,001,999,090,001,002,0000
> misc ,001,099,180,001,002,0000
> housekeeping ,001,999,365,001,002,0000
>
> **** tape-pool file end*******
>
> **** jukebox file *******
> 0,sybaseA.1,f
> 1,sybaseA.2,f
> 2,sybaseA.3,f
> 3,sybaseB.1,f
> 4,sybaseB.2,f
> 5,sybaseB.3,m
> 6,misc.1,f
> 7,empty,e
> ***** jukebox file end ******
>
> ******** Code start *************
> #!/usr/local/bin/perl
#!/usr/local/bin/perl -w
use strict;
> use Getopt::Std;
> use String::Strip;
> $usage_statement = "\nUsage statement:
my $usage_statement = "\nUsage statement:
> backitup -p<pool> -s<source> -d<destination> -t[tar or dump] -L<catalog>
> [-o<options> -c<cleanup script>]\n";
> $debug_on = 1;
my $debug_on = 1;
> #..Change these to fit your environment
> $masdir = "/sd6/tape-catalog";
> $tapedev = "/dev/rmt/0u";
> $nextvolume = "<file-spec of the next-volume-script>";
my $masdir = "/sd6/tape-catalog";
my $tapedev = "/dev/rmt/0u";
my $nextvolume = "<file-spec of the next-volume-script>";
> #..Get the job
> getopt('s:d:t:ho:c:L:p:');
> print "switch s = $opt_s\n" if $debug_on;
my %options;
getopt( 's:d:t:ho:c:L:p:', \%options );
print "switch d = $options{'d'}\n" if $debug_on;
...
> print "switch d = $opt_d\n" if $debug_on;
> print "switch t = $opt_t\n" if $debug_on;
> print "switch o = $opt_o\n" if $debug_on;
> print "switch c = $opt_c\n" if $debug_on;
> print "switch L = $opt_L\n" if $debug_on;
> print "switch p = $opt_p\n" if $debug_on;
> #..Process the options
> if ($opt_h)
> {
> die $usage_statement;
> }
> #...These parameters are mandatory
> if ($opt_s)
> {
> $source = $opt_s;
> }
> else
> {
> print "\nYou must specify what you want to back up...\n";
> die $usage_statement;
> }
> if ($opt_d)
> {
> $destination = $opt_d;
> }
> else
> {
> print "\nYou must specify where you want the back up to go...\n";
> die $usage_statement;
> }
> if ($opt_L)
> {
> $catalog_file = $opt_L;
> }
> else
> {
> print "\nYou must specify what catalog to update...\n";
> die $usage_statement;
> }
> if ($opt_p)
> {
> $pooltouse = $opt_p;
> }
> else
> {
> print "\nYou must specify what tape-label or pool you want to write
> too...\n";
> die $usage_statement;
> }
> #..These parameters are optional
> if ($opt_c)
> {
> $cleanup = $opt_c;
> }
> if ($opt_t)
> {
> #...Add some sanity checks so we don't end up with crap
> $backup_type = $opt_t;
> }
> else
> {
> $backup_type = "tar";
> }
> if ($opt_o)
> {
> $backup_options = $opt_o;
> }
> #.......Start crunching here
> #..Get the contents of tape-pool
> #...Open file for input
> %tpool = (); #...declare an associative array
my %tpool; #...declare a hash
> open(POOL, "<$masdir/tape-pool");
open POOL, "<$masdir/tape-pool" or die "Cannot open $masdir/tape-pool:
$!";
> while (<POOL>)
> {
> chop;
> ($poolname, $restofline) = split /,/,$_,2;
> $tpool{$poolname} = "$restofline";
chomp;
#...First field is 15chars in length, spaces used to pad string
my ( $poolname, $restofline ) = unpack 'A15 x A*', $_;
$tpool{ $poolname } = $restofline;
> }
> close (POOL);
> #..Get the contents of the jukebox
> $i=0;
> open(JBOX, "<$masdir/jukebox");
open JBOX, "<$masdir/jukebox" or die "Cannot open $masdir/jukebox: $!";
> while (<JBOX>)
> {
> chop;
> $jukebox[$i] = $_;
> $i++;
chomp;
push @jukebox, $_;
> }
> close (JBOX);
>
> #..This came from www.perldoc I think.
> for $item (%tpool)
my %foundit;
for my $item ( keys %tpool ) {
> {
> #..Strip off trailing spaces
> StripTSpace($item);
> print "item = $item..\n";
> print "pool = $pooltouse..\n";
> $foundit{StripTSpace($item)}++;
> }
>
> #..Now check to see if it is in the "authorized" pool
> #..BUT it never works!!!!
> if ( $foundit{$pooltouse} )
if ( exists $tpool{ $pooltouse } )
> {
> #...Then the value exists
> print "Continueing...\n";
> print "pooltouse = $tpool{$pooltouse}\n";
> }
> else
> {
> die "Pool/tape-label specified not found in the current list\n";
> }
>
> #..Is the tape/pool we want already loaded, i.e., in the jukebox?
>
> #....If Yes
> #.......Is the tape mounted on the tape-drive?
> #.......If not, then
> #..........Mount the tape
> #.......endif
> #........put the data to tape
> #.......not, then mount the tape
John
--
use Perl;
program
fulfillment
------------------------------
Date: 20 Apr 2001 17:50:12 -0400
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Re: regexp matching with optional part
Message-Id: <oct8zkv6y23.fsf@nerd-xing.mit.edu>
Ronald Fischer <ronald.fischer.gp@icn.siemens.de> writes:
> I'm trying to write a regexp matching which should cut off an optional leading
> "x-" or trailing "-x". the following cases:
>
> In any case, the extracted part (after cutting off the leader or trailer)
> should consist of at least one character; otherwise, the regexp should
> fail. Example:
>
> x-abc-x -> return abc
> x-foo -> return foo
> bar-x -> return bar
> baz -> return baz
> x--x -> fail
>
> Can this be done easily in a single regexp? The closest I came was
>
> /^(x-)?(.+?)(-x)$/
Not /^(x-)?(.+?)(-x)?$/ ?
--
Omri Schwarz ---
Timeless wisdom of biomedical engineering:
"Noise is principally due to the presence of the
patient." -- R.F. Farr
------------------------------
Date: Fri, 20 Apr 2001 20:47:05 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Returning 2 arrays from a sub
Message-Id: <te1829qeq01325@corp.supernews.com>
E.Chang <echang@netstorm.net> wrote:
> Bryan Coon <bcoon@sequenom.com> wrote in <3ADCBC27.E728B44B@sequenom.com>:
>>
>>Ian Howlett wrote:
>>
>>>
>>> use strict;
>>>
>>> sub getConfigInfo {
>>> my $sectionName;
>>> my @clientDirectories;
>>> my @serverDirectories;
> <code details snipped>
>>>
>>> return (\@clientDirectories, \@serverDirectories) ;
>>>
>>> } # end of getConfigInfo
>>>
>>> my @a;
>>> my @b;
>>>
>>>> Attempt to put the array values into @a and @b
>>> ($a, $b) = getConfigInfo() ;
>>>
>>
>>Don't forget to dereference here.....
>>i.e.
>>(@$a, @$b) = getConfigInfo();
>>
> You need to dereference, but not there. A test run with that modification
> would show there's no output for the array values. You need to dereference
> when attempting to actually use the array contents. Here's an example
> with a simplified subroutine. Notice that @a and @b are gone.
TMTOWTDI.
### Attempt to put the array values into @a and @b
($a, $b) = getConfigInfo();
@a = @{$a};
@b = @{$b};
Chris
--
Christopher E. Stith
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty. -- Mohandas K. Gandhi
------------------------------
Date: Fri, 20 Apr 2001 19:37:55 GMT
From: "Kenneth Eide" <js@hotmail.com>
Subject: Searching a File for a string, displaying the reults
Message-Id: <ne0E6.363$w9.36752@news01.chello.no>
I have a file, "morning.ini" which looks like this:
-----------------------------------------------
url0=http://europe.cnn.com
url0name=CNN Europe
url1=http://bbc.co.uk
url1name=BBC
url2=http://cnn.com/europe
url2name=CNN Europe
-----------------------------------------------
I made a script that searches for the name, and displays the Name + the URL
open (OLD, "<morning.ini") or die "Error: Could not open morning.ini: $!\n";
if ($ARGV[0] =~ /^search$/i) {
$sstring = "@ARGV[1..$#ARGV]";
while (<OLD>) {
if ($_ =~ /$sstring/i) {
$urlname = $_;
$urllinenum = $. - 1;
$exists = "yes";
}
}
if (defined $exists) {
}
else {
die "Error: Found no matches for \"$sstring\" in morning.ini\n";
}
close(OLD);
open (OLD, "<morning.ini");
while (<OLD>) {
if ($. == $urllinenum){
$urlline = $_;
}
}
$urlname =~ s/^url\dname=//;
$urlline =~ s/^url\d=//;
print "$urlname\n";
print "$urlline\n";
close(OLD);
}
./search.pl search CNN
If there is only one occurance (e.g the first one) of CNN in morning.ini it
would display:
CNN Europe
http://europe.cnn.com
Which is exactly the output i want, but I'm having trouble finding out how
to display Name + URL if there is more than one match (like there are the
"file" at the top of this post).
Anyone know how this could be solved?
Kai Pettersen
------------------------------
Date: Fri, 20 Apr 2001 21:13:11 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Secure key generator/Algorithum
Message-Id: <te19j7ak0bii43@corp.supernews.com>
nobull@mail.com wrote:
> Jason Hurst <variant@shell.pacifier.com> writes:
>> This probably isnt the best place to be asking this question, but I really
>> didnt now where to post this.
> Certainly not here - it definitely has nothing to do with Perl.
I think the question is if there's an easy way to do it from Perl,
which there is.
>> Im trying to create a simple validation program. Id like to be able to
This is a common use for cookies.
>> to set a mathematical value that I could run an algorithm against to make
>> sure it checks out.
> You mean a cryptograpically strong hashing (aka "message digest") algorithm.
Digest::MD5 comes to my mind immediately. So do Crypt::Blowfish, Crypt::RSA,
PGP::Sign, Crypt::PasswdMD5, Crypt::GPG, and Crypt::TEA.
>> My math skills are only so-so and I was wondering if anyone already had
>> something like this or could point me in the right direction to start.
> Actually that's a good start in itself. If you were moderately good
> at maths then you'd be temped to roll your own crypto alorithm.
>
>> Ive really got no idea how Id even go about doing something like
>> that.
> perldoc -f crypt
> Note: I'm not suggesting you necessarily choose crypt() as your
> hashing alorithm, there are stonger ones on CPAN, but it'll give you
> the idea.
>> I dont need ultra hard to crack security, just something simple.
> In that case crypt() may be stong enough.
True. Crypt is pretty easy to use, too. It's used for passwords all
over the world (of course, MD5 is popular now too), so you can take
it dependability from that.
Chris
--
Christopher E. Stith
Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.
------------------------------
Date: Fri, 20 Apr 2001 12:10:50 -0600
From: Mark Thurston <mdt27@email.byu.edu>
Subject: Re: server timeout
Message-Id: <3AE07BA9.673FEF00@email.byu.edu>
Thanks. I was thinking about how this could be done and that will
probably work. I will just have to write another script.
Mark
PS- I can't beleive that someone asking for help would then get angry
when their question was answered, that is unfortunate.
nobull@mail.com wrote:
> Mark Thurston <mdt27@email.byu.edu> writes:
>
> > Newsgroups: comp.lang.perl.misc
> > Subject: Re: server timeout
>
> When this question wes asked here a few weeks back I pointed out it
> wasn't Perl related the person who asked it became angry and rude.
>
> Are you going to do the same?
>
> My approach to CGI scripts that take a long time has been: fork
> processing into backgroud, create temporary entity, redirect brouser
> to latter with periodic refresh.
>
> There are more elegant varients on this approach and I'm sure the
> nettizens over in CIWAC (where this is on-topic) would be able to
> help.
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Fri, 20 Apr 2001 21:06:24 GMT
From: alex@hoopsie2.com
Subject: Storable question
Message-Id: <kx1E6.3431$0d.747024@newsrump.sjc.telocity.net>
On a web application I have a couple of simple subroutines
to retrieve/store a hash of session data from/to a file.
They are essentially wrappers for Storable.pm's lock_retrieve
and lock_store. However, one time, the site was rendered
useless because the storable file became corrupted. I was
not able to find the cause of the corruption, but either
way I decided I wanted to trap this error through an eval
and delete the bad session file.
Here are some code snippets (... refers to unrelated code):
## 1. get session ########################################
my $sessionref;
...
eval {
$sessionref = lock_retrieve( $file )
or die "Could not lock_retrieve sessions from '$file': $@\n";;
};
if ( $@ ) {
...
unlink ( $file );
}
...
# 2. session is created and placed in $sessionref here if not already present
&create_new_session($sessionref);
...
## 3. store session ########################################
# some error checking here
lock_store( $sessionref, $file ) or
die "Could not lock_store sessions to '$file': $@\n";
--end code---
Once I coded what's above, I deliberately created a null storable
file which should make lock_retrieve fail. This should be OK,
because $sessionref is left untouched (#1) in this case.
A session hash is then created (#2) and referenced in $sessionref.
When it comes time to store, a new storable file is created
and that session is stored (#3). However, this is not what's
happening. The lock_store call (in #3) is giving me a "Bad
Hash" error. I've used Data::Dumper to dump the hash
right before the lock_store and it looks just like it
would when the lock_retrieve doesn't fail!
FYI, I even hardwired a hash to be used by lock_store
*regardless* of what happens elsewhere in the script and
it STILL gives me a bad hash error *only* when the lock_retrieve
fails.
Am I doing something wrong? I don't want to have to change
to Apache::Session or any other module unless absolutely
necessary (having to do with my job more than programming).
Is there a better approach to error trapping here?
Thanks in advance,
-- Alex
------------------------------
Date: Fri, 20 Apr 2001 15:07:33 -0500
From: Jesse James Jensen <jesse@uchicago.edu>
Subject: Re: Things I'm just not getting in Perl
Message-Id: <3AE09705.9DD19905@uchicago.edu>
Lou Moran wrote:
>
> print "Are you IN the office or OUT of the office? Enter IN or OUT:
> ";
> my $loc = <STDIN>;
> chomp $loc;
> $loc =~ tr/A-Z/a-z/;
> # print $loc; #test regex
>
> if ($loc eq "in" or $loc eq "out") {
> } else {
> die "\n*******\nPlease enter IN or OUT. No changes made to
> hosts file.\n*******\n"
> }
>
> $loc =~ s/in/i/;
> $loc =~ s/out/o/;
> # print $loc; #test regexen
>
> open (FileHandle, '+> C:/WINNT/system32/drivers/etc/hosts') || die
> "There is no hosts file.";
> #Yes, I want to erase the hosts file
>
> if ($loc eq "i") {
> print "Writing the internal hosts file.\n\n"; #write the file
> #print << hosts; THis is where it would write $in
> } else {
> print "Writing the external hosts file.\n\n";
> #print << hosts; This is where it would write $$out
> }
>
Why are you changing $loc from "in" or "out" to "i" or "o"? You could
just leave it and check for the whole word in your if statement.
------------------------------
Date: 20 Apr 2001 20:20:26 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Things I'm just not getting in Perl
Message-Id: <9bq5ma$8ba$1@towncrier.cc.monash.edu.au>
mjd@plover.com (Mark Jason Dominus) writes:
> I usually follow this pattern:
>
> do {
> print "Enter a number: ";
> chomp($response = <>);
> } while $response !~ /^\d+$/ ;
Or just use the special C<< =<>=~ >> operator:
do { print "Enter a number: " }
until ($response)=<>=~/^(\d+)$/;
;-)
> Sometimes:
>
> while (1) {
> print "Enter a number: ";
> chomp($response = <>);
> last if $response =~ /^\d+$/;
> print "That isn't a number, stupid!\n";
> }
Or just use the special C<< 1-print >> built-in:
do { print "enter a number: " }
until ($response)=<>=~/^(\d+)$/
or 1-print "No, stupid, ";
;-)
Damian
PS: Seriously though: use something like MJD's suggestions.
Those who come after you will be far more grateful
for clarity than for conciseness.
------------------------------
Date: Fri, 20 Apr 2001 15:33:30 -0400
From: Mark-Jason Dominus <mjd@plover.com>
Subject: US$50 prize for hash failure from 'delete' inside an 'each' loop
Message-Id: <20010420193330.20662.qmail@plover.com>
The 'perlfunc' man page says:
each ...
If you ... delete elements of a hash while you're
iterating over it, you may get entries skipped or
duplicated...
I will give a $50 prize to the first person who can come up with an
example that demonstrates this.
Restrictions:
* Stock Perl 5.6.0 or 5.6.1 only.
* I must be able to reproduce the error.
* You must submit code that demonstrates the described problem. That
is, you must define a hash, iterate over the hash with 'each', and
cause some duplication or incorrect omission by deleting elements
from the hash while inside the loop.
The code should probably have the following form:
%hash = ...;
while (my ($k, $v) = each %hash) {
print "Processed key $k.\n";
if (...) {
delete $hash{...};
}
}
Possible failures are:
* "Processed key K" appears twice for some key K
* "Processed key K" appears *after* K was deleted
* There is some key K in the has, which was never deleted, for
which "Processed key K" does not appear
* Any other obvious misbehavior (for example, perl dumps core,
or 'Processed key K' appears when K was never in the hash to
begin with)
* Adding items to the hash inside the each() loop is not permitted;
this offer applies only to deletions.
* This is in investigation of the interaction of 'delete' and 'each'.
It is not an attempt to find the most ingenious method of bending
the contest rules. If you have questions, please send email.
Judgments will be made by me; all judgements are final.
Mark-Jason Dominus mjd@plover.com
I am boycotting Amazon. See http://www.plover.com/~mjd/amazon.html for details.
------------------------------
Date: 20 Apr 2001 12:38:41 -0600
From: gls@byu.edu
Subject: use of Perl, Was Re: Can't open file, dies
Message-Id: <uy9svmn66.fsf_-_@SNOW.i-did-not-set--mail-host-address--so-shoot-me>
minorseventhSPAMBLOCK@earthlink.net (Jim Kroger) writes:
> Thanks everyone for the help....
>
> Can't help but wonder what a statistician uses Perl for....
I first learned Perl when I was doing a bunch of simulations. I
needed to run one program to generate a random dataset then analyze
the dataset using 8 different programs. Each of those programs
generated 10-100 pages of output, I only cared about 10 numbers in all
of that output. Then I needed to repeat the whole process 100 times,
then change some conditions and repeat another 100 times, ...
(and all of this time my boss was modifying some of the programs so
that the page the interesting output was on kept changing).
Perl was a life saver for that job.
Now I use Perl for data manipulation, extracting the important data
from a file with other junk in it, among other things.
Last semester I had students in one of my classes get their final exam
via a CGI script. They would enter their name and the script would
randomly generate a dataset for them to analyze (and save a copy of
the data along with the correct answer for me to compare to their
submitted results).
My current project is a CGI script so that my students can enter their
e-mail adress, the script will look it up in the file with their
homework/quiz/test scores and e-mail a summary to them any time
durring the semester.
This summers project will be to rewrite a program in perl Tk for the
World Health Organization to use in analyzing imunization levels in
developing countries (I already wrote a version for them using some
proprietary software and want to rewrite it in Perl so they can
distribute it to small countries without them having to pay anything
extra).
Perl is extreemly useful to Statisticians (I'm trying to convince more
of them of that :-).
--
Greg Snow, PhD Office: 223A TMCB
Department of Statistics Phone: (801) 378-7049
Brigham Young University Dept.: (801) 378-4505
Provo, UT 84602 email: gls@byu.edu
------------------------------
Date: Fri, 20 Apr 2001 07:13:57 -0700
From: "Matt" <mnm@mnm.com>
Subject: Re: use strict & require...
Message-Id: <9bpud1$fhc$1@uranium.btinternet.com>
> Yes.
>
> Look up the message:
>
> perldoc perldiag
>
>
> ---------------
> =item Global symbol "%s" requires explicit package name
>
> (F) You've said "use strict vars", which indicates that all variables
> must either be lexically scoped (using "my"), declared beforehand using
> "our", or explicitly qualified to say which package the global variable
> is in (using "::").
> ---------------
>
>
> If it requires an explicit package name, then provide an explicit
> package name.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
Thank you very much.
--
Matt
------------------------------
Date: 20 Apr 2001 19:25:22 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Why Perl?
Message-Id: <9bq2f2$g2l$1@neptunium.btinternet.com>
Bart Lateur <bart.lateur@skynet.be> wrote:
> Tad McClellan wrote:
>
>>I run 'htmltidy' on it.
>>
>> http://www.w3.org/People/Raggett/tidy/
>
> Is it still as buggy? It sure was 3 months ago.
>
Not as buggy as the 'htbeauty.pl' I made some 4 years ago - I stopped
developing it when I discovered 'tidy' :)
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Fri, 20 Apr 2001 16:21:47 -0500
From: "Uday Murthy" <murthy@cox-internet.com>
Subject: Win32::OLE problem -- command line vs. CGI
Message-Id: <9bq97c$kp8$1@news.tamu.edu>
I have a Perl script using Win32::OLE that interacts with an Excel
spreadsheet. The script works perfectly from the command line on the
server, but fails when run as a CGI program. Any ideas? The script fails
at the line defining the Excel object, i.e., :
my $ex = Win32::OLE->GetActiveObject('Excel.Application') ||
Win32::OLE->new('Excel.Application', 'Quit');
$ex does not get defined when the script is run from remote via CGI, but
does get defined when the script is run from the command line on the Web
server.
Using ActiveState Perl, build 623 on O'Reilly's WebSite Pro. But tested on
an IIS machine with the same result.
Uday
------------------------------
Date: Fri, 20 Apr 2001 14:12:37 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: YARQ (Yet another regex question)
Message-Id: <GS%D6.513$IM1.261790@news.uswest.net>
Hi all,
Regex question. Perl 5.6 on Solaris 8 (does that matter).
First, the -DDEBUGGING option wasn't used on the perl I have available, so I
can't try that. I'm talking to the sys admin now.
Here's some sample text. All text will be in one of these two formats (text
and numbers may vary):
000910_181716: 153 (865) completed orders to AOL
000910_181716: 153 (865) completed orders to Amazon {icn#4444}
Please see the regex I have so far below...
The trouble I'm having is making the '{icn#4444}' optional. I've tried
putting a '*' and a '?' after the match in line #8 below, but somehow that's
barfing the output, starting with the expected results from line #6 (text
description). I don't think my non-greedy expression works like I think it
does.
Any ideas? Thanks in advance for any help.
Dan
if($line =~ /^
(\d+?_\d+?:\s*?) # 1. date_time, a colon and optional whitespace $1
(\d+) # 2. quantity $2
\s+ # 3. one or more whitespaces
(\(\d+\)) # 4. type - digits within parenthesis $3
\s*? # 5. optional whitespace
(.+?) # 6. text description $4
\s*? # 7. optional whitespace
(?:\{.*?(\d+)\}) # 8. ICN number within brackets $5 - I want this to
be optional.
/x
){
print "\n";
print "Date: $1$2\n";
print "Quantity: $2\n";
print "Type: $3\n";
print "Desc: $4\n";
print "ICN: $5\n";
print "\n-----------------\n";
}
else{ print "No match\n" }
------------------------------
Date: Fri, 20 Apr 2001 15:24:31 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: Re: YARQ (Yet another regex question)
Message-Id: <2W0E6.1617$Uc2.218990@news.uswest.net>
Nevermind. Got burned by the (.*?) somehow. I changed it to ([A-Za-z0-9 !]*)
and that fixed it.
------------------------------
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 731
**************************************