[11062] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4663 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 15 19:03:52 1999

Date: Fri, 15 Jan 99 16:01:32 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 15 Jan 1999     Volume: 8 Number: 4663

Today's topics:
    Re: Regex challenge (Larry Rosler)
    Re: Regex challenge <aqumsieh@matrox.com>
    Re: Regex challenge (Greg Bacon)
        Removing spaces from arrays... (Hawkwynd)
    Re: script produced no output (Bart Lateur)
    Re: Searching a string, with a headache <aqumsieh@matrox.com>
    Re: Searching a string, with a headache jackmac@my-dejanews.com
    Re: Set current position in a file <aqumsieh@matrox.com>
        Socket reads hang for some Mac servers. <jc@uwm-dev.gte.com>
        sybperl password jackmac@my-dejanews.com
    Re: Treating Strings as FILEHANDLES <rick.delaney@home.com>
    Re: Treating Strings as FILEHANDLES <aqumsieh@matrox.com>
    Re: Which Perl reference book? <aem@netzero.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 15 Jan 1999 14:13:14 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regex challenge
Message-Id: <MPG.11095d5946ce43b9989996@nntp.hpl.hp.com>

In article <36a0a051.1190005@news.skynet.be> on Fri, 15 Jan 1999 
20:27:23 GMT, Bart Lateur <bart.lateur@skynet.be> says...
+ Eric Smith wrote:
 ...
