[7418] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1043 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 18 09:17:10 1997

Date: Thu, 18 Sep 97 06:00:52 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 18 Sep 1997     Volume: 8 Number: 1043

Today's topics:
     Algorithm for splitting flat files <eelco@bicho.eui.upm.es>
     Re: Change /etc/passwd (Jeremy Brinkley)
     Re: Change /etc/passwd (brian d foy)
     Re: Client/Server over serial line... (Mark Nottingham)
     Re: homogenous/nonhomogenous list test? <ajohnson@gpu.srv.ualberta.ca>
     Re: How do I change a line in a file? <seay@absyss.fr>
     Re: How to assign new vals to hash elements? <seay@absyss.fr>
     Re: Impossible dbm size (Jeremy D. Zawodny)
     IP checking <makela@riksu.hamkk.fi>
     KornShell to Perl (peter jacobsson)
     Re: looping through an sql query using win32::odbc (Jeremy D. Zawodny)
     Re: postmail and perlis <rene.sorger@onlinemedia.de>
     Re: postmail and perlis (Jeremy D. Zawodny)
     Re: Reg Exp Question <rovf@earthling.net>
     Re: Reg Exp Question (Matti Kinnunen)
     Re: Reg Exp Question (Bart Lateur)
     Re: reg expression help! <rovf@earthling.net>
     Re: reg expression help! (Bart Lateur)
     Rounding numbers problem <david.nurse@ndcb.ox.ac.uk>
     Re: Selena Sol's Classified Ad Script (Jeremy D. Zawodny)
     Re: Something of the day script (Jeremy D. Zawodny)
     Re: The CSV format stinks! <seay@absyss.fr>
     Re: The CSV format stinks! (Bart Lateur)
     Re: Win32 Perl FAQ Addition? (WAS Re: Is Perl for Win32 (Jeremy D. Zawodny)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 18 Sep 1997 11:58:34 +0200
From: "E.R. Daams" <eelco@bicho.eui.upm.es>
Subject: Algorithm for splitting flat files
Message-Id: <Pine.SUN.3.96.970918115632.28980B-100000@bicho.eui.upm.es>

Hi y'all,

does somebody have an algorithm to split flat files. We want to create a
dynamic database that splits when it contains one hundred records and we
want it to concatenate when 2 files together contain less then hundred.

Any help  would be appreciated.

	Eelco

P.S. Answering through email works the best!







------------------------------

Date: 18 Sep 1997 10:29:54 GMT
From: jeremy@wishbone.stanford.edu (Jeremy Brinkley)
Subject: Re: Change /etc/passwd
Message-Id: <5vqvr2$h9t$1@nntp.Stanford.EDU>

On Thu, 18 Sep 1997 10:16:53 +0200, Juan Carlos del Rio (jcarlosd@ford.com) put forth:
> Our web server is running on HP-UX 10.2. Some of our users are able to
> input files on it, because I have created them as unix users. 
> 
> My question is the following: is it possible to run a perl program so
> they can change the access password (updating /etc/passwd file)?

See passwd.  But you aren't really authenticating web uses using j/etc/passwd, are
you?

--
Jeremy Brinkley
System Administrator
Stanford Blood Center
jeremy@wishbone.stanford.edu

finger for PGP key (2.6.2) or
http://wishbone.stanford.edu/~jeremy


------------------------------

Date: Thu, 18 Sep 1997 06:50:17 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Change /etc/passwd
Message-Id: <comdog-ya02408000R1809970650170001@news.panix.com>

In article <3420E375.3F3@ford.com>, jcarlosd@ford.com wrote:

>Our web server is running on HP-UX 10.2. Some of our users are able to
>input files on it, because I have created them as unix users. 
>
>My question is the following: is it possible to run a perl program so
>they can change the access password (updating /etc/passwd file)?

sure, but they would have ot be superuser (or somehow get their process
to be root).

if they want to change their password, use the passwd command.  that's
why it's there :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


------------------------------

Date: Thu, 18 Sep 1997 22:06:56 +1000
From: mnot@pobox.com (Mark Nottingham)
Subject: Re: Client/Server over serial line...
Message-Id: <mnot-ya02408000R1809972206560001@192.168.1.1>



I looked at the termio stuff in POSIX and then quickly averted my eyes ;-)

