[18099] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 259 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 9 18:11:41 2001

Date: Fri, 9 Feb 2001 15:10:25 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981760225-v10-i259@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 9 Feb 2001     Volume: 10 Number: 259

Today's topics:
    Re: General Tool(s) for browsing/editing DB tables? <terrence.brannon@oracle.com>
        get and https <twhu@lucent.com>
    Re: Getting LWP::UserAgent to perform a sequence of eve <godzilla@stomp.stomp.tokyo>
    Re: Getting LWP::UserAgent to perform a sequence of eve <pobbard@hotresponse.com>
        insertion sort algorithm shogun415@my-deja.com
    Re: killing a cgi nicely (Rich Lafferty)
    Re: Net::FTP error - timeout on put() <terrence.brannon@oracle.com>
        net::telnet not closing? <xuvetyn@my-deja.com>
    Re: newbie regexp gnari@my-deja.com
    Re: newbie regexp <monty@primenet.com>
    Re: newbie regexp (LK)
    Re: newbie regexp <tore@extend.no>
    Re: newbie regexp aramis1631@my-deja.com
    Re: newbie regexp <lxq79@hotmail.com>
        Newbie's Stuck <jlm@cca-int.com>
    Re: Newbie's Stuck (LK)
    Re: Newbie's Stuck (Brandon Metcalf)
    Re: non repeating random numbers (Craig Berry)
    Re: passing in a regex aramis1631@my-deja.com
    Re: passing in a regex ericr@yankthechain.com
    Re: passing in a regex aramis1631@my-deja.com
        Problem with multi-line format <czech@olgrande.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 09 Feb 2001 13:21:47 -0800
From: Terrence Monroe Brannon <terrence.brannon@oracle.com>
Subject: Re: General Tool(s) for browsing/editing DB tables?
Message-Id: <3A845F6B.16D09A62@oracle.com>



David Coppit wrote:

> [posted & mailed]
>
> On Wed, 13 Dec 2000, John Stumbles wrote:
>
> >       Is there a module or some ready-rolled utilit[y|ies] for browsing
> > and editing databases/tables/records via DBI/DBD? I'm thinking od the sort
> > of visual tool one gets with MS (sorry :-) Access where you can point and
> > drag fields from tables to indicate relations etc. I did get partway
> > through a homebrew effort using a CGI front end but it was slow and not
> > very functional, and I guess Perl/TK would be better for an interface.
>
> I recommend phpMyAdmin
> (http://www.phpwizard.net/projects/phpMyAdmin/). It's built on PHP and
> not CGI, but does pretty much anything you'd want to do.

You mean built up on PHP and not Perl. Both are built on CGI :-)

Also, this tool only works for MySQL. But I do agree we need something like
phpMyAdmin for other databases.

Informix comes with one. Oracle comes with one... how about postgres?



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

Date: Fri, 9 Feb 2001 17:19:27 -0500
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: get and https
Message-Id: <961qe3$cjm@nntpb.cb.lucent.com>

I'm trying to use LWP to get a file content via proxy server and https.
The following code works without a proxy; however, it fails if I am trying
to ge a page out side of proxy server. What perl modules do I need to
make it work?

Thanks,
-------------
use strict;
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->proxy(['http', 'ftp'], 'https://my.proxy.com:8000/');
my $req = new HTTP::Request('GET', 'https://a.secure.site.com');
print "request\n";
my $res = $ua->request($req);

#check the outcome
if ($res->is_success) {
        print "Connect successful\n";
        print $res->message . "\n" . $res->code . "\n";
        print $res->content . "\n";
}
else {
        print "Error: " . $res->status_line . "\n";
}





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

Date: Fri, 09 Feb 2001 12:46:19 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Getting LWP::UserAgent to perform a sequence of events (GET, POST,   GET, etc.)
Message-Id: <3A84571B.84DD4D6E@stomp.stomp.tokyo>

Philip Obbard wrote:
 
> You're right! Even with LWP, I could do
> $ua->referer('http://www.hotresponse.com/')
> ...and it works fine. Thanks for the tip. 
> It was in the documentation for
> HTTP::Header, which is used by LWP.

I had a strong suspicion you would find what
you need, if you looked. =)

