[18966] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1161 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 20 00:06:42 2001

Date: Tue, 19 Jun 2001 21:05:06 -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: <993009906-v10-i1161@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 19 Jun 2001     Volume: 10 Number: 1161

Today's topics:
    Re: 2 questions about flock (Alan Barclay)
    Re: CGI Expect.pm - unknown terminal type (David Efflandt)
        execute perl from browser <indy@bms.calstate.edu>
    Re: execute perl from browser <bwalton@rochester.rr.com>
        Finding if an executable... kurt.hindenburg@gte.net
    Re: Get all the possibilities (Jay Tilton)
    Re: Get all the possibilities (Craig Berry)
    Re: Graphical user interfacing? <ron@savage.net.au>
        Help with Rewriting Application in OO Perl (E. Moore)
    Re: HowTo: Run a command in backticks as root? (David Efflandt)
    Re: MAJOR perl bug <bwalton@rochester.rr.com>
    Re: multiple file upload (David Efflandt)
        Newbie requests help with Net::Ping module to use as le (Demitri Borg)
    Re: Printing filenames that are in a directory <mjcarman@home.com>
    Re: redirection to a file <bwalton@rochester.rr.com>
    Re: Regexps, using variables to get $1, $2, etc. googlenews@edge-web.com
    Re: Regexps, using variables to get $1, $2, etc. googlenews@edge-web.com
    Re: Regexps, using variables to get $1, $2, etc. <ren@tivoli.com>
    Re: replace with logic in Perl <mjcarman@home.com>
        trying to optimize -> system call questions (Shon)
    Re: Why does this split not work? <ren@tivoli.com>
    Re: Why does this split not work? <nospam@cfl.rr.com>
    Re: Why does this split not work? <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 20 Jun 2001 00:09:26 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: 2 questions about flock
Message-Id: <992995764.359081@elaine.furryape.com>

In article <slrn9i2dql.i3u.abigail@tsathoggua.rlyeh.net>,
Abigail <abigail@foad.org> wrote:
>Alan Barclay (gorilla@elaine.furryape.com) wrote on MMDCCCXXXVII
>September MCMXCIII in <URL:news:991910905.521540@elaine.furryape.com>:
>--  You've programmed a busy loop, where the CPU will be busy working
>--  just to delay. That would have been ok back in the days of DOS, when
>--  you could be sure that the CPU would only have been trying to run
>--  that one program, but if you're running Windows or any of the Unix
>--  variants you're preventing the other programs that are running from
>--  getting any CPU time.
>
>I don't want to speak on behalf of Windows, but that claim is certainly
>not true on Unix. Otherwise, it would never have taken off as a popular
>multi-user environment. One programming mistake (or evil intention) and
>you have a denial-of-service attack.

It won't cause a denial of service attack, but it will use up a lot
of CPU time doing nothing. If you have another program, which is
doing something useful, then the second program cannot use that
CPU time.


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

Date: Wed, 20 Jun 2001 02:27:59 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: CGI Expect.pm - unknown terminal type
Message-Id: <slrn9j02he.hel.see-sig@typhoon.xnet.com>

On Tue, 19 Jun 2001 13:14:12 -0500, Mark Gaither <markg454@hotmail.com> wrote:
> I have successfully created a script using Expect.pm and Perl 5 which
> runs
> nicely from the command line (perl ./backup.pl).
> 
> I am trying to move this script to a CGI but I have have run into
> a problem. I get an 'unknown terminal "unknown"' message and I suspect
> that this is related to the fact that a CGI session is not runing as a
> known
> terminal such as vt100. I know how to set the terminal in Expect but
> not using Expect.pm. Any help would be greatly appreciated. I've
> included the code at the end of this message.

It didn't occur to try:  $ENV{TERM} = 'vt100';

early in your script, or if that fails, with a shell command after you
login, or from your .profile or .login depending upon destination shell.  
You could set it there to default to vt100 (.profile example for Solaris
which doesn have terminfo for linux):

if [ "$TERM" = "linux" ]
then
        TERM=vt100
        export TERM