Hmm. I looked at Comm.pl, and it seemed to be in going in the right
direction for me. Particularly, I need to talk between two UNIX boxen about
four feet from each other (i.e., null modem), with perl happening on both
ends (CGI and post-processing, respectively). Could I sit Comm.pl on both
ends and develop a primative protocol? (it's just pushing small text files
one way, and sending acks and so forth the other)...

Thanks,


In article <gerlachEGnqK6.MqM@netcom.com>, gerlach@netcom.com (Matthew H.
Gerlach) wrote:

>With UNIX the answer is TIMTODI!  The most UNIX like method would involve
>using the termio interface in the POSIX.pm.  If your were programming in C
>that's how you'd do it.
>
>Having done a lot of termio stuff in C, I prefer a slightle different 
>approach.  I use Comm.pl's expect-like feature to open a bidirectional 
>connection to a serial program like kermit, tip, or cu.  Then your perl 
>code simply "print"'s to the serial program to write out the serial 
>connection and "expect"s to read characters.  
>
>The down side to this method is that there is an extra process involved.  
>The upside, especially if you use kermit, is that you leverage the 
>functionality in the kermit program.  This includes built in support
>for file transfer, logging of the serial session to a file, and a library
>of modem support for more modems than you could imagine.

-- 
Mark Nottingham
Melbourne, Australia
mnot@pobox.com


------------------------------

Date: Wed, 17 Sep 1997 22:12:39 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: homogenous/nonhomogenous list test?
Message-Id: <34209C27.36F9D002@gpu.srv.ualberta.ca>

Harold Todd Chapman wrote:
> 
> Raymond K. Bush wrote:
> >
> > Is there an efficient way i can check to see if a list of names is
> > homogenous.  A 1-4 liner please.  Right now i am using a foreach and an
> > if but somehow this seems like the wrong way and slow if the list (
> > rather LoL) is big (20000 entries per list and around 8000 lists so you
> > can see why it's important to speed this bugger up).  Is a foreach/if
> > loop the best that can be done (ps i return when i find one entry not
> > like the others)?
> >
> 
> The method you pick has alot to do with what you data sets typically
> look like. A method that is very fast on one data set could be very slow
> on another.
> 

here's some further possibilities for testing homogeneity
(takes array; return 1 if homogenous, 0 if heterogenous):

sub is_homo_grep {
   $first=$_[0];
   return 0 if scalar grep{$_ ne $first} @_;
   return 1;
}

although the grep has to run through every element, even
after detecting heterogeny (so to speak...ie; can't jump out
like 'last' in foreach), it should be fairly good in the
worst case of a homogeneous array (where the foreach would
go through it all as well).


sub is_homo_hash {
   my %hash=();
   @hash{@_}=();
   return 1 if keys %hash ==1;
   return 0;
}

this one might be ok, though with very large heterogeneous
arrays it may slow down and or consume more memory by 
generating a lot of keys in the hash slice?

sub is_homo_regex {
   return 1 if "@_"=~/^(\S+)(\s\1)*$/;
   return 0;
}

this one has good potential...it assumes no spaces within
an element...one could change this to set $"="|" (for
example) and /^([^|]+)(\|\1)*$/ or some such thing known to
not be in an array element. Being anchored at both ends
should keep up speed, and it will fail at the first sign
of heterogeny (like foreach with last).

as Harold said, a good method depends on the typical data
sets looked at.

regards
andrew


------------------------------