Now you know more, know where to look and,
have information you can pass along to others.
Knowing where to look for knowledge is vastly
more important than knowing this knowledge.

 
> One last question: the first time I ran the script, I saw something like
> this get returned:
> Set-Cookie: MyPage=558; expires=Sat, 10-Feb-02 00:00:00 GMT;path=/;
> domain=.hotresponse.com;

(snipped)

* gags *

Our internet does not provide milk with cookies.
I don't bother with cookies.

More accurately, I only have a basic foundation
knowledge of cookies. I don't like them, never
use them and keep them turned off in my browser.
It would be remiss of me to pretend I know enough
about cookies to help you. I wish I could help but
I am not qualified to give advice on cookies.

There are handful of people here who know lots and
lots about cookies. Maybe one of these people will
respond with helpful information. Randal Schwartz
is an exemplary expert on cookies. If you can attain
his attention, he can give you an answer in a flash.
However, don't expect him to give you a glass of milk.

Godzilla!


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

Date: Fri, 9 Feb 2001 15:15:52 -0500
From: "Philip Obbard" <pobbard@hotresponse.com>
Subject: Re: Getting LWP::UserAgent to perform a sequence of events (GET, POST,  GET, etc.)
Message-Id: <961irl$ee1$1@taliesin.netcom.net.uk>

You're right! Even with LWP, I could do
$ua->referer('http://www.hotresponse.com/')
 ...and it works fine. Thanks for the tip. It was in the documentation for
HTTP::Header, which is used by LWP.

One last question: the first time I ran the script, I saw something like
this get returned:
Set-Cookie: MyPage=558; expires=Sat, 10-Feb-02 00:00:00 GMT;path=/;
domain=.hotresponse.com;

But, on all subsequent runs, I did not see a cookie message. Reading the LWP
documentation at
http://search.cpan.org/doc/GAAS/libwww-perl-5.50/lwpcook.pod, it appears
that LWP should *reject* cookies by default, and if not, there would be a
file called lwpcookies.txt on my server. However, I cannot find such a file.
If that's true - and I'm "uncookied" - why wouldn't the external webserver
be cookie-ing my UserAgent again?

I know, this is getting obscure, but I'm just wondering if anyone's
encountered this yet.

Thanks,
Philip


"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3A842BAF.DF2B7D94@stomp.stomp.tokyo...
> LWP is a very decent module. However, I only use LWP Simple
> for my scripts. I have found for more complex socket use,
> it is quicker and more efficient to write my own socket.
> When a referrer variable is needed, as you describe, I add
> a referrer variable to my socket script to 'fool' a site
> cgi which employs $ENV{REFERER} for redirection. In some
> cases, adding $ENV{REFERER}, after setting a value, works.
> For others, running tests will yield a variable name used
> by a remote script for referrer. Use of $env_ref is very
> common with programmers.  A custom variable name can be
> included in a socket call as well,





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

Date: Fri, 09 Feb 2001 22:44:06 GMT
From: shogun415@my-deja.com
Subject: insertion sort algorithm
Message-Id: <961rrl$qjm$1@nnrp1.deja.com>

I am a complete newbie learning algorithms to add to my arsenal of
programming skills. I am using Introduction to Algorithms by Cormen,
Leiserson and Rivest.

I am using PERL of course for the language.

Here is my scenario, I have an @array of 20 integers ranging from 1-20,
the algo works almost flawlessly EXCEPT that the number 5 is always the
first number and the rest of the numbers fall into the correct order.

I am enclosing the code, I would appreciate it if someone who knows
algos could check my code and tell me where the error is in my version
of the algo...

p.s I know that I am not using strict...

##---------------------------------
# code start
##---------------------------------

#!/usr/bin/perl -w

my @A = qw( 5 3 1 7 9 2 10 4 8 6 20 18 16 14 12 19 17 15 13 11);

for( $j = 2; $j < scalar( @A ); $j++ ) {
    $key = $A[ $j ];
    $i = $j - 1;
    while( $i > 0 && $A[ $i ] > $key ) {
	$A[ $i + 1] = $A[ $i ];
	$i = ($i -  1);
    }
    $A[ $i + 1] = $key;
}

print "\n", join "\n", @A, "\n";

##----------------------------------
##----------------------------------

thx in advance,
-shogun


Sent via Deja.com
http://www.deja.com/


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

Date: 9 Feb 2001 19:22:46 GMT
From: rich@bofh.concordia.ca (Rich Lafferty)
Subject: Re: killing a cgi nicely
Message-Id: <slrn988h2s.afn.rich@bofh.concordia.ca>

