[6890] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 515 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 22 17:17:52 1997

Date: Thu, 22 May 97 14:00:23 -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, 22 May 1997     Volume: 8 Number: 515

Today's topics:
     Re: "Bad free() ..." message from perl v4.036 (Bob Apthorpe)
     Re: A perl routine to fetch an url (Martti Rahkila)
     Re: Address parsing one-liner (Chipmunk)
     Re: C/C++ function calls in perl <amit@csd.sgi.com>
     Re: C/C++ function calls in perl (Nathan V. Patwardhan)
     Re: getting next line in while (Chipmunk)
     Re: Help: How to Split a file at a Null Line??? (Colin Kuskie)
     how do I format text <Scott@wwide.com>
     Re: how to remove carriage returns in form <amit@csd.sgi.com>
     Re: how to remove carriage returns in form <rootbeer@teleport.com>
     HOW?  rmdir -rf <richard@ccis.adisys.com.au>
     Installing a Module in local directory (Brian Lavender)
     Re: Locking my Log file... (Tung-chiang Yang)
     Make problem on NCR MP-RAS 3.00 (Dale McSwain)
     Making a pool, but one man = one vote <podeurda@hpweb.utc.fr>
     Re: New Perl User Question <djohnson@uu.net>
     Re: Reading the last line of a file (Craig Berry)
     Re: SEGV from hash declaration <rootbeer@teleport.com>
     Re: Split function <djohnson@uu.net>
     Re: What is the octal range for meta charachters? <usenet-tag@qz.little-neck.ny.us>
     Re: Year 2000 compliance <ajohnson@gpu.srv.ualberta.ca>
     Re: yet another perl regex Q (Abigail)
     Re: yyyymmdd from localtime? (Abigail)
     Re: yyyymmdd from localtime? (felix k sheng)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 22 May 97 05:37:39 GMT
From: arclight@io.com (Bob Apthorpe)
Subject: Re: "Bad free() ..." message from perl v4.036
Message-Id: <5m0m35$o67@news.jump.net>

In article <fl_aggie-ya02408000R0805971620080001@news.fsu.edu>,
   fl_aggie@hotmail.com (I R A Aggie) wrote:
>In article <5kt1ll$bv8@news.service.uci.edu>, ehood@medusa.acs.uci.edu
>(Earl Hood) wrote:
>
>+ on economics, business politics, and human resource management, so
>+ if you (and others) do not know an answer to the original question,
>+ please do not respond.
>
>Several of us have provided you with the correct answer: upgrade to
>v5. That the answer does not solve your problem to your satisfaction
>is not our problem.

That is not an answer, it's flippant and smug abuse in response to a 
reasonable (if esoteric) question. Worse yet, it's not productive.

The "answer" of upgrading to perl5 solves the fundamental social problem and 
I'm certain Mr. Hood would have pursued that option had it been available to 
him. However the answer of "upgrade perl" is equivalent to "replace management 
with individuals less inclined to have their heads lodged in their ass" or 
"amend software policy to reflect reality", neither of which address the 
*technical* question posed.

Given that the code must work with versions of perl from 4.036 through the 
current rev, what's the answer? I don't know and as far as I can tell, nobody 
who's responded to this post knows either.

Oh, and for those of you in an environment where you can change versions of 
software on a whim, consider yourself blessed - there are a lot of people who, 
for better or worse, don't have that level of control over their environment. 
Karma may bite you in the ass one day and you may find yourself in their 
shoes. So cut 'em a little slack, eh?

>+ BTW, I am well aware of the status of Perl 4.
>
>Then you are aware that Perl 4 is unsupported and that you are on your
>own.

Generally one posts a question to a newsgroup when one has exhausted all other 
available options.

Bob Apthorpe
arclight@io.com


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

Date: 22 May 1997 18:10:51 GMT
From: mara@cc.hut.fi (Martti Rahkila)
Subject: Re: A perl routine to fetch an url
Message-Id: <5m227b$h7u@nntp.hut.fi>

Thanks everyone for your help. The 'HEAD' method was indeed what I wanted.

My reply address in my previous articles was wrong due to misconfiguration of my
news client. Hopefully this is now fixed.
-- 

/Mara  
	Internet: Martti.Rahkila@hut.fi
	X.400: G=Martti;S=Rahkila;O=hut;PRMD=inet;ADMD=fumail;C=fi
	URL http://www.hut.fi/~mara/index.html


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