Date: Thu, 18 Sep 1997 12:15:20 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: How do I change a line in a file?
Message-Id: <3420FF38.52AAD133@absyss.fr>

comp.lang.perl deleted from the Newsgroup line because it don't exist no
more.  Someone (or someones) should talk to some USENET admins to get
the thier news spool cleaned up.

Tanya Quinn wrote:
>
>  Chocolate wrote:
> >
> > How do I change a line in a file from a web page?  I have this database
> > file and there is one entry per line.  If the password is correct then
> > the entry appears and you can edit it.  The only thing is how do I
> > replace the old entry with the new one.  I don't want to replace the
> > whole file just the line that matches the password.  How do I do this
> > using perl?
> 
> You can open the file for reading and writing, find the line you want to
> change, seek to that position and overwrite.
> 
> For example,
> open (MY_FILE, "+<$myfilename");
> $filepos = tell (MY_FILE);
> 
> while (<MY_FILE>) {
>         chop; #remove the newline character
>     if (!found) {
>           if ($_ =~ /somepattern/) {
>                  $found = 1;
>              seek (MY_FILE, $filepos, 0);
>         print $newstuff;
>           }
>         }
>         $filepos = tell (MY_FILE);
> }
> 
> This will work if the entry is the same size, otherwise you may be
> writing over more of the file, and I think you'll have to do it by
> echoing the rest of the file to a new file.

With Unix boxes, this is true.  Data is just a stream, so you can modify
the stream if and only if the modification is the same size as the
original.  Sinced passwords are usually variable length (he doesn't
mention making a 128-bit MD5 key or some other fixed size munge of the
cleartext), I doubt if this will work well.  For other OSes (DOS, VMS,
whatever), things could be much different.  I don't know enough about
thier filesystems to say.

Chocolate,

You might want to do something like

	$standardized_pw = sprintf '%50.50s', $real_pw;

to make what you are dealing with fixed size so you can use Tanya's
solution.  Of course, depending on what you are doing, this could be a
serious no-no.

- doug


------------------------------

Date: Thu, 18 Sep 1997 12:02:48 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: How to assign new vals to hash elements?
Message-Id: <3420FC48.4BD77E1F@absyss.fr>

dave wrote:
> 
> I use references a lot and wish to assign new values to hash elements
> without "moving" the "location" of the element.
> 
> For example:
> 
> %hash = ( 'key1' => 'fred', 'key2' => 'wilma' );
> $valref = \$hash{key1};
> 
> If I then do:
> 
>      %hash = %similarHash;
> 
>           $valref is nolonger valid.
> 
> while if I do:
> 
>     foreach $k ( keys %similarHash ) {
>          $hash{$k} = $similarHash{$k};
>     }
> 
>         $valref remains valid.

Do you know what is happening here?  $valref is a pointer to a scalar
that happens to be the value half of a key=>value pair in a hash table. 
When you do %x=%y basically all the key=>value paris of x are deleted
and copies of the the key=>value pairs from %y are injected into %x. 
You reference still points to a valid scalar value (the string "fred"),
but this scalar is not in any key=>value pair.  Your second solution
(the foreach loop) just inserts %y kv pairs into %x without deleting
what was already there.  Of course, if %y has a key that was already
used in %x, the value in %x is changed to the one from %y.

Yes, the two examples are fundamentally different.  There is no way that
they will have the same functionality.


> I keep thinking there must be a perl func or core library call that's
> shorter than the foreach loop, but I'm about ready to give up trying
> to find it.  Is there anything?

I can't think of any solution better than your foreach loop.  Why do you
think that there should be something "shorter than the foreach loop"? 
This is Perl, not APL.  We like consise code, but one-liners aren't our
raison d'etre (well, except for Randal, but we try to forgive him).  If
you *have* to do this on one line, try

	$x{$_} = $y{$_} foreach ( keys %y );

Note that picking smaller variable names does help cut down on size, but
at the cost of legibility :-)

