[19634] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1829 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 27 06:10:31 2001

Date: Thu, 27 Sep 2001 03:10:13 -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: <1001585412-v10-i1829@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 27 Sep 2001     Volume: 10 Number: 1829

Today's topics:
        Parsing a string <gte574u@prism.gatech.edu>
    Re: Parsing a string <rob_13@excite.com>
    Re: Parsing a string <krahnj@acm.org>
    Re: Parsing a string <bart.lateur@skynet.be>
    Re: Perl running slow... (Adam)
    Re: Perl running slow... <wyzelli@yahoo.com>
    Re: Problems with $ character <goldbb2@earthlink.net>
    Re: Security of letting user specify regex in CGI scrip <bart.lateur@skynet.be>
        Sourcing Things in Perl ? slightlysprintingdog@ntlworld.com
    Re: Sourcing Things in Perl ? (Martien Verbruggen)
    Re: Sourcing Things in Perl ? (Tim Hammerquist)
    Re: Sourcing Things in Perl ? (Tim Hammerquist)
    Re: Transforming HTML <oneconcept@yahoo.co.uk>
    Re: Validating 2 Sets of Languages! <goldbb2@earthlink.net>
    Re: wait interferes with $? from system call <goldbb2@earthlink.net>
    Re: What's wrong with this code ? <goldbb2@earthlink.net>
    Re: Win32 Perl - Setting ENV Variables from Command-lin <hkdennis2k@yahoo.com.hk>
    Re: Win32 Perl - Setting ENV Variables from Command-lin <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Sep 2001 00:51:46 -0400
From: "Brady Doll" <gte574u@prism.gatech.edu>
Subject: Parsing a string
Message-Id: <9oub86$hhs$1@news-int.gatech.edu>

I am attempting to parse a string which has an attribute followed by a
value...

Attribute="value"

I want to make a hash table out of the attributes and values...

$hash{'Attribute'} = "value";

I was attempting to make a reg. ex. to parse out both the attribute name and
the value, however i'm not sure how to get the part of the string between
the quotes with a reg. ex.