fi

if [ "$TERM" = "" -o "$TERM" = "unknown" ]
then
        TERM=vt100
        export TERM
fi


-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Tue, 19 Jun 2001 17:03:57 -0700
From: Indy Singh <indy@bms.calstate.edu>
Subject: execute perl from browser
Message-Id: <3B2FE86D.AA3EC63A@bms.calstate.edu>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>I am kind of new to perl.
<br>i have installed perl on my window nt workstation.
<br>The same workstation have webdb (webserver software).
<p>at win nt prompt i am able to execute the script
<br>eg
<br>c>example
<br>Hello !!!!!
<br>c>
<p>the problem is when i try to execute same script using browser, (netscape/ie)
<br>it open up window to download the script file, rather it should execute.
<p>any idea what is wrong with it?????
<p>--
<br>Indy Singh
<br>&nbsp;</html>



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

Date: Wed, 20 Jun 2001 01:26:30 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: execute perl from browser
Message-Id: <3B2FFB95.F1AEC356@rochester.rr.com>

Indy Singh wrote:
 ...
> i have installed perl on my window nt workstation.
> The same workstation have webdb (webserver software).
> 
> at win nt prompt i am able to execute the script
> eg
> c>example
> Hello !!!!!
> c>
> 
> the problem is when i try to execute same script using browser,
> (netscape/ie)
> it open up window to download the script file, rather it should
> execute.
> 
> any idea what is wrong with it?????
> 
> --
> Indy Singh
> 
You need to configure your web server to run a CGI program when it
encounters a Perl program file, rather than offer it for download (which
is probably the default).  You will need to peruse your web server's
docs for information on where CGI scripts should be located, how to
specify that they are to be executed, and with what program, etc.  Your
problem isn't a Perl problem, and thus doesn't really belong on this
newsgroup.
-- 
Bob Walton


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

Date: Wed, 20 Jun 2001 03:31:09 GMT
From: kurt.hindenburg@gte.net
Subject: Finding if an executable...
Message-Id: <1OUX6.354$34.394434@news1.iquest.net>