- doug


------------------------------

Date: Thu, 18 Sep 1997 12:20:27 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Impossible dbm size
Message-Id: <34241c34.168903680@igate.hst.moc.com>

[cc'd automagically to original author]

On Wed, 17 Sep 1997 15:28:12 -0400, Charles Jaimet <cjaimet@ican.net>
wrote:

>My server says my dbm database file takes up 4,800 GB!

Way cool... :-)

>The server doesn't have nearly that much storage space and when I dump
>the file to text it's only 239 kB.

Ok.

>The database and all the scripts I use to add/display/modify records
>work fine. There are 1067 records and no duplicates. 
>
>What's wrong? I've racked my brain and pored through books and online
>guides but I can't find the error.

I believe DBM files (like core files) can contain lots of large
"holes" that are still reported as used space. I think it's documented
in the man pages for one of the DBM implementations, but I don't have
a Unix box handy at the moment to check.

Either that, or someone on this group explained it a year ago, and
I've just remembered... :-)

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

Date: Thu, 18 Sep 1997 13:15:30 -0200
From: Toni Makela <makela@riksu.hamkk.fi>
Subject: IP checking
Message-Id: <Pine.SOL.3.91.970918131057.38A-100000@riksu>


How can i check if the users IP-address is allowed IP!

Example, all users form 222.222.222.xxx are allowed to access, no-one else! 


   _________________________
 /'                         '\_______________________________________
|  Toni Makela                                                       '\
|  Mustikkamaentie 4            e-mail : makton@sci.fi                 |
|  11710 RIIHIMAKI                       makela@riihimaki.hamkk.fi     |
|  FINLAND                               toni.makela@compost.fipnet.fi |
'\________________________      TEL    : +358-40-5932413               |
                          '\    WWW    : 193.166.86.77/cre/toni.html   |
                            '\________________________________________/'



------------------------------

Date: 18 Sep 1997 13:12:02 +0200
From: petja@weald.air.saab.se (peter jacobsson)
Subject: KornShell to Perl
Message-Id: <5vr2a2$1sf@limes.air.saab.se>


Hi all,

Is there a Kornshell to Perl translator??

Peter


------------------------------

Date: Thu, 18 Sep 1997 12:33:44 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: looping through an sql query using win32::odbc
Message-Id: <34271e49.169436206@igate.hst.moc.com>

[cc'd automagically to original author]

On 18 Sep 1997 02:41:03 GMT, bob@cafemedia.com (Bob Maillet) wrote:

>I have been using the win32 odbc module to write the contents on a file
>into an access database unfortunately it will only write the first line of
>that file...What I am having trouble figuring out is how to construct a
>loop which will read the next line of that file and then run the sql to
>import it into access.  It seems inefficient to do it this way but after
>trying to open another $DSN and running into permission errors when
>writing that data this seems the logical solution.  Below is the script I
>have put together.  Any suggestions would be appreciated.

Hmm... That should be doable... Let's see.

>#!/usr/bin/perl
>
>use Win32::ODBC;

Don't forget your "use strict" -- it'll have fun with your code, but
you'll be safer in the long run.

>$data = "C:/Perl/down.txt";
># open reads and closes files
>open (FILE, $data);

open (FILE, $data) or die "Open Failed: $!";

Always check return codes from open().

>@file = (<FILE>);

Read each line into a list. Okay for non-huge files.

>close(FILE);

You might want to check the return code from close(), too. I sometimes
do, I sometimes don't. YMMV.

># separates each line of the file and breaks each line up into an array
>foreach $line (@file){
>   $_ = $line;

That line probably isn't necessary.

>   @ok = split(/ /,   $line);
>}

These must be space-delimited records, then...

>#open database 
>
>$DSN ="Bob";

Not Microsoft Bob, I hope. :-)