this was the code i was attempting to use, however the (.*) causes it to
freeze.
m/(?:\s*)([\w])(?:\=)(?:[\'\"])(.*)(?:[\'\"])/;

What should be put in place of the (.*)...is there anything or am I just
going to have to result to a different method to parse this string then
using a reg. ex.?




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

Date: Thu, 27 Sep 2001 05:15:24 GMT
From: "Rob - Rock13.com" <rob_13@excite.com>
Subject: Re: Parsing a string
Message-Id: <Xns9129CB919449rock13com@64.8.1.227>

Brady Doll <news:9oub86$hhs$1@news-int.gatech.edu>:

> I am attempting to parse a string which has an attribute
> followed by a value... Attribute="value"

> this was the code i was attempting to use, however the (.*)
> causes it to freeze.
> m/(?:\s*)([\w])(?:\=)(?:[\'\"])(.*)(?:[\'\"])/;
> 
> What should be put in place of the (.*)...is there anything or
> am I just going to have to result to a different method to
> parse this string then using a reg. ex.?

My first thought would be, perhaps?
m/(.*)=['|"]([^"]+)['|"]/;

However, without knowing just what kind of characters are legal in 
the key and value can't say much more. The above will leave some 
whitespace attached to your values though.
-- 
Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: Thu, 27 Sep 2001 08:20:36 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Parsing a string
Message-Id: <3BB2E1D1.DEA6BD33@acm.org>

Brady Doll wrote:
> 
> I am attempting to parse a string which has an attribute followed by a
> value...
> 
> Attribute="value"
> 
> I want to make a hash table out of the attributes and values...
> 
> $hash{'Attribute'} = "value";
> 
> I was attempting to make a reg. ex. to parse out both the attribute name and
> the value, however i'm not sure how to get the part of the string between
> the quotes with a reg. ex.
> 
> this was the code i was attempting to use, however the (.*) causes it to
> freeze.
> m/(?:\s*)([\w])(?:\=)(?:[\'\"])(.*)(?:[\'\"])/;
> 
> What should be put in place of the (.*)...is there anything or am I just
> going to have to result to a different method to parse this string then
> using a reg. ex.?

Why not just use split?


my %hash;
my $string = qq[Attribute="value"];

my ( $attr, $val ) = split /=/, $string, 2;

if ( length $attr and length $val ) {
    $hash{ $attr } = $val;
    }



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 27 Sep 2001 09:41:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Parsing a string
Message-Id: <fas5rt49tvirqp7lco9h7o2qbe3c6f2iv5@4ax.com>

Brady Doll wrote:

>I am attempting to parse a string which has an attribute followed by a
>value...
>
>Attribute="value"
>
>I want to make a hash table out of the attributes and values...
>
>$hash{'Attribute'} = "value";
>
>I was attempting to make a reg. ex. to parse out both the attribute name and
>the value, however i'm not sure how to get the part of the string between
>the quotes with a reg. ex.

It depends on whether you want to allow escaping of the quotes, and on
the manner of escaping. How do you represent a value like 2"1/4?

	"2\"1/4"	# perl style
or
	"2""1/4"	# Microsoft style

If you want to use the perl style, you'll have to escape the backslashes
as well. It's the same situation inside perl's syntax, with single
quoted strings.

I'd do it in two steps: (1) get what you want and (2) unescape.

For perl style:

	$_ = 'Attribute = "2\"1/4"';
	if(my($attr, $value) = /^\s*(\w+)\s*=\s*"((?:\\[\\"]|[^"])*)"/){
	    ($hash{$attr} = $value) =~ s/\\([\\"])/$1/g;
	}

For Micosoft style:

	$_ = 'Attribute = "2""1/4"';
	if(my($attr, $value) = /^\s*(\w+)\s*=\s*"((?:""|[^"])*)"/){
	    ($hash{$attr} = $value) =~ s/""/"/g;
	}

If you don't need escaping, a simple

	$_ = 'Attribute = "value"';
	if(my($attr, $value) = /^\s*(\w+)\s*=\s*"([^"]*)"/){
	    $hash{$attr} = $value;
	}

will do.

-- 
	Bart.


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

Date: 27 Sep 2001 00:16:30 -0700
From: adcoment@ameritech.net (Adam)
Subject: Re: Perl running slow...
Message-Id: <e2768ea2.0109262316.240efdee@posting.google.com>

"Wyzelli" <wyzelli@yahoo.com> wrote in message news:<nCus7.36$ou4.619@wa.nnrp.telstra.net>...
> "Adam" <adcoment@ameritech.net> wrote in message
> news:e2768ea2.0109261403.43d42be5@posting.google.com...
> > Using some simple benchmarks, I am having problems with Perl 5.6 on a
> > cobalt raq3 (running redhat -- not cobalt linux).  Using a simple  use
> > CGI and a print loop, I have yeilded the following:
> >
> > 1) raq3, P XMHZ, 64MB, perl 5.6.0
> > 2) PIII 700MHZ, 128MB, perl 5.6.0
> > 3) PII 450MHZ, 256MB, perl 5.005_03
> 
> The first obvious difference between the systems is the RAM.  What else is
> running on the raq3?  Are you being forced to use swap because there isn't
> enough available RAM for your process because something else is hogging the
> memory?  This is just a pretty wild guess, but I would throw some more RAM
> at it first to see what affect that has.
> 
> Wyzelli

Everything seems honkey dorey... what do you think??? Why would it be
so slow? I didn't build it on the box and think it was part of the
Linux distribution.  Hmmm?  Thanks
Adam

%CPU%MEM 	VSZ	 	RSS		COMMAND
0	0.8		1340	512		init [3]
0	0		0	0		[keventd]
0	0		0	0		[kswapd]
0	0		0	0		[kreclaimd]
0	0		0	0		[bdflush]
0	0		0	0		[kupdated]
0	0		0	0		[mdrecoveryd]
0	0.8		1400	556		syslogd -m 0
0	1.7		1880	1060	klogd -2
0	0.8		1484	536		portmap
0	1.1		1536	724		rpc.statd
0	0.9		1452	592	/usr/sbin/automount --timeout 60 /misc file /etc
0	0.7		1372	472		/usr/sbin/atd
0	1.5		2560	968		/usr/sbin/sshd
0	2.5		4976	1604	sendmail: accepting connections
0	0.6		1368	408		gpm -t ms -m /dev/mouse
0	1		1524	632		crond
0	4.7		4264	2988	xfs -droppriv -daemon
0	0.6		1312	432		/sbin/mingetty tty2
0	0.6		1312	432		/sbin/mingetty tty3
0	0.6		1312	432		/sbin/mingetty tty4
0	0.6		1312	432		/sbin/mingetty tty5
0	0.6		1312	432		/sbin/mingetty tty6
0	1.5		2104	984		/bin/sh /usr/bin/safe_mysqld
0	9.8		28304	6160	/usr/libexec/mysqld --basedir=/usr --datadir=/va
0	9.8		28304	6160	/usr/libexec/mysqld --basedir=/usr --datadir=/va
0	9.8		28304	6160	/usr/libexec/mysqld --basedir=/usr --datadir=/va
0	9.8		28304	6160	/usr/libexec/mysqld --basedir=/usr --datadir=/va
0	1.4		2204	912	xinetd -stayalive -reuse -pidfile /var/run/xinet
0	0.6		1312	432		/sbin/mingetty tty1
0	7.9		8832	4976	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8976	5228	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5220	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5196	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8976	5228	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5196	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5196	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5216	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8976	5224	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8968	5196	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	8.3		8964	5196	/usr/sbin/httpd -DHAVE_PROXY -DHAVE_ACCESS -DHAV
0	1		1536	672	CROND
0	1.4		1892	888	/bin/bash /usr/bin/run-parts /etc/cron.hourly
0	0.8		1624	552		awk -v progname=/etc/cron.hourly/sysstat prognam
0	1.3		1876	852	/bin/sh /usr/lib/sa/sa1 600 6
0	0.7		1324	492	/usr/lib/sa/sadc 600 6 /var/log/sa/sa27
6.1	2.9		3452	1868	/usr/sbin/sshd
2.2	2		2340	1292	-bash
0	1.3		2712	820	ps -aux
8.3	165.1   265820	104688

  2:56am  up 17 days,  4:38,  1 user,  load average: 0.00, 0.00, 0.00
44 processes: 43 sleeping, 1 running, 0 zombie, 0 stopped
CPU states:  0.5% user,  1.7% system,  0.0% nice, 97.6% idle
Mem:    62288K av,   40424K used,   21864K free,       0K shrd,   
2048K buff
Swap:  197528K av,     228K used,  197300K free                  
17968K cached


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

Date: Thu, 27 Sep 2001 17:06:59 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Perl running slow...
Message-Id: <EyAs7.64$ou4.1003@wa.nnrp.telstra.net>

"Adam" <adcoment@ameritech.net> wrote in message
news:e2768ea2.0109262316.240efdee@posting.google.com...
> "Wyzelli" <wyzelli@yahoo.com> wrote in message
news:<nCus7.36$ou4.619@wa.nnrp.telstra.net>...
> > "Adam" <adcoment@ameritech.net> wrote in message
> > news:e2768ea2.0109261403.43d42be5@posting.google.com...
> > > Using some simple benchmarks, I am having problems with Perl 5.6 on a
> > > cobalt raq3 (running redhat -- not cobalt linux).  Using a simple  use
> > > CGI and a print loop, I have yeilded the following:
> > >
> > > 1) raq3, P XMHZ, 64MB, perl 5.6.0
> > > 2) PIII 700MHZ, 128MB, perl 5.6.0
> > > 3) PII 450MHZ, 256MB, perl 5.005_03
> >
> > The first obvious difference between the systems is the RAM.  What else
is
> > running on the raq3?  Are you being forced to use swap because there
isn't
> > enough available RAM for your process because something else is hogging
the
> > memory?  This is just a pretty wild guess, but I would throw some more
RAM
> > at it first to see what affect that has.
> >
> > Wyzelli
>
> Everything seems honkey dorey... what do you think??? Why would it be
> so slow? I didn't build it on the box and think it was part of the
> Linux distribution.  Hmmm?  Thanks
> Adam
>
> %CPU%MEM VSZ RSS COMMAND

