[9680] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3274 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 28 10:23:38 1998

Date: Tue, 28 Jul 98 07:01:14 -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           Tue, 28 Jul 1998     Volume: 8 Number: 3274

Today's topics:
    Re: Breaking out of a block <simonf@conduit.co.uk>
    Re: Breaking out of a block <simonf@conduit.co.uk>
    Re: Breaking out of a block (David Cantrell)
    Re: CHOMP not working on some servers <tonylabb@infonline.net>
        deadlocking sockets faganb@my-dejanews.com
    Re: deadlocking sockets <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: File Sizes <barnett@houston.Geco-Prakla.slb.com>
    Re: file system operations on open files (M.J.T. Guy)
    Re: fork() problem <maraism@sterlingdi.com>
    Re: Help reg. exp: shouldn't ^ match at beginning only? (M.J.T. Guy)
    Re: How can I get the name of the current subroutine ? (I.J. Garlick)
    Re: How Do I Access my Modules? <barnett@houston.Geco-Prakla.slb.com>
    Re: Im Willing to pay or give a free DOMAIN for a custo <perlguy@inlink.com>
        Net::Telnet -like module without telnet (Antti-Jussi Korjonen)
    Re: newbie string questions. <maraism@sterlingdi.com>
        Perl 5.004/5.005 difference? (Bug?) <barse@acc.umu.se>
    Re: Pid number of called process?? (Mike Stok)
    Re: Premature end of script headers (Mike Stok)
    Re: regexp as subroutine parameter <simonf@conduit.co.uk>
    Re: regexp as subroutine parameter (M.J.T. Guy)
    Re: Same code, diff machines, diff results (Ken Williams)
    Re: Try perl on Ms Dos <gdonohoe@nmp.nokia.com>
        upload form variables (500 Internal Error) <niemann@erlm.siemens.de>
    Re: upload form variables (500 Internal Error) (I R A Aggie)
        Using Perl to Determine default browser <phenning@phoenix-int.com>
    Re: Using Perl to Determine default browser scott@softbase.com
    Re: Y2K problem in PERL with localtime() (Bart Lateur)
    Re: Y2K problem in PERL with localtime() (I R A Aggie)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 28 Jul 1998 12:25:21 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: Breaking out of a block
Message-Id: <35bdb43f.0@nnrp1.news.uk.psi.net>

How about:

foreach $i (@files)

LOOP: {
  if(-d $i)

    # Do some stuff                        <---
    last LOOP unless(chdir($i));           <---
    # Do some more stuff                   <---
  } else

    # Do some different stuff
  }
}
}

Does that do wat you want?

Simon

David Cantrell wrote in message <35bca0a3.341007112@thunder>...
>Subject: Breaking out of a block
>
>If you look at the code below, I hope you can see what I'm _trying_
>to do ... I want to break out of the block I've marked unless
>chdir($i) succeeds.  And yes, I _do_ realise that the interpreter
>doesn't like the 'break_out' ;-)
>
>foreach $i (@files)
>  { if(-d $i)
>      { # Do some stuff                        <---
>        break_out unless(chdir($i));           <---
>        # Do some more stuff                   <---
>      }
>     else
>      { # Do some different stuff
>      }
>  }
>
>I've tried various mixtures of last, next, and even <SHUDDER> goto
>without any luck, and really don't want to have to use ...
>
>    if(-d $i)
>      { # Do some stuff
>        if(chdir($i))
>          { # Do some more stuff
>          }
>      }
>
>because it looks ugly ;-)  Does anyone have any suggestions?
>
>--
>Dave the Puzzled




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

Date: Tue, 28 Jul 1998 12:27:39 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: Breaking out of a block
Message-Id: <35bdb4c3.0@nnrp1.news.uk.psi.net>

Hmmm seem to have lost some trailing '{'s in the post well hopefully you get
my drift!