>if (!($db = new Win32::ODBC($DSN))){
>   print "Error connecting to $DSN\n";
>   print "Error: " . Win32::ODBC::Error() . "\n";
>   exit;
>}

Looks good.


Wrap this whole thing in something like:

foreach $row (@file) {
 ...

># execute SQL command
>
>$sql = "INSERT INTO test (1,2,3) VALUES ($ok[0],'$ok[1]','$ok[2]');";
>if ($db->Sql($sql)){
>   print "SQL failed.\n";
>   print "Error: " . $db->Error() . "\n";
>   $db->Close();
>   exit;

Move the exit() outside of the loop, of course.

> }
>
>#  close the connection to the database:
>$db->Close();

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

Date: Thu, 18 Sep 1997 11:19:57 +0200
From: Rene Sorger <rene.sorger@onlinemedia.de>
Subject: Re: postmail and perlis
Message-Id: <3420F23D.AA1B7567@onlinemedia.de>

Its me again.

Rene Sorger wrote:
> 
> Is there any other way to send email via perl with iis ?
> 

I found a good script by Christian Mallwitz called sendmail that seems
to work. But the problem is that this won't work :

read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );

If I print $buffer it empty, while $ENV{'CONTENT_LENGTH'} has a valid
value (i.e. 53). I think its still the same problem, piping with perlis
could be ok, but if there is no data passed to the script, postmail does
not know what to send.

How can I access data passed to the script using a form and the POST
method ?

Thanks,
Rene
-- 
---------------------------------------------------------------------
I  Rene Sorger                    I                                 I
I  Online Media Riedlbauer GmbH   I         Ich hab' Hunger !       I
I  Xlink PoP Krefeld              I                                 I
---------------------------------------------------------------------


------------------------------

Date: Thu, 18 Sep 1997 12:17:21 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: postmail and perlis
Message-Id: <34231b16.168617278@igate.hst.moc.com>

[cc'd automagically to original author]

On Thu, 18 Sep 1997 11:19:57 +0200, Rene Sorger
<rene.sorger@onlinemedia.de> wrote:

>Its me again.
>
>Rene Sorger wrote:
>> 
>> Is there any other way to send email via perl with iis ?
>> 
>
>I found a good script by Christian Mallwitz called sendmail that seems
>to work. But the problem is that this won't work :
>
>read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH' } );
>
>If I print $buffer it empty, while $ENV{'CONTENT_LENGTH'} has a valid
>value (i.e. 53). I think its still the same problem, piping with perlis
>could be ok, but if there is no data passed to the script, postmail does
>not know what to send.
>
>How can I access data passed to the script using a form and the POST
>method ?

Something like this... (untested, but likely to be almost right)

---begin---

#!/usr/local/bin/perl -w

use CGI;
my $page = new CGI;
print $page->header;

my $form_field = $page->param('form_field'); # assumes there was
					# a field named "form_field"
					# on the page

print $page->start_html(-title=>"Test page...");
print "<P>$form_field</P>";
print $page->end_html;

exit;

---end---

In other words:

(1) Get CGI.pm from CPAN.
(2) Scan the docs for features you need and relevant examples.
(3) [This is the key...] Use it. :-)

Good Luck,

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

Date: 18 Sep 1997 10:46:44 +0200
From: Ronald Fischer <rovf@earthling.net>
Subject: Re: Reg Exp Question
Message-Id: <xz2n2lbt3ez.fsf@uebemc.siemens.de>

>>>>> On Wed, 17 Sep 1997 22:28:36 -0400
>>>>> "a" == appcs  <appcs@iwaynet.net> wrote:
a> From a line such as the one below
a> <LI><LI><LI><LI>..Pattern..</LI></LI></LI></LI>
a> 
a> is there a way to remove the <LI>..Pattern..</LI> substring if we are
a> not told how many <LI></LI> pairs surround it?  
a> 
a> the .. stands for stuff.
a> 
a> s/<LI>.*?Pattern.*?</LI>//  seems to eat up the whole line.
No. Actually, it produces a syntax error (note that the '/' before the
LI terminates the search pattern). If you know that at least one
<LI></LI> pair is present, you could use
    s((<LI>)+.*Pattern.*(</LI>)+)()