<snip>

>   2:56am  up 17 days,  4:38,  1 user,  load average: 0.00, 0.00, 0.00
> 44 processes: 43 sleeping, 1 running, 0 zombie, 0 stopped
> CPU states:  0.5% user,  1.7% system,  0.0% nice, 97.6% idle
> Mem:    62288K av,   40424K used,   21864K free,       0K shrd,
> 2048K buff
> Swap:  197528K av,     228K used,  197300K free
> 17968K cached

Well, 20Mb free should be OK.  The other thing you could try is a fresh
build of 5.6.1, and see if that is different.

Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_!=1)? 's':'';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';





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

Date: Thu, 27 Sep 2001 01:29:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problems with $ character
Message-Id: <3BB2B950.A9B49380@earthlink.net>

JJ wrote:
> 
> "Benjamin Goldberg" <goldbb2@earthlink.net> wrote in message
> news:3BAE53E8.EFE10411@earthlink.net...
> > JJ wrote:
> > >
> > > Hi,
> > >
> > > Problem 1.
> > > Step 1.1: I have a perl script that collects table names from a
> > > Oracle database.
> > > Step 1.2: In that script it then execute another perl script with
> > > the table as argument, that extracts the table (data and
> > > structure).
> > >
> > > The table name from step 1.1 can contain the character '$' such as
> > > 'MLOG$_WI_PISECTIONUS'. When executing the second script it says:
> > > "Table MLOG does not exist"
> > >
> > > Earlier when I executed those scripts on Linux it worked with the
> > > fix in the first script:
> > > $replace='\$';
> > > while(@row = $sth->fetchrow_array())
> > > {
> > >   $tmp = $row[0];
> > >   # fix the '$' in the table name if it exist
> > >   $tmp =~ s/\$/$replace/g; ## <<<== The fix <<<<
> > >   push @tables, $tmp;
> > > }
> > >
> > > # For each table, dump the data
> > > foreach $table ( @tables )
> > > {
> > >   $outfile = "$dataDir$table$dumpFileExtension";
> > >   print "Dumping table $table for schema $dbSchema\n";
> > >   $command = "./oracledump_to_mySQL.pl --add-drop-table -u $dbSchema
> > > -p $password $database $table >> $outfile";
> > >   system($command);
> > > }
> >
> > Eww.  Why do it like this?  Surely dropping the table from within
> > your script would be better than calling an external program to do
> > it...
[snip my code, which just drops tables]