Simon Fairey wrote in message <35bdb43f.0@nnrp1.news.uk.psi.net>...
>How about:
>
>foreach $i (@files)
>
>LOOP: {
>  if(-d $i)
>
>    # Do some stuff                        <---
>    last LOOP unless(chdir($i));           <---
>    # Do some more stuff                   <---
>  } else
>
>    # Do some different stuff
>  }
>}
>}
>
>Does that do wat you want?
>
>Simon
>
>David Cantrell wrote in message <35bca0a3.341007112@thunder>...
>>Subject: Breaking out of a block
>>
>>If you look at the code below, I hope you can see what I'm _trying_
>>to do ... I want to break out of the block I've marked unless
>>chdir($i) succeeds.  And yes, I _do_ realise that the interpreter
>>doesn't like the 'break_out' ;-)
>>
>>foreach $i (@files)
>>  { if(-d $i)
>>      { # Do some stuff                        <---
>>        break_out unless(chdir($i));           <---
>>        # Do some more stuff                   <---
>>      }
>>     else
>>      { # Do some different stuff
>>      }
>>  }
>>
>>I've tried various mixtures of last, next, and even <SHUDDER> goto
>>without any luck, and really don't want to have to use ...
>>
>>    if(-d $i)
>>      { # Do some stuff
>>        if(chdir($i))
>>          { # Do some more stuff
>>          }
>>      }
>>
>>because it looks ugly ;-)  Does anyone have any suggestions?
>>
>>--
>>Dave the Puzzled
>
>




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

Date: Tue, 28 Jul 1998 12:50:43 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: Breaking out of a block
Message-Id: <35bec8e3.71320363@thunder>

On Tue, 28 Jul 1998 12:25:21 +0100,
  "Simon Fairey" <simonf@conduit.co.uk> wrote in c.l.p.misc:

>How about:

[snip]

Something like that ;-)  I get the idea - thanks.

--
David Cantrell, part-time NT/java/SQL techie
                full-time chef/musician/homebrewer
                http://www.ThePentagon.com/NukeEmUp


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

Date: Tue, 28 Jul 1998 08:55:27 -0400
From: Tony Labbiento <tonylabb@infonline.net>
Subject: Re: CHOMP not working on some servers
Message-Id: <35BDCA3F.14126350@infonline.net>

Programming Perl 2nd Edition: chomp removes any line ending
corresponding to the current value of $/, and not just any last
character. If $/ is empty chomp removes all trailing newlines from the
selected string.

Chris Denman wrote:
> 
> I have been coding perl for 9 months and obviously have had no
> problems with CHOMP.  Just recently I moved some code from one
> server to another - a daily thing for me - and the code would
> not work at all.  After a bit of debugging I found that chomp
> only took the last character off of the string and left some
> crap (I thought that chomp took off all of the crap off the end
> of a string?).
> 
> Any thoughts?
> 
> Chris

-- 
			****************************************
			*    Tony Labbiento                    *
			*    Infinity Online, Inc.             *
			****************************************


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

Date: Tue, 28 Jul 1998 12:49:41 GMT
From: faganb@my-dejanews.com
Subject: deadlocking sockets
Message-Id: <6pkhd5$k4p$1@nnrp1.dejanews.com>

I am trying to write a c/s app using sockets and developing my own
application level protocol.  I can't send and receive on the socket without
deadlocking. Does anyone have a more extensive example of a send-receive-send
scenario?  I've got camel, llama, and leopard to no avail. I'm missing
something obvious.

Thanks in advance.

--Brant

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


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

Date: 28 Jul 1998 15:21:08 +0200
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: deadlocking sockets
Message-Id: <7x4sw2f6wr.fsf@fidelio.vcpc.univie.ac.at>

Re: deadlocking sockets, faganb <faganb@my-dejanews.com>
said:

faganb> I am trying to write a c/s app using sockets and
faganb> developing my own application level protocol.  I
faganb> can't send and receive on the socket without
faganb> deadlocking. Does anyone have a more extensive
faganb> example of a send-receive-send scenario?  I've got
faganb> camel, llama, and leopard to no avail. I'm missing
faganb> something obvious.

Have you tried the Net::Cmd and IO::Socket modules?

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,      | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!    | personal email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.  |     tony_curtis32@hotmail.com


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

Date: Tue, 28 Jul 1998 08:21:41 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: File Sizes
Message-Id: <35BDD065.C6911DB@houston.Geco-Prakla.slb.com>

Ford wrote:
> 
> Hey gang,
> 
>         Hopefully this is a quick one.  I've been trying to get the
> size of several files for some logging purposes.  I've been using
> something along the lines of:
> 
> $size = -s $filename;
#!/usr/local/bin/perl -w
#
$file = 'junk3.perl';
$path = '/auto/dapdserv_dsk4/barnett/junk';
 
$fsize = -s $file;
$pfsize = -s "$path" . "/" . "$file";
 
