[15487] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2897 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 28 18:10:29 2000

Date: Fri, 28 Apr 2000 15:10:20 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <956959820-v9-i2897@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 28 Apr 2000     Volume: 9 Number: 2897

Today's topics:
        Evaluating string as math expression <sigurd.schioth@ilf.uio.no>
    Re: Evaluating string as math expression <lauren_smith13@hotmail.com>
    Re: Evaluating string as math expression <lr@hpl.hp.com>
    Re: Evaluating string as math expression jlamport@calarts.edu
    Re: Evaluating string as math expression (Craig Berry)
    Re: HELP! text file problem! (Craig Berry)
    Re: HELP! text file problem! <sariq@texas.net>
        Help: bol regexp in split string occitan@esperanto.org
    Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT O (Craig Berry)
    Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT O <lr@hpl.hp.com>
        how do you find perl? <mrsparkle@gamerzuniverse.com>
    Re: how do you find perl? <zigouras@mail.med.upenn.edu>
        If slices are so great... <quantum_mechanic@my-deja.com>
    Re: If slices are so great... <aqumsieh@hyperchip.com>
    Re: If slices are so great... <lr@hpl.hp.com>
    Re: Installing Modules In General <grichard@uci.edu>
    Re: perl backtic problem with slapd (Eric R. Jorgensen)
        Perl Free Online Courses <kkentkNOkkSPAM@yahoo.com.invalid>
    Re: perl v5.6.0 install and the "otherlibdirs" variable <cedelis@uillinois.edu>
        Perl/Oracle-SLQ*Loader error (Bhavesh Gosar)
    Re: Perl/Oracle-SLQ*Loader error <makarand_kulkarni@My-Deja.com>
    Re: Print Just Once When in (<>)? swaroop_g@my-deja.com
    Re: Random number <andrew.mcguire@walgreens.com>
    Re: Random number <andrew.mcguire@walgreens.com>
    Re: Random number <lr@hpl.hp.com>
    Re: Random number <godzilla@stomp.stomp.tokyo>
    Re: Random number <lr@hpl.hp.com>
    Re: Random number <godzilla@stomp.stomp.tokyo>
    Re: Random number (Craig Berry)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 28 Apr 2000 20:47:03 +0200
From: Sigurd Schi|th <sigurd.schioth@ilf.uio.no>
Subject: Evaluating string as math expression
Message-Id: <3909DCA7.F74E9F6@ilf.uio.no>

Is there a compact (and pref. fast) way to evaluate/convert a string
as/to a mathematical expression in Perl (without splitting and
iterating)? Say, for a string like "1+2*3" I want the scalar '7'.

Thanks,

Sigurd.
--




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

Date: Fri, 28 Apr 2000 11:57:48 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Evaluating string as math expression
Message-Id: <8ecmui$mlt$1@brokaw.wa.com>


Sigurd Schi|th <sigurd.schioth@ilf.uio.no> wrote in message
news:3909DCA7.F74E9F6@ilf.uio.no...
> Is there a compact (and pref. fast) way to evaluate/convert a string
> as/to a mathematical expression in Perl (without splitting and
> iterating)? Say, for a string like "1+2*3" I want the scalar '7'.

$str = '1+2*3';
$ans = eval $str;
print $ans;

7

But I'd be very careful about what kind of input the user is allowed to
enter.

$str = 'rm -rf';

perldoc -f eval

Lauren




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

Date: Fri, 28 Apr 2000 12:11:53 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Evaluating string as math expression
Message-Id: <MPG.13738256c61c53e098a9a9@nntp.hpl.hp.com>

In article <3909DCA7.F74E9F6@ilf.uio.no> on Fri, 28 Apr 2000 20:47:03 
+0200, Sigurd Schi|th <sigurd.schioth@ilf.uio.no> says...
> Is there a compact (and pref. fast) way to evaluate/convert a string
                                             ^^^^