> NO. The snipplet:
> foreach $table ( @tables )
> {
>   $outfile = "$dataDir$table$dumpFileExtension";
>   print "Dumping table $table for schema $dbSchema\n";
> $command = "./oracledump_to_mySQL.pl --add-drop-table -u $dbSchema -p
> $password $database $table >> $outfile";
>   system($command);
> }
> 
> Exports the Oracle database to mySQL files (one file/table and each
> file containing DROP CREATE and N * INSERT).

Ok then.  You can still do all this in perl without needing to run an
external program.

my $dbi1 = DBI->connect( "DBI:Oracle", ..., {RaiseError=>1} );
my $dbi2 = DBI->connect( "DBI:mySQL", ...., {RaiseError=>1} );
my $query  = $dbi1->prepare( "SELECT * FROM ?" );
my $drop   = $dbi2->prepare( "DROP TABLE ?" );
foreach my $table ($dbi1->tables) {
        $query->execute($table);
        create_table( $table, $query );
        my $store = $dbi2->prepare(do { local $" = ", "; qq[
                INSERT INTO $table (@{$query->{NAME}})
                VALUES (@{[("?") x $query->{NUM_OF_FIELDS}]})
        ] } );
        while( my @row = $query->fetchrow_array ) {
                $store->execute( @row );
        }
        # $drop->execute( $table );
}