print "fsize =\t$fsize\n";
print "pfsize =\t$pfsize\n";
__END__

The above works fine for me.  You do have the path seperator in there
properly, right?  I forgot it on my first attempt at the above.  Are you
using '\' path delimiters (under DOS/Win '95)?  (You must use '\\' per
'\', remember.  Or let Perl do it for you by using the '/' character
instead.)
> 
> This works when the files are in the same directory but when I try to
> give it a path to the file it comes up blank.  I know that it's dying
> because of me trying to include the path.  Any ideas?
Are you using the -w switch?  When I ran my initial code with it, it was
what pointed me in the right direction to find the error.  That and perl
-d to look at what was happening.

> 
> Ford
Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer

No need to tell me the incredibly obvious, the merely obvious will do
nicely, thank you.


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

Date: 28 Jul 1998 13:24:02 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: file system operations on open files
Message-Id: <6pkjdi$7d7$1@pegasus.csx.cam.ac.uk>
Keywords: chute escrow fowl officious

In article <6pj579$2sm$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>
>In article <6pit0b$k4p$1@nnrp1.dejanews.com>,
> <benglazer@my-dejanews.com> wrote:
>>until ( open(PASSWD, "+</etc/passwd") && flock(PASSWD, $LOCK_EX) ) {
>>  close(PASSWD);
>
>Bad move.  Closing the filehandle releases the lock.  I'm not sure
>exactly what you're trying to accomplish here, but whatever it is,
>you're not accomplishing it.

Wrong.   He's only closing the file if the flock() failed.    (Or if
the open failed.)


Mike Guy


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

Date: Tue, 28 Jul 1998 10:01:06 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: fork() problem
Message-Id: <35BDD9A2.3396D424@sterlingdi.com>

dwiesel@my-dejanews.com wrote:
> 
> Hi,
> 
> I have a fork() problem. I can't figure out what is wrong. Look at this
> code...
> 
> #! /usr/local/bin/perl
> $number_of_forks = 0;
> 
> $SIG{CHLD} = sub { $number_of_forks--; wait;};
> 
> for ($i = 0; $i < 3; $i = $i + 1)
> {
>   $number_of_forks++;
>   $pid = fork;
> 
>   # If child
>   if ($pid eq 0)
>   {
>         &do_something_that_takes_a_while($i);
>         exit;
>   }
> }
> 
> while($number_of_forks > 0)
> {
>   print "Number of forks: $number_of_forks\n";
>   sleep 1;
> }
> 
> When I run this small program I get the following output:
> 
> my_computer:~$ test.pl
> Number of forks: 3
> Number of forks: 1
> Number of forks: 1
> Number of forks: 1
> etc. etc. (looping forever)
> 
> I can't figure out what I have done wrong... can you help me?

I'm not completely sure, but try this on for size...
Multiple CHLD signals may be sent before each can be serviced, thus
loosing calls to your handler.  This is especially true if you have
multiple fast exiting scripts.. They will all exit before the next
context switch to your parent.  Thus, it only receives a single signal. 
You therefore only decrement your counter once, and have an infinite
loop.

Wait waits for a single process.  I've successfully used the following

use vars qw( $lastChild $lastReturnValue );

sub WNOHANG { 0100; } # wait no-hang

sub catchCHLD {
   my $limitLoop = 5;
   while( ( $lastChild = waitpid( -1, WNOHANG )) != -1 ) {
      $lastReturnValue = $?;
      last if $limitLoop-- <= 0;
   }
} # end catchCHLD

$SIG{'CHLD'} = \&catchCHLD;

The limitLoop probably isn't necessary, but I don't like potential
infinite loops.


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

Date: 28 Jul 1998 13:43:28 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Help reg. exp: shouldn't ^ match at beginning only?
Message-Id: <6pkki0$7mu$1@pegasus.csx.cam.ac.uk>

In article <6pjb9k$7u0$1@nnrp1.dejanews.com>,  <cortez@ali.com.au> wrote:
>...........................................
>$s = 'This is a test line';
>$s =~ /^([^ ]* )*/;
>print $1, "\n";
>...........................................
>
>The script above will give:
>test
>
>Isn't  ' ^ ' suppossed to match at the beginning of the string only?

Not when it's inside [].  Then it negates the character class.
Here's a regular expression with three different meanings for ^ :

     m/^[^^]/;


Mike Guy


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