Date: 22 May 1997 04:28:25 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Address parsing one-liner
Message-Id: <5m0i19$158$1@dartvax.dartmouth.edu>

In article <re4tbwsuqq.fsf@eyrie.graphics.cornell.edu>
jwd@graphics.cornell.edu (James W. Durkin) writes:

> Does anyone have a one-liner hanging around that will parse the email
> address out of the headers of mail message or newsgroup post?  I know
> I could do it using one of the CPAN modules, but the lack of control
> of what's available at the site's where this might be used precludes
> that route.

What will you use it for?

Because it could be used to collect email addresses for spamming, you
may not get a lot of responses...

Chipmunk


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

Date: Thu, 22 May 1997 11:27:31 -0700
From: amit kothari <amit@csd.sgi.com>
To: Greg <galoi@sdcc13.ucsd.edu>
Subject: Re: C/C++ function calls in perl
Message-Id: <33849013.59E2@csd.sgi.com>

Greg wrote:
> 
> Is it possible to call C/C++ functions from inside a perl script?
> 
> If so how is it done, and is there any documentation that has
> more information on this kind of thing.
> 
>                                         galoi@sdcc13.ucsd.edu
> 
> --
> 
>                                                                         --greg--


look up the site
http://www.metronet.com/0/perlinfo/perl5/manual/pod/perlcall.html

Amit
-- 
==========================================================================
Knowledge is not assimilation of data but liberation of mind -
Vivekananda
email : amit@csd.sgi.com     
Home Page: http://www.geocities.com/ResearchTriangle/4960/
==========================================================================


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

Date: 22 May 1997 18:16:35 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: C/C++ function calls in perl
Message-Id: <5m22i3$qs2@fridge-nf0.shore.net>

Greg (galoi@sdcc13.ucsd.edu) wrote:

: Is it possible to call C/C++ functions from inside a perl script?

Yes.

: If so how is it done, and is there any documentation that has
: more information on this kind of thing.

man perlxs and perlxstut.  Also, pick up _Programming Perl, 2nd Ed_.

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: 22 May 1997 04:32:11 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: getting next line in while
Message-Id: <5m0i8b$3nr$1@dartvax.dartmouth.edu>

In article <5lsoe1$569$1@mark.ucdavis.edu>
etfinley@ece.ucdavis.edu (Eric Finley) writes:

> How can I get the next line of the file while in the while loop without going through the
> next iteration of the while.  My code looks like:
> 
> while (<FILE>) {
>     if (/foo/) {
>         print;
>     }
>     if (/bar/) {
>         print;
>         get next line;
>         print next line;

print scalar(<FILE>);

>     }
> }

Chipmunk


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

Date: 22 May 1997 09:20:40 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: Re: Help: How to Split a file at a Null Line???
Message-Id: <5m1roo$pi6@defiant.latticesemi.com>

In article <5lvjst$92q$1@dartvax.dartmouth.edu>,
Chipmunk <Ronald.J.Kimball@dartmouth.edu> wrote:
>In article <tcyangEAG3C7.4Jy@netcom.com>
>tcyang@netcom.com (Tung-chiang Yang) writes:
>
>It won't 'skip over' lines 14-35 and 36-87, but, I think they'll be
>missing from the second output file.  It looks like the second file is
>overwritten every time a blank line is encountered.
>
>That would be easy to fix, of course, either by opening for append
>  open(OUT, ">>file2")
>or by adding a flag so that the second file is only opened once
>  if (!$opened) { open(OUT, ">file2") || die "could not open file2  $!"
>}
>  $opened = 1;

What about the brute force method:

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

##Do a file slurp
undef $/;
$_ = <>;
my @chunks = split "\n\n", $_;  ##Note, could modify split for
                                ##multiple blank lines,
				##ie \n\n\n => /\n\n+/
##Open as many output files as wanted
open (OF1, ">file1") or die "Can't open file1 $!\n";
open (OF2, ">file2") or die "Can't open file2 $!\n";

foreach $num (0..$#chunk) {
  ##Decide where each chunk goes and dump it out, maybe like
  if ($num % 2 == 1) {
    print OF2 $chunk[$num],"\n";
  }
  else {
    print OF1 $chunk[$num],"\n";
  }
}

Colin Kuskie


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

Date: Wed, 21 May 1997 22:54:36 -0100
From: Scott <Scott@wwide.com>
Subject: how do I format text
Message-Id: <33838B3C.6B44@wwide.com>

Hi!

 I now have a script that reads in the proper lines of text from my text