my %types;
sub create_table {
        my ($tablename) = @_;
        foreach( @{$query->{TYPE}} ) {
                $types{$_} ||= ($dbi1->type_info($_))[0]{TYPE_NAME};
        }
        my @names = @{ $query->{NAME} };
        my @types = map $types{$_}, @{$query->{TYPE}};
        my @create = map "$names[$_] $types[$_]", 0..$#names;
        
        my $create = $dbi2->prepare( do { local $" = ", ";
                "CREATE TABLE $tablename ( @create )" } );
        $create->execute;
}

> I'm surley _NOT_ want to drop my data source since this a way to move
> data and structure from Oracle to mySQL.

Ok.  It's not as if you had said that anywhere before now.

Maybe you thought you implied it, but it wasn't clear.

Anyway, regardless of whether you're just dropping tables, or moving
tables, there's no need to call any external program to do this, you
can, as I have shown above, do this entirely within one perl process.

NB: this code is untested.  I would suggest you leave $drop->execute
commented out until you are sure that the copying works right.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Thu, 27 Sep 2001 08:28:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Security of letting user specify regex in CGI script?
Message-Id: <hdo5rt4d1kohe76n1e3icgtardjqpb1f3v@4ax.com>

Jay McGavren wrote:

>Well, I'd already done a module search for "search" and another for
>"regex" on search.cpan.org, but closest thing those turned up were
>modules intended for indexing and searching large numbers of files
>(and nothing to form regexes from plain English that I could see).  Am
>I looking for the wrong kind of module?

I think Text::Query goes in the right direction, though I haven't tried
it myself.

BTW there's no need to create one regex of it. After all, perl knows
eval, so it's easy to create a sub that checks if a string matches your
requirements. For example, "a and (b or c)" can be converted to

	$query = eval "sub { /\ba\b/ and (/\bb\b/ or /\bc\b/ }";

and you can check for a match using;

	$_ = $string;
	$matched = &$query;  # or:  $query->()

If you don't like the dependency on $_, you can make it a parameter to
the sub.

-- 
	Bart.


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

Date: Thu, 27 Sep 2001 09:51:24 +0100
From: slightlysprintingdog@ntlworld.com
Subject: Sourcing Things in Perl ?
Message-Id: <3BB2E88C.3D348123@ntlworld.com>

I trying to source some stuff in a Perl Tk script.

Basically I have a string setup somewhere else in the program ;
$sourceme which contains the full path of the source file.

And then I'm using the system command to source it like so :

system ( "source $sourceme" );

I don't get anything written to the console and the file is definately
not sourced.

Any ideas ?



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

Date: Thu, 27 Sep 2001 19:32:04 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Sourcing Things in Perl ?
Message-Id: <slrn9r5sgk.t75.mgjv@martien.heliotrope.home>

On Thu, 27 Sep 2001 09:51:24 +0100,
	slightlysprintingdog@ntlworld.com <slightlysprintingdog@ntlworld.com> wrote:
> I trying to source some stuff in a Perl Tk script.

What does that mean? Are you trying to use the source command of csh?

Read Perl FAQ section 8, question

       I {changed directory, modified my environment} in a perl
       script.  How come the change disappeared when I exited the
       script?  How do I get my changes to be visible?

> Basically I have a string setup somewhere else in the program ;
> $sourceme which contains the full path of the source file.

You will really need to be much, much more specific about what exactly
you're trying to achieve. Is that 'source file' perl code? Then look
into require and do (see perlfunc)

> And then I'm using the system command to source it like so :
> 
> system ( "source $sourceme" );

Some shells have that as a builtin command, but I haven't seen it as an
external command on any system I've worked on. In either case, it won't
'source' anything into the current process.

> I don't get anything written to the console and the file is definately
> not sourced.

It probably was sourced, or maybe not. Depends on the shell that got
fired up. However, you won't really know, since you don't check the
return value of system, which you should do.

> Any ideas ?

Lots. But the first thing _you_ need to do is explain what you want. Not
what you think you need to do.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Thu, 27 Sep 2001 09:55:42 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Sourcing Things in Perl ?
Message-Id: <slrn9r5um1.uim.tim@vegeta.ath.cx>