But note that this does not match pairs when the number of </LI> is
not equal to the number of <LI>. For example, if the subject were
    "before<LI>fooPatternBar</LI></LI>after",
it would produce
    "beforeafter"
and not
    "before</LI>after"
-- 
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is 
clearly marked as such.]


------------------------------

Date: 18 Sep 1997 13:46:15 +0300
From: matti@universe.pc.helsinki.fi (Matti Kinnunen)
Subject: Re: Reg Exp Question
Message-Id: <lzvhzy7vd4.fsf@universe.pc.helsinki.fi>


   appcs (appcs@iwaynet.net) wrote:
   : From a line such as the one below
   : <LI><LI><LI><LI>..Pattern..</LI></LI></LI></LI>
   : is there a way to remove the <LI>..Pattern..</LI> substring if we are
   : not told how many <LI></LI> pairs surround it?  
   : the .. stands for stuff.

**** 
My regular expression translator gives:
universe:~/Haskell/Nancy$ ROutput 
Give a description for me to translate

	>Find "<LI>" at least once and assign them to $lis. Find "<LI>". Find non-greedily some characters, "Pattern" and non-greedily some characters. Find "</LI>". Replace everything with $lis.   
***RE:	
	Haskell:
subst </
 lis@((\<LI\>){1,})                     -- Find "<LI>"  at least once and assign them to $lis
\<LI\>                                  -- Find "<LI>"
 .*?Pattern.*?                           -- Find non-greedily some characters, "Pattern" and non-greedily some characters
\<\/LI\>                                -- Find "</LI>"
/                                       -- Replace everything with
${lis}                                  -- $lis
/>                                      -- 
	Perl:
s/
((\<LI\>){1,})                          # Find "<LI>"  at least once and assign them to $lis
\<LI\>                                  # Find "<LI>"
 .*?Pattern.*?                           # Find non-greedily some characters, "Pattern" and non-greedily some characters
\<\/LI\>                                # Find "<\/LI>"
# Replace everything with
# $lis
/$1/x                                     


****

from where you can cut'n'paste the correct reg.exp together with comments.

HTH.

- matti - 
-- 
* matti.kinnunen@helsinki.fi *
* http://universe.pc.helsinki.fi/~matti/contact.html *
* +358-(0)40-593 50 91 but try first +358-(0)9-191 23978 *


------------------------------

Date: Thu, 18 Sep 1997 12:22:40 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Reg Exp Question
Message-Id: <342619f0.16668364@news.tornado.be>

appcs <appcs@iwaynet.net> wrote:

><LI><LI><LI><LI>..Pattern..</LI></LI></LI></LI>
>
>is there a way to remove the <LI>..Pattern..</LI> substring if we are
>not told how many <LI></LI> pairs surround it?  

My idea would be to erase the basic substring, containing only one
<LI>-</LI> pair, and keep repeating that until there are no more
replacements.

while(s/<LI>(...)</LI>//) {}

The (...) should match anything that doesn't contain any "<LI>" or
"</LI>". Only, I have no clue how to put that into one regexp. Any
takers?

	Bart.


------------------------------

Date: 18 Sep 1997 10:36:46 +0200
From: Ronald Fischer <rovf@earthling.net>
Subject: Re: reg expression help!
Message-Id: <xz2oh5rt3vl.fsf@uebemc.siemens.de>

>>>>> On Thu, 18 Sep 1997 00:47:06 GMT
>>>>> "AK" == Alex Krohn <alex@gossamer-threads.com> wrote:
AK> I have a string that can be of the form
AK> 
AK> i)    "one"
AK> ii)  "one/two"
AK> iii) "one/two/three/four"
AK> 
AK> or some combination of words sepearted by "/". What I want to do is
AK> retrieve in one variable ($base) everything except the trailing word
AK> and in another variable ($name) the trailing word.
I assume that, in case (i), you want to go "one" into $name. Here we
go (assuming that your string is on $word):

    ($base,$name) = $word =~ m((.*/)([^/]+)$) ? ($1,$2) : ("",$word);

