[9567] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3161 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 15 06:07:59 1998

Date: Wed, 15 Jul 98 03:00:37 -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           Wed, 15 Jul 1998     Volume: 8 Number: 3161

Today's topics:
        a foreach within a foreach? <bravo@bravodesign.com>
    Re: a foreach within a foreach? <quednauf@nortel.co.uk>
    Re: a foreach within a foreach? <quednauf@nortel.co.uk>
    Re: anyone working on CDO or CDONTS module? (Martien Verbruggen)
    Re: Arrays (Martien Verbruggen)
    Re: Chomp() on win32 and unix perl (Marc Haber)
        Dump a GUI to /dev/null on SGI workstation <butty@iet.mavt.ethz.ch>
    Re: efficiency: print<<"xxx" vs. print <rlogsdon@io.com>
        Expect.pm and HP-UX (Eric Hagen)
    Re: forms and sub routines <quednauf@nortel.co.uk>
    Re: HELP: Programming Question merzky@physik.hu-berlin.de
    Re: inconstant behavior of constants (Larry Rosler)
    Re: IO.pm in which versions? (M.J.T. Guy)
    Re: Locking SDBM files <clint@netcomuk.co.ukXX>
        Midnight Oil reference in Perl book? (Kelly Larnach)
    Re: Midnight Oil reference in Perl book? (Larry Rosler)
        module help <matt2@lonelyplanet.com.au>
    Re: newbie question on pattern match (Abigail)
    Re: Perl Beautifier Home Page (M.J.T. Guy)
    Re: perl IDE and compiler (Martien Verbruggen)
        Pre-pending data to a database or file. <mastered@paclink.com>
    Re: qn on string substitution (M.J.T. Guy)
    Re: qn on string substitution <xuchu@iscs.nus.edu.sg>
    Re: Sticking in NULL after split merzky@physik.hu-berlin.de
    Re: Win NT Perl 5.0 Y2K compliance <quednauf@nortel.co.uk>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Wed, 15 Jul 1998 01:51:31 -0500
From: Darrick Wolfe <bravo@bravodesign.com>
Subject: a foreach within a foreach?
Message-Id: <35AC5173.1ABF@bravodesign.com>

Hello,

I'm having some problems with a chat script I'm writting (snippet is
attached).  I am taking data from 2 seperate text files.  One is the
actual chat messages, starting each line with their name, and the other
is a name filter.

The object here is to print out what each person is saying, unless you
have that name ignored.

I can get this to work perfectly if I only have one name in the name
filter file.  But I don't know how to do it formore than one name.  The
name filter file is comma delimited.