+ >2) I want to march a lower case, upper case or mixed word and 
+ >_replace_ it with the same case layout in the new word
+ >so
+ >Table becomes Chair
+ >TABLE becomes CHAIR
+ >table becomes chair
+ 
+ Wait a minute... I've done this once... But I didn't use just a regex,
+ though. More something like:
+ 
+ 	s/\b(table)\b/&copycase('chair',$1)/ige;
+ 
+ with
+ 
+ 	sub copycase {
+ 		my($replace,$orig) = @_;
+ 		if($orig eq uc($orig)) {
+ 			return uc $replace;
+ 		} elsif($orig eq lc($orig)) {
+ 			return lc($replace);
+ 		} elsif($orig eq "\uL$orig" {

  		} elsif($orig eq "\u\L$orig") {

+ 			return "\u\L$replace";
+ 		} else {
+ 			# oh, well...
+ 			return $replace;
+ 		}
+ 	}

Even with the syntax errors corrected, this doesn't work in general, 
because it doesn't examine each character in $orig and apply the case to 
$replace.  It works for 'table', 'TABLE' and 'Table' but not otherwise.

On the other hand, those three cases are the ones submitted and maybe 
all that is desired, so perhaps all our character-by-character solutions 
are wasted effort.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 15 Jan 1999 16:19:50 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Regex challenge
Message-Id: <x3y67a8qlmx.fsf@tigre.matrox.com>


eric@nafex.comi (Eric Smith) writes:

> 1) I want to match a word, say `table' but the character \& or ampersand
> can appear anywhere in table so all these are legal:
> \&table
> t\&able
> ta\&ble
> ... [snip] ...
> table\&
> 
> any elegant solutions for my regex?

Hmm.. I have an interesting, yet by no means elegant solution.

$word = "table";
$regexp = join '\&?', split //, $word;
# now $regexp = 't\&?a\&?b\&?l\&?e'

$string = 'tab&le'; # or 'ta&ble' or whatever
print "YEAH.\n" if $string =~ /$regexp/;

> 
> 2) I want to march a lower case, upper case or mixed word and _replace_ it
> with the same case layout in the new word
> 
> so
> Table becomes Chair
> TABLE becomes CHAIR
> table becomes chair
> 
> thanx guys. 

Larry Rosler's solution seems the best to me.

Hope this helps,
Ala



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

Date: 15 Jan 1999 23:58:25 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Regex challenge
Message-Id: <77okn1$76p$1@info.uah.edu>

In article <77o2po$899$4@client2.news.psi.net>,
	abigail@fnx.com (Abigail) writes:
:     m {${\('&?' . (join '&?' => split // => 'table') . '&?')}};

I read his request as "table" with exactly one ampersand.  Your regular
expression would match "&t&a&b&l&e&" as well.  I think it be something
like

    my $amp = '(?:&(?!.*?&))?';
    m {${\($amp . (join $amp => split // => 'table') . '&?')}};

would do that.  Hmm..  I wonder whether it would be faster to study.
Hmm.. I wonder whether it would be faster to be greedy.

[17:54] ettsn% cat try
#! /usr/bin/perl -w

use strict;

use Benchmark;

my $amp;

$amp = '(?:&(?!.*&))?';
my $greedy   = "^(?=.*&)$amp" . (join $amp => split // => 'table') . '&?$';

$amp = '(?:&(?!.*?&))?';
my $cautious = "^(?=.*?&)$amp" . (join $amp => split // => 'table') . '&?$';

sub st_ca {
    local $_ = shift;
    study;

    m/$cautious/o;
}

sub st_gr {
    local $_ = shift;
    study;

    m/$greedy/o;
}

sub ca {
    local $_ = shift;

    m/$cautious/o;
}

sub gr {
    local $_ = shift;

    m/$greedy/o;
}

#print "yes\n" if st_ca("ta&ble");
#print "yes\n" unless st_ca("tab&l&e");
#exit;

timethese 100000 => {
    'st_ca_match' => 'st_ca("ta&ble"); st_ca("table&")',
    'st_ca_fail'  => 'st_ca("table");  st_ca("tab&l&e")',
    'st_gr_match' => 'st_gr("ta&ble"); st_gr("table&")',
    'st_gr_fail'  => 'st_gr("table");  st_gr("tab&l&e")',
    'ca_match'    => 'ca("ta&ble");    ca("table&")',
    'ca_fail'     => 'ca("table");     ca("tab&l&e")',
    'gr_match'    => 'gr("ta&ble");    gr("table&")',
    'gr_fail'     => 'gr("table");     gr("tab&l&e")',
};
[17:54] ettsn% ./try
Benchmark: timing 100000 iterations of ca_fail, ca_match, gr_fail, gr_match, st_ca_fail, st_ca_match, st_gr_fail, st_gr_match...
   ca_fail:  3 wallclock secs ( 3.88 usr +  0.01 sys =  3.89 CPU)
  ca_match:  5 wallclock secs ( 5.33 usr +  0.00 sys =  5.33 CPU)
   gr_fail:  3 wallclock secs ( 3.84 usr +  0.01 sys =  3.85 CPU)
  gr_match:  5 wallclock secs ( 5.29 usr +  0.01 sys =  5.30 CPU)
st_ca_fail:  7 wallclock secs ( 7.90 usr +  0.03 sys =  7.93 CPU)
st_ca_match: 10 wallclock secs ( 9.41 usr +  0.03 sys =  9.44 CPU)
st_gr_fail:  8 wallclock secs ( 7.81 usr +  0.01 sys =  7.82 CPU)
st_gr_match: 10 wallclock secs ( 9.34 usr +  0.03 sys =  9.37 CPU)

Interesting.

Greg
-- 
A lawyer is an expert on justice in the same way that a whore is an expert on
love.


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

Date: Fri, 15 Jan 1999 23:22:59 GMT
From: hawkwynd@adelphia.net (Hawkwynd)
Subject: Removing spaces from arrays...
Message-Id: <369fb52a.14895778@news.fwi.com>

I have a database file that has fields seperated by spaces, and would
like to have each field assigned to it's own variable as it is read in
from the file. 

An example of the data file :

6606677   Y    R  SF00 01/13/99 07:48 40-006990 INFO      
                                                          
6600151   Y    R  SF00 01/12/99 08:27 A359      ADIC      
                                                          
6602719   Y    R  SF00 01/12/99 11:48 B603      ADIC      
                                                          
6603118   Y    R  SF00 01/12/99 12:15 10-509610 ADAPTEC   

 The problem here, is the spaces between lines, and between the
variables. 

This is how I want the data to be outputted...

6606677 | Y|R|SF00|01/13/99|07:48|40-006990|INFO      
6600151|Y|R|R|SF00|01/12/99|08:27|A359|ADIC

For the life of me I've been unable to get the script to do this... 

Any suggestions?

Here's a snippet of the code I've been struggling with:

(open (INF, "$file"))or die("Can't open $file");

@ary = <INF>;
close(INF);
open (NEW,">$outfile") || die "Cannot open $outfile!"; 

&header_print;			#Set up the header page...

foreach $line (@ary){ 

if ($line=" "){
	$spaceflag = 1;
	}

if ($spaceflag == 0 && $line ne " "){

print "|"; 
print NEW "|";

$spaceflag=0;

}# end if 

#&format_stuff;  #set up the data to be printed to file.

#output the results
print "$line\n";
print NEW "$line\n";

}#end foreach

close(NEW) || die "cannot close..";
exit;


Thanks in advance!
hawkwynd

-------------------------------------------------
Talk about it at Hawkwynd's keep Discussion Forum
http://hawkwynd.tzo.com/discus/index.html


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

Date: Fri, 15 Jan 1999 20:27:20 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: script produced no output
Message-Id: <369f9f15.873197@news.skynet.be>

mikael j wrote:

>I get the message "script produced no output " when my gustbook script are
>going to write to the guestbook HTML-page. It seems like the information
>disappear from the webserver. Can anyone help me with this?
>
>I use a perl script on a IIS 3.0 server.

It's not unlikely that your script doesn't produce any output, because
it never runs, because it won't compile. That's right, it probably
contains some syntax errors. Try checking the syntax of the script with
an offline Perl.

	Bart.


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

Date: Fri, 15 Jan 1999 16:49:24 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Searching a string, with a headache
Message-Id: <x3y1zkwqk9n.fsf@tigre.matrox.com>


jim <webmaster@link-maker.com> writes:

> 
> all I can say is
> @stuff=split('|',$line);
> @more=split('*',$stuff[0])

and I can say that you didn't test before you posted!

@stuff = split /\|/, $line;



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

Date: Fri, 15 Jan 1999 23:10:52 GMT
From: jackmac@my-dejanews.com
Subject: Re: Searching a string, with a headache
Message-Id: <77ohtl$59d$1@nnrp1.dejanews.com>

In article <369f3db0.2660665@news.mtt.net>,
  gigatronman@email.com (Giga Tron) wrote:
> Hi fellow nerds,
>
> I have a unique situation,
>
> I have to read a file that can be any size, and contain unstructured
> data. The file could be like this.
>
>
stuff|morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stuff|
morestuff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|stuff|morest
uff*morestuff*morestuff*morestuff|evenmorestuff*evenmorestuff|
>
--- snip ----
some code to make it work smoother.
>
> Giga Tron Man
> gigatronman@email.com
>

I am sure you will get many valid replies to your request, but please don't
refer to us as fellow nerds.  You do not deserve the "nerd" title untill you
at least take a stab at solving the problem.

My 2 cents.

Jack

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 15 Jan 1999 16:47:20 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Set current position in a file
Message-Id: <x3y3e5cqkd3.fsf@tigre.matrox.com>


gigatronman@email.com (Giga Tron) writes:

> how can I set the current position in a file. do something and then
> continue from that position

It depends on what you want to do.
Have a look at

seek()
tell()



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

Date: Fri, 15 Jan 1999 16:51:42 -0500
From: John Chambers <jc@uwm-dev.gte.com>
Subject: Socket reads hang for some Mac servers.
Message-Id: <369FB86E.CA0028DA@uwm-dev.gte.com>

Digging around in TFFAQ and DejaNews found lots of nice answers
to other questions with similar keywords, but not to this one.  What
I've done is used the Socket module to connect to a server (web and
other) on various systems.  In a few cases, especially the WebStar
server on some Macs, attempts to read simply hang.  This happens
with both <F> and read(F,$b,$n).

Connecting via telnet and typing a GET command works.  The data
that comes down the line shows a nice snafu:  the HTTP header lines
are separated with \n, while the data portion uses \r as a separator.

Fine, I thought; I'll just use read() and demux the stuff myself.  But
the read() hangs.  For some other Mac servers, it doesn't hang.

With the same server, I found that the GET program that comes with
the LWP module also hangs, so I'm not the only one with a problem.

Anyone seen this?  Any clues lying about?




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

Date: Fri, 15 Jan 1999 22:50:24 GMT
From: jackmac@my-dejanews.com
Subject: sybperl password
Message-Id: <77ognd$486$1@nnrp1.dejanews.com>

Cannot connect to sql server with password in a variable if the password
contains a dollar sign.

Example:
$User=myUser;
$Server=myServer;
$Passwd='myPa$s';
$dbh = new Sybase::CTlib "$User", "$Passwd", "$Server";

I get error:  Message String: Login failed.  (and some other msg. stuff)

when I change last line above to:
$dbh = new Sybase::CTlib "$User", 'myPa$s', "$Server";a
everything works fine.

Then I tried:
$Passwd =~ s#\$#\\\$#g;
which puts a backslash in front of each dollar sign.
It still failed.
I also tried:
$Passwd="myPa\$s";
another failure.

I will be passing the password in thru argv.  How can I connect with a
variable?

Any help will be greatly appreciated.

Jack

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 15 Jan 1999 23:07:45 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <369FCC0C.8C6EFAF5@home.com>

Tad McClellan wrote:
> 
>    If you insist on slurping into a single scalar:
> 
>    while ( $string =~ /(.*\n)/g ) {

This will fail for those freak files that are missing their last
newline.  

This will work if the processing was going to involve chomping the lines
anyway.

    while ( $string =~ /^(.*)$/gm ) {

I'm having trouble coming up with a clean way to retain the newlines,
though.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Fri, 15 Jan 1999 16:01:41 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <x3y90f4qmh6.fsf@tigre.matrox.com>


dmulholl@cs.indiana.edu writes:

> 
> Greetings All,
> 
>   I am writing to ask if there is a way I can use a string as
> a stream.  The scenario I have is a string that contains newlines
> (the string holds the contents of a whole file) and I would like
> to process it one line at a time.  I would rather not split it

You don't need to treat your string like that. You just need to
extract one line at a time. That's easy.

> up into an array (seems unduely memory consuming to have to
> copy the data).  Nor open an external shell (performance), so I

Ok .. if you so wish.

> *think* open(STRINGHANDLE, "echo $string |") is not an option either.

yuck!

> What would be ideal might be:
> 
>   while ( <$string> ) {
> 
>    ...some processing...
> 
>   }

I would use a regexp:

$string = "line1\nline2\nline3\n";

while ($string =~ /^(.*)$/mg) {
        print "YEAH, $1.\n";
}

This prints:

YEAH, line1.
YEAH, line2.
YEAH, line3.


Hope this helps,
Ala



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

Date: Fri, 15 Jan 1999 15:28:25 -0800
From: "AE Meza" <aem@netzero.net>
Subject: Re: Which Perl reference book?
Message-Id: <BfQn2.2464$yt4.10269@typhoon-sf.pbi.net>

What about Perl 5 Interactive Course by Jon Orwant? Is it a good book for
learning perl? Anybody used it?

Regards,

AE Meza





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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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