In comp.lang.perl.misc,
emelin <emelin@my-deja.com> wrote:
> 
> >
> > Add the following line near the top of your script :
> > use CGI::Carp qw(fatalsToBrowser);
> >
> > You can then use the normal ... die "This went wrong : $!\n";
> > code in your script, and it will show up in the browser.
> 
> but this will print out lots of stuff, and that's what i was trying to
> avoid...

Perhaps you should tell us exactly what you see, and then describe
exactly what you want instead.

  -Rich

-- 
Rich Lafferty ----------------------------------------
 Nocturnal Aviation Division, IITS Computing Services
 Concordia University, Montreal, QC
rich@bofh.concordia.ca -------------------------------


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

Date: Fri, 09 Feb 2001 14:14:58 -0800
From: Terrence Monroe Brannon <terrence.brannon@oracle.com>
Subject: Re: Net::FTP error - timeout on put()
Message-Id: <3A846BE2.33B4C955@oracle.com>

maybe you could email this output to the author, Graham Barr. I'm sure he
would help you. It would be nice if the debug output had times in it so you
could see if there really were a timeout error.

lawrenceang@my-deja.com wrote:

> Hi all,
>
> I am using WinNT Srv 4.0, ActivePerl 5.6.0.616.
> FTP Server is a IBM CS V2R10.
>
> I have a perlscript that uploads an ASCII file from a NT server to a
> IBM host. It puts() the file to a certain dataset name, executes a
> quote site command, and then puts() another (trigger) file that sends
> that dataset to a job queue (or something to that effect).
> Snippet of script follows-:
>
> if (!($ftp = Net::FTP->new($SITE)))
> {
>         $test_item="new()";
>         next;
> }
>
> $ftp_ret=$ftp->login($USER, $PASS);
> if (!$ftp_ret)
> {
>         $test_item="login()";
>         next;
> }
>
> $ftp_ret=$ftp->cwd($TARGETDIR);
> if (!$ftp_ret)
> {
>         $test_item="cwd()";
>         next;
> }
>
> $ftp_ret=$ftp->put($Filename, "\C020.USER.GCR.TESTING\'");
> if (!$ftp_ret)
> {
>         $test_item="put1()";
>         next;
> }
>
> $ftp_ret=$ftp->quot("SITE", "FILETYPE=JES");
> if (!$ftp_ret)
> {
>         $test_item="quote()";
>         next;
> }
>
> $ftp_ret=$ftp->put('//ssbcsgf01/share/A_GCR/bin/perl/gcrjcl');
> if (!$ftp_ret)
> {
>         $test_item="put2()";
>         next;
> }
>
> -----------------------------------------------------------------
>
> Recently, my perlscript that was functioning pretty well suddenly
> failed to work altogether. I can't quite figure out what was wrong, and
> so turned on the debug level to look at the output.
>
> Debug output follows-:
>
> Net::FTP: Net::FTP(2.56)
> Net::FTP:   Exporter(5.562)
> Net::FTP:   Net::Cmd(2.18)
> Net::FTP:   IO::Socket::INET(1.25)
> Net::FTP:     IO::Socket(1.26)
> Net::FTP:       IO::Handle(1.21)
>
> Net::FTP=GLOB(0x203e604)<<< 220-ZFTPIP1 IBM FTP CS V2R10 at <Site>,
> 01:25:50 on 2001-02-09.
> Net::FTP=GLOB(0x203e604)<<< 220 Connection will close if idle for more
> than 5 minutes.
> Net::FTP=GLOB(0x203e604)>>> user ftp88
>
> Net::FTP=GLOB(0x203e604)<<< 331 Send password please.
> Net::FTP=GLOB(0x203e604)>>> PASS ....
> Net::FTP=GLOB(0x203e604)<<< 230 FTP88 is logged on.  Working directory
> is "FTP88.".
> Net::FTP=GLOB(0x203e604)>>> PORT 163,37,72,179,6,21
>
> Net::FTP=GLOB(0x203e604)<<< 200 Port request OK.
> Net::FTP=GLOB(0x203e604)>>> STOR 'C020.USER.GCR.TESTING'
>
> Net::FTP=GLOB(0x203e604)<<< 125 Storing data set C020.USER.GCR.TESTING
> Net::FTP=GLOB(0x203e604): Timeout at
> D:/Perl/site/lib/Net/FTP/dataconn.pm line 71
> Net::FTP=GLOB(0x203e604)>>> QUIT
>
> Net::FTP=GLOB(0x203e604): Timeout at O:\A_GCR\bin\perl\FTP-GC~1.PL line
> 119
>
> -----------------------------------------------------------------
>
> Seems like the problem lies with the timeout at occured at line 71 in
> dataconn.pl. Anyone has any idea how I can resolve this?
>
> Thanks! :)
>
> Sent via Deja.com
> http://www.deja.com/



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

