[22142] in Perl-Users-Digest
Perl-Users Digest, Issue: 4363 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 8 03:11:38 2003
Date: Wed, 8 Jan 2003 00:10:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 8 Jan 2003 Volume: 10 Number: 4363
Today's topics:
Re: Need to enter to finish perl script <kasp@epatra.com>
Re: Need to enter to finish perl script (c0rum_z)
Re: Need to enter to finish perl script <uri@stemsystems.com>
perl efficiency tip (Walter Roberson)
Re: Reg Expression help <Jodyman@hotmail.com>
Re: Reg Expression help <uri@stemsystems.com>
Re: Reg Expression help <removeX_stevensx4000x@earthlinxk.next>
the length of empty? <ie_qjzhu@yahoo.ie>
Re: These are discouraging stats to Perlistas & Pythoni <stuart@bmsi.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 8 Jan 2003 11:40:05 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Need to enter to finish perl script
Message-Id: <avgfc1$ut8$1@newsreader.mailgate.org>
"c0rum_z" <c0rum_z@yahoo.com> wrote in message
news:dcfb988b.0301071711.3b6b61e7@posting.google.com...
> I have this perl script and it's running fine in unix/linux, but in
> WIndows, I need to press enter to finish the execution of the script.
>
> Any idea how do I troubleshoot where is the enter key need to be
> simulated by print "\r\n"; or any other way to make my script run to
> the end without have to press enter?
Can you show us the script? Otherwise people are just going to shoot in the
dark.
--
Perl is designed to give you several ways to do anything, so
consider picking the most readable one.
-- Larry Wall
------------------------------
Date: 7 Jan 2003 22:20:40 -0800
From: c0rum_z@yahoo.com (c0rum_z)
Subject: Re: Need to enter to finish perl script
Message-Id: <dcfb988b.0301072220.63df2a84@posting.google.com>
<mouseslinger@hotmail.com> wrote in message news:<20LS9.603980$P31.219065@rwcrnsc53>...
> "c0rum_z" <c0rum_z@yahoo.com> wrote in message
> news:dcfb988b.0301071711.3b6b61e7@posting.google.com...
> > Hi all,
> >
> > I'm a very new person in Perl.
> >
> > I have this perl script and it's running fine in unix/linux, but in
> > WIndows, I need to press enter to finish the execution of the script.
> >
> > Any idea how do I troubleshoot where is the enter key need to be
> > simulated by print "\r\n"; or any other way to make my script run to
> > the end without have to press enter?
> >
> > Many thanks in advance
> >
>
> When asking for help, you need to be as specific as possible and it also
> would be helpful if you could include any relevant script code that you
> might be talking in reference to.
>
> Please post the relevant code so that we can see it.
>
> - David
> - http://www.cgiwebsite.com
>
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.437 / Virus Database: 245 - Release Date: 1/6/03
Hi David,
Thanks for replying.
Attached is my script which I did not write.
Sorry if it's very long
rgds,
c0rum_z
#!/usr/bin/perl
;# Version %%%%IDA3625 | Control Release
$audit_prog="eapsend";
;#establish defaults
;#
$env{"USER"}='USER';
$env{"PASSWORD"}='PASSWORD';
$env{"FINISHSTRING"}='<<<<!!!!>>>>';
$env{"CONFIGFILE"}=".eaprc";
$env{"TRANSPORT"}="TEXT";
$env{"TIMEOUT"}=60;
$SIG{'ALRM'}='timeOutSocket';
;# read command line for possible CONFIGFILE override
;#
&parseCmd;
;# read configuration file for overrides
;#
&readEnv($env{"CONFIGFILE"});
;# reprocess command line
;#
&parseCmd;
;# set local date and time
;#
&getDate;
;# set DATAFILE for audit report
;#
if ($env{"INPUTFILE"}){
$env{"DATAFILE"}=$env{"INPUTFILE"};
}
else {
$env{"DATAFILE"}="STDIN";
}
$env{"PARTNER"}="none";
if ($env{"RECEIVER"}){
$env{"PARTNER"}=$env{"RECEIVER"};
}
else {
if ($env{"EDISCANNING"}) {
$c1 = substr($env{"EDISCANNING"},0,1);
$c1 =~ tr/[a-z]/[A-Z/;
if ($c1 eq 'Y') {
$env{"PARTNER"}="SCANNED FROM DATA";
}
}
}
;# if in DEBUG mode display environment
;#
if ($debug){
&dispEnv;
}
&eapSocket;
;# send signon
;#
$outline = "*SIG(USER=$env{'USER'}, PASSWORD=$env{'PASSWORD'},";
$outline .= "FINISHSTRING=$env{'FINISHSTRING'},TRANSPORT=$env{'TRANSPORT'})\n";
print "signing on\n";
$action="write $outline to socket";
if ($debug){
print "$action\n";
}
&writeSockData($outline);
&getAck(0);
;# indicate intention to send data
;#
$outline = "*SEND(";
if ($env{'RECEIVER'}){
$outline .= "RECEIVER=$env{'RECEIVER'}";
}
if ($env{'APRF'}){
$outline .= ", APRF=$env{'APRF'}";
}
if ($env{'SNRF'}){
if ($env{'SNRF'} eq "*AUTO"){
&autoSnrf();
}
$outline .= ", SNRF=$env{'SNRF'}";
}
if ($env{'EDISCANNING'}){
$outline .= ", EDISCANNING=$env{'EDISCANNING'}";
}
$outline .= ")\n";
$action="write $outline to socket";
if ($debug){
print "$action\n";
}
&writeSockData($outline);
&getAck(0);
;# send data
;#
print "sending data\n";
if (!$env{"INPUTFILE"}) {
$action="reading from STDIN";
print "$action\n";
while (<STDIN>) {
if ($debug){
print "data>$_";
}
&writeSockData($_);
}
}
else {
$action="opening $env{'INPUTFILE'}";
if ($debug){
print "$action\n";
}
if (!open(INPUTFILE,$env{"INPUTFILE"})){
&writeAudit("Failure on open INPUTFILE");
die("Failure on open INPUTFILE $env{'INPUTFILE'}\n");
}
$action="reading from INPUTFILE $env{'INPUTFILE'}";
print "$action\n";
while (<INPUTFILE>) {
if ($debug){
print "data>$_";
}
&writeSockData($_);
}
close(INPUTFILE);
}
$action="Sending finish string $env{'FINISHSTRING'}";
if ($debug){
print "$action\n";
}
$outline=$env{'FINISHSTRING'}."\n";
&writeSockData($outline);
$exiterr=&getAck(1);
&writeAudit($response);
print "session response:$response\n";
if ($exiterr){
print STDERR "Send failed $response\n";
}
else {
if (($env{"DELETE"}) && ($env{"INPUTFILE"})){
$action="attempt to delete $env{'INPUTFILE'}";
if ($debug){
print "$action\n";
}
if ($env{"NT"}){
if (system("del $env{'INPUTFILE'} /F")){
&writeAudit('Delete INPUTFILE failed');
die("Delete $env{'INPUTFILE'} failed\n");
}
} else {
if (system("rm -f $env{'INPUTFILE'}")){
&writeAudit('Delete INPUTFILE failed');
die("Delete $env{'INPUTFILE'} failed\n");
}
}
}
}
;# quit
;#
$outline="*QUIT()\n";
$action="write $outline to socket";
if ($debug){
print "$action\n";
}
&writeSockData($outline);
&getDate;
print "process complete $date\n";
print "----------------------------------------------------\n";
exit($exiterr);
sub dispSyntax {
print "\n";
print "Syntax: eapsend [-keyword=value]\n";
print "\n";
print "keyword default value\n";
print "------------ -------------\n";
print "USER USER \n";
print "PASSWORD PASSWORD \n";
print "INPUTFILE none \n";
print "FINISHSTRING <<<<!!!!>>>> \n";
print "PORT 10241 \n";
print "ENTERPRISE localhost \n";
print "CONFIGFILE .eaprc \n";
print "ERRORFILE eaperror \n";
print "AUDITFILE STDOUT \n";
print "TRANSPORT TEXT \n";
print "RECEIVER none \n";
print "APRF none \n";
print "SNRF none \n";
print "EDISCANNING not set \n";
print "DELETE not set \n";
print "DEBUG not set \n";
print "TIMEOUT 60 (seconds) \n";
print "\n";
print "use SNRF=*AUTO for automatic SNRF generation.\n";
print "\n";
exit(0);
}
;# >>> from eap_socket
;# Version %%%%IDA801 | Control Release
sub eapSocket {
$action="start eapSocket";
if ($debug){print "...$action\n";}
$action="use Socket";
use Socket;
$eap_port = 10240 unless $eap_port;
$enterprise = 'localhost' unless $enterprise;
$action="getprotobyname";
($name,$aliases,$proto)=getprotobyname('tcp');
$action="getservbyname";
($name,$aliases,$eap_port) =getservbyname($eap_port,'tcp')
unless $eap_port =~ /^\d+$/;;
$action="gethostbyname $enterprise";
($name,$aliases,$type,$len,$r_host_addr)=gethostbyname($enterprise);
if (!$r_host_addr) {
&writeAudit("$enterprise host not recognized");
&writeFatal("eap_socket: $enterprise not recognized host
name");
}
$sockaddr =' S n a4 x8';
$remote=pack($sockaddr,PF_INET,$eap_port,$r_host_addr);
$action="socket";
if (socket(S, PF_INET, SOCK_STREAM, $proto)) {
if ($debug){
print "socket OK\n";
}
}
else {
&writeAudit($!);
&writeFatal("eap_socket: $!");
}
$action="connect socket";
if (connect(S,$remote)){
if ($debug){
print "connect OK\n";
}
}
else {
&writeAudit($!);
&writeFatal("eap_socket: $!");
}
select(S); $|=1; select(STDOUT); $|=1;
}
sub getSockData {
local ($sockData);
$action="start getSockdata";
$gotFinishString=0;
if ($env{'NT'}) {
$sockData=<S>;
}
else {
alarm ($env{'TIMEOUT'});
$sockData=<S>;
alarm(0);
}
$fspos = index($sockData,$env{'FINISHSTRING'});
if ($fspos >= 0) {
$gotFinishString=1;
$sockData = substr($sockData,0,$fspos);
}
return ($sockData);
}
sub writeSockData {
$action="start writeSockdata";
local ($sockData)=@_;
if ($env{'NT'}) {
print S $sockData;
}
else {
alarm ($env{'TIMEOUT'});
print S $sockData;
alarm(0);
}
return;
}
sub timeOutSocket {
&writeAudit("Socket read/write timed out");
&writeFatal("Socket read/write timed out");
}
;# >>> from eap_audit
;# Version %%%%IDA385 | Control Release
format AUDITFILE =
@<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<< @<<<<<<<<<<<<<
@<<<<<<<<<<<<<<<<<<<<<<<<<<<
$audit_prog,$audit_date,$audit_datafile,$audit_partner,$audit_snrf,$audit_aprf,$audit_text
.
format AUDITFILE_TOP =
FUNCTION DATE DATAFILE PARTNER
SNRF APRF STATUS
-------- ---------------------------- ------------
----------------------------------- -------------- --------------
----------------------------
.
format NULL_TOP =
.
sub writeAudit {
local ($text)=@_;
local ($nohead);
if ($env{"AUDITFILE"}){
if (-e $env{"AUDITFILE"}){
$nohead=1; #file exists/no heading needed
}
unless (open (AUDITFILE,">>$env{'AUDITFILE'}")) {
print "Failure on open auditfile $env{'AUDITFILE'}: $!\n";
delete $env{"AUDITFILE"};
}
}
if (!$audit_prog){
$audit_prog = "!^X";
}
$audit_date = $date;
if ($env{"DATAFILE"}){
$audit_datafile = $env{"DATAFILE"};
}
else {
$audit_datafile = "none";
}
if ($env{"PARTNER"}){
$audit_partner = $env{'PARTNER'};
}
else {
$audit_partner = "none";
}
if ($env{"SNRF"}){
$audit_snrf = $env{'SNRF'};
}
else {
$audit_snrf = "none";
}
if ($env{"APRF"}){
$audit_aprf = $env{'APRF'};
}
else {
$audit_aprf="none";
}
if ($text){
$audit_text = $text;
}
else {
$audit_text = "unknown process failure";
}
if ($env{"AUDITFILE"}){
if ($nohead){
select(AUDITFILE);
$^="NULL_TOP"; #dont print header
select(STDOUT);
}
write AUDITFILE;
close (AUDITFILE);
}
else {
$^ = "AUDITFILE_TOP";
$~ = "AUDITFILE";
write STDOUT;
}
}
sub writeFatal {
local ($text)=@_;
local ($errorfile);
if ($env{'ERRORFILE'}){
$errorfile=$env{'ERRORFILE'};
}
else {
$errorfile="eaperror";
}
open (ERRORFILE,">$errorfile") ||
die ("Failure on open errorfile eaperror: $!\n");
&getDate;
select(ERRORFILE);
print "FATAL ERROR DETECTED $date\n";
print "Function : $audit_prog\n";
print "Error : $text\n";
print "Last Action : $action\n";
print "Last Response: $response\n";
&dispEnv;
die ("$text\n");
}
;# >>> from eap_ack
;# Version %%%%IDA385 | Control
Release
sub getAck {
local ($nakok)=@_;
local ($acknak);
local ($status);
;# wait for ACK
;#
$response=&getSockData;
chop($response);
if ($debug){
print "response from socket <$response> \n";
}
$acknak=substr($response,0,4);
if ($acknak ne "*ACK"){
if (!$nakok) {
&writeAudit($response);
&writeFatal("EAP did not return a postive
acknowledgment:<$response>");
}
else {
$status=substr($response,12,4);
if ($status < 1){
$status=1; #if error, must return >0 error code
}
if ($debug){
print "status: $status\n";
}
$status; #flag to indicate not ACK
}
}
else {
0; #flag to indicate ACK
}
}
;# >>> from eap_env
;# Version %%%%IDA653 | Control Release
sub readEnv {
local ($config)=@_;
print "----------------------------------------------------\n";
print "$audit_prog session started\n";
$action="open/read config file $config";
if (open(CONFIG,$config)){
while (<CONFIG>) {
chop; # remove NL
@line=split(/=/); # split into two
components
&setEnv($line[0],$line[1]);
}
}
}
sub parseCmd {
foreach $arg (@ARGV) {
if ($debug){
print $arg."\n";
}
if ($arg eq "-?"){
&dispSyntax;
}
$char1=substr($arg,0,1);
if ($char1 eq '-' ) {
@line=split(/=/,$arg); # split into two
components
@line[0] =~ s/^-//; # strip leading dash
&setEnv($line[0],$line[1]);
}
}
}
sub setEnv {
local ($key,$val)=@_;
local ($temp);
if ($debug) {
print "in setEnv key:<$key> val:<$val>\n";
}
$key =~ tr/[a-z]/[A-Z]/; # upper case key value
if ($key eq "PORT") {
$eap_port=$val;
}
elsif ($key eq "ENTERPRISE") {
$enterprise=$val;
}
elsif ($key eq "DEBUG") {
$debug=1;
}
elsif ($key eq "NT") {
$env{"NT"}=1;
}
else {
# if SNRF=*AUTO used uppercase val otherwise retain case
#
if ($key eq 'SNRF') {
$temp =$val;
$temp =~ tr/[a-z]/[A-Z]/;
if ($temp eq "*AUTO"){
$val=$temp;
}
}
# if DELETE look for special value TRUE
#
if ($key eq 'DELETE') {
$temp =$val;
$temp =~ tr/[a-z]/[A-Z]/;
if ($temp eq "TRUE"){
$val=$temp;
}
else {
$key="#"; #if not true treat as comment
}
}
$char1=substr($key,0,1);
if ($char1 ne '#') { # '#' is comment character
$env{$key}=$val;
}
}
}
sub dispEnv {
print "\nEAP Environment\n";
print "---------------------\n";
foreach $key (keys %env) {
print "$key = $env{$key}\n";
}
print "ENTERPRISE = $enterprise\n";
print "PORT = $eap_port\n";
if ($debug){
print "DEBUG ON\n";
}
print "PERL VERSION = $]\n";
print "---------------------\n\n";
}
;# >>> from eap_snrf
;# Version %%%%IDA385 | Control Release
sub autoSnrf {
$action="create SNRF";
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=gmtime(time);
$p_day =&zero_fill($day,2);
$p_hour =&zero_fill($hour,2);
$p_min =&zero_fill($min,2);
$p_sec =&zero_fill($sec,2);
$p_pid =&zero_fill(($$ % 1000000),6);
$env{"SNRF"} = ($p_day).($p_hour).($p_min).($p_sec).($p_pid);
if ($debug){
print "set SNRF=$env{'SNRF'}\n";
}
}
;# >>> from eap_date
;# Version %%%%IDA385 | Control Release
sub getDate {
local ($thisday);
local ($thismon);
local ($thisyear);
$action="build Date";
if (!$env{"NT"}){
$date=`date`;
chop($date);
}
else {
;# special date setting logic for NT platform
($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$p_day =&zero_fill($day,2);
if ($year<96) {
$thisyear="20".(&zero_fill($year,2));
}
else {
$thisyear="19".($year);
}
$thisday=(Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday];
$thismon=(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
$p_hour =&zero_fill($hour,2);
$p_min =&zero_fill($min,2);
$p_sec =&zero_fill($sec,2);
$date = ($thisday)." ".($thismon)." ".($p_day)."
".($thisyear)." ";
$date .= ($p_hour).":".($p_min).".".($p_sec);
}
if ($debug){
print "set date to=$date\n";
}
}
sub zero_fill {
local ($val,$fil)=@_;
$len=length($val);
$nzr=$fil-$len; # number zeroes required
if ($nzr > 0) {
"0"x$nzr . ($val);
}
else {
$val;
}
}
------------------------------
Date: Wed, 08 Jan 2003 06:33:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need to enter to finish perl script
Message-Id: <x7isx0p2vm.fsf@mail.sysarch.com>
>>>>> "cz" == c0rum z <c0rum_z@yahoo.com> writes:
cz> Attached is my script which I did not write.
then write the author to get help.
cz> Sorry if it's very long
long and very poorly written. a few notes follow.
cz> #!/usr/bin/perl
no -w
no strict
cz> &parseCmd;
perl4 style calls
cz> print "\n";
cz> print "Syntax: eapsend [-keyword=value]\n";
cz> print "\n";
cz> print "keyword default value\n";
here documents are needed
cz> sub eapSocket {
cz> $action="start eapSocket";
cz> if ($debug){print "...$action\n";}
cz> $action="use Socket";
cz> use Socket;
that happens at compile time, not at runtime like the author seems to think
cz> $action="getprotobyname";
cz> ($name,$aliases,$proto)=getprotobyname('tcp');
cz> $action="getservbyname";
cz> ($name,$aliases,$eap_port) =getservbyname($eap_port,'tcp')
cz> unless $eap_port =~ /^\d+$/;;
cz> $action="gethostbyname $enterprise";
cz> ($name,$aliases,$type,$len,$r_host_addr)=gethostbyname($enterprise);
cz> if (!$r_host_addr) {
cz> &writeAudit("$enterprise host not recognized");
cz> &writeFatal("eap_socket: $enterprise not recognized host
cz> name");
cz> }
cz> $sockaddr =' S n a4 x8';
cz> $remote=pack($sockaddr,PF_INET,$eap_port,$r_host_addr);
GACK!! use IO::Socket
cz> sub getSockData {
cz> local ($sockData);
local is perl4.
cz> $action="create SNRF";
cz> ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=gmtime(time);
cz> $p_day =&zero_fill($day,2);
cz> $p_hour =&zero_fill($hour,2);
cz> $p_min =&zero_fill($min,2);
cz> $p_sec =&zero_fill($sec,2);
cz> $p_pid =&zero_fill(($$ % 1000000),6);
cz> $env{"SNRF"} = ($p_day).($p_hour).($p_min).($p_sec).($p_pid);
what is with those parens?
cz> sub getDate {
cz> local ($thisday);
cz> local ($thismon);
cz> local ($thisyear);
cz> $action="build Date";
cz> if (!$env{"NT"}){
cz> $date=`date`;
cz> chop($date);
GACK! why do that when you have all this nice ugly date code below?
cz> }
cz> else {
cz> ;# special date setting logic for NT platform
cz> ($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=localtime(time);
cz> $p_day =&zero_fill($day,2);
cz> if ($year<96) {
cz> $thisyear="20".(&zero_fill($year,2));
cz> }
cz> else {
cz> $thisyear="19".($year);
cz> }
Y2K ALERT!! (i was expecting this and looked for the date sub)
a single strftime call would do all of that.
cz> sub zero_fill {
cz> local ($val,$fil)=@_;
cz> $len=length($val);
cz> $nzr=$fil-$len; # number zeroes required
cz> if ($nzr > 0) {
cz> "0"x$nzr . ($val);
cz> }
cz> else {
cz> $val;
cz> }
cz> }
gack! default returning a val from an if/else is horrible.
so the best thing to do is delete this script and find a better
one. hell, random noise on a modem would write better code.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 8 Jan 2003 07:33:49 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: perl efficiency tip
Message-Id: <avgk8t$7df$1@canopus.cc.umanitoba.ca>
Many of you probably already know this -- but like me, you might have
temporarily "misplaced" the information.
I had a generalized syslog processing tool that I hacked up for
a special case, removing a lot of code unnecessary for the purpose,
lifting tests out to a higher level so as to avoid expensive
operations such as 'split', and so on.
The special case tool then ran several times *slower* than the
original :(
I thought it was due to a difference in how I was handling I/O, but
testing showed that not to be the case, so I used -dSmallDprof .
The expensive line turned out to be a pattern match of the
form X.*Y.*Z where X was a plain string, and Y and Z had simple (?:a|b)
semantics.
I replaced this with two pattern matches in succession, matching
against first Y and then Z (and assumed X would always be present for my
purpose).
Even though the new code had two matches instead of one, the result
was twice as fast -- probably because perl didn't have to be bothered
with expensive back-up semantics on the .*'s.
So... the tip for today is that if you are doing a lot of matches,
processing large files, then multiple matches in succession might be
MUCH faster for you then using .*'s to join required subsequences.
======
I keep forgetting that the regex engine doesn't use a finite state
machine. I don't think I've ever written a perl script that
required the more general power. Does 5.8 have built-in finite-state
capabilities?
--
I don't know if there's destiny,
but there's a decision! -- Wim Wenders (WoD)
------------------------------
Date: Wed, 08 Jan 2003 05:08:36 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Reg Expression help
Message-Id: <onOS9.19979$134.2109553@newsread1.prod.itd.earthlink.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb1m7j8.h15.tadmc@magna.augustmail.com...
> Steven Coutts <scoutts.work@btinternet.com> wrote:
>
> > Just a quickie, been puzzling over this I'm not too hot on regular
> > expressions, how would I write a reg exp to replace '+' signs with
spaces?
>
>
> You would not write a regex for that task.
>
> You would use tr///
>
A Tad bit too easy, try this one:
#!c:\perl\bin\perl -w
use strict;
my $test = 'asdf+qwerty+jklm+zxcv++zoo+perl';
my @letters = split //, $test;
my @newletters;
foreach (@letters) {
if ($_ eq '+') { push (@newletters, " ") }
else { push (@newletters, $_) };
};
my $newtest = join ("",@newletters);
print "old = $test\n";
print "new = $newtest\n";
Very elegant and it works.
Jody
------------------------------
Date: Wed, 08 Jan 2003 06:01:45 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reg Expression help
Message-Id: <x7ptr8p4c6.fsf@mail.sysarch.com>
>>>>> "J" == Jodyman <Jodyman@hotmail.com> writes:
J> "Tad McClellan" <tadmc@augustmail.com> wrote in message
J> news:slrnb1m7j8.h15.tadmc@magna.augustmail.com...
>> You would use tr///
J> foreach (@letters) {
J> if ($_ eq '+') { push (@newletters, " ") }
J> else { push (@newletters, $_) };
J> };
gack. if you are going to write bad code, do it well.
push @newletters, $_ eq '+' ?, ' ' : $_ ;
J> Very elegant and it works.
not that elegant.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class
------------------------------
Date: Wed, 08 Jan 2003 06:45:10 GMT
From: mbS <removeX_stevensx4000x@earthlinxk.next>
Subject: Re: Reg Expression help
Message-Id: <4eon1voeubperfnggaq2om7curnpqmgaaj@4ax.com>
On Tue, 7 Jan 2003 13:58:51 -0000, "Steven Coutts"
<scoutts.work@btinternet.com> wrote:
||Just a quickie, been puzzling over this I'm not too hot on regular
||expressions, how would I write a reg exp to replace '+' signs with spaces?
s/\+/ /g
(Note that there is a space between the last two forward slashes.
The thing that looks like an up arrowhead is a forward slash followed
by a backslash. The "+" is backslashed {escaped} because it is a
symbol with special meaning to the regexp evaluator. The "g" says to
do it 'globally' to every "+", not just the firs one encountered.) It
might be clearer like this:
s!\+! !g
m
http://www.mbstevens.com/
------------------------------
Date: Wed, 8 Jan 2003 15:11:32 -0800
From: "qjzhu" <ie_qjzhu@yahoo.ie>
Subject: the length of empty?
Message-Id: <avgj1a$2b92$1@mail.cn99.com>
Hi folks,
@test = undef;
print scalar @test; #print 1
@test = ();
print scalar @test; #print 0
what's the difference?
------------------------------
Date: Wed, 08 Jan 2003 03:51:57 GMT
From: "Stuart D. Gathman" <stuart@bmsi.com>
Subject: Re: These are discouraging stats to Perlistas & Pythonistas...
Message-Id: <xfNS9.8081$t06.210048@news2.east.cox.net>
On Tue, 07 Jan 2003 13:56:18 -0500, Warren Postma wrote:
> These stats confirm what we already knew, which is that there are more
> VB idiots and Cobol old-timers out there than you can possibly count.
> And Java? It's the new cobol.
Why so anti-Java? There is Java the language and Java the virtual
machine. Java the language is slightly higher level than C - more
productive than C/C++, but not nearly as productive as Python. However,
Python runs great on Java the virtual machine.
Why use the virtual machine? It provides an airtight software sandbox -
as good as hardware sandboxing (e.g. unix users). The weakness of both
lie in the gatekeeper software, e.g. buggy root daemons in unix or buggy
access checking in Java (like the applet bug that allowed read access to
file: urls - or any other protocol it didn't recognize). I trust Java
application security a little more because there can be no buffer overflow
exploits, but I still use unix kernel security as a backup by running the
JVM as an appropriately privileged user. I don't think the restricted
mode in the CPython VM is as watertight.
The JVM also lets the Java/Python code run on AIX, Linux/x86, Linux/PPC,
MacOS, Windows without any porting - and only a little debugging of
machine depencies that leak through.
The Java VM provides great performance for a virtual machine. The JIT
versions are memory hogs, but I routinely run Java applications in as
little as 256K text + 256K heap in interpreter mode. The core interpreter
is only 128K, and basic native extensions like networking are only 30K or
so. Simple non-graphical Java applications require only 256K or less of
heap - similar to CPython. JPython has a lot of Java code, but it needs
the JIT to perform like CPython - and JITs are already a memory hog,
nobody misses an extra meg or so.
In summary, Java the VM is good for security and binary portability - and
has decent performance with both memory efficient (interpreter) and CPU
efficient (JIT) implementations. Java the language is good for C level
coding that doesn't have to worry about stomping on memory and has built
in object support. Both have their place in the world along with the
wonderful high level Python language. Why do you think Jython is so
popular?
--
Stuart D. Gathman <stuart@bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
------------------------------
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 4363
***************************************