below is the code snippet:

	# getting the chat posts
	open(CHAT,"$root/room/$croom.txt") || &do_die("Can't open
$IN{'room'}.txt!\n");
	flock(CHAT, $LOCK_EX) || &do_die("Can't lock $nick.txt!");
	@chat = <CHAT>;
	flock(CHAT, $LOCK_UN);
	close(CHAT);
	
	# get each users ignore list
	open(IGNORE2,"$root/ignore/$nick.txt") || &do_die("Can't open
$nick.txt!");
	flock(IGNORE2, $LOCK_EX) || &do_die("Can't lock $nick.txt!");
	$ignored1 = <IGNORE2>;
	flock(IGNORE2, $LOCK_UN);
	close(IGNORE2);

	# temp code here to split everything seperated by a comma and put into
an array
	@gone = split(/,/,$ignored1);

	# this variable is here to count the lines for use later in the script
	$e = 1;
		foreach $line (@chat){
			@checkig = split(/ /,$line);
			
			# can get rid of the HTML, but concerned about other things now
			# This part filters out the line If their nick equals the line nick
			if($checkig[0] eq "<B>$gone[0]:</B>"){

				#Ignore them!
				print "";
				}else{
				
				#I want to see their post!
				$line =~ s/(\w{70})(?=\w)/$1 /g;
				print "$line<BR>\n";
				$e++;
			}
		}


I hope at least one of you out there understands what I'm asking.  I'm
positive there is a prittier way to do all of this, and if you know it,
let me know!  I appreciate any help I can get!

If possible, please CC my e-mail!

Thanks Alot!


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

Date: Wed, 15 Jul 1998 09:27:27 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: a foreach within a foreach?
Message-Id: <35AC67EF.695553C9@nortel.co.uk>

Darrick Wolfe wrote:
> 
> I can get this to work perfectly if I only have one name in the name
> filter file.  But I don't know how to do it formore than one name.  The
> name filter file is comma delimited.
> 
> below is the code snippet:
> 
>         open(CHAT,"$root/room/$croom.txt") || die;
>         @chat = <CHAT>;
>         close(CHAT);
> 
>         open(IGNORE2,"$root/ignore/$nick.txt") || die;
>         $ignored1 = <IGNORE2>;

I suppose your stuff is on one line, as above you've used an array.

>         close(IGNORE2);
> 
>         @gone = split(/,/,$ignored1);
> 
>         $e = 1;
>           foreach $line (@chat){
>              @checkig = split(/ /,$line);
>              if($checkig[0] eq "<B>$gone[0]:</B>"){print "";}

You're always comparing to the first element of the @gone array. So
that's only the first name of your filter list. So why not doing indeed
a foreach within a foreach, as you suggest in your subject ? :)

LOOP:   foreach $name(@gone) {
          next LOOP if "<B>$name:</B>" eq @{[split(' ', $line)]}[0];
          $line =~ s/(\w{70})(?=\w)/$1 /g;
          print "$line<BR>\n";
        }

Something like that anyway....

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Wed, 15 Jul 1998 10:31:19 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: a foreach within a foreach?
Message-Id: <35AC76E7.CCC86F9E@nortel.co.uk>

F.Quednau wrote:
> 
 
> LOOP:   foreach $name(@gone) {
>           next LOOP if "<B>$name:</B>" eq @{[split(' ', $line)]}[0];
                                            ^^^^^^^^^^^^^^^^^^^^^^^^
This is silly, as you do a split operation in every loop. So better
store it in an intermediate variable before entering the loop.

      next LOOP if "<B>$name:</B>" eq $ignorance;


>           $line =~ s/(\w{70})(?=\w)/$1 /g;
>           print "$line<BR>\n";
>         }


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

Date: 15 Jul 1998 05:57:38 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: anyone working on CDO or CDONTS module?
Message-Id: <6ohgci$c7p$3@comdyn.comdyn.com.au>

In article <t0ww9gjely.fsf@hcirisc.cs.binghamton.edu>,
	Tim Gray <tim@hcirisc.cs.binghamton.edu> writes:
> At work we use MS Exchange and I would really like to get some more
> functionality out of it.  But the way most people do that is with
> Outlook forms and other unfriedly or highly proprietary and costly
> solutions.  So I was wondering if anyone is working on a module to use

How is Outlook any more proprietory and costly than Exchange?

> Microsoft's Collaborative Data Objects.

And that's not propietory?

Did you check CPAN to see if there's already something there? Did you
check ActiveState's site?

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 15 Jul 1998 05:46:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Arrays
Message-Id: <6ohfn4$c7p$1@comdyn.comdyn.com.au>

In article <35AB3140.42ADBF7F@email.sps.mot.com>,
	Paul Keenan <r11354@email.sps.mot.com> writes:

> The most serious error seems to be that you don't increment your
> loop variable $i.
> 
> Replace
>     for (...; ...; $i)

Errrr.. I don't know what's going wrong with your news reader, but the
original post contained:

for ($i = 0;$i < MAX;$i++) {
    $array[$i] = $i;
}

That clearly increments $i.

> with
>     for (..., ..., $i+-+-)

Where is the operator +-+- documented?

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Wed, 15 Jul 1998 07:57:32 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Re: Chomp() on win32 and unix perl
Message-Id: <6ohnel$qac$2@nz12.rz.uni-karlsruhe.de>

drummj@mail.mmc.org (Jeffrey Drumm) wrote:
>On Tue, 14 Jul 1998 18:50:13 GMT, Marc.Haber-usenet@gmx.de (Marc Haber)
>wrote:
>>Jonathan Feinberg <jdf@pobox.com> wrote:
>>> Also: use ASCII mode when transferring your file between platforms;
>>>this will automagically translate end-of-line sequences between
>>>platforms.
>>
>>This is not an option if you are using Samba or NFS.
>>
>Of course it's an option. It just isn't as *simple* an option.
>
>IOW, Samba and NFS don't stop your FTP server from serving, or your FTP
>client from, uh, clienting. unless, of course, you've done something
>horribly wrong . . . ;-)

Imagine developing a perl script on a UNIX box while sitting at a
Windows machine's console. It is much more comfortable to have a
Windows editor editing the script file over a samba or NFS connection,
do a simple save, click over to the ssh connection to the UNIX box and
run the script instead of editing in the ssh window or saving locally
and then ftp'ing the script file over to the UNIX box.

Greetings
Marc

-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | Mailadresse im Header
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: Wed, 15 Jul 1998 10:45:30 +0200
From: Butty Vincent <butty@iet.mavt.ethz.ch>
Subject: Dump a GUI to /dev/null on SGI workstation
Message-Id: <35AC6C2A.4058DB00@iet.mavt.ethz.ch>

Hi,

As my knowledge of Perl is not so deep, I need some help from you. Here
is my problem:

I want to use Perl in order to call a program with the system() or
exec() command, but I want to dump the graphic interface of this program
to /dev/null for security problem.

I try to redirect the STDOUT and STDERR to /dev/null but the GUI still
appears.

If somebody has an idea how to dump the GUI to /dev/null using Perl, I
would be glad to get some tips.

Thanks,

Vincent Butty



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

Date: Wed, 15 Jul 1998 01:42:29 -0500
From: REUBEN LOGSDON <rlogsdon@io.com>
To: Dan Schmidt <dfan@harmonixmusic.com>
Subject: Re: efficiency: print<<"xxx" vs. print
Message-Id: <Pine.BSF.3.96.980715014131.9619J-100000@dillinger.io.com>

I think the big difference is using print <<'xxx' versus print <<"xxx".
Single quotes are faster and if you have a block of text with one little
variable substitution in it then you have to use doubles so you get a hit.

Regards,
Reuben Logsdon


On 14 Jul 1998, Dan Schmidt wrote:

> rjking@blue.seas.upenn.edu (Rachel J King) writes:
> 
> | I'm wondering about the efficiency of using print<<"xxx" versus that of 
> | just writing a whole bunch of print statements.  Is there any huge 
> | difference in terms of the lower-level machine code that actually gets 
> | executed?  I'm asking b/c I wrote a bunch of code just using a lot of print 
> | statements before I learned the other way and I'm wondering how worth my 
> | time it is to go and change it all or if I could leave it the way it is 
> | without wasting a huge amount of time each time the scripts are run.
> 
> I didn't see any difference when I tried it.
> 
> ====
> 
> use Benchmark;
> open TMPFILE, ">tmpfile" or die;
> 
> timethese (50000, {
>                   'Heredoc' => sub {
>                     print TMPFILE <<FOO
> I'm wondering about the efficiency of using print<<"xxx" versus that of 
> just writing a whole bunch of print statements.  Is there any huge 
> difference in terms of the lower-level machine code that actually gets 
> executed?  I'm asking b/c I wrote a bunch of code just using a lot of print 
> statements before I learned the other way and I'm wondering how worth my 
> time it is to go and change it all or if I could leave it the way it is 
> without wasting a huge amount of time each time the scripts are run.
> FOO
>                   },
>                   'Prints' => sub {
> print TMPFILE "I'm wondering about the efficiency of using print<<\"xxx\" versus that of\n";
> print TMPFILE "just writing a whole bunch of print statements.  Is there any huge\n";
> print TMPFILE "difference in terms of the lower-level machine code that actually gets\n";
> print TMPFILE "executed?  I'm asking b/c I wrote a bunch of code just using a lot of print\n";
> print TMPFILE "statements before I learned the other way and I'm wondering how worth my\n";
> print TMPFILE "time it is to go and change it all or if I could leave it the way it is\n";
> print TMPFILE "without wasting a huge amount of time each time the scripts are run\n";
>                    }
>                  });
> 
> ====
> 
> Benchmark: timing 50000 iterations of Heredoc, Prints...
>    Heredoc: 18 secs (17.69 usr  0.00 sys = 17.69 cpu)
>     Prints: 18 secs (17.89 usr  0.00 sys = 17.89 cpu)
> 
> -- 
>                  Dan Schmidt -> dfan@harmonixmusic.com, dfan@alum.mit.edu
> Honest Bob & the                http://www2.thecia.net/users/dfan/
> Factory-to-Dealer Incentives -> http://www2.thecia.net/users/dfan/hbob/
>           Gamelan Galak Tika -> http://web.mit.edu/galak-tika/www/
> 
> 



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

Date: 15 Jul 1998 07:50:33 GMT
From: ehagen@Hawaii.Edu (Eric Hagen)
Subject: Expect.pm and HP-UX
Message-Id: <6ohn09$s3m@news.Hawaii.Edu>

I Posted this to comp.lang.perl.modules but no clear answers yet, hoping for a
wider group here.

Has anyone had any luck in getting the Expect.pm module to work with HU-UX
10.20?  I have Expect.pm-1.07, and saw the part in the FAQ about:
Q:      How come Expect.pm doesn't run properly under HP-UX?
A:      There seems to be a bug in IO::Tty. More to the point, HP-UX. When
a process dies the parent end of it's tty does not receive an EOF, or so
I have been told. I do not have a machine to test this on.
        One solution is when you spawn a process, follow it with a unique
string that would indicate the process is finished.

        $process = Expect->spawn('telnet somehost;echo ____END____');

        And then
$process->expect($timeout,'____END____','other','patterns');

This just does not seem to work for me, In most cases I can match and
return correctly from the  first match, then I get nothing, the
Accumulator is '', and there seems to be no more "interaction".  I have
tried everything I could find in the FAQ, Tutorial and Dejanews.  Below is
the the important part of the debug output.

Matched pattern 1 ('Name (system:user): ')!
        Match string: 'Name (system:user): '
        After match string: ''
Returning from expect successfully.
Accumulator: ''

Beginning expect from spawn id(3).
Accumulator: ''
Expect timeout time: 30 seconds.
expect: Pty=spawn id(3), time=900454956, loop_time=30
Expecting from spawn id(3): 'Password:'
Does ''
from spawn id(3) match:
        pattern 1 ('Password:')? No.
Returning from expect unsuccessfully. Error: 1:TIMEOUT.

I have tried it with ftp, telnet, ssh, etc.  I really need to be able to
get some type of complex interactions going, and straight socks is alien
to me, and I need to be able to get expect like functionality.

Could anyone help?  Or how can I call expect scripts from perl while
passing environments, variables etc.

Thank you very much in advance.


--
Eric Hagen                  "Sometimes we get lost in the darkness, 
ehagen@Hawaii.Edu	     the dreamers learn to steer by the stars..."
			    "You fight for something because it is good.
	 				Not because it stands to succeed."


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

Date: Wed, 15 Jul 1998 08:39:52 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: forms and sub routines
Message-Id: <35AC5CC8.D461AA09@nortel.co.uk>

Dave Paules wrote:
> 
>  ... I would like to stick
> these little subroutines in a library later so that the main script
> would simply be some calls to subroutines that are linked to form
> buttons. Is this possible?
>     Dave Paules, senior, University of Delaware
>     Summer intern, ARL

For examples check out a few of my scripts at my Homepage

-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Wed, 15 Jul 1998 07:20:37 GMT
From: merzky@physik.hu-berlin.de
Subject: Re: HELP: Programming Question
Message-Id: <6ohl85$ioj$1@nnrp1.dejanews.com>

In article <35ABA90F.E684F8A6@cas-inc.com>,
  "J. Paul Hill" <paul.hill@cas-inc.com> wrote:
> I have just started playing with Perl and have been working through the
> exercises in my Perl book.  I wrote a short script to calculate the
> circumference of a circle and decided to give it the option of repeating
> this calculation more than once.  Unfortunately, the logic statement
> seems to only execute correctly the first time through.  After that, it
> either quits or repeats infinitely depending on which logic operator I'm
> using.  Here's the code:
>
> #!/usr/bin/perl
> $answer = "yes";
> $pi = 3.141592654;
> while ($answer eq "yes") {
>    print "Input radius of circle ";
>    $radius = <STDIN>;
>    (Then it calculates the circumference and prints out the results)
>    print "Would you like to compute another circumference? ";
>    $answer = <STDIN>;
> }
>
> With the "while" it executes once.  If I use "while ($answer ne "no")",
> it computes repeatedly.  What am I doing wrong?

after $answer = <STDIN> answer also contains a newline.
you could use a regular expression (cas insensitive possibly:
while ($answer =~ /^yes/i) {
or get rid of the newline using:
chomp ($answer);

regards, Andre.

>
> Thanks for your help!
>
>


--
 _________________________________________________________________
|     __o    pinocchio@earthling.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 14 Jul 1998 23:20:41 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: inconstant behavior of constants
Message-Id: <MPG.1015ea101e62164f989743@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6ohfdh$p4b$6@marina.cinenet.net> on 15 Jul 1998 05:41:05 GMT, 
Craig Berry <cberry@cinenet.net> says...
> Craig Berry (cberry@cinenet.net) wrote:
> : So would the correct (or a correct) way of writing such a bareword
> : constant being evaluated for its numeric value
> : 
> :   $myhash{+STARTYEAR} = 1984;
> : 
> : And how would one best make this work for a string constant?

+ works just fine there too.  From `perldoc perlop`:

Unary "+" has no effect whatsoever, even on strings.

> Never mind, Larry Rossler just posted the answer to this.  LSNED...

LSNED???

The theme of last Sunday's New York Times crossword was "If I had a 
nickel for every dollar I put in the bank, I'd have 1/20 of what I have 
now."  If I had a nickel for every extra 's' in my name, I'd be lots 
richer than I am now. :-)

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


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

Date: 15 Jul 1998 07:25:20 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: IO.pm in which versions?
Message-Id: <6ohlh0$k2l$1@pegasus.csx.cam.ac.uk>

David Thompson <domainsource@usa.net> wrote:
>I heard that the IO library comes bundled with some releases of Perl
>5.... does 5.003 and/or 5.004 included it by default (especially
>IO::socket)?  Thanks.

All perl releases since 5.004 have included the IO:: modules.
Earlier releases do not include them.


Mike Guy


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

Date: Wed, 15 Jul 1998 08:58:45 +0100
From: "Clinton Gormley" <clint@netcomuk.co.ukXX>
Subject: Re: Locking SDBM files
Message-Id: <6ohnft$7oh$1@taliesin.netcom.net.uk>

thanks mike

just to expand on this :

Is a shared lock a lock that allows multiple people to read, whilst
preventing anybody from establishing a write lock until all shared locks are
removed?

using the tie hash, sdbm_file method, do i just need to use flock to
establish the lock or is there something else i need to do.

if i'm using flock, do i need to open the file first to create a filehandle
that points at my database?

thanks

clint




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

Date: 15 Jul 1998 06:40:07 GMT
From: s339792@student.uq.edu.au (Kelly Larnach)
Subject: Midnight Oil reference in Perl book?
Message-Id: <6ohis7$37d$1@bunyip.cc.uq.edu.au>

Just reading the second edition of Programming Perl. And on
page 189 the line of code: my $country = @_;  # right or wrong?
seems to resemble the lyrics of a Midnight Oil song quite closely.

Is this just coincidence or is Larry, Tom or Randal, fans
of Midnight Oil?




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

Date: Wed, 15 Jul 1998 00:03:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Midnight Oil reference in Perl book?
Message-Id: <MPG.1015f43aaf72a856989744@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6ohis7$37d$1@bunyip.cc.uq.edu.au> on 15 Jul 1998 06:40:07 
GMT, Kelly Larnach <s339792@student.uq.edu.au> says...
> Just reading the second edition of Programming Perl. And on
> page 189 the line of code: my $country = @_;  # right or wrong?
> seems to resemble the lyrics of a Midnight Oil song quite closely.
> 
> Is this just coincidence or is Larry, Tom or Randal, fans
> of Midnight Oil?

We all reveal our age or culture.  The following was the favorite toast 
of Commodore Stephen Decatur, Jr. (1779-1820), a hero of the American 
War of 1812 (against England):

"Our Country!  In her intercourse with foreign nations, may she always be 
in the right; but our country, right or wrong!"

Americans probably still learn that bit of patriotism in elementary 
school.  But I see you are Australian, so all is forgiven. :-)

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


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

Date: Wed, 15 Jul 1998 19:59:10 +1000
From: "Matt Eckhaus" <matt2@lonelyplanet.com.au>
Subject: module help
Message-Id: <35ac7d07.0@news.syd.att.net.au>

Hi

I am writing two modules, which provide quite seperate functionality, but
each of which may need to call each other at some stage. I don't want to
force scripts which want to use one of the modules to explicitly use both of
them, since it's not obvious that both are needed.

I have made each module use the other one. Is this a sensible thing to do?
Does it cause each module to be loaded twice? Does in cause any problems
with re-defining subroutines etc? Is there a more sensible way to do it?

Thanks,
Matt.




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

Date: 15 Jul 1998 08:19:12 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: newbie question on pattern match
Message-Id: <6ohom0$np9$1@client3.news.psi.net>

wings (xuchu@iscs.nus.edu.sg) wrote on MDCCLXXIX September MCMXCIII in
<URL: news:6oh5uk$eb13@id4.nus.edu.sg>:
++ thx for all replies. i am clear now:) yes, my original thought was
++ 	s/(\d)(\d\d\d)(\D)*/$1,$2/; and s/(\d)(\d\d\d)(\D)+/$1,$2/;
++ but neither of them worked. i was confused at that time coz the output
++ ate the trail of my original string.