Date: Fri, 09 Feb 2001 20:34:42 GMT
From: entropy <xuvetyn@my-deja.com>
Subject: net::telnet not closing?
Message-Id: <961k92$jf8$1@nnrp1.deja.com>

i'm using net::telnet to connect to connect to a server, start a
program then exit. i'm doing this to test a program that sometimes
leaves a process running when users disconnect from their terminals.
i do this by first logging in and starting a program, then closing the
connection, then i log back in as a different user and grep ps like "ps
aux | grep "user.ksh" | grep -v grep" (their shell shouldn't be running
when they after they disconnected) and if that process still exists,
kill it and start over.
the problem is... it ALWAYS returns a ksh process which is why i don't
think my former connection's closing. because if i do it manually, by
way of logging in as the first user then manually closing my connection
then grep-ing ps, there's never anything there! so net::telnet must not
be fully disconnecting. i'm doing it as "$t->close;" and have even
tried "undef $t;" to no avail. is there a way to make 100% sure that it
disconnects?

thanks in advance,
entropy


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 09 Feb 2001 19:37:35 GMT
From: gnari@my-deja.com
Subject: Re: newbie regexp
Message-Id: <961gtu$g74$1@nnrp1.deja.com>

In article <20010210035309.51dae62c.lxq79@hotmail.com>,
  LXQ <lxq79@hotmail.com> wrote:
> Sorry, the while($file =<>) part should be while (line<>)
>
> On Sat, 10 Feb 2001 03:41:44 +0900
> LXQ <lxq79@hotmail.com> wrote:
>
> > Hi,
> >
> > Im trying to change all words in a file:
> > from desk -> table
> > from house -> home
> > from dog -> cat
> >

> > while($file = <>){
ok , you have fixed this
while(<>)

> > 	$line = s/desk/table/:
this line ends with a colon not semicolon.
this means that you you did not use cut and paste for this posting
Always post exactly the code that you tested, not some other code

anyways your problem is probably that you magically expect the
variable $line to contain $_ after the substitution

s/// returns the number of substitutions made
so $line will be 0 or 1 in your example, depending on whether a match
was found
if you had done $line = s/desk/table/g;
then line could be a number > 1



> > 	$line = s/house/home/;
> > 	$line = s/dog/cat/;
> > }
> >
> > But it failed! Anyone can tell me how to do this correctly please?

You should always tell what you mean by failed. what did happen?
what did you expect to happen?
what did you do to verify what happened?

you should read the perlop manpage,
look for  Quote and Quote-like Operators
also you should read perlre

if you dont have man, use perldoc


good luck
gnari


Sent via Deja.com
http://www.deja.com/


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

Date: 9 Feb 2001 19:54:25 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: newbie regexp
Message-Id: <961jh9$6ug$1@nnrp1.phx.gblx.net>

LXQ <lxq79@hotmail.com> wrote:
> Im trying to change all words in a file:
> from desk -> table
> from house -> home
> from dog -> cat
>
> The file is just like:
> this is the file, deskdesk. desk desk-.
> home-home-home. home+home, homehome.
> dog-dog-dog test test or even dogdog
>
> So the position is random, and it can be another letter (not space) stick
> to it.

Huh?

> Then I wrote a script like this....
>
> while($file = <>){
> 	$line = s/desk/table/:
> 	$line = s/house/home/;
> 	$line = s/dog/cat/;
> }
>
> But it failed! Anyone can tell me how to do this correctly please?

$ cat subst.pl
#!/usr/local/bin/perl -w

while (<DATA>) {
    s/\bdesk\b/table/g;
    s/\bhouse\b/home/g;
    s/\bdog\b/cat/g;
    print;
}

