[19328] in Perl-Users-Digest
Perl-Users Digest, Issue: 1523 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 18:05:37 2001
Date: Tue, 14 Aug 2001 15:05:12 -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: <997826712-v10-i1523@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 14 Aug 2001 Volume: 10 Number: 1523
Today's topics:
Re: $string = s/\|//g; error - why? <tony_curtis32@yahoo.com>
Re: 2 dimensional array suntax help, please <ren@tivoli.com>
Re: 2 dimensional array suntax help, please (Stan Brown)
Re: 2 dimensional array suntax help, please <goldbb2@earthlink.net>
behavior in a while loop (djcabz)
Re: behavior in a while loop (Tad McClellan)
Re: behavior in a while loop (Tad McClellan)
Crypt::DES problem (Yiqiang Ding)
exit <min_c_lee@yahoo.com>
Re: exit <ilya@martynov.org>
Re: exit <rsherman@ce.gatech.edu>
FAQ: I still don't get locking. I just want to increme <faq@denver.pm.org>
Re: Flock: Just to be sure ! <krahnj@acm.org>
Re: Format error?? <miscellaneousemail@yahoo.com>
Re: help :) <yanoff@yahoo.com>
Re: help :) (Tad McClellan)
Re: help :) (Tad McClellan)
Re: How do I assing an entire array? (Steve van der Burg)
Re: Line counting in a file <joe+usenet@sunstarsys.com>
Re: modules and variables <gnarinn@hotmail.com>
newbie cgi question (Yijia Zhao)
Re: newbie cgi question <tony_curtis32@yahoo.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Aug 2001 15:52:25 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: $string = s/\|//g; error - why?
Message-Id: <87d75y2wl2.fsf@limey.hpcc.uh.edu>
>> On 13 Aug 2001 07:25:21 -0700,
>> ralawrence@my-deja.com (Richard Lawrence) said:
> Hi all, I'm a little lost. Can someone please explain to
> me why:
> $string = s/\|//g;
> causes the error:
> Use of uninitialized value in substitution (s///)
You said "=" but you meant "=~".
> All I want to do is take a string and remove all the
> pipes from it!
"perldoc perlop", see entry for "tr", esp. the /d bit.
$string =~ tr/|//d;
hth
t
--
Beep beep! Out of my way, I'm a motorist!
------------------------------
Date: 14 Aug 2001 13:49:36 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <m3zo925ven.fsf@dhcp9-161.support.tivoli.com>
On 14 Aug 2001, stanb@panix.com wrote:
>>Hmm, I'm still doing something wrong here:
>
>>Global symbol "@vals" requires explicit package name at ./foo.pl
>>line 920.
This is a big hint....
>>Let me sketch out the problem again. I;m loading an array of
>>refeences to arrays in a subroutine, like this:
>
>>my $row = 0;
>>my $col = 0;
>>while ( @extracted_data = $sths->fetchrow_array ) {
>> for ($col = 0; $col < $col_qty; $col++) {
>> $rval[$col][$row] = $extracted_data[$col];
>> print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
>> }
>>$row++;
>>}
>
>>BTW, I'm fairly certain that this does what I want, which is creates
>>a two dimensional array. The first dimension is filled with
>>references to arrays. Each of these arrays contain all the values
>>that the SELECT returned for a given collumn, That is all data
>>brough back in extrated_data[0] will go in one array, all data from
>>extrated_data[1] will go in the next array ....
>
>>Am I crossed up here?
>
>>The I return this to the caller as:
>
>>return @rval;
So get_foreign_key_values() returns a list (the contents of @rval) in
list context, or a scalar (the number of elements in @rval, in this
case, 2) in scalar context.
>>Now in the caller, I need to pass each of these arrays (as a list)
>>to Tk::entry->insert. The second argumnet to this call is a list.
>
>>Here is what I am trying:
>
>>my $vals = get_foreign_key_values(
>> $$hash_pointer{$col}{'SRC_TABLE'},
>> $$hash_pointer{$col}{'SRC_COLS'});
>>$entry->insert(0,@{ $vals[0] });
Uh-oh.... get_foreign_key_values() has been called in scalar context,
so $vals gets the number 2. Then you use $vals[0], which is the first
element from the @vals array. You have not declared that array
anywhere, so you get the error message above (at the top).
Change the "my $vals" to "my @vals" and both problems are solved.
>>The logic is that $vals in the caller should be a refernce to an
>>array of references to arrays.
Why? You didn't return a reference, you returned an array.
>>Where am I going wrong?
It seems that you are confused about references. Have a look at
perlreftut(1), perlref(1), perlsub(1), perldsc(1) and perllol(1).
> The closest I have gotten is when I do this:
>
> $entry->insert(0,$$vals[0 ]);
>
> Whic tells me it can't use '2' as a reference
Yes, "use strict" is preventing that, which is a very good thing.
> This is with vals declared as a scalr.
>
> I've also tried this:
>
> $entry->insert(0,$vals[0]);
>
> with vals declared as an array
That's closer. But what you really want is what you did above, but
with @vals:
$entry->insert(0, @{$vals[0]});
> This results in the array ref being displayed as the only choice in
> the Browsentry feild.
>
> The first dereferences one to many times, the second one to few :-(
I hope that helps. Good luck!
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 14 Aug 2001 16:37:42 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <9lc26m$r26$1@panix3.panix.com>
In <m3zo925ven.fsf@dhcp9-161.support.tivoli.com> Ren Maddox <ren@tivoli.com> writes:
>On 14 Aug 2001, stanb@panix.com wrote:
>>>Hmm, I'm still doing something wrong here:
>>
>>>Global symbol "@vals" requires explicit package name at ./foo.pl
>>>line 920.
>This is a big hint....
Hints I'v got, just not insight :-)
>>>Let me sketch out the problem again. I;m loading an array of
>>>refeences to arrays in a subroutine, like this:
>>
>>>my $row = 0;
>>>my $col = 0;
>>>while ( @extracted_data = $sths->fetchrow_array ) {
>>> for ($col = 0; $col < $col_qty; $col++) {
>>> $rval[$col][$row] = $extracted_data[$col];
>>> print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
>>> }
>>>$row++;
>>>}
>>
>>>BTW, I'm fairly certain that this does what I want, which is creates
>>>a two dimensional array. The first dimension is filled with
>>>references to arrays. Each of these arrays contain all the values
>>>that the SELECT returned for a given collumn, That is all data
>>>brough back in extrated_data[0] will go in one array, all data from
>>>extrated_data[1] will go in the next array ....
>>
>>>Am I crossed up here?
>>
>>>The I return this to the caller as:
>>
>>>return @rval;
>So get_foreign_key_values() returns a list (the contents of @rval) in
>list context, or a scalar (the number of elements in @rval, in this
>case, 2) in scalar context.
Ah, here goes my C bacground again, getting me in trouble. I did not
realize that a subroutine could return different values, based upon how it
was called. That partly explains why I have been going in circles all day!
When I changed the call, the results cahnged, ARGHH!
>>>Now in the caller, I need to pass each of these arrays (as a list)
>>>to Tk::entry->insert. The second argumnet to this call is a list.
>>
>>>Here is what I am trying:
>>
>>>my $vals = get_foreign_key_values(
>>> $$hash_pointer{$col}{'SRC_TABLE'},
>>> $$hash_pointer{$col}{'SRC_COLS'});
>>>$entry->insert(0,@{ $vals[0] });
>Uh-oh.... get_foreign_key_values() has been called in scalar context,
>so $vals gets the number 2. Then you use $vals[0], which is the first
>element from the @vals array. You have not declared that array
>anywhere, so you get the error message above (at the top).
OK, I see that.
>Change the "my $vals" to "my @vals" and both problems are solved.
>>>The logic is that $vals in the caller should be a refernce to an
>>>array of references to arrays.
>Why? You didn't return a reference, you returned an array.
>>>Where am I going wrong?
>It seems that you are confused about references. Have a look at
>perlreftut(1), perlref(1), perlsub(1), perldsc(1) and perllol(1).
>> The closest I have gotten is when I do this:
>>
>> $entry->insert(0,$$vals[0 ]);
>>
>> Whic tells me it can't use '2' as a reference
>Yes, "use strict" is preventing that, which is a very good thing.
>> This is with vals declared as a scalr.
>>
>> I've also tried this:
>>
>> $entry->insert(0,$vals[0]);
>>
>> with vals declared as an array
>That's closer. But what you really want is what you did above, but
>with @vals:
> $entry->insert(0, @{$vals[0]});
>> This results in the array ref being displayed as the only choice in
>> the Browsentry feild.
>>
>> The first dereferences one to many times, the second one to few :-(
>I hope that helps. Good luck!
OH boy did it help.!
This message arived, just as I was about to go home for the evening, since
I don't have access to the machine I'm doing this on from home, it was
going to be a miserable night worying baout it.
Thanks you VERY VERY much, this really made my day!
------------------------------
Date: Tue, 14 Aug 2001 18:10:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: 2 dimensional array suntax help, please
Message-Id: <3B79A1D7.A7AED971@earthlink.net>
Stan Brown wrote:
>
> Just as I thought I was getting a handle on this, I have managed to
> confuse myself again :-(
>
> I have a subroutine I call that creates and array of refeences to
> arrays. The relevant bits look like this:
>
> my @rval = undef ;
This creates a one element array, whose value is (undef). You should
either not be initializing, or initializing using ();
my @rval;
or
my @rval = ();
> $rc = $sths->execute or die $DBI::errstr;
> my $row = 0;
> my $col = 0;
> while ( @extracted_data = $sths->fetchrow_array ) {
> for ($col = 0; $col < $col_qty; $col++) {
> $rval[$col][$row] = $extracted_data[$col];
> print_debug(5,"Added $extracted_data[$col] to [$row][$col]\n",0);
> }
> $row++;
> }
>
> return @rval;
sub get_foreign_key_values {
my ($table, $cols);
local $dbi->{RaiseError} = 1;
local $" = ", ";
my $sth = $dbi->prepare("SELECT @$cols FROM $table");
$sths->execute();
my @rval;
while( my $onerow = $sths->fetchrow_arrayref ) {
for my $col ( 0 .. $#$onerow ) {
push @{$rval[$col]} => $onerow->[$col];
print_debug(5, "Added $$onerow[$col] to " .
"[$col][$#{$rval[$col]}]\n", 0);
}
}
return wantarray ? @rval : \@rval;
}
This returns a reference to the array if called in scalar context, or an
list if called in list context.
> All of this _seems_ br working corectly. The trouble arises in using
> it.
> Like this:
>
> my $vals = get_foreign_key_values(
> $$hash_pointer{$col}{'SRC_TABLE'},
> $$hash_pointer{$col}{'SRC_COLS'});
Since your get_foreign_key_values always tries to return an array,
regardless of it's context, $vals ends up with the number of elements of
that array, not it's contents. In other words, it's likely going to end
up as "2" or somesuch.
> $entry->insert(0,$$vals[0]);
insert wants a list. $$vals[0] starts with a $ which means it's a
scalar. For that matter, it's taking "$vals" using it as a reference to
an array, and since $vals is 2, this line is essentially like saying:
$entry->insert(0, ${'2'}[0]);
So either:
my $vals = ... # with my code, which returns \@vals in scalar context.
$entry->insert(0, @{$vals->[0]} );
or
my @vals = ...# with either my or your code.
$entry->insert(0, @{$vals[0]} );
By the way, are you *sure* entry takes a list, not a reference to a
list?
--
The Swedish Chef has been assimilated. "Borg borg borg!"
------------------------------
Date: 14 Aug 2001 13:08:05 -0700
From: c_barbet@hotmail.com (djcabz)
Subject: behavior in a while loop
Message-Id: <4256dfd1.0108141208.c743b91@posting.google.com>
Hello! I am looking for code that reads from a text file the name of
files to be moved and moves them. The code I included works *HOWEVER*
there is a problem. If the directory being searched is empty it then
moves the file associated with FSN_LIST. Why? *** this is the
important question.
I do have an easy second question(yes I be a perl newbie). What is
considered proper syntax using the keyword 'or' or '||' when working
with filehandles. I read a bit on precedence (camel head), and
recommended was the literal 'or' however I see many people using the
logical operator (???)
thanks in advance
---- almost good code ----
open(FSN_LIST, "./fromscan.lst") or die ERROR_LOG, "\nCould not read
./fromscan.lst: $!";
while (<FSN_LIST>) {
print "I passed this file: $_"; #just to make sure we see a file.
chomp($_); #get rid of that newline
rename("$fsndir/$_", "./fsn/$_") || die ERROR_LOG, "\nCould not
copy $_: $!";
}
#code below is original code, code above was done for TESTING some
theories.
#they perform the same exact function with the same exact weirdness.
#while ($fileFSNL = <FSN_LIST>) {
# print "I passed this file: $fileFSNL"; #just to make sure we see
a file.
# chomp($fileFSNL);
# rename("$fsndir/$fileFSNL", "./fsn/$fileFSNL") or die ERROR_LOG,
"\nCould not copy $fileFSNL: $!";
#}
------------------------------
Date: Tue, 14 Aug 2001 16:31:52 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: behavior in a while loop
Message-Id: <slrn9nj2ln.b3i.tadmc@tadmc26.august.net>
djcabz <c_barbet@hotmail.com> wrote:
>I do have an easy second question
Two questions should go in two posts.
Help other Perl programmers. Nobody is going to look at articles
about while loops when they are wondering about or vs. ||
Subject: or vs. ||
>(yes I be a perl newbie).
Could it be that you are also new to programming in general?
Must be, else you would grok precedence and not need to ask
the question :-)
We need to know your background enough to target the answer
at the appropriate level.
I will assume that Perl is your first programming language.
>What is
>considered proper syntax using the keyword 'or' or '||' when working
>with filehandles.
The proper syntax is whatever works correctly.
There is no relationship with filehandles at all, don't fall
for red herrings.
>I read a bit on precedence (camel head), and
>recommended was the literal 'or' however I see many people using the
>logical operator (???)
or and || are *both" logical operators, so your use of "the logical
operator" seems to reveal a misunderstanding.
or and || are *the same operator*. They behave exactly the same
(short circuit...) except for one thing. or is low precedence,
|| is high precedence.
Precedence only matters when there is an ambiguity. If there is
no ambiguity, then precedence is never consulted.
For example, when perl sees:
open FILE, $file or die "could not open '$file' $!";
it is ambiguous whether it should be parsed as:
# if "or" is lower precedence than everything else in the statement
(open FILE, $file) or (die "could not open '$file' $!");
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
or
# if or is higher precedence than the comma
open FILE, ($file or die "could not open '$file' $!");
^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Perl "sees" that second one when given:
open FILE, $file || die "could not open '$file' $!";
because ||'s precedence is high. We don't want that ordering.
It sees the first one if you use "or" instead of "||".
The "best" solution is to have no ambiguities, so that you never
need to concern yourself with precedence :-)
You can remove ambiguities by adding parenthesis to determine
the correct order of evaluation. So to fix that last open()
we add parens:
open(FILE, $file) || die "could not open '$file' $!"; # works fine
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Aug 2001 16:43:52 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: behavior in a while loop
Message-Id: <slrn9nj3c8.b3i.tadmc@tadmc26.august.net>
[ Please fix your word wrap. It breaks your code. ]
djcabz <c_barbet@hotmail.com> wrote:
>Hello! I am looking for code that reads from a text file the name of
>files to be moved and moves them. The code I included works *HOWEVER*
>there is a problem. If the directory being searched
Eh? I don't see any directory searching going on anywhere in
your code.
>is empty it then
>moves the file associated with FSN_LIST. Why? *** this is the
>important question.
I do not understand the question.
If you can come up with a short and complete program that we
can run, we can probably help you fix it.
>open(FSN_LIST, "./fromscan.lst") or die ERROR_LOG, "\nCould not read
^^^^^^^^^
>./fromscan.lst: $!";
You should put quotes around your strings.
Since you already _have_ a string, you can just put it there:
open(FSN_LIST, "./fromscan.lst") or die "ERROR_LOG\nCould not read ...
I get the feeling you think that ERROR_LOG is a filehandle. It isn't.
>while (<FSN_LIST>) {
> print "I passed this file: $_"; #just to make sure we see a file.
> chomp($_); #get rid of that newline
warn("./fsn/$_ already exists"), next if -e "./fsn/$_";
Don't want to go stomping over existing files (or do we?).
> rename("$fsndir/$_", "./fsn/$_") || die ERROR_LOG, "\nCould not
>copy $_: $!";
We dunno what is in $fsndir. You never showed us. So we can't
help with debugging that part.
And your diag message says "copy" when you are NOT doing
any copying. That's kinda misleading.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Aug 2001 12:23:40 -0700
From: Ding_yiqiang@yahoo.com (Yiqiang Ding)
Subject: Crypt::DES problem
Message-Id: <6c95f2e4.0108141123.6dffb99b@posting.google.com>
Hi,
A question about Crypt::DES. How can I setup larger blocksize and
keysize other than default 8?
Thanks,
YQ
------------------------------
Date: Tue, 14 Aug 2001 19:06:45 GMT
From: "Michael" <min_c_lee@yahoo.com>
Subject: exit
Message-Id: <9Fee7.13703$Up.383981@sea-read.news.verio.net>
Just a quick question,
which command to use to exit a WHILE loop
without exiting the entire program?
Michael
------------------------------
Date: 14 Aug 2001 23:10:48 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: exit
Message-Id: <874rrawj7r.fsf@abra.ru>
M> Just a quick question,
M> which command to use to exit a WHILE loop
M> without exiting the entire program?
last
See 'perldoc -tf last', 'perldoc -tf next', 'perldoc -tf redo' and
'perldoc perlsyn' for more information.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Tue, 14 Aug 2001 15:09:31 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: exit
Message-Id: <3B78F8DB.10E5E15B@ce.gatech.edu>
Michael wrote:
>
> Just a quick question,
> which command to use to exit a WHILE loop
> without exiting the entire program?
>
> Michael
last
--
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa
------------------------------
Date: Tue, 14 Aug 2001 18:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: I still don't get locking. I just want to increment the number in the file. How can I do this?
Message-Id: <xWde7.97$V3.212108800@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
I still don't get locking. I just want to increment the number in the file. How can I do this?
Didn't anyone ever tell you web-page hit counters were useless? They
don't count number of hits, they're a waste of time, and they serve only
to stroke the writer's vanity. It's better to pick a random number;
they're more realistic.
Anyway, this is what you can do if you can't help yourself.
use Fcntl qw(:DEFAULT :flock);
sysopen(FH, "numfile", O_RDWR|O_CREAT) or die "can't open numfile: $!";
flock(FH, LOCK_EX) or die "can't flock numfile: $!";
$num = <FH> || 0;
seek(FH, 0, 0) or die "can't rewind numfile: $!";
truncate(FH, 0) or die "can't truncate numfile: $!";
(print FH $num+1, "\n") or die "can't write numfile: $!";
close FH or die "can't close numfile: $!";
Here's a much better web-page hit counter:
$hits = int( (time() - 850_000_000) / rand(1_000) );
If the count doesn't impress your friends, then the code might. :-)
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.19
--
This space intentionally left blank
------------------------------
Date: Tue, 14 Aug 2001 21:05:34 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Flock: Just to be sure !
Message-Id: <3B799339.DFAEDB37@acm.org>
Anno Siegel wrote:
>
> Instead of "1" you should use the constant LOCK_SH from the Ioctl
> module. Similar comments apply below.
$ perldoc Ioctl
No documentation found for "Ioctl".
perldoc Fcntl
> open( FILE, "+>$file);
>
> This will open for read/write, retaining the contents. Then, after your
^^^^^^^^^^^^^^^^^^^^^^
perldoc -f open
[snip]
You can put a `'+'' in front of the `'>'' or `'<''
to indicate that you want both read and write
access to the file; thus `'+<'' is almost always
preferred for read/write updates--the `'+>'' mode
would clobber the file first.
^^^^^^^^^^^^^^^^^^^^^^
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 14 Aug 2001 20:40:12 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Format error??
Message-Id: <MPG.15e33a63d3e46070989741@news.edmonton.telusplanet.net>
In article <slrn9nieck.9os.tadmc@tadmc26.august.net>, Tad McClellan at
tadmc@augustmail.com says...
> I haven't used "format" for years. printf() and a word-wrapping
> module do it for me.
Which module do you use Tad?
> formats will be removed from the core in perl6.
>
> The payback you get for learning them is not worth the trouble, IMO.
Makes sense. Now that I know they are being removed in Perl6 I will
definitely get away from using them.
Thanks.
--
Carlos
www.internetsuccess.ca
*NOTE*: Internet Success is NOT yet fully operational
so although you are welcomed to visit and take a
look, trying to subscribe will only be a frustration
for you as your data will not be saved at this time.
------------------------------
Date: Tue, 14 Aug 2001 14:45:30 -0500
From: Scott Yanoff <yanoff@yahoo.com>
Subject: Re: help :)
Message-Id: <3B797FDA.D33320D6@yahoo.com>
Tad McClellan wrote:
>
> Scott Yanoff <yanoff@yahoo.com> wrote:
> >jtjohnston wrote:
> >>
> >> Can someone help?
> >>
> >> I want to check input (case insensitive) to cjeck if it matches one of
> >> the lines in the array above. I have tried and fialed. Here is what I
> >> have so far.
> >>
> >> ---------snip---------
> >> $user_input = $in{'P2WC3Q4'};
> >> $Return_Value = 0;
> >> foreach $i (0..$#MyArray)
> >> {
> >> if (/$MyArray[$i]/i eq /$user_input/i) #obviously not
> >> correct
> >
> >Try using =~ instead of eq in the above equation.
>
> That is really silly.
>
> /$MyArray[$i]/i =~ /$user_input/i
>
> if the first pattern matched, then you will be trying to match
> against a string representing a true value, probably "1".
>
> if it does not match, then you will be trying to match
> against a string representing a false value, probably the
> empty string.
Tad:
Can you explain further, please, perhaps with an example even?
Isn't the above checking to see $user_input was contained within
$MyArray[$i]?
Thanks,
--
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY
------------------------------
Date: Tue, 14 Aug 2001 15:56:56 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help :)
Message-Id: <slrn9nj0k8.b3i.tadmc@tadmc26.august.net>
Scott Yanoff <yanoff@yahoo.com> wrote:
>Tad McClellan wrote:
>> Scott Yanoff <yanoff@yahoo.com> wrote:
>> >Try using =~ instead of eq in the above equation.
>>
>> That is really silly.
>>
>> /$MyArray[$i]/i =~ /$user_input/i
>>
>> if the first pattern matched, then you will be trying to match
>> against a string representing a true value, probably "1".
>>
>> if it does not match, then you will be trying to match
>> against a string representing a false value, probably the
>> empty string.
>
>Tad:
>Can you explain further, please, perhaps with an example even?
First the /$MyArray[$i]/i is matched against the string in $_,
because it is not bound (=~) to some other string.
The the _result_ of the pattern match (true/false) is bound
to the /$user_input/i pattern match.
So you have the equivalent of one of these:
'' =~ /$user_input/i; # if match failed
'1' =~ /$user_input/i; # if match succeeded
Which is not likely to be wildly useful :-)
You can see what is returned by /$MyArray[$i]/i:
-------------------------
#!/usr/bin/perl -w
use strict;
$_ = 'yanoff';
my @MyArray = qw( scott yanoff);
my $unmatched = $_ =~ /$MyArray[0]/i;
my $matched = $_ =~ /$MyArray[1]/i;
print "'$unmatched'\n";
print "'$matched'\n";
-------------------------
>Isn't the above checking to see $user_input was contained within
>$MyArray[$i]?
No it isn't, which is why I said it is silly :-)
eq is the Right Operator For The Job here, but if we did insist
on using patterns, we ought to be anchoring both the start and end:
/^$MyArray[$i]$/i
^ ^
^ ^
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 14 Aug 2001 15:58:15 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help :)
Message-Id: <slrn9nj0mn.b3i.tadmc@tadmc26.august.net>
Scott Yanoff <yanoff@yahoo.com> wrote:
>Tad McClellan wrote:
>> Scott Yanoff <yanoff@yahoo.com> wrote:
>> /$MyArray[$i]/i =~ /$user_input/i
[snip]
>Isn't the above checking to see $user_input was contained within
>$MyArray[$i]?
No, if we wanted that we would write this instead:
$MyArray[$i] =~ /$user_input/i
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 14 Aug 2001 20:13:07 GMT
From: steve.vanderburg@lhsc.on.ca (Steve van der Burg)
Subject: Re: How do I assing an entire array?
Message-Id: <37117.6757144775D2stevevanderburglhsco@142.158.212.244>
>Well, perhaps because I'm still thinking in C, but I do ahve a
>largish script that runs as a daemon, and it's got a memory leak
>somewhere. I have to eventually find it, because it eventuallu runs
>out of memory, after several weeks.
I have the feeling that I'm coming into this thread very late, but
you might want to think about having the daemon exec itself
periodically instead of trying to figure out why it's eating memory.
From one of my perl daemons:
if ( $time_to_die ) {
close LOG if $opts{log};
exec "$daemon_home/the_daemon",@args;
}
Of course, you may need to figure out if it's safe to exec, and if
there's any state information that needs to be saved (as a file that
the new process would read upon startup, for instance).
...Steve
--
Steve van der Burg
Technical Analyst, Information Services
London Health Sciences Centre
London, Ontario, Canada
Email: steve.vanderburg@lhsc.on.ca
------------------------------
Date: 14 Aug 2001 17:03:16 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Line counting in a file
Message-Id: <m38zgm9wx7.fsf@mumonkan.sunstarsys.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
>
> % perldoc -f readline
> ...
> Note that the notion of "line" used here is however you may
> have defined it with "$/" or "$INPUT_RECORD_SEPARATOR"). Each
> call to readline increments "$." or $INPUT_LINE_NUMBER. See
^ ^ ^^^^^^
successful " ". For details see
> the sections on "$." and "$/" in the perlvar manpage.
^^^^^^^^^^^^
entries for
F'ups set.
--
Joe Schaefer "Experience is one thing you can't get for nothing."
-- Oscar Wilde
------------------------------
Date: Tue, 14 Aug 2001 20:03:11 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: modules and variables
Message-Id: <997819391.27105993591249.gnarinn@hotmail.com>
In article <3B8276D5.51A6DB30@sprintmail.com>,
Jeff Thies <cyberjeff@sprintmail.com> wrote:
> I have a few functions that I've moved into a module. I'm unsure how
>to initialize/reset global variables for these functions.
>
> Here's what I have:
>
>use myModule($enviornment_var1,$enviornment_var2);
the list after the 'use myModule' is the import list and are not some
sort of arguments passed to your module
>
>and "myModule"
>*********************
>my($env1,$env2)=@_;
nope.
what you probably want is:
use myModule;
...
myModule::initialize($enviornment_var1,$enviornment_var2);
and "myModule":
my ($env1,$env2);
sub initialize {
($env1,$env2)=@_;
}
...
if you prefer you can replace the 'my ($env1,$env2);' line by:
use vars qw($env1,$env2);
in that case, $env1 and $end2 can be exported by your module or
accessed as $myModule::env1 and $myModule::env2
>That seems a little funky to me (I can't quite make sense of "perlmod"
>yet).
you should also read perlmodlib
>How do I refer to these module variables so I can change them later?
call myModule::initialize again
good luck
gnari
------------------------------
Date: Tue, 14 Aug 2001 20:35:04 GMT
From: yzhao1@students.uiuc.edu (Yijia Zhao)
Subject: newbie cgi question
Message-Id: <slrn9nj2ut.g40.yzhao1@ux13.cso.uiuc.edu>
Hi, I just started programming in Perl for a web site, and I have a
question. I would like to know how to make a perl file opens up a html file
in the browser after the perl file finishes all what it is supposed to do to
the database.
So it will be like:
the form in html
fill in the form
submit
perl file gets called and does things to the database
goes to a different html file in the browser
Thanks in advance.
Yijia
------------------------------
Date: 14 Aug 2001 15:41:18 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: newbie cgi question
Message-Id: <87heva2x3l.fsf@limey.hpcc.uh.edu>
>> On Tue, 14 Aug 2001 20:35:04 GMT,
>> yzhao1@students.uiuc.edu (Yijia Zhao) said:
> Hi, I just started programming in Perl for a web site,
> and I have a question. I would like to know how to make
> a perl file opens up a html file in the browser after
> the perl file finishes all what it is supposed to do to
> the database.
> So it will be like: the form in html fill in the form
> submit perl file gets called and does things to the
> database goes to a different html file in the browser
use CGI ... ;
...
print redirect('http://www.here.there/some/where/');
"perldoc CGI" for more.
hth
t
--
Beep beep! Out of my way, I'm a motorist!
------------------------------
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 1523
***************************************