[8520] in Perl-Users-Digest
Perl-Users Digest, Issue: 2136 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 19 14:11:25 1998
Date: Thu, 19 Mar 98 11:00:40 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 19 Mar 1998 Volume: 8 Number: 2136
Today's topics:
Re: (Newbie to Perl) - can you improve my program? (Richard Bellavance)
ActiveState Build 315 Win32:EventLog - Time Confusion? <NO.SPAM.bob.murphy@clorox.com>
Appropriate or not ? <birgitt@order.booktraders.com>
Re: Assign lines of a text file into an array <ludlow@us.ibm.com>
Re: Assign lines of a text file into an array <ludlow@us.ibm.com>
Re: Challenge your programming skill schwern@starmedia.net
Re: Dynamically checking for existing functions (Bart Lateur)
Getting another servers environmental variables joshmccormack@yahoo.com
Re: Good Perl book scott@softbase.com
How do you capture command line arguments? <rickryan@mindspring.com>
Re: How do you create a directory? Please enlighten!? (Tom Grydeland)
Re: How to implement "timeouts" in perl? <jay@rgrs.com>
Insensetive EQ wsayegh@lynx.neu.edu
Re: Insensetive EQ <dboorstein@shopcfn.com>
Re: Insensetive EQ (I R A Aggie)
Re: Insensetive EQ (Lack Mr G M)
Installing on Solaris <con2royd@pie2rcom.ie>
IPC::Open2 in CGI script <shahada@icky.pc.my>
Re: IPC::Open2 in CGI script (brian d foy)
Re: Is there a "Newsgroup" for Newbies to Perl? (I R A Aggie)
MAPILogon Issues With Perl32 <Wheeler@Virginia.edu>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Mar 1998 10:52:57 -0500
From: charlot@CAM.ORG (Richard Bellavance)
Subject: Re: (Newbie to Perl) - can you improve my program?
Message-Id: <6erf0p$31k@ocean.CAM.ORG>
In article <3510C5CB.1F83979B@coos.dartmouth.edu>,
Ronald J Kimball <rjk@coos.dartmouth.edu> wrote:
>Matthew Kennedy wrote:
>>
>> if ($#ARGV != 0) {
>> warn "Syntax: perl psfragx eps_file";
>> exit 1;
>
>Add a newline; you don't need the line number in the error message.
>warn "Syntax: perl psfragx eps_file\n";
>
As long as we're in this vein, why not die() instead of warn() and exit() ?
Richard.
--
Richard Bellavance -- charlot@cam.org -- http://www.cam.org/~charlot/
"All along this path I tread / My heart betrays my weary head
With nothing but my love to save / From the cradle to the grave"
(Eric Clapton, "From the cradle")
------------------------------
Date: Thu, 19 Mar 1998 09:40:06 -0800
From: Bob Murphy <NO.SPAM.bob.murphy@clorox.com>
Subject: ActiveState Build 315 Win32:EventLog - Time Confusion?
Message-Id: <35115876.3C12A0D3@clorox.com>
Please see the bug I submitted to ActiveState, below. On a sequential
read, Win32::EventLog seems to be confused by two eventlog entries at
the exact same hour/min/second, even though the log entries appear to
have different record numbers.
Has anyone else encountered this? What's causing the read to get
'stuck'?
Do you have any work-around?
Answer this group or email to bob.murphy@clorox.com.
TIA,
-bob
=======================Filed ActiveState
Bug====================================
Entry Date : Thu Mar 19 09:14:39 1998
Bug ID : 1487
Request-type : bug
Contact infomation:
Name : Bob Murphy
Email : bob.murphy@clorox.com
Company : The Clorox Services Company
Phone : (510)271-1639
Platform information:
Platform : Windows NT Workstation 4.0
WebServer : None
BuildNumber : 315
SoftwarePackage : Perl for Win32
Bug information:
Title : Win32:EventLog - Multiple Simultaneous Events
Description======================================================
When using Win32:EventLog against an Event Log with at
least two events with
exactly the same time to the second, Win32:EventLog will
not do a sequential
read after the events are encountered.
Expected behavior: read the next sequential record
Exhibited behavior: 'stuck' on the first record which was
recorded at
exactly the same time
Example of EventLog entries:
2922 98-03-19 07:04:44 Perflib 1008 0 Error CAPLEQ03
Netscape Web Servers
C:\Netscape\Server\bin\httpd\nsctr.dll
2921 98-03-19 07:04:44 nsctrs 2003 0 Error CAPLEQ03
2920 98-03-19 07:04:44 nsctrs 2000 0 Error CAPLEQ03
2919 98-03-19 06:34:35 MSSQLServer 17055 1 Error CAPLEQ03
18204 tbsvolopen: Backup device '\\.\TAPE0' failed to
open,
operating system error = 32(The process cannot access the
file because it is being used by another process.)
2918 98-03-19 06:34:32 MSSQLServer 17055 1 Error CAPLEQ03
18204 tbsvolopen: Backup device '\\.\TAPE0' failed to
open,
operating system error = 32(The process cannot access the
file because it is being used by another process.)
2917 98-03-19 06:34:28 MSSQLServer 17055 1 Error CAPLEQ03
18204 tbsvolopen: Backup device '\\.\TAPE0' failed to
open,
operating system error = 32(The process cannot access the
file because it is being used by another process.)
2916 98-03-19 06:04:44 Perflib 1008 0 Error CAPLEQ03
Netscape Web Servers
C:\Netscape\Server\bin\httpd\nsctr.dll
2915 98-03-19 06:04:44 nsctrs 2003 0 Error CAPLEQ03
2914 98-03-19 06:04:44 nsctrs 2000 0 Error CAPLEQ03
2913 98-03-19 05:04:43 Perflib 1008 0 Error CAPLEQ03
Netscape Web Servers
C:\Netscape\Server\bin\httpd\nsctr.dll
2912 98-03-19 05:04:43 nsctrs 2003 0 Error CAPLEQ03
2911 98-03-19 05:04:43 nsctrs 2000 0 Error CAPLEQ03
2910 98-03-19 04:04:43 Perflib 1008 0 Error CAPLEQ03
Netscape Web Servers
C:\Netscape\Server\bin\httpd\nsctr.dll
2909 98-03-19 04:04:43 nsctrs 2003 0 Error CAPLEQ03
2908 98-03-19 04:04:43 nsctrs 2000 0 Error CAPLEQ03
2907 98-03-19 03:04:42 Perflib 1008 0 Error CAPLEQ03
Netscape Web Servers
C:\Netscape\Server\bin\httpd\nsctr.dll
2906 98-03-19 03:04:42 nsctrs 2003 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
2905 98-03-19 03:04:42 nsctrs 2000 0 Error CAPLEQ03
And So On....
Sample_Code====================================================
$EventObj->GetOldest($oldestevent); # Get the record
number of the oldest event currently in the log
$EventObj->Read((EVENTLOG_SEEK_READ |
EVENTLOG_BACKWARDS_READ), $numevents +
$oldestevent, $EventData);
while($numevents) {
$EventObj->Read((EVENTLOG_SEQUENTIAL_READ |
EVENTLOG_BACKWARDS_READ), 0,
$EventData);
$recordnumber = $EventData->{'RecordNumber'};
$source = $EventData->{'Source'};
$timewritten = $EventData->{'Timewritten'};
$id = $EventData->{'EventID'} & 0xffff;
$category = $EventData->{'Category'};
$type = $EventData->{'EventType'};
$strings = $EventData->{'Strings'}; chomp($strings);
$strings =~ s/,/,\n\t/g;
$computer = $EventData->{'Computer'};
($timewritten < $timewindow) && last;
($sec,$min,$hour,$mday,$mon,$year,$sday,$yday,$isdst) =
localtime($timewritten);
$twritten = sprintf("%02d\-%02d\-%02d
%02d:%02d:%2d",$year,$mon+1,$mday,$hour,$min,$sec);
if(($source =~ /$eventsource/) && ($eventtype eq
$EventTypes[$type]) && ($id == $eventid) &&
(!$eventstring || ($strings =~ /$eventstring/))) {
$EventList[$eventsfound++] = ("\t$recordnumber
"."$twritten "."$source "."$id "."$category
"."$EventTypes[$type] "."$computer\n"."\t$strings\n");
}
$numevents--;
}
Workaround=====================================================
Have tried using EVENTLOG_SEEK_READ with an absolute
record number, same
behavior occurs. Tried changing the offset on
EVENTLOG_SEQUENTIAL_READ, same
behavior occurs.
Other_Comments==================================================
Don't really know if this is a bug with Perl Win32 Build
315, or if there is a
bug in the EventLog Object itself...
************************************************************************
--
==============================================================
For Reply Mail: Remove the "NO.SPAM. " from my e-mail address -
bob.murphy@clorox.com
==============================================================
------------------------------
Date: Thu, 19 Mar 1998 12:40:14 -0500
From: Birgitt Funk <birgitt@order.booktraders.com>
Subject: Appropriate or not ?
Message-Id: <3511587E.5DD060E3@order.booktraders.com>
Hi,
Is it appropriate for a beginner who has written his first Perl
programs,
he needs to use for his own business purposes (meaning they absolutely
need to work safely and correctly), to ask experts to test the programs
and eventually make suggestions how to systematically debug them and
make them safer ?
How is this done among professionals ? Is the request for something like
thing of a magnitude that a one time work contract is appropriate or
does this fall under "peanuts" for experts and is not worth to be looked
at ?
If a request like this would be posted here, would it be considered
"getting a lunch for free" (I am not asking for writing a program,
just for testing one, which is written by an inexperienced beginner)
and punished with flames, or is it acceptable.
I have a lot of Perl programs on my server written by an expert, whose
code is left under the GNU Public License and which I will use to learn
Perl.
I am scared to add my own first code snippets and scripts for some
little customized applications I need on basis of his huge program.
What is the appropriate way to get it tested for safety ?
(I know of course that I could ask the expert to do it and pay him,
but the question is asked here under the assumption that my bank
account doesn't allow this option or that this work is not a desirable
work for an expert to deal with.)
I would appreciate your advice very much.
Birgitt Funk
------------------------------
Date: Thu, 19 Mar 1998 11:48:19 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Assign lines of a text file into an array
Message-Id: <35115A63.7F6F9FAB@us.ibm.com>
Eric Bohlman wrote:
>
> C.S.M.Leung <csml1@ukc.ac.uk> wrote:
> : Is it possible to assign each line of a text file into an associative array where
> : the key will be the line number and the value will be a string variable containing
> : the whole line?
>
> It's trivially easy once you remember that $. contains the line number
> from the most recently read filehandle. Here's one of many ways to do it:
>
> my %lines=map {$.,$_} <FILE>;
Are you sure that this actually works? It seems that after sucking
<FILE> into the array used as map's input, the value of "$." would be
fixed at the value of the last line number in the file. So, wouldn't
you end up assigning each line to the same key, which would leave you
with a hash consisting of one value (the last line in the file)?
Correct me if I'm wrong, please.
Using a while loop doesn't make it that much more difficult.
while (<FILE>) {
$lines{$.} = $_;
}
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support and all opinions are my own.
------------------------------
Date: Thu, 19 Mar 1998 11:50:41 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Assign lines of a text file into an array
Message-Id: <35115AF1.4D91186@us.ibm.com>
Eric Bohlman wrote:
>
> C.S.M.Leung <csml1@ukc.ac.uk> wrote:
> : Is it possible to assign each line of a text file into an associative array where
> : the key will be the line number and the value will be a string variable containing
> : the whole line?
>
> It's trivially easy once you remember that $. contains the line number
> from the most recently read filehandle. Here's one of many ways to do it:
>
> my %lines=map {$.,$_} <FILE>;
Are you sure that this actually works? It seems that after sucking
<FILE> into the array used as map's input, the value of "$." would be
fixed at the value of the last line number in the file. So, wouldn't
you end up assigning each line to the same key, which would leave you
with a hash consisting of one value (the last line in the file)?
Correct me if I'm wrong, please.
Using a while loop doesn't make it that much more difficult.
while (<FILE>) {
$lines{$.} = $_;
}
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support and all opinions are my own.
------------------------------
Date: Thu, 19 Mar 1998 12:13:56 -0600
From: schwern@starmedia.net
To: kiml@zplace.com
Subject: Re: Challenge your programming skill
Message-Id: <6ern93$ueq$1@nnrp1.dejanews.com>
An idea, which is probably wrong, but I'm throwing in here just to see how
Abigail tears it apart. :)
Keep an index of your customer's coordinates at a granularity level that's
appropriate... like an index point every degree...
# Enter the customer into the regular DB.
$customerDB->{$id}{name} = 'Fred';
$customerDB->{$id}{long} = 72.672;
$customerDB->{$id}{lat} = 45.223;
# Add them to the coordinates index at 73,45
push @{ $CoordsIndex->{long}{round $customerDB->{$id}{long}} },
$customerDB->{$id};
push @{ $CoordsIndex->{lat}{round $customerDB->{$id}{lat}} },
$customerDB->{$id};
# Search for the nearest customer to 73.125, 44.888
@nearbyCustomers = intersection $CoordsIndex->{round 73.125},
$CoordsIndex->{round 44.888};
# If @nearbyCustomers is empty, expand your search to
# $long + and - 1 degree and $lat + or - 1 degree
# continue expanding until you find a customer.
# After you find customers, expand +1 and -1 once more to compensate
# for the problem that your closest customer might be in the next "grid"
# over.
# Then check for the minimum distance of the set of @nearbyCustomers
This is a very sloppy indexing scheme, but it reduces the problem from O(n) to
O(n/granularity of your indexing scheme). And its very suseptable to
clustering of customers in one area of the country (the indexing won't be as
effective in NYC as in say... Iowa).
I should have a look at Ab's suggested books myself, though I've been holding
off for the new edition of Knuth.
In article <3510AEA6.DF610245@zplace.com>,
Kim Lo <kiml@zplace.com> wrote:
>
> Perl programmers,
> I am facing with the challenge of writing a program to find the closest
> customer name based on an input zipcode. I have the data file containing
> zipcode, state, longitude and latitude in a database already.
> My approach to this problem is very simple however I want to find out
> from you programmers if this is the most efficient way to do it. Here're
> the steps:
> 1. Get the long and lat based on the input zipcode
> 2. For each customer do
> a. Get customer zipcode and determine long and lat
> b. Delta long and lat from step1 and 2a. Get the absolute value
> c. Convert the long and lat into an R value using pythagore
> theorem (R^2=x^2+y^2)
> 3. Sort the R value and the smallest R will contain the closest customer
> to the input zipcode.
>
> The problem I am having with this algorithm is that it could take a long
> time to compute as the number of customers grow. To minimize computing,
> I thought of just getting customers from the same state as the input
> zipcode and compute those only. The caveat to this approach is that for
> someone that lives closeby 2 states (especially on the East Coast), this
> may return incorrect result.
> Any feedback is welcome.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Thu, 19 Mar 1998 16:31:04 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Dynamically checking for existing functions
Message-Id: <3514479e.30744543@news.tornado.be>
Andrew M. Langmead wrote:
>The other suggestion of using "defined &coder" (to use your example
>name) only involves a symbol table lookup, and doesn't actually call
>the subroutine to check for its existance.
This indicates to me that there is (yet another) ambiguity in Perl's
syntax.
$result = &coder;
if (defined $result) { ... }
This behaves completely differently from
if (defined &coder) { ... }
Nice. NOT!
"defined \&coder" would have made more sense, I think. But why does
print \&James;
print something like "CODE(0x153b14)", even though sub James was not
defined?
Bart.
------------------------------
Date: Thu, 19 Mar 1998 10:21:05 -0600
From: joshmccormack@yahoo.com
Subject: Getting another servers environmental variables
Message-Id: <6ergho$k8s$1@nnrp1.dejanews.com>
I've seen the scripts that tell you what the environmental variables are for
the server you're using (http://www.getscript.com/variable.cgi), but I'd like
one that could get them for any server. Connected to a form, user puts in name
(i.e. www.scriptsearch.com) and gets the data. Would I just need to use one of
the Perl scripts that get your own data and change $ENV to something and make
an HTML page with a form something like this:
<form action="http://www.getscript.com/variable.cgi" method=GET>
Enter the name of the site to ask below: (eg. www.phillynews.com)<br>
<input name=server value="" type=text size=48><br>
<input name=action value="Tell me" type=submit>
</form>
Thanks for the help,
Josh
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 19 Mar 1998 18:29:02 GMT
From: scott@softbase.com
Subject: Re: Good Perl book
Message-Id: <6ero5e$r8l$1@scully.new-era.net>
> Anyone written something similar to the perl reference 'card' for the
> CPAN library?
Que has a "6 in 1" desktop web reference which covers Perl, Java,
HTML, etc. I find it very useful. This book is now on the
discount shelves, so you can pick it up for about $10. If you
do web programming, it's nice to have.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Thu, 19 Mar 1998 12:02:18 -0600
From: "rickryan@ Mindspring" <rickryan@mindspring.com>
Subject: How do you capture command line arguments?
Message-Id: <6erm5g$1b9@camel21.mindspring.com>
I'm trying to run a perl script directly from the browser's address line as
follows:
anyscript.pl?arg1
I've tried reading stdin, getopt, and $_[0] with no success.....How do I
capture the command line argument "arg1" into a program variable?
------------------------------
Date: 19 Mar 1998 17:56:19 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: How do you create a directory? Please enlighten!?
Message-Id: <slrn6h2n23.l.Tom.Grydeland@mitra.phys.uit.no>
On Thu, 19 Mar 1998 10:28:14 -0500,
Mark Polakow <mark@imp.net> wrote:
> or method for creating directories? I know about unlink and rmdir can
perldoc -f mkdir
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: 19 Mar 1998 11:55:46 -0500
From: Jay Rogers <jay@rgrs.com>
To: Marco Paganini <paganini@paganini.net>
Subject: Re: How to implement "timeouts" in perl?
Message-Id: <82btv2k4bx.fsf@shell2.shore.net>
Marco Paganini <paganini@paganini.net> writes:
> Jay Rogers <jay@rgrs.com> writes:
> > Both IO::Socket::INET and Net::Telnet allow you to connect with a
> > timeout. However, both use alarm() within an eval to timeout the
> > connect.
>
> Yes, the timeout problem on the connect() call was solved using
> IO::Socket::INET. It works fine.
>
> > I've never heard of anyone having a "non-reentrant" problem as you
> > describe. I'd think you could only have a problem of that nature
> > using threads?
>
> Signal processing is very tricky. Doing things inside subroutines
> that catch signals is problematic, since (as I said), many parts
> of the kernel (and perl itself?) are non-reentrant. So, even
> a malloc (used by many perl commands, for sure) could cause
> problems. This is documented in the perlipc man page and
> (believe me) it really happens. :)
>
> When your singal handler is called, you can do nothing (safely),
> except set a variable. Even calling a "print" could cause a
> syssegv (in theory).
Fear not :-) In the context of your original problem, none of what you
are worrying about here is a problem. Your problem had to do with
timing-out a connect using alarm in an eval.
If you're blocked, waiting on a slow system call like connect, and you
receive and handle the signal SIGALRM, the connect is interrupted and
fails (i.e. it's not restarted). There are no issues of malloc or
non-reentrant code.
You say you're now using IO::Socket::INET and it works fine. The
version that comes with a distribution of perl implements the timeout
using the method that you were trying to avoid. Again I don't think
this is a problem and I've have never heard of anyone having a problem
with it dumping core when timing-out a connect.
--
Jay Rogers
jay@rgrs.com
------------------------------
Date: Thu, 19 Mar 1998 10:26:03 -0600
From: wsayegh@lynx.neu.edu
Subject: Insensetive EQ
Message-Id: <6ergr2$kis$1@nnrp1.dejanews.com>
Hey PERL eXperts:
How could I come up with an insesetive EQ in perl. Here is a function that I
wrote, and which is missing the "test" part.. if you know how to modify the
code go ahead.. If you would like to suggest another way to do it, then go
ahead too. What I am trying to accomplish is to have a function that will
store the files wich have "_sim" in array1, and the files that don't have
"_sim" in array2. Here is a part of the code:
@files = <*>; # Store the list of files in an array
$lenght = @files; # Get the lenght of the array
foreach $file (0 .. $lenght){ # Loop for each file
$temp=@files[$file]; # Temp is equal to the current file
if ( temp has _sim in it){ # Here is the part that I don't know
@array1="@array1 $temp"; # Store all _sim in array1
}
else {
@array2="@array2 $temp"; # Store all none _sim in array2
}
}
Please note.. Don't give me the nonesense you give to everyone else, "Go read
the perl manual", "did you check out perl.com before you asking this dumb
question". Well I didn't.. I have the PERL O'Reilly book, and it wasn't as
helpfull as the Korn Shell O'Reilly book, nore the Sed & Awk O'Reilly book,
and frankly I don't have time surfing the web to look for these simple
tutorials that do nothing. If you want to help me.. Hey go ahead.. if you
don't want to do so.. then keep your comments to yourself. And thanks to those
that helped me, are helping me, and will help me.
Waseem
wsayegh@lynx.neu.edu
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Thu, 19 Mar 1998 13:06:06 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: Insensetive EQ
Message-Id: <35115E8E.1289ACF0@shopcfn.com>
wsayegh@lynx.neu.edu wrote:
>
> Hey PERL eXperts:
>
[SNIP]
> ahead too. What I am trying to accomplish is to have a function that will
> store the files wich have "_sim" in array1, and the files that don't have
> "_sim" in array2. Here is a part of the code:
>
> @files = <*>; # Store the list of files in an array
> $lenght = @files; # Get the lenght of the array
> foreach $file (0 .. $lenght){ # Loop for each file
> $temp=@files[$file]; # Temp is equal to the current file
> if ( temp has _sim in it){ # Here is the part that I don't know
> @array1="@array1 $temp"; # Store all _sim in array1
> }
> else {
> @array2="@array2 $temp"; # Store all none _sim in array2
> }
> }
>
> Please note.. Don't give me the nonesense you give to everyone else, "Go read
[SNIP]
the only help i will give you with an attitude like that is as follows:
'$lenght' is spelled incorrectly if it is an attempt to reflect the
english word 'length'. luckily for you, despite any lack of accuracy,
your precision was perfect.
'$temp=@files[$file]' is considered bad form since your are using a
single element array slice to assign a scalar. -w would have told you
this.
your array assignments are screwy as well. you are going to end up
with a single element array with its single value as string of space
separated filenames. when you find a matching file use 'push' instead.
and while you're at it, why not throw out the 'foreach' stuff for a
'while':
while(<*>) {
if ( temp has _sim in it ){
push @array1, $_;
}
else {
push @array2, $_;
}
}
almost there... stay on target...
to see if your file name has the string '_sim' in it may i suggest
you read the appropriate documentation on regular expressions:
man perlre
perldoc perlre
blue camel pg 57
you will wonder how you ever got along without them.
i hope this helps. and remember: attitude begets attitude.
--
# dan boorstein <dboorstein@shopcfn.com>
seek DATA,0,0;print scalar<DATA>,__END__
Just another Perl hacker,
------------------------------
Date: Thu, 19 Mar 1998 13:18:09 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Insensetive EQ
Message-Id: <fl_aggie-1903981318090001@aggie.coaps.fsu.edu>
In article <6ergr2$kis$1@nnrp1.dejanews.com>, wsayegh@lynx.neu.edu wrote:
+ ahead too. What I am trying to accomplish is to have a function that will
+ store the files wich have "_sim" in array1, and the files that don't have
+ "_sim" in array2. Here is a part of the code:
+
+ @files = <*>; # Store the list of files in an array
[trivial two line case-insensitive 'grep' solution deleted]
+ Please note.. Don't give me the nonesense you give to everyone else,
I just deleted out the solution 'cause of this statement. BTW, you
should refer to individual elements of a list as:
$list[$num]; # instead of:
@list[$num];
+ "Go read the perl manual",
You should try a 'perldoc -f grep' some time, too...
+ "did you check out perl.com before you asking this dumb
+ question". Well I didn't.. I have the PERL O'Reilly book, and it wasn't as
+ helpfull as the Korn Shell O'Reilly book, nore the Sed & Awk O'Reilly book,
So what? it has an index. Is it the blue Camel? page 629 ( the INDEX )
has _four_ entries that begin with "eq" -- that _is_ what you're looking
for? One of the entries reads:
equality operators, 87
Gosh, I look at page 87, and lo and behold! equality operators, both
numeric and string! You have the book...did you _use_ it for something
_other_ than a paperweight?
+ and frankly I don't have time surfing the web to look for these simple
+ tutorials that do nothing.
But you have time to bug us?
+ If you want to help me.. Hey go ahead.. if you
+ don't want to do so.. then keep your comments to yourself.
I am helping you. Your address indicates an institution of higher learning.
By now you should be aware of _how_ to use an index in a book to find
_specific_ instances of a particular subject. Use it. If not, find someone
who'll teach you how to use it. It'll take less than 30 minutes.
+ And thanks to those that helped me, are helping me, and will help me.
You're welcome. I've given you enough hints to figure this one out
on your own, _if_ you figure out how to use an index...
James - hint: grep, regular expressions and the fragment '_sim', and case
insensitivity,
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Thu, 19 Mar 1998 17:58:57 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Insensetive EQ
Message-Id: <1998Mar19.175857@ukwit01>
In article <6ergr2$kis$1@nnrp1.dejanews.com>, wsayegh@lynx.neu.edu writes:
|> Hey PERL eXperts:
|>
|> How could I come up with an insesetive EQ in perl.
You want a regular expression.
|> @files = <*>; # Store the list of files in an array
|> $lenght = @files; # Get the lenght of the array
|> foreach $file (0 .. $lenght){ # Loop for each file
|> $temp=@files[$file]; # Temp is equal to the current file
|> if ( temp has _sim in it){ # Here is the part that I don't know
|> @array1="@array1 $temp"; # Store all _sim in array1
|> }
|> else {
|> @array2="@array2 $temp"; # Store all none _sim in array2
|> }
|> }
a) Assuming that you don't want @files elsewhere in your code, you don't
need to keep a copy.
b) You don't need to loop with a number. Your code generates a copy of
a list with the numbers 0 to $length in it.
c) To do what you had you would have needed
$lenght = $#files;
ie. you want the number of the last element, not the number of entries
in the array (which is one higher - usually).
d) You don't add elements at the end of an array by using interploation
within a string.
So, with that in mind:
foreach $file (<*>) {
if ($file =~ /_sim/) {
push @array1, $file;
} else {
push @array2, $file;
}
}
|> Please note.. Don't give me the nonesense you give to everyone else, "Go read
|> the perl manual",
Well, you're not going to get very far until you do....the above code
does what you asked, but you don't stand much chance of making it do
anything *useful* by being part of a larger program until you put more
effort into reading how to do it. Try reading some of the source in the
standrad modules and figuring out what the code is doing.
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: Thu, 19 Mar 1998 18:22:28 GMT
From: Damien Conroy <con2royd@pie2rcom.ie>
Subject: Installing on Solaris
Message-Id: <35116198.41C6@pie2rcom.ie>
Hi,
I've downloaded and installed perl5.004_04 successfully on osf. However,
when I try to install on a solaris 2 machine the
lib/perl5/sun4-solaris/5.00404 directory doesn't seem to be created, nor
does the lib/perl5/site_perl/sun4-solaris directory. The perl executable
is fine. This is being installed under my user directory using gcc as
the compiler. Any comments appreciated.
Thanks,
:D
--
Just delete the two 2s from my email address
------------------------------
Date: Fri, 20 Mar 1998 01:17:15 +0800
From: shahada abubakar <shahada@icky.pc.my>
Subject: IPC::Open2 in CGI script
Message-Id: <3511531A.2DF6E390@icky.pc.my>
I'm having problems using IPC::Open2 from within a CGI script, running
under Apache 1.2.5. I'm not sure if this is a Perl issue or perhaps a
CGI one. To help debug, I've reduced my code to the following:
#!/usr/bin/perl
use IPC::Open2;
use Symbol;
print "Content-Type: text/HTML\n\n";
print "Line 1\n<br>";
$WTR = gensym ();
$RDR = gensym ();
$pid = open2 ($RDR, $WTR, 'ls -l');
while (<$RDR>)
{
print "$_<br>\n";
};
close $WTR;
close $RDR;
print "Line 2<br>\n";
In my actual CGI I don't actually call "ls -l", but this is just an
example. My real case requires both reading and writing to the other
process, which is why I can't just do an open with a "|". Anyway, when I
run this as a CGI, I get the following in the browser:
Line 1
Content-Type: text/HTML Line 1
total 3
-rwxr-xr-x 1 shahada users 744 Mar 17 22:14 kaka
-rwxr-xr-x 1 shahada users 268 Mar 17 22:18 loo.cgi
-rwxr-xr-x 1 shahada users 792 Mar 17 22:02 test.cgi
Line 2
Notice that the Content-Type and "Line 1" are repeated. For some reason,
when the Open2 call is made, it causes the CGI, or at least the output,
to repeat up to the point of the call.
Can anyone help with this? An email reply would be appreciated, but a
post to the group would be fine.
Regards,
.sha
------------------------------
Date: Thu, 19 Mar 1998 13:32:25 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: IPC::Open2 in CGI script
Message-Id: <comdog-1903981332250001@news.panix.com>
Keywords: just another new york perl hacker
In article <3511531A.2DF6E390@icky.pc.my>, shahada abubakar <shahada@icky.pc.my> posted:
> I'm having problems using IPC::Open2 from within a CGI script, running
> under Apache 1.2.5. I'm not sure if this is a Perl issue or perhaps a
> CGI one. To help debug, I've reduced my code to the following:
there's nothing special about IPC::* in CGI (that is, beyond the
normal concerns of a user with a limited environment). just as a guess:
absolute paths are a good thing.
--
brian d foy <http://computerdog.com>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
------------------------------
Date: Thu, 19 Mar 1998 13:28:02 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <fl_aggie-1903981328020001@aggie.coaps.fsu.edu>
In article <35113184.D804164E@west.net>, John Callender <jbc@west.net> wrote:
+ I R A Aggie wrote:
+ > Those sorts of folks really shouldn't a) be writing CGI applications,
+ > and b) using perl to do it.
+ All the more reason.
They can take a look at my sig, too...
+ As with the release of tools like CBW or Satan, you
+ can't put the genie back into the bottle just by squeezing your eyes
+ shut and wishing really hard.
Satan has to do with newbies doing CGI how? I'm unfamiliar with CBW,
but satan was an attempt at leveling the playing field against crackers
by giving _everyone_ the same set of tools, instead of just hiding them
in the dark corners where "reputable" folks don't go.
+ So some beginner-oriented resources (preferably, resources that don't
+ impugn their intelligence by calling them "idiots") would probably be a
+ good idea. For an investment of a small fraction of the effort currently
+ going into the game of "see how clever I can be in devising newbie
+ put-downs," some very useful resources could be created.
And you guarantee they'll be read how?
And that's the rub. You can create resources till you're blue in the
face, but the number of newbies who won't find them/use them will
still be Legion.
If they can't be bothered to 'perldoc perlfaq' or 'perldoc CGI',
why do you believe they'll 'perldoc CGIcookbook' ??
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: Thu, 19 Mar 1998 12:57:25 -0500
From: "David E. Wheeler" <Wheeler@Virginia.edu>
Subject: MAPILogon Issues With Perl32
Message-Id: <35115C85.2632484C@Virginia.edu>
HI all,
I'm using MAPI to send mail on NT. I got the code out of _Learning Perl on Win32
systems_, pp. 214-217. It works great, except for one thing.
The script will run on a server, called by server application (Remedy), and
needs to be able to send mail without a user being logged on. That means I can't
use a profile.
The MS SDK Documentation on MAPI says that with the MAPILogon method, one can
use ProfileInfo to create a temporary profile. Here's the relevant portion of
the doc (from
http://premium.microsoft.com/msdn/library/sdkdoc/mapisdk/oleobjis_31ym.htm):
ProfileInfo
Optional. String. Contains the server and mailbox names that Logon should use to
create a new profile for this session. The profile is deleted after logon is
completed or terminated. The ProfileInfo parameter is only used by applications
interfacing with Microsoft Exchange Server. The profileName parameter is ignored
if ProfileInfo is supplied.
...
The ProfileInfo parameter is used to create a temporary profile for the session.
CDO generates a random name for the profile. For an authenticated profile, the
format of the string is <server name> & vbLf & <mailbox name> where the server
and mailbox names can be unresolved. Note that the mailbox name is not the
messaging user's display name, but rather the alias or account name used
internally by the user's organization. For example, "johnd" should be used
instead of "John Doe".
However, I can't figure out the proper syntax for this option, if it even works
in Perl. I don't expect that the answer is complex. If anyone has any experience
with this, please contact me directly.
TIA!
David
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2136
**************************************