__DATA__
this is the file, deskdesk. desk desk-.
house-house-house. house+house, househouse.
dog-dog-dog test test or even dogdog
$ ./subst.pl
this is the file, deskdesk. table table-.
home-home-home. home+home, househouse.
cat-cat-cat test test or even dogdog
$

Hope these hints help. Good luck.

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA


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

Date: Fri, 09 Feb 2001 19:56:21 GMT
From: lkenny@fisheries.org (LK)
Subject: Re: newbie regexp
Message-Id: <3a844b43.16456491@wingate>

On Sat, 10 Feb 2001 03:41:44 +0900, LXQ <lxq79@hotmail.com> wrote:

>Hi,
>
>Im trying to change all words in a file:
>from desk -> table
>from house -> home
>from dog -> cat
>
>The file is just like:
>this is the file, deskdesk. desk desk-.
>home-home-home. home+home, homehome.
>dog-dog-dog test test or even dogdog
>
>So the position is random, and it can be another letter (not space) stick
>to it.
>
>Then I wrote a script like this....
>while($file = <>){
>	$line = s/desk/table/:
>	$line = s/house/home/;
>	$line = s/dog/cat/;
>}
>
>But it failed! Anyone can tell me how to do this correctly please? Thanks
>so much :)


Then I wrote a script like this....

>	$line = s/desk/table/:
			      ^This should be a semicolon

LK


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

Date: Fri, 9 Feb 2001 21:02:25 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: newbie regexp
Message-Id: <MPG.14ee6b39bb8312f29898a0@news.online.no>

In article <20010210034144.6dd54dff.lxq79@hotmail.com>, lxq79
@hotmail.com says...
> while($file = <>){
> 	$line = s/desk/table/:
> 	$line = s/house/home/;
> 	$line = s/dog/cat/;
> }

Simplify;

while (<FILE>) {
	s/desk/table/;
	s/house/home/;
	s/dog/dog/;
}

Note the difference between '=' and '=~'.


-- 
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/


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

Date: Fri, 09 Feb 2001 20:11:30 GMT
From: aramis1631@my-deja.com
Subject: Re: newbie regexp
Message-Id: <961it9$i92$1@nnrp1.deja.com>

In article <20010210034144.6dd54dff.lxq79@hotmail.com>,
  LXQ <lxq79@hotmail.com> wrote:
> Hi,
>
> Im trying to change all words in a file:
> from desk -> table
> from house -> home
> from dog -> cat
>
> The file is just like:
> this is the file, deskdesk. desk desk-.
> home-home-home. home+home, homehome.
> dog-dog-dog test test or even dogdog
>
> So the position is random, and it can be another letter (not space)
stick
> to it.
>
> Then I wrote a script like this....
> while($file = <>){
> 	$line = s/desk/table/:
> 	$line = s/house/home/;
> 	$line = s/dog/cat/;
> }
>
> But it failed! Anyone can tell me how to do this correctly please?
Thanks
> so much :)

Um, $line will contain the number of matches, not the changed record as
you wanted. The match/substitution is running against $_. You will
change only the first occurence of each string on each line.

Consider...

while (<FH>) {                # reads line into $_
    chomp;                    # remove newline char
    print "before [$_]\n";
    s/desk/table/g;           # g global match and replace
    s/house/home/g;
    s/dog/cat/g;
    print "after  [$_]\n";    # results are in $_
}

Or, binding s/// to $line...

while (my $line=<FH>) {         #read record into $line
    chomp $line;
    print "before [$line]\n";
    $line =~ s/desk/table/g;    #match agains $line use bind op '=~'
    $line =~ s/house/home/g;
    $line =~ s/dog/cat/g;
    print "after  [$line]\n";
}


Sent via Deja.com
http://www.deja.com/


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

Date: Sat, 10 Feb 2001 05:26:38 +0900
From: LXQ <lxq79@hotmail.com>
Subject: Re: newbie regexp
Message-Id: <20010210052638.401a1bda.lxq79@hotmail.com>


> $ cat subst.pl
> #!/usr/local/bin/perl -w
> 
> while (<DATA>) {
>     s/\bdesk\b/table/g;
>     s/\bhouse\b/home/g;
>     s/\bdog\b/cat/g;
>     print;
> }

Thanks, I forgot the print thats why :) I thought the script would
automatically change the file for me :P


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