Date: Tue, 28 Jul 1998 11:11:26 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
To: tzahi uni <tzahi@tase.co.il>
Subject: Re: How can I get the name of the current subroutine ?
Message-Id: <Ewsxr2.7Kr@csc.liv.ac.uk>

[Posted and mailed]

In article <35BC7624.B7445391@tase.co.il>,
tzahi uni <tzahi@tase.co.il> writes:
> hi ,
> please help,
> I need to know in which variable I can get the name of the current
> subroutine.
> 
> thanks ,
> tzahi
> 
Have a look at perlfunc man page.

Inparticular caller built in routine.

There is an example of how to use this to get subroutine names in the cammel
section on TIEHASH (forget the page) or the perltie man page.

HTH

-- 
--
Ian J. Garlick
ijg@csc.liv.ac.uk

Science is facts; just as houses are made of stones, so is science made
of facts; but a pile of stones is not a house and a collection of facts
is not necessarily science.
                -- Henri Poincaire


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

Date: Tue, 28 Jul 1998 08:32:42 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: Tom Turton <tturton@cowboys.anet-dfw.com>
Subject: Re: How Do I Access my Modules?
Message-Id: <35BDD2FA.DC4DF459@houston.Geco-Prakla.slb.com>

Tom Turton wrote:
> 
> Ralph Jaeger wrote:
> 
> > Hi,
> >
> > you can either extend the @inc or you can use
> >
> > use lib 'mydirectorywheremyperllibsarein';
> 
> Still getting same behavior.
> Added:
> 
> push (@INC,"/home/tturton/PERL/MyPerlLib");
> use MyPerlLib::Airline;
> 
> When running from /home/tturton/PERL,  what_airline.pl (located in
> /home/tturton/PERL) works fine, but when I run what_airline.pl from any other
> directory, it "Can't locate MyPerlLib/Airline.pm in @INC"
> 
> Any additional clues?
> 
> Thanks,
> ---Tom
Tom:

Unless I misread what you have stated, you are telling Perl to 'use lib
 ...PERL/MyPerlLib', and are then telling perl to 'use
MyPerlLib::Airline'.  Perl is going to look for
/home/tturton/PERL/MyPerlLib/MyPerlLib/Airline.pm.  I highly doubt that
this is really what you were looking for.

Perhaps you want to:
use lib '/home/tturton/PERL';
use MyPerlLib::Airline;

or
use lib '/home/tturton/PERL/MyPerlLib';
use Airline;

Either one should resolve the problem, assuming that
/home/tturton/PERL/MyPerlLib/Airline.pm is the file you are after.

Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer (281) 596-1434


Have fun.  It's not just a statement, it's really good advice.


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

Date: Tue, 28 Jul 1998 11:38:45 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: Im Willing to pay or give a free DOMAIN for a custom cgi!
Message-Id: <35BDB845.66F63900@inlink.com>

Why not try to steal their money through some more ethical means, try
armed robbery for example...


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

Date: 28 Jul 1998 12:23:39 GMT
From: aajii@aajii.ton.tut.fi (Antti-Jussi Korjonen)
Subject: Net::Telnet -like module without telnet
Message-Id: <6pkfsb$1pf$1@baker.cc.tut.fi>

Hi!

I'm using Net::Telnet module now to execute commands on another computer.
I don't need to log onto another computer any more, I can use the same 
computer where the script is located. 
I'd like to use similar method in executing programs, that is used in
Net::Telnet module. 
Can anybody help me with this?
Expect?

--
  
         __/                __/ __/  __/     Antti-Jussi Korjonen
      __/ __/    __/       __/ __/__/       Vaajakatu 5 D 85
    __/    __/      __/   __/ __/__/       33720 TAMPERE, FINLAND
  __/       __/    __/__/__/ __/  __/     tel. +358-(0)40-577 83 23
                                         Antti-Jussi.Korjonen@sonera.fi
   --------->>  http://www.students.tut.fi/~k150556  <<---------
     


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

Date: Tue, 28 Jul 1998 09:29:47 -0400
From: Michael Maraist <maraism@sterlingdi.com>
Subject: Re: newbie string questions.
Message-Id: <35BDD24A.AE574963@sterlingdi.com>