Me parece que slightlysprintingdog@ntlworld.com dijo:
> I trying to source some stuff in a Perl Tk script.
> 
> Basically I have a string setup somewhere else in the program ;
> $sourceme which contains the full path of the source file.
> 
> And then I'm using the system command to source it like so :
> 
> system ( "source $sourceme" );
> 
> I don't get anything written to the console and the file is definately
> not sourced.
> 
> Any ideas ?

Is the file you're sourcing a shell script?  Is it for the same shell
that the perl script is running under? Is it the for the same shell that
an individual user of your script uses? Can you guarantee that this is
always the case?

Are you checking the return value of system?  Was it successful?

Of course, even if all the above is acceptable, it still won't work.
Assuming the file is sourced:
    system() creates a child process
    the child process sources the file
    the child process terminates
    all results of sourcing are lost
    period

If I understand your situation, this is one of the oldest questions
asked, and the answer is:
    No, a child process cannot alter it's parents environment except by
    very complicated, increasingly dangerous (not to mention just
    plain "bad") hacks.  This was intended as a feature.

Try rethinking your problem. I've actually recently sought a Perl module
for parsing shell scripts.  It could return a hash of variables set
within the script (since you probably don't want an arbitrary shell
script to mess with your %ENV directly) and possibly taint it.  I
searched on cpan but didn't turn up anything (but then, I could've been
blind). Anyone know of anything?  Even Python has an shutil script.

Of course, if you're trying to "source" a perl script, you probably want
to 'require' or 'use' it...not system().

HTH

-- 
A child of five would understand this.
Send someone to fetch a child of five.
    -- Groucho Marx


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

Date: Thu, 27 Sep 2001 09:57:06 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Sourcing Things in Perl ?
Message-Id: <slrn9r5uom.uim.tim@vegeta.ath.cx>

Me parece que Tim Hammerquist <tim@vegeta.ath.cx> dijo:
> Of course, if you're trying to "source" a perl script, you probably want
> to 'require' or 'use' it...not system().

Of course, 'use' would only work if it were a module.

Also, 'do' is a valid option.

Tim
-- 
I have never let my schooling interfere with my education.
    -- Mark Twain


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

Date: Thu, 27 Sep 2001 10:20:06 +0100
From: "Raj" <oneconcept@yahoo.co.uk>
Subject: Re: Transforming HTML
Message-Id: <1001582400.725.0.nnrp-12.c2d95a2c@news.demon.co.uk>

<nobull@mail.com> wrote in message news:u97kulvm9u.fsf@wcl-l.bham.ac.uk...
>
> Obviously in this very restricted case you can simply do
>
> s/(<INPUT TYPE="text") (NAME="x(\w+)")>/$1 VALUE="$address{$3}" $2/;
>
> This will not work if the <INPUT> tag does not appear exactly as you
> describe all on one line.

Thanks Nobull!  This is just what I need....this is a very restricted case
and will not need changing in the near future.  Many things would have to
change before a change could occur, but I wanted the number of fields to be
variable as opposed to hard-coding the field names.  I did not want to parse
the HTML, just plug values into the text boxes.

I'll try this now and hope it works!

Once again thanks!

Regards,
Raj




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

Date: Thu, 27 Sep 2001 02:21:37 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Validating 2 Sets of Languages!
Message-Id: <3BB2C571.B2A15560@earthlink.net>

biG wrote:
> 
> How do I validating 2 sets of languages or character sets?

Combine the validators:
$myEngValidation = 'm/([A-Za-z\-\. ]){1,100}/';
$myHebValidation = 'm/([à-ú\-\. ]){1,100}/';
$myHebEngValidation = 'm/([A-Za-zà-ú\-\. ]){1,100}/';

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Thu, 27 Sep 2001 00:33:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: wait interferes with $? from system call
Message-Id: <3BB2ABFE.A2A5C458@earthlink.net>