Another way to skin the cat would be:

    @tmp = split m(/),$word;
    $name = pop @tmp;
    $base = (join '/',@tmp).'/';
-- 
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is 
clearly marked as such.]


------------------------------

Date: Thu, 18 Sep 1997 12:22:35 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: reg expression help!
Message-Id: <34271ab2.16863238@news.tornado.be>

alex@gossamer-threads.com (Alex Krohn) wrote:

>I have a string that can be of the form
>
>i)    "one"
>ii)  "one/two"
>iii) "one/two/three/four"
>
>or some combination of words sepearted by "/". What I want to do is
>retrieve in one variable ($base) everything except the trailing word
>and in another variable ($name) the trailing word.

If I remember correctly, this should work. It uses the greediness of
regexps.

	$base=''; $name = $_;	#in case the next one fails
	($base,$name) = /(.*)\/(.*)/;

HTH,
Bart.


------------------------------

Date: Thu, 18 Sep 1997 12:52:04 +0000
From: "David R. Nurse" <david.nurse@ndcb.ox.ac.uk>
Subject: Rounding numbers problem
Message-Id: <342123F2.C73B1E18@ndcb.ox.ac.uk>

I need to round some numbers to different numbers of decimal places and
then to the nearest half, e.g.

to 2 decimal places:
1.34456 becomes 1.35
2.57876 becomes 2.60

to 1 decimal place:

1.34456 becomes 1.5
2.57876 becomes 2.5

any of you Perl experts think of an easy way of doing this ?


thanks in advance


Dave Nurse
Oxford Medical Informatics
david.nurse@ndcb.ox.ac.uk



------------------------------

Date: Thu, 18 Sep 1997 12:23:56 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Selena Sol's Classified Ad Script
Message-Id: <34251cbc.169039806@igate.hst.moc.com>

[cc'd automagically to original author]

On Wed, 17 Sep 1997 20:31:50 GMT, crypted@hotmail.com (Crypted) wrote:

>Ok, I really need some help with a problem I am having.  I need to
>have this script that I am modifying do two things at once.

What about having it do one right after another? Surely you don't want
me to invent multi-tasking Perl. :-)

>When it
>posts the information that a person submits as a new ad I need it to
>also send the admin a comfirmation of the ad that was placed.  Can
>anyone help me figure this one out?  Here is a snippet of the code
>involved in the ad section of the script.  If you can help me please
>drop me a line at crypted@crypted.com.

[code snipped]

Hmm... You haven't quite told us enough to help you figure it out.
*How* do you want to "send the admin a confirmation"? Via e-mail?
Pager? Post a new web page? Post to Usenet?

What have you tried (if anything), and what were the results?

I'll guess that you want to send an e-mail message, so you might want
to look at Net::SMTP (or similar) modules on CPAN.

 http://www.perl.com/CPAN/

Good Luck,

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

Date: Thu, 18 Sep 1997 12:34:43 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Something of the day script
Message-Id: <34281fb7.169802182@igate.hst.moc.com>

[cc'd automagically to original author]

On 18 Sep 1997 05:03:03 GMT, mosey@alpha3.csd.uwm.edu (John Thomas
Mosey) wrote:


>Does anyone out there know of a daily rotation script program. For
>example, quote of the day or picture of the day? 
>
>I'm not looking for a random roation, I'd like everyone to see the same
>thing for one 24 hour period. I'd just like to program the quotes and
>pictures for a month period at a time.

I would use a scheduling service. If you're on Unix, look into cron.
If you're on NT, look into 'at' and the Schedule Service.

No Perl required. :-)

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