Date: Fri, 9 Feb 2001 15:40:24 -0500
From: "jlm" <jlm@cca-int.com>
Subject: Newbie's Stuck
Message-Id: <961kct$dbc$1@stingray.cca-int.com>

How would I search for the presense of @ in a string?
Assume an email addr. in variable $email - how do I test $email for an at
sign.
many thanks for your help...




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

Date: Fri, 09 Feb 2001 20:54:00 GMT
From: lkenny@fisheries.org (LK)
Subject: Re: Newbie's Stuck
Message-Id: <3a8456c0.19397577@wingate>

On Fri, 9 Feb 2001 15:40:24 -0500, "jlm" <jlm@cca-int.com> wrote:

>How would I search for the presense of @ in a string?
>Assume an email addr. in variable $email - how do I test $email for an at
>sign.
>many thanks for your help...
>
>

I am a newbie, but I have gotten a lot of help from here, so I will
try and contribute and answer.

If this is a CGI situation through a form, you could use a Javascript
function to make sure that an @ is in the entry before submission.
This code could be something like:

function validate{
	if (document.form.Email.value.indexOf("@")==-1) {

tmpData=window.prompt("txt",document.form.Email.value);
		if (tmpData==null || tmpData.indexOf("@")==-1) {
			return false;
		}
		document.form.Email.value=tmpData;
	}
}

If you want to see if a variable has the @, you could do a matching
regex like:

#!/usr/local/bin/perl

$email = "joeblow\@somewhere.com\n";

if($email =~ /.\@.*/){
 	print "It has an \@\n";
}else{
	print "No \@\n";
}

Hope this helps.

LK


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

Date: 9 Feb 2001 22:09:56 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: Newbie's Stuck
Message-Id: <961prk$h7h$1@nrchh45.us.nortel.com>

lkenny@fisheries.org writes:

 > On Fri, 9 Feb 2001 15:40:24 -0500, "jlm" <jlm@cca-int.com> wrote:
 > 
 > >How would I search for the presense of @ in a string?
 > >Assume an email addr. in variable $email - how do I test $email for an at
 > >sign.
 > >many thanks for your help...

 > If you want to see if a variable has the @, you could do a matching
 > regex like:
 > 
 > #!/usr/local/bin/perl
 > 
 > $email = "joeblow\@somewhere.com\n";
 > 
 > if($email =~ /.\@.*/){
 >  	print "It has an \@\n";
 > }else{
 > 	print "No \@\n";
 > }

Or simply

if ($email =~ /@/) { ... }

Brandon


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

Date: Fri, 09 Feb 2001 21:51:47 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: non repeating random numbers
Message-Id: <t88pjjg260lra3@corp.supernews.com>

Jason from The Workshop (jason@cyborgworkshop.com) wrote:
: I have need to generate a random number between 1 and 50 without using a
: number that has already been generated.

Put the questions (or, better, references to them, or their index numbers)
into an array, shuffle it (see 'perldoc -q shuffle'), and then iterate
over the resulting array.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Fri, 09 Feb 2001 19:29:31 GMT
From: aramis1631@my-deja.com
Subject: Re: passing in a regex
Message-Id: <961gee$fmc$1@nnrp1.deja.com>

In article <961eb1$do9$1@nnrp1.deja.com>,
  ericr@yankthechain.com wrote:
> Let's say I want to do something like this:
>
> my $regex = shift;
> $string =~ $regex;
>
> passing the entire regular expression in as a variable. Obviously the
> above example itself doesn't work, but what will?

I do it like this...

$string =~ /$regex/;

Of course, I don't pass the slashes.


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 09 Feb 2001 19:50:21 GMT
From: ericr@yankthechain.com
Subject: Re: passing in a regex
Message-Id: <961hlp$h3f$1@nnrp1.deja.com>

I'm talking about being able to pass in a whole regex, like s/\n|\s//g

In article <961gee$fmc$1@nnrp1.deja.com>,
  aramis1631@my-deja.com wrote:
> In article <961eb1$do9$1@nnrp1.deja.com>,
>   ericr@yankthechain.com wrote:
> > Let's say I want to do something like this:
> >
> > my $regex = shift;
> > $string =~ $regex;
> >
> > passing the entire regular expression in as a variable. Obviously
the
> > above example itself doesn't work, but what will?
>
> I do it like this...
>
> $string =~ /$regex/;
>
> Of course, I don't pass the slashes.
>
> Sent via Deja.com
> http://www.deja.com/
>


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 09 Feb 2001 20:47:51 GMT
From: aramis1631@my-deja.com
Subject: Re: passing in a regex
Message-Id: <961l1l$k61$1@nnrp1.deja.com>