Tom Hoffmann wrote:
> 
> I am running into a problem using the 'wait' function in a subroutine
> that handles SIGCHLD signals. What I have found is that a '$waitpid =
> wait' statement in the SIGCHLD handler subroutine sets the return code
> ($?) from the corresponding 'system' call that forked a process to
> '-1' even though the system call was successful.
> 
> Since I can get a SIGCHLD signal from a 'system' call as well as from
> the process I forked, I need the 'wait' function so I know whether it
> was my forked process that ended or one of the 'system' calls.
> 
> I can get around this problem by ignoring the SIGCHLD signals from the
> system calls (by setting a flag that is used by the SIGCHLD handler),
> but this seems kind of clumsy and does not allow me to reap the child
> processes. However, when I use this approach, the value of the return
> code ($?) from the 'system' call is '0' as expected.

There's two possible solutions:  The first is simplest: don't look at $?
after system, look at the return value of system, which will be either
$? or -1, depending on whether the fork and waitpid succeeded.

A better solution may be to not install a signal handler, and instead
explicitly wait for children... for example:

unless( my $kidpid = fork ) {
	die "Couldn't fork: $!" if !defined $kidpid;
	print "Sleep to simulate child processing...\n";
	sleep 300;
}

unless( system("foo") ) {
	die "Foo failed: $? $!";
}

if( waitpid($kidpid, 0) ) {
	my ($sig, $ret) = ($?&255, $?>>8);
	die "child died from signal $sig" if $sig;
	die "child exited with code $ret" if $ret;
} else {
	die "waitpid: $!";
}

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Thu, 27 Sep 2001 02:33:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What's wrong with this code ?
Message-Id: <3BB2C81E.6C456125@earthlink.net>

Uri Guttman wrote:
> 
> >>>>> "DW" == David Wall <darkon@one.net> writes:
> 
>   DW> while ( <DATA> ) {         # change to your filehandle
>   DW>     my @names =  $_ =~ m/(name-\S+)/g ;
> 
> no test if the regex worked. you don't know what will be put into
> @names.

Yes he does.  It will either be a list of matches, or an empty list.

However, I will say that @names is unnecessary.

while( <DATA> ) {
	foreach my $name (m/(name-\S+)/g) {
		last if !defined($_ = <DATA>);
		redo if !/^#?\s*service/;
		next if /^#/;
		print "name    = $name\n";
		print "service = ", /^service\s*(\S*)/, "\n";
	}
}

This code should be a tiny bit less fragile.

NB: this code is untested.

-- 
"I think not," said Descartes, and promptly disappeared.


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

Date: Thu, 27 Sep 2001 15:44:33 +0800
From: "Dennis" <hkdennis2k@yahoo.com.hk>
Subject: Re: Win32 Perl - Setting ENV Variables from Command-line
Message-Id: <9oul44$9sg5@rain.i-cable.com>

You can try to install a APACHE for win32 to test your CGI (is it CGI?).......

or

You can goto MS-DOS console, use
C:\>SET REMOTE_USER_IP=xxx.xx.xxx.x
before you run the script....


--
¤ßÂÅ Dennis
============
¤ßÂźô : http://hkdennis2k.virtualave.net
¤ßÂŨ¦ : news://news.d2g.com/personal.hkdennis2k
°Êµe¨¦ : news://news.d2g.com/talk.anime




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

Date: Thu, 27 Sep 2001 09:56:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Win32 Perl - Setting ENV Variables from Command-line
Message-Id: <flt5rtocgjh1imsmc8d86ft44eiekeid68@4ax.com>

Jeremy Smith wrote:

>I wondered how variables like REMOTE_USER_IP (or somesuch) and
>"QUERY_STRING" are actually passed from the server program (which knows the
>values of such variables) to the Perl interpreter (which doesn't)?

It sets the environment variables before calling the script. Because the
script runs as a child process, it can see the changes.

>So that
>when I run a Perl script from the interpreter, it runs as it would if it
>were running on a website.

>So the question is: How do I set ENV variables when running a local Perl
>script on a local interpreter.

Set them before running the script, for example in a BAT file that also
runs the script. Set them in perl by assigning to $ENV{BLAH}, before
calling system() on the script.

Or, entirely different approach: set them in a module that you load when
starting up the script:

	perl -MSetEnv yourscript.cgi

under the assumption that your variables get set in SetEnv.pm.

-- 
	Bart.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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 V10 Issue 1829
***************************************


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