> >: Ok, i have  avariable, say $para, that contains a whole paragraph of text.
> >: what is the command that would cut $para so i stops when it sees a certain
> >: character?
> >: for example... let say i want &para to be the first sentence and not the
> >: whole paragraph so how would i set $para so i contains all the characters
> >: from the first to the first period?
> >
> >
> >    $para =~ s/^([^.]*\.).*/$1/s;
> 
> Just to add a warning to this:
> 
> This indeed gives all characters from the start of the string, up to
> and including the first full stop (period for the US). But...
> 
> $para = 'I can think of a way this breaks, e.g. like this.';
> 
> The original poster asked for 'the first sentence', and a warning
> should be given that that is not at all trivial. Even looking for a
> full stop followed by spacing and a capital letter won't always work
> (think of Dr. Spock, Rev. Doolittle, St. Joan).

Simple enough.. Just require that a sentence be defined as a line of
characters followed by a period and two spaces.  That's how I've always
been taught at least.. Then you could do something like.

$para =~ s/^(.*?\.)  .*$/$1/;

Maybe it could be cleaned up a bit, since the non-greedy .*? will go
pretty slow, and the entry and exiting of the parenthesis will occur
rather often.  This might also be a little faster:

( $x ) = $x =~ /^(.*?\.)  /;

This could work too, but supposedly, it messes up perls internal reg-ex
optimization for the whole script:

$x =~ /^.*?\.  /;
$x = $&;

Hmm, how about this:

$x =~ /\.  /;
$x = $` . ".";


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

Date: Tue, 28 Jul 1998 14:02:06 +0200
From: Lars Andersson <barse@acc.umu.se>
Subject: Perl 5.004/5.005 difference? (Bug?)
Message-Id: <Pine.A41.3.96.980728134004.17610A-100000@stalin.acc.umu.se>

Hello

I think I found a bug in the 5.005 version of Perl. The program

foreach $i (60..90) {
	if ($i =~ /7/g){next}
	else {print "$i "}
}

results in the following output when run in Perl 5.003_07 (Debian) or
5.004_04 (Solaris):

60 61 62 63 64 65 66 68 69 80 81 82 83 84 85 86 88 89 90


When I try running it through Perl 5.004_71 (MSWin32-x86) or 5.004_75
(RedHat) I get the following output:

60 61 62 63 64 65 66 68 69 71 73 75 78 80 81 82 83 84 85 86 88 89 90


Strange... Is there something that changed between the 5.004_04 the later
versions that I don4t know about or is this simply a bug?




	/Lasse

-----------------------------------------------------------------------------
  Lars Andersson  barse@acc.umu.se  Lars.Andersson@HEXagon.se  ICQ#:8159825
-----------------------------------------------------------------------------

DISCLAIMER:
  Use of this advanced computing technology does not imply an endorsement
  of Western industrial civilization.

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





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

Date: 28 Jul 1998 11:53:59 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Pid number of called process??
Message-Id: <6pke4n$b7g@news-central.tiac.net>

In article <6pj63q$mr$1@nnrp1.dejanews.com>,  <kreed@my-dejanews.com> wrote:
>This should be real easy but I can't figure it out.
>
>I've got a server that needs to be run in background.  I need to know
>what Pid number is assigned to it as there can be many copies of
>the same program running.  From the command line you can
>execute:
>
>     somecommand &
>
>And it will tell you the pid number, but I need an automated way to
>store that number.
>
>I've tried doing this with Perl so that I can place the Pid number of
>that process into a file for later access.
>
>What I can't figure out is how to get the Pid number of the
>process itself, using fork all I ever get is the Pid number of the
>child that is calling the process.
>
>Something like:
>
>unless ( $pid = fork ) {
>        unless (fork) {
>                `/usr/local/bin/somecommand &`;
>                exit 0;
>        }
>        exit 0;
>}
>waitpid ($pid, 0);
>print "Pid number of the actual somecomand is $pid\n";

Have you considered the method described in perl's fork documentation:

  There's also the double-fork trick (error checking on fork returns
  omitted); 

      unless ($pid = fork) {
          unless (fork) {
              exec "what you really wanna do";
              die "no exec";
              # ... or ...
              ## (some_perl_code_here)
              exit 0;
          }
          exit 0;
      }
      waitpid($pid,0);

  See also the perlipc manpage for more examples of forking and reaping
  moribund children. 

The exec is the key here, but for real code you need to remember that fork
can fail and return undef and do the right thing...

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 28 Jul 1998 11:41:55 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Premature end of script headers
Message-Id: <6pkde3$apt@news-central.tiac.net>

In article <6pj4ic$84d$1@fir.prod.itd.earthlink.net>,
chris <tulkas@relaypoint.net> wrote:
>The website that I administer/program was transferred from a
>PC/BSD/Apache server to a Sun Solaris 2.5.1 server. Perl scripts that
>worked on the Apache server all give the same error now: Premature end
>of script headers. Can anyone explain this?

You might want to take a look at
http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html or
http://computerdog.com/CGI_MetaFAQ.html

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 28 Jul 1998 13:35:52 +0100
From: "Simon Fairey" <simonf@conduit.co.uk>
Subject: Re: regexp as subroutine parameter
Message-Id: <35bdc4c2.0@nnrp1.news.uk.psi.net>

Why not just do something like:

$match = '$id';
$substitute = '$hash{$id}';

Then in your subroutine do:

    foreach $id (keys %hash)

      $search = eval $match;
      $contents =~ s/\Q$search/$substitute/gismee
    };

The double 'e' will evaluate the right hand side '$substitution' twice thus
giving the correct value, I am not sure if there is a way to avoid the
initial eval but the \Q prevents special characters from being treated as
such ( See FAQ section 6 )

I hope that gives you something to start with.

Simon
ryan pc gibson wrote in message <35BD3259.32F272A5@lbin.com>...
>hello,
>
> i damn near lost my mind trying to figure out how to pass a regexp as a
>parameter to a subroutine (that i am trying to make as general as
>possible).  the tricky part is i want the perl regexp to contain
>variables that get interpolated once they are inside the subroutine, not
>before.
> i would be very interested in any suggestions or thoughts.
>
> - ryan*(pc)
>
> here is a skeleton of the code...
>
>########################################
># somewhere in main loop
>
>$regexp = 's/$id/$hash{$id}/gism'
>&insert_hash(\%hash,$file);
>
>########################################
># replaces occurences of the key with value for each hash item
>
>sub insert_hash {
>
>    my %hash = %{@_[0]};    # hash of ids/values to replace
>    my $file = @_[1];       # file to modify
>
>    # convert file to string
>    open(IN,$file); $contents=join('',<IN>); close IN;
>
>    foreach $id (keys %hash) { $contents =~ $regexp;     };
>
>    open(OUT,">$file") or die "Could not open $file for output\n";
>    print OUT $contents or die "Could not write to $file\n";
>    close OUT;
>
>}; # end insert_hash sub
>
>--
>::__            ____________ ryan pc gibson __________________
>::__ webmaster: ___                                       ____
>::_________________ lightbinders, inc., san francisco, ca ____




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

Date: 28 Jul 1998 13:48:45 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: regexp as subroutine parameter
Message-Id: <6pkkrt$7qo$1@pegasus.csx.cam.ac.uk>

In article <35BD85F2.7EB4@fatnet.net>, Yary Hluchan  <fecund@fatnet.net> wrote:
>]   foreach $id (keys %hash) {  $contents =~ $regexp;     };
>
>have you tried $contents =~ /$regexp/ge ?

What's that supposed to mean?   There's no /e modifier for m//.


Mike Guy


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

Date: Sun, 26 Jul 1998 17:33:57 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: Re: Same code, diff machines, diff results
Message-Id: <ken-2607981733570001@news.swarthmore.edu>

In article <35b91b16.12972891@nntpd.databasix.com>, gburnore@databasix.com
wrote:
>On 24 Jul 1998 23:27:33 GMT, in article <6pb595$7r4$1@condor.cns.iit.edu>,
>chhahar@charlie.cns.iit.edu (Harshal S. Chhaya) wrote:
>
>>On machine1 (FreeBSD, perl 5.004_01) this prints:
>>and on the other machine (Solaris 2.5, perl 5.003)
>
>
>DUH!!!  The difference isn't the machine, it's the perl.

If you're going to be so unpleasant to the guy who asked the question, you
should at least be right.

The difference has nothing to do with Perl, Perl is just executing an
external command and returning the result.  As Hymie suggested, try
running the /bin/date program outside of Perl, you'll get the same results
as inside Perl.


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

Date: Tue, 28 Jul 1998 13:02:22 +0100
From: Graham Donohoe <gdonohoe@nmp.nokia.com>
Subject: Re: Try perl on Ms Dos
Message-Id: <35BDBDCE.1088@nmp.nokia.com>

Suruchi wrote:
> 
> Hi Everyone
> i would like to try executing some perl scripts on my stand alone pc. I
> know that perl compiel is available for Ms Dos. i've downloaded it but i
> can't save my file with the extention .pl . can some one help me.
> i'm using notepad to make the program.

Is this a perl question? No, it's not.

Do you even know how to use your computer ( or MS-DOS/Windows)? Doesn't
seem like it.

If the name of your file is incorrect, try *RENAMING* it.

If you want to save your file, try the *SAVE AS* menu.


Now go and get some lessons. Don't bother coming back here until you
have done that.


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

Date: Tue, 28 Jul 1998 15:12:25 +0200
From: Charly <niemann@erlm.siemens.de>
Subject: upload form variables (500 Internal Error)
Message-Id: <35BDCE39.2ACA@erlm.siemens.de>

I have to write a script that allows me to store about 
5 lines of text, submitted by a textarea named notes in 
a file named test.htm. I wrote this perl-script (my first
one) and I am getting always an 500 Internal Error.
My FTP is configured to ascii so there is definitely no ^M.
And chmoded to 777, perl-location is ok, too. What do I 
do wrong?

Best regards,
 Charly

+++++++++++++++ text.htm +++++++++++++++

<form action=store.pl method=post>
  <textarea name=notes>
  </textarea>
</form>

++++++++++++ store.pl +++++++++++++

#!/usr/bin/perl

open (FILE,">test.htm");
print FILE "***$FORM{'notes'}\n";
print FILE "***\n";
close (FILE);


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

Date: Tue, 28 Jul 1998 09:51:24 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: upload form variables (500 Internal Error)
Message-Id: <fl_aggie-2807980951240001@aggie.coaps.fsu.edu>

In article <35BDCE39.2ACA@erlm.siemens.de>, Charly
<niemann@erlm.siemens.de> wrote:

+ What do I  do wrong?

You failed to check the results of your open:

+ open (FILE,">test.htm");

open (FILE,">test.htm") or die $!;

At that point, check the error logs. I suspect you don't have permission to
create "test.htm" in the cgi-bin/ directory...

James


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

Date: Tue, 28 Jul 1998 07:48:36 -0400
From: "P.J. Henningson" <phenning@phoenix-int.com>
Subject: Using Perl to Determine default browser
Message-Id: <35BDBA94.6EE16E11@phoenix-int.com>

Is it possible to use perl (on WINNT) to determine
the users default web browser (IE/Netscape)??

Thanks,

P.J. Henningson


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

Date: 28 Jul 1998 12:08:43 GMT
From: scott@softbase.com
Subject: Re: Using Perl to Determine default browser
Message-Id: <35bdbf4b.0@news.new-era.net>

P.J. Henningson (phenning@phoenix-int.com) wrote:
> Is it possible to use perl (on WINNT) to determine
> the users default web browser (IE/Netscape)??

Yes. Kind of. You'd have to use the Registry functions to open
the file association for HTML documents and read the executable
associated with it.

The key you'd be looking for is:

HKEY_CLASSES_ROOT\htmlfile\shell\open\command

This key defines what happens when someone opens an HTML file.

If you just want this information to invoke the default browser,
remember that you can use "start" and a URL and have it done for you
automatically.

Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more. 


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

Date: Tue, 28 Jul 1998 13:54:42 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <35bed780.23922418@news.tornado.be>

Tad McClellan wrote:

> So 02-29-100 is *unambiguously* (100 + 1900) the year 2000
>
>   It can be no other year.
>
>   It can only be 2000.
>
>   No bug.

Are you sure it's not the year 100? Are you also sure that "1900" is not
the year 3800?

	Bart.


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

Date: Tue, 28 Jul 1998 09:47:24 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <fl_aggie-2807980947240001@aggie.coaps.fsu.edu>

In article <35bed780.23922418@news.tornado.be>, bart.mediamind@tornado.be
(Bart Lateur) wrote:

+ Tad McClellan wrote:
+ 
+ > So 02-29-100 is *unambiguously* (100 + 1900) the year 2000
+ >
+ >   It can be no other year.
+ >
+ >   It can only be 2000.
+ >
+ >   No bug.
+ 
+ Are you sure it's not the year 100? Are you also sure that "1900" is not
+ the year 3800?

Yes. By *definition*. As per 'perldoc -f localtime':

 Also, $year is the number of years since 1900, that is, $year is 123
 in year 2023.

James


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

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

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