Note that all the proposed solutions, correct or not, suffer from
one thing: they are quadractic in the size of the number. Note a
problem if you numbers are below a million, but a potential one
if the numbers are huge.

The problem is of course due to the backwardness of the substitution.
Here's one that's linear, and doesn't need a while:


s((\d+))(local $_ = reverse $1; s((\d\d\d)(?=\d))($1,)g; reverse)e;



Abigail
-- 
   This reply took over 3 hours to compose, and included patching
   pod2man and perlop.pod.


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

Date: 15 Jul 1998 07:47:48 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Perl Beautifier Home Page
Message-Id: <6ohmr4$kr4$1@pegasus.csx.cam.ac.uk>

Zenin  <zenin@bawdycaste.org> wrote:
>
>	The statement:
>		if (scalar @{ $foo } != scalar @{ $bar }) {
>	got changed to:
>		if (scalar @
>			{
>			$foo
>			}
>			!= scalar @
>			{
>			$bar
>			}
>		)
>		{
>	Ack! :-)

It's obviously trying to tell you that your code is being rendered
difficult to read by unnecessary clutter.        :-)

                if (@$foo != @$bar) {


Mike Guy


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

Date: 15 Jul 1998 05:52:43 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: perl IDE and compiler
Message-Id: <6ohg3b$c7p$2@comdyn.comdyn.com.au>

In article <6ofgdj$kvn$2@mainsrv.main.nc.us>,
	scott@softbase.com writes:
>> Is there any Perl compiler for win32/unix?
> 
> Perl is its own compiler. (How many languages can say THAT?) Add Emacs
> and you're in business. The great thing is, they work both on Win32
> and UNIX.

There is no reason to add Emacs. Any text editor will do. If you're
comfortable with emacs, use it. If you're not, use something else. 

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Tue, 14 Jul 1998 00:31:51 -0700
From: David Hemmer <mastered@paclink.com>
Subject: Pre-pending data to a database or file.
Message-Id: <35AB0967.47CCB3C8@paclink.com>

I know that I can append information to a flatfile db or other file,

example:
open (DATABASE, ">>./$data");

but is there some way to pre-pend the data to the specified file?

Thanks

Dave Hemmer
'rainman'
visionaryone@unforgettable.com
Mastered Media Productions





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

Date: 15 Jul 1998 08:58:40 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: qn on string substitution
Message-Id: <6ohr00$o11$1@pegasus.csx.cam.ac.uk>

In article <6ogprj$an2$1@nnrp1.dejanews.com>,  <vibhu@fjst.com> wrote:
>#!/usr/is/gnu/bin/perl -w
>
>$n1 = "q[0]"; # 1
>$n2 = "q[0]"; # 2
>
>$sign = "a b c $n1 d"; # 3
>print STDOUT "$sign\n"; # 4
>$n2 =~ s/\[/\\[/g; # 5
>$sign =~ s/$n2/DONE/; # 6
>
>print STDOUT "$sign\n"; # 7
>print STDOUT "-$n1-$n2-\n"; # 8
>
>-------------------
>
>$sign could have come from any other source. I want to substitute
>the q[0] with "DONE". The substitution statement in line 6 does not
>work, as is. Line 5 is also rewquired. Why? The "[" is being considered
>as a (array) range? How can I make the substitution work without having
>to do line 5? Can anyone explain/point me to the right resource to find out?

perldoc perlre

[ is a regular expression metacharacter, introducing a character class
such as [a-z].

>Interestingly, if I use the "\" in line 2 itself, and get rid of line 5,
>it does not work. Why?:

>$n2 = "q\[0]"; # 2

After that line, $n2 will have the value 'q[0]'.   To get the effect
you want, use single quotes:

 $n2 = 'q\[0]';

perldoc perlop / "Quote and Quote-like Operators"


But the best way of dealing with these sorts of problems is to use
\Q \E.    They deal with _all_ metacharacter problems.   As a rule,
*always* put \Q \E round any variable interpolated in a pattern,
unless you have a specific reason not to.


Mike Guy


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

Date: 15 Jul 1998 08:59:18 GMT
From: wings <xuchu@iscs.nus.edu.sg>
Subject: Re: qn on string substitution
Message-Id: <6ohr16$eb114@id4.nus.edu.sg>

vibhu@fjst.com wrote:
: $sign = "a b c $n1 d"; # 3
: print STDOUT "$sign\n"; # 4
: $n2 =~ s/\[/\\[/g; # 5
: $sign =~ s/$n2/DONE/; # 6

: work, as is. Line 5 is also rewquired. Why? The "[" is being considered
: as a (array) range? How can I make the substitution work without having
: to do line 5? Can anyone explain/point me to the right resource to find out?

i can only tell it is not a range symbol here. i wanna know the answer too.

: Interestingly, if I use the "\" in line 2 itself, and get rid of line 5,
: it does not work. Why?:

: #!/usr/is/gnu/bin/perl -w

: $n1 = "q[0]"; # 1
: $n2 = "q\[0]"; # 2

i can only answer this question since i myself am a newbie.. u use a "\" in 
line 2 and it doesnt work because you should have used single quote instead
of double quotes. try 
	$n2 = 'q\[0]';
and it works merrily. this is coz double quotes inteprets "\" in $n2 while
single quote doesnt.

-- 
wings
------
World is a book, those dont travel read only one page.

Email: xwings@usa.net, xuchu@iscs.nus.edu.sg
ICQ UIN: 1440319
http://gump.iscs.nus.edu.sg


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

Date: Wed, 15 Jul 1998 07:26:01 GMT
From: merzky@physik.hu-berlin.de
Subject: Re: Sticking in NULL after split
Message-Id: <6ohli9$j6o$1@nnrp1.dejanews.com>

In article <6ogfea$4ug$1@cronkite.cc.uga.edu>,
  beatle@arches.uga.edu (Benjamin Dixon) wrote:
> I am trying to write a perl script that will generate a create statement
> for an SQL server. Its pretty much just parsing an ascii file exported
> from a different server... anyways, I split the thing into separate
> variables like so:
>
> ($var1, $var2, $var3) = split(/:/);
>
> then I want to print the results, separated by commas like so:
>
> print "$var1, $var2, $var3";
>
> But say $var2 is an empty string... so that the output is:
>
> var1,,var3
>
> In this case I see that I could just use s// and get the output to look
> like this var1,NULL,var3. but if I have more than two commas, say
> var1,,,var3, or even 100, how can I place the word 'NULL' inbetween each?
> Probably a simple answer but I'm pretty new to perl. Thanks.

A simple workaround would be:
(for all vars, you could use a field here...)

@vars = split (/:/);
foreach $var (@vars) {
   unless (defined ($var)) {
      $var = "NULL";
}

#... stick them togethsr:
$outstring = join (/,/, @vars);

hope this helps...
Andre.


> --
> ******************************************************************************
> Benjamin R. Dixon, jr.				"It was an age of Empires.
> UCNS Student Consultant				 So is this one, not all
> http://www.arches.uga.edu/~beatle		 that well disguised."
> beatle@arches.uga.edu						-Vonnegut
>
> ------------------------------------------------------------------------------
>


--
 _________________________________________________________________
|     __o    pinocchio@earthling.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Wed, 15 Jul 1998 08:27:18 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Win NT Perl 5.0 Y2K compliance
Message-Id: <35AC59D6.F17BAE05@nortel.co.uk>

Michael Yee wrote:
> 
> Hello,
> 
> Does anyone know if Perl 5.0 for Windows NT 4.0 (SP3) is Year 2000
> compliant? Thanks,

No. This is to ensure that the whole Internet will go down on the year
2000, as the Internet is ruled by Perl. Of course this is all a big
marketing scam to prepare the mass market dominance of internet2, and
the new Perl version from Larry, Perl6.66 , which will be even more evil
than that not Y2K compliant Perl

*****************************************
Alternatively you shouldn't believe and READ THE DOCUMENTATION, or, Oh
my God, even weirder, use Infoseek (Infoseek!) and type in 'perl y2k'.
The first page leads you to a certain Michael Peppler, who says on the
FIRST page that "As far as I know neither sybperl nor perl suffer from
any Y2K problems." - And you know what? He's right!
*****************************************


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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