Date: Thu, 18 Sep 1997 12:24:45 +0200
From: Doug Seay <seay@absyss.fr>
Subject: Re: The CSV format stinks!
Message-Id: <3421016D.3EC69D8C@absyss.fr>

Chris Leach wrote:
> 
> In article <5vkofi$dpr$1@wn.aksi.net>,
>           daniel@aksi.net (Daniel Freeman) writes:
> >
> >    We can even have quotes inside our quotes, oddly, like so:
> >
> >            "MY 3.5" DISK","MY 5" INCH FLOPPY","MY 10" RECORD"
> >
> >    Now the parser for this was a real pain in the butt to write.
> 
> If you CVS file was not broken I'd suggest using the CVS module
> to parse your file.
> I suggest you get whatever produces this file fixed the use
> the CVS.

I guess I'm feeling a bit picky this morning, but CVS is "concurrent
versioning system" or something like that (I use it, but I don't
remember what it stands for).  It is a layer over rcs and a deals with
keeping versions of files with multiple users and parallel threads of
modifications.  This thread has been dealing with CSV which stands for
"comma separated values", which can be used genrically (/etc/passwd can
be said to be an a "colon separated values" format), but here it deals
with some Microsoft format or another.

Chris, I'd guess that you know the difference and just made typos when
replying, but I'm just trying to prevent anyone else from getting
confused.

- doug


------------------------------

Date: Thu, 18 Sep 1997 10:56:33 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: The CSV format stinks!
Message-Id: <342cf7db.8031078@news.tornado.be>


Steven Tolkin <steve.tolkin@fmr.com> wrote:

>It is possible that the data was written by dbase, or another Xbase
>style database program.

The tiny bit of info found on Wotsit (<http://www.wotsit.demon.co.uk/>)
says, and I quote:

>Also Paradox version approx.4 has the bug. When converting to
>.CSV, it always writes values surrounded by "s -- but if in the 
>source database file we have a field containing "s, them will not
>be doubled in CSV. 
>
>E.g.: abc"dfg will be translated to "abc"dfg" instead of "abc""dfg".

Funny. They call it "THE" bug.

	Bart.


------------------------------

Date: Thu, 18 Sep 1997 12:13:35 GMT
From: zawodny@hou.moc.com (Jeremy D. Zawodny)
Subject: Re: Win32 Perl FAQ Addition? (WAS Re: Is Perl for Win32 really as brain damaged as it seems?)
Message-Id: <34221a84.168470988@igate.hst.moc.com>


[cc'd automagically to original author]

On Wed, 17 Sep 1997 12:10:02 -0700, Tom Phoenix
<rootbeer@teleport.com> wrote:

>On Wed, 17 Sep 1997, Jeremy D. Zawodny wrote:
>
>> A Perl script *could* search the registry for all references to A:\
>> (or B:\ for that matter) using some of the Win32::* modules. However,
>> the hard part would be making sure the Perl script only nukes the
>> unnecessary ones. :-)
>
>Well, I was thinking of making it a command-line option whether to ask or
>simply automatically to delete those refs. By default, it should nuke them
>all, IMHO.

Unfortunately, too many clueless users would run such a program, not
fully understanding the consequences, and then wonder why some other
program stopped working a few weeks later... Then again, all of the
reg keys could be saved in a .reg file so that they could be merged
back in (selectively, even) at a later date...

Hmm... If I get bored this weekend... :-)

Jeremy
-- 
Jeremy Zawodny
Internet Technology Group
Information Technology Services
Marathon Oil Company, Findlay Ohio

http://www.marathon.com/

Unless explicitly stated, these are my opinions only--not those of my employer.


------------------------------

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 1043
**************************************

home help back first fref pref prev next nref lref last post