I'm attempting to find a way to determine if an executable is on a system.
I would like it to work on any OS.  I would prefer not to search through
the $PATH variable (I'm not even sure if Mac OS has one).  MS Windows does
not handle 2>&1 correctly, so I can't run the executable and look at the
results.  Other than redirectly all the output to a temp file, is there
a way to do this?
  Kurt


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

Date: Tue, 19 Jun 2001 22:05:11 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Get all the possibilities
Message-Id: <3b2fcb92.477511304@news.erols.com>

On Tue, 19 Jun 2001 12:55:09 -0700, Marco UClink
<mblanche@uclink.berkeley.edu> wrote:

>I am trying to write a small Perl script that display all the possible
>strings from 1 character long to x characters long using a 4 letter alphabet
>(A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n AT\n CA\n etc... I am sure
>this is pretty simple but I donšt have the training to resolve the issue.

Quick and dirty, ignores a recursive solution in favor of one that abuses
map{}, but here goes.

  #!perl
  use strict;

  my @strings = string_letters([qw/A C G T/], 5);
  print "$_\n" foreach @strings;

  sub string_letters {
    my ($letters, $max_length) = @_;
    my @words = my @working = @$letters;
    for (2..$max_length) {
      #Tack each letter in @$letters onto the end of each string in
      #@working. Add the results to @words, and overwrite the old
      #contents of @working
      push @words,
        @working = map { my $foo = $_; map {"$_$foo"} @working } @$letters;
    }
    return @words;
  }



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

Date: Wed, 20 Jun 2001 00:00:38 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Get all the possibilities
Message-Id: <tivpt6ililba1f@corp.supernews.com>

Marco UClink (mblanche@uclink.berkeley.edu) wrote:
: I am trying to write a small Perl script that display all the possible
: strings from 1 character long to x characters long using a 4 letter alphabet
: (A,G,C,T). I mean A\n C\n G\n T\n AA\n AC\n AG\n AT\n CA\n etc... I am sure
: this is pretty simple but I donšt have the training to resolve the issue.
: 
: Any sugestions?

Stop messing with DNA before you unleash a horrible mutant monster which
will destroy mankind as punishment for your hubris.

Other than that, though, what you have is a problem in combinatorials.
Here's one approach:

#!/usr/bin/perl -w
# dna - generate all dna sequences up to length provided as argument.
# Craig Berry (20010619)

use strict;

my $maxlen = shift || 5;

foreach my $len (1..$maxlen) {
  fill('', $len);
}

sub fill {
  my ($str, $len) = @_;
  if (length $str == $len) {
    print "$str\n";
  }
  else {
    fill("$str$_", $len) foreach qw(A T G C);
  }
}


-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Wed, 20 Jun 2001 12:05:27 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Graphical user interfacing?
Message-Id: <0ATX6.7859$qJ4.327550@ozemail.com.au>

http://search.cpan.org/search?dist=Win32-CtrlGUI-0.20

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html

flash <bop@mypad.com> wrote in message news:LGHX6.20183$Vl2.1062499@news20.bellglobal.com...
> Is it possible to interface with a grapical program (GUI)?
> What modules?





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

Date: 19 Jun 2001 15:41:05 -0700
From: emoore@cofs.net (E. Moore)
Subject: Help with Rewriting Application in OO Perl
Message-Id: <f024c24d.0106191441.1e968954@posting.google.com>

Hello,

I have an web application written in Perl that works with MySQL. I
would like to improve my code and am trying to see where and how much
PERL OO would help.  Unfortunately, I am not familiar with OO and I
find it confusing, despite owning and reading the recommended books.

Quick Overview
--------------
The basic framework of the application is a config file 'above' the
web server directory:

     config.file
          |
    +--web server--+
    |              |
  cgi-bin        html
    
Most of the subroutines are in a common file (common.cgi).  The common
file creates the menus  (e.g. maintaining a user profile ) and a
separate script handles the data updates (update_user.cgi).

Config File
-----------
The config file is just a series of hashes that include any data that
might require changing on the site, including the titles of web pages,
submit buttons, URLs, etc. Some of these hashes are quite lengthy:

%DB =   (   host => 'localhost',
            user => 'me',
            pass => 'secret',
            name => 'something'
         );
         
%UNIX_PATHS, %SECURE_URI, %DEFAULT_VALUES...etc.


common.cgi
----------
Near the top this script imports the config.file data: 

use vars qw( %DB %UNIX_PATHS %SECURE_URI %DEFAULT_HTM %in);
do '/www/something/config.file';


other cgi's
------------
all other scripts have near the top

require 'common.cgi';

All parameter passed between an 'other' cgi and common.cgi are passed
in the %in hash.  This makes substitution on web pages very simple
since everything I want replaced in an html page is framed
{{something_like_this}} and then replace with the respective value
using:

open( FILE, "<$UNX{htm}/$in{nxthtm}" ); 
   while( <FILE> )
   {
       while( ( $key, $value )  = each ( %in ) ){
            s/{{$key}}/$value/g;
           }
       while ( ( $key, $value ) = each ( %DEFAULT_HTM ) ){
            s/{{$key}}/$value/g;  
           }
       while ( ( $key, $value ) = each ( %SECURE_URI ) ){
            s/{{$key}}/$value/g;  
           }   
       $html .= $_;
   }
close( FILE );      


Next Steps
----------
First, how much of a performance 'hit' should I expect if I
'objectify' this code?

Second, with the 'use' builtin, if I quote only those methods I want
to use out of common.pm, (e.g. use MyMods::Common qw( login logout) )
does that improve compile time over simply calling use MyMods::Common?

Third, I don't quite understand how to create a MyConfig.pm so that
all the object attributes are available to other scripts?  Along that
line, I don't see how I access these attributes. I've looked in the
CPAN and I've gotten more confused.  I rather like the global hashes I
have now since I don't have to know anything about them, which is the
point of OO as I understand it.

Sorry this was a bit wordy.

Thanks,

Eric Moore


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

Date: Wed, 20 Jun 2001 02:36:33 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: HowTo: Run a command in backticks as root?
Message-Id: <slrn9j031g.hel.see-sig@typhoon.xnet.com>

On Tue, 19 Jun 2001, Bruno Montagnac <bruno.montagnac@renault.com> wrote:
> hi,
> 
> it's typically an UNIX pb, not a Perl one...
> if u want to run a process with root rights, u'll have to "give" the
> binary to root (chown) & to activate the suid bit (chmod)
> then, u can run the nmap binary from Perl under the apache user (the
> process will still be owned by root)
> remember to set acces rights on for the apache user (others +rx or with
> ACLs may be)

The suid bit is ignored by most systems, but you can probably get it to
work by using 'suidperl' in the shebang line at the top instead of 'perl'.  
See 'perldoc perlsec' about untainting.

> take care to nmap safety... or only give read/exec rights to apache user
> (playing with a subdirectory set) to avoid everyone launch it...

Probably should protect it with crypted password or web authentication.

> Simon Devlin wrote:
> 
>> [---snip---]
>> I have a utility (a portscanner) that needs to be run as root in order
>> to function fully.
>> [---snip---]
>> $command="nmap -sS -O -oX - 10.1.1.1-255 |";
>> [---snip---]
>> Basically, it's fine, but some of the features, require that NMAP be
>> run as root, and I'm not sure how to make perl do this.
>> [---snip---]
>> Note, that in this instance, the perl program is running under the
>> apache user as the result of a webfronted report generator.
>> [---snip---]
> 
> --
>  //\  Bruno Montagnac
> // \\ DTSI/DSO/Service:18741
> \\ // XX XXX XX XXX [API:SQY-OVA-613]
>  \//  Technocentre RENAULT (Place Ovale)
> 
> 
> 


-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 20 Jun 2001 00:30:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: MAJOR perl bug
Message-Id: <3B2FDFCE.942BF436@rochester.rr.com>

Philip Newton wrote:
 ...
> perl -V should give you the version and, with ActivePerl, also the

Actually, that's:

    perl -v

 ...
> Philip
 ...
-- 
Bob Walton


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

Date: Wed, 20 Jun 2001 02:53:19 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: multiple file upload
Message-Id: <slrn9j040u.hel.see-sig@typhoon.xnet.com>

On 19 Jun 2001 07:45:08 -0700, isterin <isterin@hotmail.com> wrote:
> The browser restricts you to upload only one file at a time per post
> request.  You can set it up where you upload one file at a time, but
> it then resubmits itself time and time again until all files are
> uploaded.

Not so.  I have uploaded 5 files at a time.  But the variable 'name' for 
each file upload field has to be different.  If you give all upload fields 
the same name, the second time you try to read it, it would be empty, 
since you have already read that filehandle to eof.  For example for a 
variable number of files up to 5 (upload1..upload5):

# File upload routine
if (param('upload')) {
    for $i (1..5) {
        if ($upload = param('upload'.$i)) {
        # read & save $upload filehandle
    }
}

> "Vassilis G. Tavoultsidhs" <ixanthi@ixanthi.gr> wrote in message news:<9gmq1b$o02$1@foo.grnet.gr>...
>> Hi, I don't know if this is the correct newsgroup but anyway.
>> I want to make a script to upload multiple files from the users browser to
>> my server. I have tried the following :
>> 
>>      $write_file = "../mydir/images/myfile.jpg";
>>      $filepath = "file.jpg";
>>      $bytes_read=0;
>>      $size='';
>>      $buff='';
>> 
>>      open (WFD,">$write_file") || die "Error opening ${write_file} for
>> writing \n";
>>      flock (WFD, "1");
>> 
>>      while ($bytes_read=read($filepath,$buff,2096))
>>      {
>>          $size += $bytes_read;
>>          binmode WFD;
>>          print WFD $buff;
>>      }
>> 
>>      close(WFD);
>> 
>> it does work for one file but if I repeat it for a different $writefile and
>> $filepath it will create a file on the server which will have no content.
>> Does anyone know what to do?
>> 
>> Thanks
>> 
>> Vassilis G. Tavoultsidhs
>> Electronics Engineer - Software Engineer
>> www.ixanthi.gr


-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 20 Jun 2001 01:05:59 GMT
From: demitri-borg@home.com (Demitri Borg)
Subject: Newbie requests help with Net::Ping module to use as learning example...
Message-Id: <3b2ff71e.102637484@news.grlnd1.tx.home.com>

Would anyone care to maybe demonstrate how to use Net::Ping in an
example script so that i might be able to better grasp the concept of
how to load and use modules 

or maybe give info on where i can read up more on modules and how to
use them...

Any help is greatly appreciated.

Thank you in advance,
Demitri


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

Date: Fri, 15 Jun 2001 10:48:19 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Printing filenames that are in a directory
Message-Id: <3B2A2E43.5A1E8C19@home.com>

"Mr. Ed" wrote:
> 
> I'm trying to print filenames [...] from a directory I'm opening,
> [...] Instead of printing the names of my files, I 
> get a numeral : 61 in my print response. Below is the code:

Newbies take note! Mr Ed has written a textbook request for help:
 - His subject describes his problem.
 - He tells us what he's trying to do.
 - He tells us what he expects to get.
 - He tells us what he actually gets.
 - He includes a short bit of code that exhibits the problem.

If only more people did this... *sigh*
 
> opendir THISDIR, "." 
>     or die "FATAL Problem with opening directory: $!";
> @allfiles = readdir THISDIR;

Looks okay so far.

> $allfiles=@allfiles;

This sets the scalar $allfiles to the length of the array @allfiles.

> $filecounter=0;

What's this used for? $allfiles has the count of files.

> print $allfiles;#trying to print filenames

And this prints that count. You want to print your array.

print join("\n", @allfiles), "\n"; # print files, one per line

-mjc


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

Date: Wed, 20 Jun 2001 01:18:57 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: redirection to a file
Message-Id: <3B2FF9D0.9AE10A35@rochester.rr.com>

Michael Schmidt wrote:
 ...
> I've got this command that fails.

That's not a lot to go on.  When it fails, does it generate an error
message?  Some output?  If so, what?  What specifically makes you think
it fails?  Does your command run when typed verbatim into a command
window in Windoze 2000?  And when your command fails, what is the value
of $ret?
 ...
> Michael Schmidt
-- 
Bob Walton


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

Date: Tue, 19 Jun 2001 22:51:53 -0000
From: googlenews@edge-web.com
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <tivls9d4ns4r73@corp.supernews.com>

Ren Maddox <ren@tivoli.com> tapped:

> if(my @matches = $string =~ /$match/) {
>   ($new = $replace) =~ s/\$(\d+)/$matches[$1-1]/g;
> }

> is a big improvement.

That's neat, wish I understood it. ;)

@matches would be the $1, $2, $3, etc.??? - I don't get the second line, oh well (I'm TRYING!!!)

Doesn't work with $` though (didn't try $' $&...).


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

Date: Tue, 19 Jun 2001 23:01:54 -0000
From: googlenews@edge-web.com
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <tivmf2mo08i446@corp.supernews.com>

Greg Bacon <gbacon@hiwaay.net> tapped:

[snip]

> Using the technique from "How do I expand variables in text strings?"
> in Section 4 of the Perl FAQ, I used the following:

That's a bit of a stretch... well, you did say 'technique'...

> If you want to add $`, $&, and $', then you need to make some changes:

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

>     use strict;

>     my $string  = 'this.20010420162000.txt';
>     my $match   = '^th(.*?)\.(\d{14})\.txt$';
>     my $replace = '$1.during.$2.$&';
>     my $result;

>     if (my @matches = $string =~ /$match/) {
>         my %match;
>         for (1 .. @matches, qw/ ` & ' /) {
>             no strict 'refs';
>             $match{$_} = ${$_};
>         }

>         ($result = $replace) =~ s/\$([\w`&']+)/$match{$1}/g;
>         print "result = '$result'\n";
>     }
>     else {
>         print "No match.\n";
>     }

result = 'is.during.20010420162000.this.20010420162000.txt' (is that the $& perhaps? I think you meant to do that... ;)

This one even more incomprehensible, obfuscation isn't and never will be my strong point.

But hey, both you guys helped, I think I can figure out the bricks now that the house is built (awww, how cheesy). It's my problem if I don't understand what you're doing, and figuring it out will no doubt help my m4d P3rl sk111z yo. ;)

Thanks! And even more thanks for the lack of flames!

Eg G. Head


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

Date: 19 Jun 2001 18:11:05 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regexps, using variables to get $1, $2, etc.
Message-Id: <m3ae34dq0m.fsf@dhcp9-173.support.tivoli.com>

On Tue, 19 Jun 2001, googlenews@edge-web.com wrote:

> Ren Maddox <ren@tivoli.com> tapped:
> 
>> if(my @matches = $string =~ /$match/) {
>>   ($new = $replace) =~ s/\$(\d+)/$matches[$1-1]/g;
>> }
> 
>> is a big improvement.
> 
> That's neat, wish I understood it. ;)
> 
> @matches would be the $1, $2, $3, etc.??? - I don't get the second
> line, oh well (I'm TRYING!!!)

Replaces a "$" followed by a number with the appropriate element from
@matches (which starts at 0, so the -1).

> Doesn't work with $` though (didn't try $' $&...).

True, it doesn't.  Those are tougher to handle in this way.
Basically, you would save off those before hand:

#!/usr/bin/perl
use strict;
use warnings;
my $string = "here is a string to use for matches";
my $match = '(\w+)\s*to\s*(\w+)';
my $replace = q/$1,$2,$`,$&,$'/;
my $new;
if(my @matches = $string =~ /$match/) {
  my($before, $during, $after) = ($`, $&, $');
  ($new = $replace) =~ s/\$(\d+)/$matches[$1-1]/g;
  for ($new) {
    s/\$`/$before/g;
    s/\$&/$during/g;
    s/\$'/$after/g;
  }
}
print "$new\n";
__END__

Next you'll be wanting to handle $+, @+ and @-, right?  :)

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 15 Jun 2001 10:58:53 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: replace with logic in Perl
Message-Id: <3B2A30BD.24588B92@home.com>

Bal Paudyal wrote:
> 
> Let's say I have a string.
> $_="$$&&&&abc&&&??? action someone@party.com- emailing is not easy!";

You should single quote that string instead of double quoting it.
Otherwise Perl will try to interpolate the array @party.
 
> I would like to replace all non word with a space except @ and dot.
>
> Any one line solution?

Assuming that you don't care about locale, you can do this;

tr/.@A-Za-z0-9_/ /c;

-mjc


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

Date: 19 Jun 2001 15:14:00 -0700
From: sgfoley@hotmail.com (Shon)
Subject: trying to optimize -> system call questions
Message-Id: <b0a70a3a.0106191414.4fce5cb9@posting.google.com>

I have perl script which calls many other scripts via system().  I am
re-writing these to be used as modules by the main script.  I thought
that this would improve my performance by not creating new processes.
In reality the execution time has slowed down by 20%.  Any ideas why
the system call is so much faster?


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

Date: 19 Jun 2001 16:13:16 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Why does this split not work?
Message-Id: <m3elsgdvgz.fsf@dhcp9-173.support.tivoli.com>

On Tue, 19 Jun 2001, nospam@cfl.rr.com wrote:

> I'm trying to split a pretty large buffer (>1000 lines) into
> sections based on a line that looks like
> 
> 	NAME Jane Doe
> 
> The file is a series of name-values like
> 
> 	NAME Jane Doe
> 	AGE 21
> 	ADDRESS Anytown USA
> 	!
> 	NAME John Smith
>            . 
>            .
> 
> 
> 
> so I'm using something like
> 
>    my @people=split /^\s*NAME\s+/m,$buf;
> 
> and I'm getting very odd results. It consistently fails with this
> message:
> 
>    Use of uninitialized value in split at datax.pm line 447, <IN>
>    line
> 21 (#1)

This error implies that there is a loop that is reading from
filehandle IN.  I expect we'll need to set at least that loop to
figure out what is going on, though presumably the problem lies in the
way $buf is being set.

You might consider setting $/="\nNAME".

[rest snipped]

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 20 Jun 2001 00:35:35 GMT
From: tuxy <nospam@cfl.rr.com>
Subject: Re: Why does this split not work?
Message-Id: <3B2FB8B6.FD20C255@cfl.rr.com>

This doesn't occur in any loops, and I don't even have a filehandle
named IN! Is this weird or what? Good suggestion though with the $/ -
I'll try it (But I shouldn't HAVE TO!)..

Thanks


Ren Maddox wrote:
> 
> On Tue, 19 Jun 2001, nospam@cfl.rr.com wrote:
> 
> > I'm trying to split a pretty large buffer (>1000 lines) into
> > sections based on a line that looks like
> >
> >       NAME Jane Doe
> >
> > The file is a series of name-values like
> >
> >       NAME Jane Doe
> >       AGE 21
> >       ADDRESS Anytown USA
> >       !
> >       NAME John Smith
> >            .
> >            .
> >
> >
> >
> > so I'm using something like
> >
> >    my @people=split /^\s*NAME\s+/m,$buf;
> >
> > and I'm getting very odd results. It consistently fails with this
> > message:
> >
> >    Use of uninitialized value in split at datax.pm line 447, <IN>
> >    line
> > 21 (#1)
> 
> This error implies that there is a loop that is reading from
> filehandle IN.  I expect we'll need to set at least that loop to
> figure out what is going on, though presumably the problem lies in the
> way $buf is being set.
> 
> You might consider setting $/="\nNAME".
> 
> [rest snipped]
> 
> --
> Ren Maddox
> ren@tivoli.com


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

Date: Wed, 20 Jun 2001 03:46:39 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Why does this split not work?
Message-Id: <3B301C6C.7A01F953@rochester.rr.com>

tuxy wrote:
> 
> I'm trying to split a pretty large buffer (>1000 lines) into sections
> based on a line that looks like
> 
>         NAME Jane Doe
> 
> The file is a series of name-values like
> 
>         NAME Jane Doe
>         AGE 21
>         ADDRESS Anytown USA
>         !
>         NAME John Smith
>            .
>            .
> 
> so I'm using something like
> 
>    my @people=split /^\s*NAME\s+/m,$buf;
> 
> and I'm getting very odd results. It consistently fails with this
> message:
> 
>    Use of uninitialized value in split at datax.pm line 447, <IN> line
> 21 (#1)
> 
> which I cannot comprehend. I checked perldoc perlfunc for split and
> didn't see anything that looked like this problem discussed.  How could
> something be "uninitialized"? $buf is definitely initialized since I
> guess from the message it managed to get through 10 lines of it before
> it failed. What could be "uninitialized" at line 10? Even empty lines
> parse OK with /m.
> 
> Another oddity- tweaking the code above this line (for unrelated tasks)
> CHANGES the line this fails at- sometimes it says <IN> line 2, line 10,
> 21, etc for the exact same input file. I looked at the file and see
> nothing unusual on any of those lines. I also turned on diagnostics and
> it didn't offer any further insight.
> 
> By the way, the resultant array is one element which contains the entire
> buffer, even though there are many lines that meet the regex criteria.

The regex and the split seem to work as you indicate you think it should
in my tests.

The only way I can get your statement to fail with that message is for
$buf to be undefined.  I suggest you put something like:

     die "Aha, buf is undef" unless defined $buf;

just ahead of your problem statement and see if you get the die.  If so,
check your code to see how $buf got undef'ed.  Maybe perl -d would help.

 ...
-- 
Bob Walton


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

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


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