> as/to a mathematical expression in Perl (without splitting and
> iterating)? Say, for a string like "1+2*3" I want the scalar '7'.

    print eval '1+2*3', "\n";

It certainly is compact.  It is as fast as perl can compile and execute 
the expression.

perldoc -f eval

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 19:53:40 GMT
From: jlamport@calarts.edu
Subject: Re: Evaluating string as math expression
Message-Id: <8ecq7s$k0g$1@nnrp1.deja.com>

In article <3909DCA7.F74E9F6@ilf.uio.no>,
  Sigurd Schi|th <sigurd.schioth@ilf.uio.no> wrote:
> Is there a compact (and pref. fast) way to evaluate/convert a string
> as/to a mathematical expression in Perl (without splitting and
> iterating)? Say, for a string like "1+2*3" I want the scalar '7'.
>
> Thanks,
>
> Sigurd.

It depends on how certain you are that the string really will be a valid
mathematical expression.  If you trust the string, eval will do exactly
what you want:

$string = "1+2*3";
$result = eval $string;
# $result == 7

Be careful where you get that string from, though.  Notice that you could
just as easily do something like:

$string = '`rm -fr ~/*`';
$result = eval $string;
# oops, why is my home directory suddenly empty?

If your $string comes from some not completely trustworthy source (read:
"user input" :) then you'll need to do some sort of test on $string first
to make sure it's safe to eval.

See perldoc -f eval for more info.

-jason


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 28 Apr 2000 21:21:59 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Evaluating string as math expression
Message-Id: <sgk07nkg7qo145@corp.supernews.com>

Sigurd Schi|th (sigurd.schioth@ilf.uio.no) wrote:
: Is there a compact (and pref. fast) way to evaluate/convert a string
: as/to a mathematical expression in Perl (without splitting and
: iterating)? Say, for a string like "1+2*3" I want the scalar '7'.

If you use standard Perl math syntax, eval() makes this a breeze:

/usr2/people/cberry > perl -we '$exp = "1+2*3"; print eval $exp'
7

All the usual cautions about string eval apply, of course.  In particular,
be extremely careful about accepting a string for evaluation from the
user;  evaluating "system('rm -rf /')" could ruin your whole day.  See
taint checking for a nice way to force yourself to pay attention to such
issues.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Fri, 28 Apr 2000 20:43:48 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: HELP! text file problem!
Message-Id: <sgju04kg7qo161@corp.supernews.com>

Marco Natoni (blah@nospam.com) wrote:
: Mark wrote:
: > Does anyone know how to get the total rows in a text file when 
: > using perl?
: 
:   The special variable $. does that for you. ;)
: 
: 	while (<INFILE>) {}
: 	print "$.\n";

That's one way; 'perldoc -q lines' will reveal the FAQ's more efficient
answer.  One could also do e.g.

  my $lines = 0;
  $lines++ while <INFILE>;

or

  my @text  = <INFILE>;
  my $lines = @text;

I'd suggest following the FAQ here, as in most such cases...it's well
thought out.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Fri, 28 Apr 2000 16:30:58 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: HELP! text file problem!
Message-Id: <390A0312.684BE0F4@texas.net>

Mark wrote:
> 
> hi all,
> 
> Does anyone know how to get the total rows in a text file when using
> perl?

I offer this, not because the FAQ solution is inefficient or incorrect,
but as An Ode to Abigail:

perl -wlne '}for($.){print' file  # Count the number of lines.

This was my first real introduction to perlrun.

- Tom


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

Date: Fri, 28 Apr 2000 19:56:48 GMT
From: occitan@esperanto.org
Subject: Help: bol regexp in split string
Message-Id: <8ecqdn$khn$1@nnrp1.deja.com>

Hi folks!

My iPerl allows embedding bits of Perl in text documents by way of !{
 ... }! anywhere, possibly spanning several lines, or whole lines
starting with !, as in:

text text !{ Perl code }! text
! Perl code
text
!{ Perl
code
}!
text

The way this is implemented is by having the whole document in a string
and successively shaving of beginnings up to and including a bit of Perl
for transformation.  This is done by applying various functions, like
this one (in the bang style using !, the first 2 lines of regexp do 2
more things), returning leading text, one or another bit of Perl and
following text on which it'll be applied in the next round:

	$splitter = sub {
	    return $`,  $1,  $2 || $3 || $4,  $'
		if $_[0] =~ /
		    ^\# .* \n? |
		    !< ([\s\S]*?) >! |
		    !\{ ([\s\S]*?) \}! | !(\})! |
		    ^! (.*) \n?
		/mx;
	    @_;
	};

The problem occurs when the text contains a ! right after a bit of Perl:

text text !{ Perl code }!! text

The !, which is part of plain text, is now at the beginning of the
rest-string, and thus at the beginning of line, making the last text be
falsely recognized as Perl.  This should only be allowed to happen at
the very beginning, or when several such lines succeed one another.

I'm at a total loss on how to distinguish these cases elegantly.  These
splitter functions can be quite a bit more complex, saving state and
such.  But still, I'm not sure how that would help me.  A m/.../g loop
wouldn't seem to help, since I'm in and out of this function.

On another topic, in this case, most of $1 thru $4 are not defined.  Is
there an elegant way to rewrite this such that I can use perl -w?

Thanks an awful lot in advance - Daniel Pfeiffer

--
Bring text-docs to life!              Erwecke Textdokumente zum Leben!
                   http://beam.to/iPerl/
Vivigu tekstodokumentojn!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 28 Apr 2000 21:08:34 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WRITE TO IT ?
Message-Id: <sgjveiqb7qo124@corp.supernews.com>

Ryan Downing (ryan@viadyne.com) wrote:
: Is there a call that I can use to determine whether or not someone or
: something is accessing a file. If I try and read the file I want to make
: sure that it is not being updated at the same time.

On most operating systems, there is no general solution not involving
explicit cooperation by the other program(s) accessing the file.  If you
can ensure such cooperation, then see the flock() function, which acts a
lot like a traffic light -- it will prevent collisions if and only if
everybody follows the rules. :)

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: Fri, 28 Apr 2000 14:36:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: HOW CAN I TELL IF A FILE IS OPEN BEFORE I READ IT OR WRITE TO IT ?
Message-Id: <MPG.1373a45461592b1198a9ae@nntp.hpl.hp.com>

In article <sgjveiqb7qo124@corp.supernews.com> on Fri, 28 Apr 2000 
21:08:34 GMT, Craig Berry <cberry@cinenet.net> says...
> Ryan Downing (ryan@viadyne.com) wrote:
> : Is there a call that I can use to determine whether or not someone or
> : something is accessing a file. If I try and read the file I want to make
> : sure that it is not being updated at the same time.
> 
> On most operating systems, there is no general solution not involving
> explicit cooperation by the other program(s) accessing the file.  If you
> can ensure such cooperation, then see the flock() function, which acts a
> lot like a traffic light -- it will prevent collisions if and only if
> everybody follows the rules. :)

On 'most' operating systems (i.e., on the operating systems that run 90% 
or more of the world's computers), the system imposes a mandatory lock 
on a file that is opened for writing, so no other process can read it 
until the writing process closes the file.

On 'some' operating systems ('many' by varieties of flavor, but 'few' in 
numbers of computers run), only advisory locking is available, which is 
what flock() and its friends deal with.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 15:54:06 -0400
From: "Brian Smith" <mrsparkle@gamerzuniverse.com>
Subject: how do you find perl?
Message-Id: <sgjr3iie7qo45@corp.supernews.com>

Ok, I built a linut box running latest version of RedHat to run and test
perl that I write. How do I find where perl is located? I think its
/usr/bin/perl but I keep getting internal server errors when I try to run my
scripts. And I know they work fine.

--
================================
Brian Smith
Perl Coder / Webmaster
eMail: mrsparkle@gamerzuniverse.com
ICQ: 36232576
www.gamerzuniverse.com
================================




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

Date: Fri, 28 Apr 2000 16:44:10 -0400
From: Nico Zigouras <zigouras@mail.med.upenn.edu>
To: Brian Smith <mrsparkle@gamerzuniverse.com>
Subject: Re: how do you find perl?
Message-Id: <Pine.OSF.4.21.0004281643500.28511-100000@mail.med.upenn.edu>

prompt$ which perl


On Fri, 28 Apr 2000, Brian Smith wrote:

> Date: Fri, 28 Apr 2000 15:54:06 -0400
> From: Brian Smith <mrsparkle@gamerzuniverse.com>
> Newsgroups: comp.lang.perl.misc
> Subject: how do you find perl?
> 
> Ok, I built a linut box running latest version of RedHat to run and test
> perl that I write. How do I find where perl is located? I think its
> /usr/bin/perl but I keep getting internal server errors when I try to run my
> scripts. And I know they work fine.
> 
> --
> ================================
> Brian Smith
> Perl Coder / Webmaster
> eMail: mrsparkle@gamerzuniverse.com
> ICQ: 36232576
> www.gamerzuniverse.com
> ================================
> 
> 
> 



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

Date: Fri, 28 Apr 2000 20:46:44 GMT
From: Quantum Mechanic <quantum_mechanic@my-deja.com>
Subject: If slices are so great...
Message-Id: <8ectbf$nnf$1@nnrp1.deja.com>

If slices are so great, why aren't there more references to them in
the indices of the basic Perl books?

Learning Perl, 2E ('97): 3 entries

Programming Perl, 2E ('96): 1 entry [slices of multidimensional arrays,
p261]

Perl Cookbook ('98): no entries!

Effective Perl Programming ('98): 18 entries!

(Teach Yourself) Perl in 21 Days ('97): 6 entries (and 11 pages!)

Of these, I would expect Programming Perl to have quite a few, but it
only has one, of limited application.


I discovered this while trying to find an elegant solution using slices
equivalent to the following:

   (undef, undef, @keep) = split( /,/, $string );

I wanted something like:

   @keep = split( /,/, $string )[2..-1]

but this of course doesn't DWYW. Is there another way besides a
temporary variable?

QM
--
Quantum Mechanics: The dreams stuff is made of.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 28 Apr 2000 21:23:09 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: If slices are so great...
Message-Id: <7ad7n9sywy.fsf@Merlin.i-did-not-set--mail-host-address--so-shoot-me>


Quantum Mechanic <quantum_mechanic@my-deja.com> writes:

> I discovered this while trying to find an elegant solution using slices
> equivalent to the following:
> 
>    (undef, undef, @keep) = split( /,/, $string );
> 
> I wanted something like:
> 
>    @keep = split( /,/, $string )[2..-1]
> 
> but this of course doesn't DWYW. Is there another way besides a
> temporary variable?

I don't see any temporary variables in your first snippet! And, you
can't do it the second way without using temporary variables. Here are
a couple of variations, none of which I would use :-)

	@keep = (split /,/ => $string)[2 .. $string =~ tr/,//];

	@keep = $string =~ s/^[^,]*,[^,]*,// && split /,/ => $string;

In fact, I would stick to your first attempt, although it is not the
"coolest".

Benchmarks, anyone?

--Ala

PS. To LarryR: cool != fast :-)


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

Date: Fri, 28 Apr 2000 14:47:37 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: If slices are so great...
Message-Id: <MPG.1373a6d66bacc4d898a9af@nntp.hpl.hp.com>

In article <7ad7n9sywy.fsf@Merlin.i-did-not-set--mail-host-address--so-
shoot-me> on Fri, 28 Apr 2000 21:23:09 GMT, Ala Qumsieh 
<aqumsieh@hyperchip.com> says...

 ...

> 	@keep = $string =~ s/^[^,]*,[^,]*,// && split /,/ => $string;

Needlessly destructive of $string.

  	@keep = $string =~ /[^,]*,[^,]*,(.+)/s ? split /,/ => $1 : ();

> In fact, I would stick to your first attempt, although it is not the
> "coolest".
> 
> Benchmarks, anyone?
> 
> --Ala
> 
> PS. To LarryR: cool != fast :-)

Sometimes it is. 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 13:42:26 -0700
From: "Gabe" <grichard@uci.edu>
Subject: Re: Installing Modules In General
Message-Id: <8ect9t$jes$1@news.service.uci.edu>

> Of course, it's even easier to use the CPAN module in most cases:
>
>     perl -MCPAN -e shell

I don't understand this. Can you explain what it does and why it's useful or
point me to the relevant documentation?

Thanks,
Gabe




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

Date: 28 Apr 2000 19:52:00 GMT
From: jorgy@Colorado.EDU (Eric R. Jorgensen)
Subject: Re: perl backtic problem with slapd
Message-Id: <8ecq50$eo4$1@peabody.colorado.edu>

In article <u9g0s617pu.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>jorgy@Colorado.EDU (Eric R. Jorgensen) writes:
>> `/usr/local/libexec/slapd -f /usr/local/etc/openldap/slapd.conf`;
>> 
>> For some reason, it starts the server but doesn't background.

 ... 

>Try system() instead of backticks.

Great, that works like a charm!

Thanks!


-- 
Eric R. Jorgensen			jorgy@Colorado.EDU
University of Colorado, Boulder		
"A lot of people may not know this, but I'm pretty famous." -- Sam on Cheers


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

Date: Fri, 28 Apr 2000 13:20:59 -0700
From: Luxe <kkentkNOkkSPAM@yahoo.com.invalid>
Subject: Perl Free Online Courses
Message-Id: <22d4d196.8d319389@usw-ex0105-040.remarq.com>

   A site called FreeEdu.com offers free Perl courses on the
internet.  Courses are open to anyone, and give you the freedom
to work at your own pace from a comfortable environment(such as
your own personal computer).  Courses are offered in many
computer-related subjects, such as programming(C, Visual
Basic,PowerBuilder, etc.), web development(CGI/Perl, HTML,
etc.), graphic design, and basic desktop computing(Windows, MS
Works, etc).  Other courses of study include Business Skills,
Accounting, Marketing, etc., as well as SAT prep courses, and
will eventually serve a user population as young as
Kindergarten.  You can visit the site at http://www.freeedu.com
to receive more information.

And if you sign up soon you get 100 instant knowledge points.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Fri, 28 Apr 2000 14:54:10 -0500
From: "c d" <cedelis@uillinois.edu>
Subject: Re: perl v5.6.0 install and the "otherlibdirs" variable
Message-Id: <a_lO4.12423$nb2.259466@vixen.cso.uiuc.edu>

btw,

is there a "better" way to add directories to @INC globally?  i want to
eliminate the need to push(@INC, "/path/to/lib")

thanks much,

chris

"c d" <cedelis@uillinois.edu> wrote in message
news:bijO4.12388$nb2.258253@vixen.cso.uiuc.edu...
> has anyone set this variable during an install (and have gotten it to work
> correctly)?
>
> i would like to permanently add a path to the @INC variable and thought
this
> was a way i could do it.
>
> i am building perl from source.
>
> any help would be greatly appreciated!   thanks!
>
> please send a CC: to chris@delis.net
>
>




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

Date: 28 Apr 2000 19:10:32 GMT
From: gosar@bhavesh.ebay.sun.com (Bhavesh Gosar)
Subject: Perl/Oracle-SLQ*Loader error
Message-Id: <8ecnn8$km6$2@ebaynews1.EBay.Sun.COM>

Hi,

I am calling SQLLoader (which loads data from text file into
Oracle DB) from a Perl Script (all env. variables are fine)...
This used to work a couple of days earlier....But all of a sudden 
I am getting the foll. error...

===============
SQL*Loader: Release 8.0.5.0.0 - Production on Wed Apr 26 15:3:31 2000

(c) Copyright 1998 Oracle Corporation.  All rights reserved.

ORA-12545: Connect failed because target host or object does not exist
SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [-1]
===============

I checked the Oracle Support web but without luck...

Any clue as to what is this...and what is the solution to this...

Thanks,
Bhavesh Gosar



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

Date: Fri, 28 Apr 2000 12:34:00 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: Perl/Oracle-SLQ*Loader error
Message-Id: <3909E7A8.F1892253@My-Deja.com>

> SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [-1]

The Oracle documents say the following

SQL*Loader-704: internal error: str num

Cause: An internal error has occurred.

Action: Make a note of the message and the number, then contact customer
support.

This error has nothing to do with Perl
==




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

Date: Fri, 28 Apr 2000 18:58:04 GMT
From: swaroop_g@my-deja.com
Subject: Re: Print Just Once When in (<>)?
Message-Id: <8ecmvi$gdb$1@nnrp1.deja.com>



one possible solution
create a file .overstatus containing just the  line
"#This ..."

finish your perl processing and then
#Korn shell
cat .overstatus Infile > Outfile

there are other solutions of course.

Swaroop.

In article <8ec5jp$2s7$1@wanadoo.fr>,
  "Elisa Roselli" <e.roselli@volusoft.com> wrote:
> I'm having a small bug in a script that combines Perl and Korn Shell.
>
> I want this script to test first whether it has been executed on
inputFile
> before. It scans inputFile for a line of the type "#This program has
already
> been run on this file". If so, it stops, shows a message on screen to
the
> same effect and sends an error code to a log file. Otherwise, it
starts on
> the Perl part of the program, which involves doing some text
substitutions
> on inputFile and marking inputFile so as to show that the program has
been
> run.
>
> OK, so it currently looks like this:
>
> ***
> # Korn shell :
>
> # Test for evidence of previous run
> if (grep "#This program has already been run on this file" $1) > 0
>  then
>  echo ""#This program has already been run on this file"
>  resul=3
>  else
>
> # make a backup
>  cp $1 sauvegarde_trad/$1.001
>
> # Perl part of program, still part of the "else" condition
> perl -i -e '$/ = "\n\n";
>
> # The problem line. If I put it here, it prints to screen rather than
in the
> file
>          print "# This program has already been run on this file\n";
>
>          while (<>)
>
> # Instead, if I put problem line here, it prints at the end of every
block,
> as defined by $/.
> # I only want it to print this once at the beginning of inputFile and
not
> waste all those needless bytes!
>
>          #print "# This program has already been run on this file\n";
>
> # The substitutions
>          s/blah blah/bleh bleh/g;
>
>          print $_;
>          }' $1
>
> # Back to shell
> resul=0
> fi
>
> (echo ` date +"%m:%d  -  %H:%M"  `  " - 001 - $1 - $resul")  >>
> sauvegarde_trad/trad_log
>
> ***
>
> So my question is, where to put my problem line? After the (<>) it
prints at
> every block, before the (<>) it prints to screen.
>
> I'm sure this must be simple, but I'm not very intelligent and it's
Friday
> afternoon.
>
> Thanks for any patient recommendations.
>
> Elisa Francesca Roselli
>
>

--

the future is happening   - me


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 28 Apr 2000 13:07:52 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Random number
Message-Id: <3909D378.17D5B0AC@walgreens.com>

Larry Rosler wrote:
> 
> In article <3909C246.8E31B4B@walgreens.com> on Fri, 28 Apr 2000 11:54:30
> -0500, Andrew N. McGuire <andrew.mcguire@walgreens.com> says...
> 
> ...
> 
> > srand if $] < 5.004;
> >
> > Mmmm, portable it is.
> 
> That really isn't good enough for archaic versions of perl, which still
> need initialization of the srand function (as shown in the original
> post).  Some of my code still runs using 5.002 on servers over which I
> have no control.  Sigh...

True, I was just pointing out the concept that it could all be done
inside the program.  I suppose you could use a more elaborate
initialization
scheme, for older versions, as in the documentation:

srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);

or even use an appropriate module.  The main idea I was trying to get
across to PG, is that you can formulate some sort of conditional based
on $], to initialize srand appropriately.  I should have been more
verbose, I apologize if I was misleading.

Regards,

anm
-- 
Andrew N. McGuire
andrew.mcguire@walgreens.com


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

Date: Fri, 28 Apr 2000 13:24:59 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Random number
Message-Id: <3909D77B.11AE365F@walgreens.com>

Jonathan Barker wrote:

[ snip of post that should have been here. ]

> Does it really matter?!?

Yes.  Personally, to me if you are below 5.004, you should
upgrade, but as Larry Rosler pointed out, not all people can.
You do want to check the funtionaltiy of rand.  If perl was
not compiled with the correct number of RANDBITS, you will
not get correct numbers out of rand.  If srand is called more
than once, rand will not work properly.  As Larry pointed
out some older versions of Perl require better initialization
than what I pointed out ( although that was not my point ).
Anyway, please do not post upside-down.

Cheers,

anm
-- 
Andrew N. McGuire
andrew.mcguire@walgreens.com


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

Date: Fri, 28 Apr 2000 11:49:11 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Random number
Message-Id: <MPG.13737cfe857b37eb98a9a6@nntp.hpl.hp.com>

In article <3909D77B.11AE365F@walgreens.com> on Fri, 28 Apr 2000 
13:24:59 -0500, Andrew N. McGuire <andrew.mcguire@walgreens.com> says...

 ...

> ...  If srand is called more
> than once, rand will not work properly.  As Larry pointed
> out some older versions of Perl require better initialization
> than what I pointed out ( although that was not my point ).

I might as well show the entire initialization that I use:

  srand $^T ^ $$ + ($$ << 15) if $] < 5.004 && 1 =~ ?1?; # Once only.

So shoot me for the flagless once-only switch.  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 11:59:36 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Random number
Message-Id: <3909DF98.DFC05CF5@stomp.stomp.tokyo>

Larry Rosler wrote:
 
> In article <3909BBFF.3FAF7DDE@stomp.stomp.tokyo> on Fri, 28 Apr 2000
> 09:27:43 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...

> >  srand(time() ^ ($$ + ($$ << 15)));
> >  sub randcase
> >   {
> >    rand(40) < 20 ? "\u$1" : "\l$1" ;
 
> 40 and 20 are interesting (idiosyncratic :-) choices.  Other choices:
 
>      rand < 0.5
>      int rand 2


Not at all indiansyncratic. Use of two digit
numbers allows me a wide range of how my output
appears visually. A 50/50 split is not what I
always use. Some K-rAd kEWl dUdz want their
text messed up a lot. Some of us older cool people
don't want our text messed up as much, which
leads to a need for those reading glasses.

It's all in the percentages. 40/20 is a nice
setting for those of us displaying signs of
middle age, such as reading glasses held 
backside out of sight. Additionally big
whole numbers are easier to read and much
easier to understand. Who does decimals
beside downtrodden kids in math classes?
 

> >  $in{InlaHolisso} =~  s/([a-z])/randcase($1)/gie;
 
> Either pass $1 to randcase and use it as an argument ($_[0]), or don't
> pass it and use it as a global variable.  What you show is schizoid.

Degree of portability is directly proportional
to the degree of schizoid. Besides, would you
expect anything less from an alledged schizoid,
highly imaginitive and highly skilled programmer
such as myself? My code works perfectly, does
it not? What rule have I violated? Am I to be
arrested by code police and put on Perl trial?
I think not. No rule has been violated other
than violating your personal perception of
how things should be done.

 
> >   srand;
> >   $_ = (rand(@Adjectives)) * 100000000000;
> >   s/\..+//g;
 
> How many decimal points do you expect (else why the /g modifier)?  And
> what about using the int() function, which is intended for this purpose?


* Carl Sagan Voice*

 ...billions and billions..

Why do it your way when I can enjoy doing it my way?
I mean, I do have a schizoid reputation to maintain.
Bet none of you ever thought of doing it my way or
have given thought to why I do it this way.


> >   s/(\d\d?)/\1, /g;
 
> The backreference should be written as $1, not \1.  The '-w' flag would
> warn about this archaic grandparented usage.

Why? Works just fine the way I do it, even under
archaic versions of Perl. * hint *

 
> >   chop($_);
> >   chop($_);
 
> The above three lines might be written more compactly as:
 
>     $_ = join ', ' => /\d\d?/g;


I only read two lines. Gotta watch what
you say and how you say it around an
English teacher.

Who the heck uses -w for anything? Shoot,
that will ruin your program and ruin your
imagination in a hurry. Despite what this
stupid -w screams, my code works perfectly.

Interesting, yes?



Godzilla!


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

Date: Fri, 28 Apr 2000 12:17:24 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Random number
Message-Id: <MPG.137383a3b9d8204e98a9aa@nntp.hpl.hp.com>

In article <3909DF98.DFC05CF5@stomp.stomp.tokyo> on Fri, 28 Apr 2000 
11:59:36 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...

 ...

> Interesting, yes?

Yes, and very indiansyncratic, indeed.  I trolled the troll, and got 
good laughs in return.  Thanks for making my day.

ROTFL.

HAND.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 28 Apr 2000 12:49:49 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Random number
Message-Id: <3909EB5D.F2718408@stomp.stomp.tokyo>

Larry Rosler wrote:
 
> In article <3909D77B.11AE365F@walgreens.com> on Fri, 28 Apr 2000
> 13:24:59 -0500, Andrew N. McGuire <andrew.mcguire@walgreens.com> says...

> I might as well show the entire initialization that I use:
 
>   srand $^T ^ $$ + ($$ << 15) if $] < 5.004 && 1 =~ ?1?; # Once only.




 $random_number = int(rand(4));

 if (!($random_number))
  {
   srand;
   $random_number = int(rand(4));
  }


No need to know what version of Perl.
Redundant backup in case of a glitch.

Godzilla!


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

Date: Fri, 28 Apr 2000 20:55:15 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random number
Message-Id: <sgjuljk37qo89@corp.supernews.com>

Chello (stephane@siw.ch) wrote:
: I have a little problem I have to generate a random number with two limits
: (upper limit and down limit) for example 1 and 4. When I call the script
: this script would have to display "1" or "2" or "3" or "4". Does somebody
: knows how to do it? Do you have an example?

#!/usr/bin/perl -w
# randintrange - demo of func returning rand int in integer range
# Range is inclusive of both endpoints.
# Craig Berry (20000428)

use strict;

sub randIntRange {
  die 'randIntRange - wrong arg count' unless @_ == 2;

  my ($lo, $hi) = @_;
  my $span      = ($hi - $lo) + 1;

  return $lo + int rand $span;
}

# Test

my %res;

foreach (1 .. 10_000) {
  $res{randIntRange(5, 9)}++;
}

foreach (sort keys %res) {
  print "$_ : $res{$_}\n"
}

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "The road of Excess leads to the Palace
      of Wisdom" - William Blake


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 2897
**************************************


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