In article <961hlp$h3f$1@nnrp1.deja.com>,
  ericr@yankthechain.com wrote:
> I'm talking about being able to pass in a whole regex, like s/\n|\s//g

Ah, well, that is different. TMTOWTDI.

one way...
$string =~ s/$regex//g;

another way...
$string =~ s/$regex/$newval/g;

or, maybe you fancy eval - see perldoc -f eval - like this...
$regex = 's/\n|\s//g';
$myString = '$string =~ ';
       .
       .
eval $myString.$regex;  # your answer will be in $string

I think 'eval' is what you seek... if not, there are more ways...

> In article <961gee$fmc$1@nnrp1.deja.com>,
>   aramis1631@my-deja.com wrote:
> > In article <961eb1$do9$1@nnrp1.deja.com>,
> >   ericr@yankthechain.com wrote:
> > > Let's say I want to do something like this:
> > >
> > > my $regex = shift;
> > > $string =~ $regex;
> > >
> > > passing the entire regular expression in as a variable. Obviously
> the
> > > above example itself doesn't work, but what will?
> >
> > I do it like this...
> >
> > $string =~ /$regex/;
> >
> > Of course, I don't pass the slashes.
> >
> > Sent via Deja.com
> > http://www.deja.com/
> >
>
> Sent via Deja.com
> http://www.deja.com/
>


Sent via Deja.com
http://www.deja.com/


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

Date: Fri, 09 Feb 2001 14:43:59 -0800
From: Corwin Zechar <czech@olgrande.net>
Subject: Problem with multi-line format
Message-Id: <3A8472AF.D3CD22BD@olgrande.net>

This is a multi-part message in MIME format.
--------------57945A91484F9100A7DA0E86
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Greetings!

I need to read a file containing strings with embeded newlines, and
write the
strings back out, with multiple lines for each string. I have been
trying to use
the @* format.

I can get an internal string to behave in the desired fashion, but
whenever I try
to read a string with embedded newlines, it writes the string out
exactly as it
was read.

Does anyone know why this is so? How to write multiple lines for strings
with
embedded newlines? (I could just parse the string with a regular
expression, but
I thought the @* was a rather elegant solution.)

Thanks in advance.

Corwin


Code follows:

#!/usr/local/bin/perl5 -w
#
use Carp;            # Error-printing/stack trace module

use diagnostics;     # Gives meaningful diagnostic hints on compile
errors

use FileHandle;      # allows access to FORMAT variables

$inputfile="string_list";
$outputfile="jumbled_strings";
$localstring="this\nprints\na\nword\non\nevery\nline\n";
#
#  open the INFILE file. read all strings which may contain
#   zero or more embedded newlines.
#
        open (INFILE, "<$inputfile") || die("Cannot open $inputfile\n");

        while(<INFILE>) {

                $string= $_;
        }

        close(INFILE);


#
#  write the output file
#
        open(OUTFILE,">$outputfile");

        write(OUTFILE);

        close(OUTFILE);


format OUTFILE=

@*
$string

@*
$localstring
 .


Output File:

This is a muilti-line string.\nWhy can't I get it to parse the
newlines\nwith the wonderful @* format?

this
prints
a
word
on
every
line


--------------57945A91484F9100A7DA0E86
Content-Type: text/x-vcard; charset=us-ascii;
 name="czech.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Corwin Zechar
Content-Disposition: attachment;
 filename="czech.vcf"

begin:vcard 
n:Zechar;Corwin
tel;fax:650.633.0594
tel;work:650.633.8852
x-mozilla-html:TRUE
adr:;;500 Oracle Parkway;M/S 4op12;Redwwod Shores;CA;94065-1677
version:2.1
email;internet:Corwin.Zechar@oracle.com
title:<a href="http://www.oracle.com"><img src="http://revenue-management.us.oracle.com/graphics/oracle.gif" height=40 width=182>
x-mozilla-cpt:;3464
fn:Corwin Zechar
end:vcard

--------------57945A91484F9100A7DA0E86--



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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