file.. now I need to format the data so it doesn't look like crud.  Here
is what a sample line looks like:

joe	blow	1988	blah	77	blah	99	bh  cc
fred	smith	1776	blip	71	spif	81	gg  cc
etc.

and here is how I am currently reading them in:

while (<FILE>) {  # loop through file line by line
        print if /^joe/;
        print if /^fred/;
etc.

what I want to do is separate out the 9 fields and make them into a
table. Then display the table..

any ideas?

Thanks,
Scott


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

Date: Thu, 22 May 1997 11:21:23 -0700
From: amit kothari <amit@csd.sgi.com>
To: schoy@cyp.mea.com
Subject: Re: how to remove carriage returns in form
Message-Id: <33848EA3.15FB@csd.sgi.com>

schoy@msm.mea.com wrote:
> 
> i use a perl script to save a form results in a text file.  but whenever a
> carriage return is entered in the TEXTAREA box, it will mess up the output
> file.  how can i remove all the carriage returns during parsing the form?
> or change them to spaces?
> 
> please email response to:
> schoy@cyp.mea.com
> 
> thanks,
> simon.
> 
> -------------------==== Posted via Deja News ====-----------------------
>       http://www.dejanews.com/     Search, Read, Post to Usenet

-- 

Use \s to remove all whitespaces or just use \r to remove carraige
returns.

eg.

 .....
$textarea =~ s/\s/ /g; # substitutes a whitespace (\t\n\r\f) by a space
 .....

========================================================================
Knowledge is not assimilation of data but liberation of mind -
Vivekananda
email : amit@csd.sgi.com     
Home Page: http://www.geocities.com/ResearchTriangle/4960/
========================================================================


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

Date: Thu, 22 May 1997 11:35:19 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: schoy@cyp.mea.com
Subject: Re: how to remove carriage returns in form
Message-Id: <Pine.GSO.3.96.970522113424.2923a-100000@kelly.teleport.com>

On Thu, 22 May 1997 schoy@msm.mea.com wrote:

> how can i remove all the carriage returns during parsing the form?
> or change them to spaces?

In Perl, you can use the tr/// operator to do either; it's documented in
perlop(1). Hope this helps! 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Thu, 22 May 1997 02:01:22 GMT
From: "Richie !" <richard@ccis.adisys.com.au>
Subject: HOW?  rmdir -rf
Message-Id: <3383A8F1.41C67EA6@ccis.adisys.com.au>

In perl, I know how to remove an empty directory (using rmdir),
but what I'd like to know how to recursively remove a non-empty
directory (ie. as in unix: rm -rf)

I've come up with:

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

$thedir="crap";

opendir(it, $thedir);
@files = (grep(!/^\.\.?$/, readdir(it)));
close(it);
foreach $f (@files) {
        unlink ($thedir."/".$f) || die ("Cannot remove
$thedir."/".$f\n");
}

rmdir ($thedir) || die ("Cannot rmdir $thedir\n");
------------------------------------------

But this doesn't cater for non-empty subdirectories.


Ideas? ...... => richard@ccis.adisys.com.au

Thanks,
Richie !


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

Date: Thu, 22 May 1997 05:39:14 GMT
From: brian@brie.com (Brian Lavender)
Subject: Installing a Module in local directory
Message-Id: <3383db2e.46292159@nntp.netcruiser>

The FAQ has the following answer for installing a module. Is there a
generic way to install a module in a local directory?

According to the faq located at
http://www.perl.org/CPAN/doc/FAQs/FAQ/PerlFAQ.html

>How do I install a CPAN module? 

>The easiest way is to have the CPAN module do it for you. This module comes with perl version 5.004 and later. To
>manually install the CPAN module, or any well-behaved CPAN module for that matter, follow these steps: 

>   1.Unpack the source into a temporary area. 

>   2.    perl Makefile.PL

>   3.    make

>   4.    make test

>   5.    make install

>If your version of perl is compiled without dynamic loading, then you just need to replace step 3 (make) with make perl
>and you will get a new perl binary with your extension linked in. 

>See MakeMaker for more details on building extensions. 
----------------
Brian Lavender
Napa, CA
Brie Business Directory - Napa Valley     http://www.brie.com/bbd 
(707) 226-8891

"Have you heard of the new improbability drive?"


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

Date: Thu, 22 May 1997 05:58:17 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Locking my Log file...
Message-Id: <tcyangEAKJ95.H30@netcom.com>

I believe you need to use $LOCK_EX to mean it is a variable and it
holds a numerical value by an assignment (say, $LOCK_EX = 2 or 8).  The
same thing holds for LOCK_UN.

=======================
silver@silverbergcom.com wrote:

: open (LOGGER, ">>$log_file");

: flock(<LOGGER>,LOCK_EX);

: (deleted)

: flock(<LOGGER>,LOCK_UN);

: close (LOGGER);

: But I get error messages that say "Argument "LOCK_EX" isn't numeric in
: flock at logger.pl line 71." I looked in the perl man pages but all it
: has is some stuff using subroutines and scalars. I don't want subs, I
: just want to use flock straight. Does anybody know what I am doing
: wrong?

--
Tung-chiang Yang                       tcyang@netcom.com

soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
   http://www.clever.net/tcyang/Taiwan_faq.shtml, China_faq.shtml


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

Date: 22 May 1997 18:21:11 GMT
From: mcswain@cbict3.cb.att.com (Dale McSwain)
Subject: Make problem on NCR MP-RAS 3.00
Message-Id: <5m22qn$2ol@nntpa.cb.lucent.com>




I'm having a problem with the make on perl5.003
under NCR mpras 3.00.00 on an ncr 3555. The error
that comes up is:

make: fatal error: don't know how to make /var/tmp/MWFAAa006-i (bu42).


Does this mean anything? How do I solve this?


Dale McSwain
Lucent Columbus Works.


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

Date: Thu, 22 May 1997 20:34:31 +0200
From: David Podeur <podeurda@hpweb.utc.fr>
Subject: Making a pool, but one man = one vote
Message-Id: <Pine.LNX.3.94.970522202940.32079B-100000@hpwebpc.utc.fr>


Hi.

I am trying to make a pool via the Internet, using cgi.


The pool is aimed to students who have an account on a machine called
vega. I have already make the form but what i need know is to be sure
that no student can vote twice (or more...).

Does anyone know a way to get get the student's username while he submits
his form ?

Thanks for your help.
Pod.



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

Date: Thu, 22 May 1997 13:17:19 -0500
From: Dale Johnson <djohnson@uu.net>
Subject: Re: New Perl User Question
Message-Id: <33848DAF.167EB0E7@uu.net>

Troy Bull wrote:
> 
> I am new to perl and I have a question.
> I am trying to write a perl program that will open a file, search for a
> word, then return the next word in the file and write the output to yet
> another file.
> 
> input:
> the quick brown fox jumped over the brown
> box quickly
> 
> if the "word" were brown the output would be
> inputfilename : fox
> inputfilename : box

Troy,

The script below shows the $input being scanned for a keyword ($word).
When it finds it, it sets an ON/OFF to ON (sets $test to 1).  On the
very
next word, it prints and sets the counter back to OFF (sets $test to 0).

You can use this routine over and over, simply call it with a different
$input each time (say, each line of each program, then format the print
out to match your requirements).

#!/usr/local/bin/perl

$word = "brown";
$input = "the quick brown fox jumped over the brown box quickly";

&search_word($input, $word);
##--------------------------
sub search_word {
   local($input, $word) = @_;
   foreach (split(/\s/, $input)) {
        if ($test) { print "$_\n";  $test = "0"; }
        $test = 1 if $_ eq $word;
   }
}
##--------------------------

Good luck!

-- 
Dale R. Johnson, Jr.    <djohnson@uu.net>     http://www.drsj.com/drj/
PGP Key fingerprint = D5 2D F7 96 E5 69 3A A3  F5 00 A8 FC EF 35 41 54
perl -e 'foreach(`finger johnson\@doit.net`){$a=1if/^-/;print if$a};'
-=-=-  If at first you don't succeed, skydiving is not for you.  -=-=-


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

Date: 22 May 1997 18:18:47 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Reading the last line of a file
Message-Id: <5m22m7$9su$1@marina.cinenet.net>

Jeff Wilson (jwilson@ic.ac.uk) wrote:
: Craig Berry <cberry@cinenet.net> wrote in article
: <5m029o$19u$1@marina.cinenet.net>...
: > Bob Maillet (rmaillet@inigo.us.dg.com) wrote:
: > : I am trying to get my program to read the last line of a file..
: > : I have tried a loop but had no luck..does anyone have any suggestions?
: > : here is a chunk of what I have so far which displays all the data in the
: > : file..
: > : 
: > : open (FILE, $database);
: > : @file = (<FILE>);
: > : close(FILE);
: > 
: > $lastline = $file[-1];
: or even
: 	$lastline = @file[$#file];
                    ^ Yes, if you change this to $

As near as I can tell from reading the 'perldata' doc, $list[$#list] and 
$list[-1] are entirely equivalent expressions.  

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 22 May 1997 11:28:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Geoff Mottram <minaret@sprynet.com>
Subject: Re: SEGV from hash declaration
Message-Id: <Pine.GSO.3.96.970522112314.2923X-100000@kelly.teleport.com>

On 22 May 1997, Geoff Mottram wrote:

> It's either a bug in Perl or you have a funky Perl binary.  Perl should
> never dump core.  The best thing to do is create the smallest script that
> will cause Perl to crash and post it to the "perl.porters-gw" newsgroup. 

Actually, Perl comes with a bug-reporting utility which is better than
posting to that newsgroup. perlbug is written in Perl (surprise!) and
includes helpful information about your system's configuration along with
your bug report. Unless you have a good reason for not using it, almost
every bug report for Perl should be made with perlbug. 

Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Thu, 22 May 1997 13:29:57 -0500
From: Dale Johnson <djohnson@uu.net>
Subject: Re: Split function
Message-Id: <338490A5.446B9B3D@uu.net>

Greg wrote:
> 
> I am new to perl and am a little confused as to how the split
> functin works.  In particular I am trying to spilt up a string by
> the characters / and : and by whitespace.  I have not found a nifty
> way to do this.

Greg,

If you are looking to split a line that might have delimiters of
colon(:),
slash(/), or by whitespace(/s), then you might want to use this:

@array = split(/[:|\\|\s]/, $string);

If you want to split by a single one of those, then you would use:

@array = split(/XX/, $string);

where XX is a ":", a "\s" or "\\".

Good luck.

-- 
Dale R. Johnson, Jr.    <djohnson@uu.net>     http://www.drsj.com/drj/
PGP Key fingerprint = D5 2D F7 96 E5 69 3A A3  F5 00 A8 FC EF 35 41 54
perl -e 'foreach(`finger johnson\@doit.net`){$a=1if/^-/;print if$a};'
-=-=-  If at first you don't succeed, skydiving is not for you.  -=-=-


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

Date: 22 May 1997 18:16:03 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: What is the octal range for meta charachters?
Message-Id: <5m22h3$81c$1@news.netusa.net>

(Bleh. This is my third posting after cancelling the first two. Depending
on progation you may have seen the others. Sorry about that.)

Rodney Mach <rmach@gropius.engin.umich.edu> wrote:
>I would like  to see if a person typed like META-x or META-l
>then print out the META-characher they typed
>
>I don't know what the octal range for meta charachters is, like control
>charachters are  s/([\000-\037\177])/ would be a string to search on.

AFAIK, meta chars have the high bit set. So [\200-\377] in octal would
do it. I'd prefer hex, myself: [\x80-\xFF]. I have never learned to think
in octal, which is why I don't suffer that Christmas/Halloween problem.
(Oct31==Dec25)

>For control charachters I found you could use
>	 s/([\000-\037\177])/'^'.pack('c',ord($1)^64)/eg;
>to print like ^M ^L etc, I would like the same but for meta charachters.

# Display <meta-space> as "META- "
s/([\200-\237\377])/'META-^'.pack('c',ord($1)^192)/eg;
s/([\240-\376])/'META-'.pack('c',ord($1)^128)/eg;

# Display <meta-space> as "META-^`"
s/([\200-\240\377])/'META-^'.pack('c',ord($1)^192)/eg;
s/([\241-\376])/'META-'.pack('c',ord($1)^128)/eg;

There are better conventions for representing them, but I don't remember
them offhand.

>What I don't undertand is why you OR the value
>returned by ord() with 64. Is the definition of a "control charachter"
>just the numeric ascii value or'd with 64? What is the definition of a
>"meta charachter" in that case? 

It is a rather clever way to add 64 to the low-end control characters
NUL to US (^@ to ^_) and subtract 64 from DEL (^?). 

Elijah
------
can no longer remember what all the ctrl char names stand for


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

Date: Wed, 21 May 1997 20:53:17 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Year 2000 compliance
Message-Id: <3383A70D.740D386A@gpu.srv.ualberta.ca>

Tom Phoenix wrote:
> 
> On 20 May 1997, Eli the Bearded wrote:
> 
> > (Never overestimate the bandwidth of
> > a stationwagon full of tapes in a battle against M$.)
> 
> I don't know. The folks increasing the density of storage media are
> working pretty hard. I suspect that by the time the 2038 version of
> Windows comes out, you'll be able to haul it around in a station wagon.
> 
> That is, without the docs. And using a 2038-technology station wagon, of
> course.
> 

a Windows-2038 station wagon? as in, if it ceases to
function properly just close any open windows if
possible, shut it down, wait for a few minutes and 
then restart and open the windows again (at least that's
what the nearest authorized service shop will tell you 
when you call their help line :-)


(paraphrased from an old joke)

regards
andrew


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

Date: Thu, 22 May 1997 18:22:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: yet another perl regex Q
Message-Id: <EALHoq.ABI@nonexistent.com>

On 22 May 1997 15:21:36 GMT, felix k sheng (felix@chance.em.nytimes.com)
wrote in comp.lang.perl.misc
<URL: news:slrn5o8peq.bfc.felix@chance.em.nytimes.com>:
++ On 22 May 1997 11:05:36 -0400, John L. Allen <allen@gateway.grumman.com>
++ wrote:
++ >I know this is probably explained in the Hip Owls book somewhere, but
++ >I don't have it handy, so please suffer my ignorance.  Why doesn't
++ >either of the following replace the *last* three blanks in $_ with 'bar'?
++ >
++ >	perl -e '$_="foo      xxx"; s/ {3}(?=.*)$/bar/; print'
++ >	perl -e '$_="foo      xxx"; s/ {3}(?=.*?)$/bar/; print'
++ 
++ you could use this:
++ perl -e '$_="foo      xxx"; s/ {3}(?=\S*$)/bar/; print'
++ 
++ which results in:
++ foo   barxxx
++ 
++ which is what i think you're looking for.

That will fail if there is whitespace after the last 3 spaces.
What you want is to replace 3 spaces not followed 3 spaces.

$ perl -wle '$_ = "123     45 67"; s/ {3}(?!.* {3})(?! )/XXX/; print;'
123  XXX45 67
$


Abigail


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

Date: Thu, 22 May 1997 18:08:23 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: yyyymmdd from localtime?
Message-Id: <EALH1z.9LK@nonexistent.com>

On 22 May 1997 15:13:23 GMT, felix k sheng (felix@chance.em.nytimes.com)
wrote in comp.lang.perl.misc
<URL: news:slrn5o8ove.bfc.felix@chance.em.nytimes.com>:
++ On 22 May 1997 14:51:47 GMT, felix k sheng <felix@chance.em.nytimes.com>
++ wrote:
++ >On Wed, 21 May 1997 16:32:38 -0400, Vincent Kargatis
++ ><kargatis@jackaldog.gsfc.nasa.gov> wrote:
++ >>I want to get a YYYYMMDD from localtime. [chomp]
++ >>Is there a one-line version?
++ >
++ 
++ where i had put in this version:
++ >sprintf( "19%02d%02d%02d", map { $_+=($x%=2);$x++;$_ }
++ >(localtime)[5,4,3] );
++ 
++ here's another shorter and even uglier version!
++ sprintf( "19%02d%02d%02d", map { $_+=1-($x^=1) } (localtime)[5,4,3] );

That fails on Jan 1, 2000 and any date beyond.

perl -wlMDate::Format -e 'print time2str "%Y%m%e", time;'

And guess what? It's even shorter....



Abigail


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

Date: 22 May 1997 18:22:07 GMT
From: felix@chance.em.nytimes.com (felix k sheng)
Subject: Re: yyyymmdd from localtime?
Message-Id: <slrn5o941a.d9s.felix@chance.em.nytimes.com>

On 22 May 1997 19:06:02 +0200, Gisle Aas <aas@bergen.sn.no> wrote:
>felix@chance.em.nytimes.com (felix k sheng) writes:
>> sprintf( "19%02d%02d%02d", map { $_+=1-($x^=1) } (localtime)[5,4,3] );
>Your code is not Y2K safe.  Test it with localtime(time+1e8).

yuck. forgot about that one. ;> oh well.. one could always resort
to:

use POSIX;
strftime "%Y%m%d", localtime;

which should work, methinks.  but not nearly as fun ;>

'lx

--- felix sheng                                       pager     800 979 2171
 programmer                                           tel       212 597 8069
 the new york times electronic media company          e    felix@nytimes.com


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

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

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