[7040] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 665 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 25 23:07:18 1997

Date: Wed, 25 Jun 97 20:00:24 -0700
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, 25 Jun 1997     Volume: 8 Number: 665

Today's topics:
     Re: alphabetical sort? <rootbeer@teleport.com>
     Re: associative array I/O to file <jefpin@bergen.org>
     Re: associative array I/O to file <rootbeer@teleport.com>
     Re: associative array I/O to file (Eric Bohlman)
     Re: Checking a string for "@' and "." (Bob Wilkinson)
     Re: Client-Side Execution <keys@babylon5fan.corn>
     Exporting Variables... followup (Dean Burdick)
     Exporting Variables... (Dean Burdick)
     Re: Grade my first Perl Project (Nathan V. Patwardhan)
     Re: Magical Auto-increment operator <rootbeer@teleport.com>
     Re: NEWBIE Parsing question <rootbeer@teleport.com>
     Re: NEWBIE Parsing question (Eric Bohlman)
     Re: Obfuscation of Perl <rootbeer@teleport.com>
     Re: Pattern-matching when strings have embedded "$" <rootbeer@teleport.com>
     Re: Pattern-matching when strings have embedded "$" (Eric Bohlman)
     Re: Perl Tk Tutorial (Eric Bohlman)
     Please Disregard " NEWBIE Parsing question" <ashfield.matthew@miti.nb.ca>
     Re: Q: MacPerl, MacHTTP and CGI (Chris Nandor)
     Re: Regexps on streams <rootbeer@teleport.com>
     Re: Short Circuit Question <rootbeer@teleport.com>
     Re: Sorting names with accents <rootbeer@teleport.com>
     Stumped .... <saxena_arun@jpmorgan.com>
     Re: tarring a subdir as user nobody from perl <rootbeer@teleport.com>
     Re: Trouble installing perl5.002 <rootbeer@teleport.com>
     Re: use HTTP to get a dir? <rootbeer@teleport.com>
     Re: use HTTP to get a dir? (Eric Bohlman)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Jun 1997 19:21:56 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Robin Ittigson <ittigson@cats1.admin.pps.pgh.pa.us>
Subject: Re: alphabetical sort?
Message-Id: <Pine.GSO.3.96.970625192024.1822N-100000@kelly.teleport.com>

On 25 Jun 1997, Robin Ittigson wrote:

> i want the names in the files to be listed in alphabetical order.  i
> know perl has a sort function, but i'm not sure if it works like that. 

Do you think that the sort function might be in the documentation? :-) 
See perlfunc, which you can get by typing 'perldoc perlfunc' on many
machines. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 20:15:35 -0400
From: TechMaster Pinyan <jefpin@bergen.org>
To: John Grimm <john@edm.net>
Subject: Re: associative array I/O to file
Message-Id: <Pine.SGI.3.96.970625201310.21214A-100000@davinci.bergen.org>

>I am new to perl.  I have a cgi that collects from an HTML form about
>144 fields.  cgi-lib parses them into an associative array named $in. 
>How can I output the whole array at once, and read it in again for later
>use?

Cool... I use the same cgi-lib.pl...
Anyway:
you can do:
foreach $value (sort keys %in){
	print "$value - $in{$value}<br>\n";
}
that will print them all.
The can all be keyed by the name="WHATEVER" part of each form element.
i.e.:
	<input typ=text name=fubar>
	is keyed as
	$in{'fubar'}
	that gives you the value the user entered.

hope that helps!!! :)

----------------
| "Shooting is NOT too good for my enemies!"
| 	- "The Overlord List"
----------------
Jeff "TechMaster" Pinyan | http://www.bergen.org/~jefpin
HTML/CGI Designer and Consultant and JavaScripter
jefpin@bergen.org | TechMasterJeff@juno.com
Got a JavaScript/CGI/Perl question or problem?  Let me know!
webXS - the new eZine for WebProgrammers! webXS@juno.com
Visit us @ http://www.bergen.org/~jefpin/webXS



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

Date: Wed, 25 Jun 1997 18:36:33 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: John Grimm <john@edm.net>
Subject: Re: associative array I/O to file
Message-Id: <Pine.GSO.3.96.970625183551.1822I-100000@kelly.teleport.com>

On Wed, 25 Jun 1997, John Grimm wrote:

> I have a cgi that collects from an HTML form about 144 fields.  cgi-lib
> parses them into an associative array named $in. How can I output the
> whole array at once, and read it in again for later use? 

Use CGI.pm instead of cgi-lib, and it will let you do that with the
greatest of ease. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 26 Jun 1997 02:04:34 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: associative array I/O to file
Message-Id: <ebohlmanECD1rn.CuC@netcom.com>

John Grimm (john@edm.net) wrote:

: I am new to perl.  I have a cgi that collects from an HTML form about
: 144 fields.  cgi-lib parses them into an associative array named $in. 
: How can I output the whole array at once, and read it in again for later
: use?

We now call associative arrays hashes because it's easier to say and write.

In your documentation (that is, the *free* documentation that comes with 
every Perl distribution and that contains the equivalent of a 
college-level course in Perl programming), look up the "foreach" statement 
and the keys() function.  Once you do, you'll have a blinding flash of 
inspiration and the code you need will practically write itself.  You 
might also want to re-read the section on hashes.



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

Date: Tue, 24 Jun 1997 13:39:25 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: Checking a string for "@' and "."
Message-Id: <b.wilkinson-2406971339250001@ip57-york.pindar.co.uk>

In article <33ADE275.395B@nospam.mail>, deanh@iinet.net.au wrote:

> Hello,
> 
> Can anyone point me to the required code to check whether or not a
> string has BOTH the "@" and "." characters in it?
> 
> Using Perl 5.
> 
> Regards,
> 
> d.
> 
> 
> -- 
> +--------------------------------------------------------+
> | Dean Hollister,           | deanh@iinet.net.au         |
> | Region Co-Ordinator,      | dean@odyssey.apana.org.au* |
> | APANA,                    |                            |
> | Western Australia.        | *finger A/C for DISCLAIMER | 
> +--------------------------------------------------------+
> ST:VOY Kess: "I wish people would stop talking to me as if
>               I'm still a child! I'm three years old now!"

Hello,

      This program shows how to do what you want.

Bob

#!/usr/local/bin/perl -w
use strict;
while (<DATA>) {
        print STDERR if ((/\./) and (/@/));
}
__END__
This is a line with a . in it
This is a line with both a . and a @ in it
This is a line with only a @ and no dot
This is a line with neither

-- 
Do what thou wilt shall be the whole of the law.


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

Date: Wed, 25 Jun 1997 12:42:05 -0600
From: Keys <keys@babylon5fan.corn>
Subject: Re: Client-Side Execution
Message-Id: <33B1667D.91E0F991@babylon5fan.corn>

Eric Zimmerman wrote:
> 
> I'm using the CGI.pm as a server-side library to interpret forms input.
> From my CGI server-side script, I am now interested in "calling" /
> "launching" an executable program that resides on the hard-drive of
> the browser client that kicked-off my CGI script.

It sounds like you want ActiveX, Java, JavaScript, or VBScript...  but
there are massive security implications to executing proggys on client
computers...  IE allowed that and it was exploited.

> 
> I've heard rumblings that Libwww-perl might be able to do this, but
> I'm not sure if my request is do-able, without going to a client-side
> language such as JAVA.  I'd love to stay with Perl 5 if possible.

Perl won't do it unless the client has Perl and you have some other way
(one of the above 4 suggestions) of force-downloading a perl script and
executing it with the Perl executable on the remote computer.
-- 
Keys
Spam sucks.  To reply, please change "corn" to "com" in my return
address...


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

Date: 26 Jun 1997 01:04:53 GMT
From: burdick@fcs.netguard.net (Dean Burdick)
Subject: Exporting Variables... followup
Message-Id: <5osf7l$cbk$2@news.savvis.com>

I left out a couple of things...

should read:  package MyPackage;
		use Exporter ();
		@ISA = qw(Exporter);
Thanks again.



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

Date: 26 Jun 1997 01:00:47 GMT
From: burdick@fcs.netguard.net (Dean Burdick)
Subject: Exporting Variables...
Message-Id: <5osevv$cbk$1@news.savvis.com>

Hello all,

	I have a written a module whose only task is to export
	variables to whoever may want them.  I used the example
	in "Programming Perl" 2nd Ed. as an example and it works
	fine.  I am however, trying to do it another way but it
	is not working.  From the example, I found that you must
	create a hash of tags if you wish to use the "tags" method.
	
	Instead of using the method in the book, I tried this:

	package MyPackage;
	use Exporter
	push @tags, 'tag1';
	@tag1 = (
		'$var1' => 'val1',
		'$var2' => 'val2'
	);

	push @tags, 'tag2';
	@tag2 = (
		'$my_var1' => 'my_val1',
		'$my_var2' => 'my_val2'
	);

	for $tag (@tags) {
		eval "\@vars = \@$tag";
		my @array;
		while (@vars) {
			my $var =  shift @vars;
			my $val =  shift @vars;
			eval "\$var = \"$val\"";
			push @array, $var;
		}
		$EXPORT_TAGS{$tag} = [ @array ];
	}
	Exporter::export_ok_tags(@tags);


And in the other module:

	use MyPackage qw(:tag1);
	bla bla bla.....

Can anyone tell me why this doesnt work?  I get an error under use strict
telling me that I need a package specifier for global variable $var1, so
it isn't getting imported.
I have used the debugger and all the data seems to in order.

Thanks in advance.
Dean Burdick.


	



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

Date: 26 Jun 1997 00:29:33 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Grade my first Perl Project
Message-Id: <5osd5d$1pr@fridge-nf0.shore.net>

Raymond Simmons (rsimmons@interface-designers.com) wrote:

: > BTW: comp.lang.perl no longer exists.
: What do you mean it no longer exists?

It means that it should be removed from your newsfeed's active file.
Someone told me (about two weeks ago) that their site still carried
comp.lang.perl, but it should not be so.  Wonder how many people are
still feeding it to and fro?

--
Nathan V. Patwardhan
nvp@shore.net



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

Date: Wed, 25 Jun 1997 18:27:53 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Rob Perelman <robp@electriciti.com>
Subject: Re: Magical Auto-increment operator
Message-Id: <Pine.GSO.3.96.970625180836.1822G-100000@kelly.teleport.com>

On Wed, 25 Jun 1997, Rob Perelman wrote:

> Personally, I'd take the performance hit to make sure the argument is a
> number so that '.' would be able to incrementing to '..' and not 1 as
> well as '..e1' incrementing to '..e2' instead of 1.  I can definitely be
> flexible on this, but I think the overhead for checking more than the
> first digit is worth it to be able to have strange strings being
> magically incremented. 

Well, either this different kind of magical auto-increment will make its
way into the core or it could be made into a module. If it goes in the
core, efficiency becomes an issue; we don't want to slow down everybody
else's code just to add this variation on a feature.

On the other hand, if you make it a module, you can do whatever you want,
and who cares! :-)

>From here on out, I'm going to assume that this is destined for a module,
since that way I won't have to keep complaining about how bad a change to
the core would be. :-)  

> The code I have written allows '#' to be incremented to '##',

Now, I'm trying to be open minded, but what good could that possibly do
for anyone? If you increment it five more times does it become '#######'?
That's too weird. 

> I say 'a1z9' should [increment to] 'a2a0' while Perl says 1.  I don't
> think I've gotten your comments on this case.

If you have a set of consistent rules and you follow them, that's fine.

> As for 'cats 12', I believe you agreed it should be incremented
> automagically to 'cats 13' instead of 1, but I am not positive. 

Sure; once again, consistent rules make the world go round, or something
like that. On the other hand, '12 cats' has to become numeric 13, or
you're doing something different than somebody will expect.

> And demonstrating the multi-character numeric check, I think '..e1' and
> '.' should be incremented to '..e2' and '..' respectively, but the
> one-character numeric check increments those to 1. 

Well, you see the difficulties and inefficiencies. But, hey, it's your
module. 

Will you include support for automagically generating ranges like
('cats'..$dogs)? This is a bigger can of worms... :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 17:50:51 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: mashfiel <ashfield.matthew@miti.nb.ca>
Subject: Re: NEWBIE Parsing question
Message-Id: <Pine.GSO.3.96.970625174841.1822C-100000@kelly.teleport.com>

On 25 Jun 1997, mashfiel wrote:

> Basically I have a text file with 5 varying-lenght columns of numerical
> data. Just wondering if anybody could give me a hint as to how I would
> parse this file?

I bet your columns are of varying width, rather than varying length. Well,
if my guess is right, and maybe if it's wrong, you can simply use split to
break up the line into fields. split is documented in perlfunc. 

	@fields = split /\s+/, $line;

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 26 Jun 1997 01:44:58 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: NEWBIE Parsing question
Message-Id: <ebohlmanECD0uz.9wC@netcom.com>

mashfiel (ashfield.matthew@miti.nb.ca) wrote:
: Hi, sorry if this so very basic, but just thought I'd check here first. I
: am new to the PERL environment and am learning it because I need a language
: that handles parsing rather easily. Basically I have a text file with 5
: varying-lenght columns of numerical data. Just wondering if anybody could
: give me a hint as to how I would parse this file? Note: There are 600 rows
: contained within it. Anyway, anybody who has any friendly help/advice, I'd
: very much appreciate hearing from you preferably via email at
: ashfield.matthew@miti.nb.ca

You don't say how the variable-length columns are separated; the answer 
will depend on it.  If the file contains nothing but numerical data, then 
the split() function (see the perlfunc man page or HTML document, 
depending on what platform you're using) will probably do the trick for 
you.  If it's something more complicated (such as comma-separated and 
quoted data), go to http://www.dejanews.com and search the archives of 
this group for "CSV" or "comma-separated" and read what people have 
written on the subject (it's been beaten to death).




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

Date: Wed, 25 Jun 1997 19:19:53 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Matt Mankins <matt@dotshop.com>
Subject: Re: Obfuscation of Perl
Message-Id: <Pine.GSO.3.96.970625191654.1822M-100000@kelly.teleport.com>

On Wed, 25 Jun 1997, Matt Mankins wrote:

> Does anyone know of a script to obfuscate Perl scripts?

Hey, his name is Randal. Don't call him a script! :-)

Seriously, you don't want to do that to protect your programs; there are
better ways. And if somebody claims to have a program which does that,
Perl is so difficult to parse correctly that it almost certainly
mis-obfuscates some construct that could change the meaning of your
script, so you should use it only with great care. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 18:35:12 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Charles Packer <packer@fermi.gsfc.nasa.gov>
Subject: Re: Pattern-matching when strings have embedded "$"
Message-Id: <Pine.GSO.3.96.970625182851.1822H-100000@kelly.teleport.com>

On 25 Jun 1997, Charles Packer wrote:

> I have an array @whole in which each element is a line of text.
> I do pattern matching on the lines of text with expressions such
> as
> 
> 	if (@whole[$K] =~ @whole[$J])

Whoop! Whoop! You've got something funny going on there!

First off, you probably wanted to use dollar signs instead of @-signs
there, right? Perl will warn you about that if you turn on warnings.

Also importantly, Perl will have to recompile the regular expression (the
one on the right) every time it's used. That's going to slow things down a
lot if you do many matches.

> I've discovered that if these text lines have embedded dollar
> signs, such as "it cost $3.5 million", I don't get a match
> when the two strings are, in fact, identical. 

(And if you have a dot, as shown there, you could get a match when you
shouldn't. And if you (mis-)use any of half-a-dozen other characters, your
program will crash.) 

Well, if you only want to see whether they're identical, then don't use
regular expressions. Use the 'eq' string equality operator, like this.

	if ($whole[$K] eq $whole[$J]) { ... }

You'll be much happier because your code may run dozens of times faster,
and it will Do The Right Thing. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 26 Jun 1997 01:59:18 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Pattern-matching when strings have embedded "$"
Message-Id: <ebohlmanECD1Iv.Bz2@netcom.com>

Charles Packer (packer@fermi.gsfc.nasa.gov) wrote:

: I've discovered that if these text lines have embedded dollar
: signs, such as "it cost $3.5 million", I don't get a match
: when the two strings are, in fact, identical. I didn't find
: anything in the various Perl FAQs that addressed this question.
: I hope I don't have to create two temporary variables stripped
: of "$" to do the match, 'cause it would slow down my program, no?

You don't have to.  Look up the \Q metacharacter and the quotemeta() 
function, which are there to address exactly the problem you've encountered.



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

Date: Thu, 26 Jun 1997 02:09:46 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Perl Tk Tutorial
Message-Id: <ebohlmanECD20A.Dn9@netcom.com>

Alfred P. Bartholomai (freddyb@acsatlanta.com) wrote:
: Any one know of a good tutorial ? They have been hard to find. I have
: come across one, that was quite simplistic in nature.

: Any books yet on Perl Tk ?

Eric Foster-Johnson's book on cross-platform programming with Perl (not 
sure that's the exact title, but it's close) has at least one chapter on 
PerlTk.







: -- 
: Alfred P. Bartholomai
: Advanced Control Systems
: Norcross, GA 30092

: 770 446 8854
: 770 448 0957 ( fax )

: fred.bartholomai@acsatlanta.com
: ... it is better to light a candle than curse the darkness ...


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

Date: 25 Jun 1997 19:20:50 GMT
From: "mashfiel" <ashfield.matthew@miti.nb.ca>
Subject: Please Disregard " NEWBIE Parsing question"
Message-Id: <01bc80cd$00e83440$3e080a0a@mashfiel.miti.nb.ca>

Just thought I'd apologize for posting such a simple question. I have found
a ton of info out on the web that has answered my question and further ones
a million times over. Once again, sorry for the post

Matt

mashfiel <ashfield.matthew@miti.nb.ca> wrote in article
<01bc809f$c4e61660$3e080a0a@mashfiel.miti.nb.ca>...
> Hi, sorry if this so very basic, but just thought I'd check here first. I
> am new to the PERL environment and am learning it because I need a
language
> that handles parsing rather easily. Basically I have a text file with 5
> varying-lenght columns of numerical data. Just wondering if anybody could
> give me a hint as to how I would parse this file? Note: There are 600
rows
> contained within it. Anyway, anybody who has any friendly help/advice,
I'd
> very much appreciate hearing from you preferably via email at
> ashfield.matthew@miti.nb.ca
> 
> Thanks for your time,
> 
> Matt
> ashfield.matthew@miti.nb.ca
> 


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

Date: Wed, 25 Jun 1997 18:26:18 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Q: MacPerl, MacHTTP and CGI
Message-Id: <pudge-ya02408000R2506971826190001@news.idt.net>

In article <Pine.ULT.3.96.970624234740.6642A-100000@venus>, Mousheng Xu
<mxu@eecs.ukans.edu> wrote:

#         1. What is the difference of "MacPerl" and UNIX perl? As I posted
# in the newsgroup;

The MacPerl FAQ can also help.  It is in CPAN.

But as to the specific difference, MacPerl can run a script without any
shebang line; but "#!perl" is good to have (MacPerl likes to know for sure
it is a perl script, and that lines tells it).  But having
#!/usr/local/bin/perl or something similar is just as good.


#         2. what should I do to the perl scripts? Should I run and save it
# as another file in another format or just leave it? 

With the full MacPerl distribution from CPAN, you should have received a
CGI Script extension.  If not, go get the distribution again or look around
at the various MacPerl FTP sites and CPAN.  Save it as a "CGI Script" in
the Save As ... dialog box.

--
Chris Nandor                 pudge@pobox.com                 http://pudge.net/
%PGPKey=('B76E72AD',[1024,'08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6'])


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

Date: Wed, 25 Jun 1997 19:15:39 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: Regexps on streams
Message-Id: <Pine.GSO.3.96.970625190511.1822L-100000@kelly.teleport.com>

On 25 Jun 1997, Ilya Zakharevich wrote:

> > Yes, and some regular expressions would require loading the entire stream
> > into memory to search efficiently.
> > 
> >      /(\b\w+\b).*\b\1\b/s
> 
> Why would you need to load the whole stream for something like this?
> A tiny change to your regexp would make it
> 	
> 	/(\b\w+\b).*?\b\1\b/s
> 
> which is much better when stream-oriented (though may be much slower
> on "finished" strings).

I'm sure you know more about this than I do, Ilya, but I think that either
your expression or mine will be very slow if if the implementation doesn't
keep the string in memory. I imagine that it picks a word near the
beginning, searches for a matching one (through the _entire_ string) then,
if that one fails to match it has to pick another word from the beginning
and search the entire string again. Unless it finds a match early on, it's
going to be reading the same chunk of disk again and again, isn't it? 

Also, wouldn't it have to be done with (implicit) scratch files, since the
stream may actually be a non-seekable source? Not that that would stop
you from implementing it... :-)

And could you (would you?) also implement this?

    STREAM =~ s#(\b\w+\b)(.*)\b\1\b#<BOLD>$1</BOLD>$2<BOLD>$1</BOLD>#sg;

Now I'm starting to scare myself. :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 19:01:27 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Craig M. Votava" <craig@lucent.com>
Subject: Re: Short Circuit Question
Message-Id: <Pine.GSO.3.96.970625183701.1822J-100000@kelly.teleport.com>

On Wed, 25 Jun 1997, Craig M. Votava wrote:

> open(FILE, "somefile") || die "Cannot open somefile: $!\n" && return;

Whoops! Once a die happens, your program is done. Finished. It is an
ex-process. It is no more. It has joined the Core Celestial. It is pushing
up daisies. It is...  Well, you get the idea. Dead is dead. 

But if you want to return if that open was successful, that's easy. Just
return after the open, like this.

	open FILE, "somefile"
	    or die "Can't open somefile: $!";
	return;

> So it seems that only the last command in the "and" series gets
> executed, and the intermediate ones just print out their return codes?

No; what happens is the perl does the first part of a short-circuit
operator, then it does the second only if that's necessary. Either way,
it returns the last (sub-)expression evaluated. Let's see it in action. 

> open(FILE, "/nodirectory/place") ||
>         print "first\n" && print "second\n" &&
>         print "third\n" && print "forth\n";

> Aha! This prints out:

> forth
> 111

Let's see what's happening here. A quick check in the precedence chart
shows that Perl will see this as something like this, if I'm not mistaken. 
(And I might be; precedence can be a hard nut to crack.) 

	open(FILE, "/nodirectory/place")
	||
	print ("first\n" && 
	    print("second\n" &&
		print("third\n" &&
		    print "forth\n";		# Not perl? :-)
		)
	    )
	)

So, perl has to evaluate the ||, and its first part is the open, which
returns false. But maybe the second part will be true, so perl has to go
on and use that as the value. (Which will be discarded.)

Now perl needs to get the arguments for print. (The first one.) There's
one argument, which is the result of &&. The first half of that operation
is "first\n", which is true. But maybe the second part will be false, so
perl has to go on and use that as the value. 

  Now perl needs to get the arguments for print. (The second one.) There's
  one argument, which is the result of &&. The first half of that
  operation is "second\n", which is true. So perl has to go on and use
  the second part as the value.

    Now perl needs to get the arguments for print. (The third one.) 
    There's one argument, which is the result of &&. The first half of
    that operation is "third\n", which is true. So perl has to go on and
    use the second part as the value. 

      Now perl needs to get the arguments for print. (The fourth one.) 
      There's one argument, the name of somebody else's programming
      language, which is printed. 

    The value returned from print was one, so print can print that and
    return its success value. 

  The value returned from print was one, so print can print that and
  return its success value. 

The value returned from print was one, so print can print that and return
its success value. (Which will be discarded.)

So it looks like Perl is doing the right thing: If the first half of an
and is true (or if the first half of an or is false), evaluate the second
half; either way, return the last subexpression evaluated.

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/




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

Date: Wed, 25 Jun 1997 18:01:58 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Georges Martineau <martig@cam.org>
Subject: Re: Sorting names with accents
Message-Id: <Pine.GSO.3.96.970625175226.1822D-100000@kelly.teleport.com>

On 25 Jun 1997, Georges Martineau wrote:

> Is it possible to sort the following names:
>   Manon, M=E9lissa, Micheline, John, M=E9lanie

Sure is. If you have support for a locale that has the proper collation
order, just install 5.004 and see what the perllocale manpage tells you.

Alternatively, there are some modules which offer collation methods.

And as a final method, if neither of the others works, it's really a
special case of sorting on a computed key, so you could use the
Schwartzian Transform, something like this.=20

    @sorted =3D
=09map  { $_->[0] }
=09sort { $a->[1] cmp $b->[1]  or  $a->[0] cmp $b->[0] }
=09map  { [ $_, &munge($_) ] }
=09@my_list;

    sub munge {
=09# Converts a string to a "standardized" form, making
=09# letters lower case and unaccented.
=09local($_) =3D @_;
=09tr
=09    {A-Z=E9}=09=09# Include any others which you need
=09    {a-ze}=09=09# and their equivalents here
=09;
=09$_;=09=09=09# Return value
    }

Hope this helps!

--=20
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 20:46:56 -0400
From: Arun Saxena <saxena_arun@jpmorgan.com>
Subject: Stumped ....
Message-Id: <33B1BC00.7C1F@jpmorgan.com>

-- 





Folks, 

This is what I am trying to do ..... Replace the following
text 

	 kkkk     d;ckdk  ;dkckd kkk   k    kd
	ddk      dkd   dkkdk     dkkd
	kkdk kddd kkk d      kkk

with 

	kkkk\5 d:ckdk   ;dkckd  kkk\7 k\8 kd
	...

( Basicall replace 4 or more spaces w "\<cnt # of spaces> "
 I am having one hell of a time with this. I would think the 
following would work, but it does not 

	s/(\s{4,})/join (\s, \ length$1)/eg

Please also email me any suggestions...


Arun

saxena_arun@jpmorgan.com


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

Date: Wed, 25 Jun 1997 18:06:56 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Richard Li <r.li@srs.gov>
Subject: Re: tarring a subdir as user nobody from perl
Message-Id: <Pine.GSO.3.96.970625180633.1822F-100000@kelly.teleport.com>

On 25 Jun 1997, Richard Li wrote:

> i suspect that the reason why the exact same code doesn't work in the
> cgi is because i am user nobody.

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to
solving such problems. It's available on the perl.com web pages. Hope
this helps!

   http://www.perl.com/perl/
   http://www.perl.com/perl/faq/
   http://www.perl.com/perl/faq/idiots-guide.html

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 19:03:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Brett Terry <bterry@burnettgroup.com>
Subject: Re: Trouble installing perl5.002
Message-Id: <Pine.GSO.3.96.970625190226.1822K-100000@kelly.teleport.com>

On 25 Jun 1997, Brett Terry wrote:

Newsgroups: comp.lang.perl

If your news administrator still carries comp.lang.perl, please encourage
him or her to check out the frequent posting about bogus newsgroup names
in news.announce.newgroups. You'll be doing yourself and many others a
favor to use comp.lang.perl.misc (and other valid Perl newsgroups)
instead.

    news:news.announce.newgroups

> I ran into trouble trying to install perl 5.002 on a Netra (Sparc 5)
> running Solaris 2.4 (64MB Ram, enough hard disk space) 

That's okay; you should be installing 5.004 instead. :-)  Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Wed, 25 Jun 1997 18:05:15 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Shawn Laemmrich <swlaemmr@mtu.edu>
Subject: Re: use HTTP to get a dir?
Message-Id: <Pine.GSO.3.96.970625180221.1822E-100000@kelly.teleport.com>

On 25 Jun 1997, Shawn Laemmrich wrote:

> I'm wondering if anyone has some perl (or anything else for that matter)
> code to go to a web site and get the contents of a directory, like so:
> 
> http_get www.blah.com/pub/files
> 
> and have it get everything in the dir.

Yes, and it's in the LWP module on CPAN. You should know, though, that the
webserver may have items whose names you don't know, and it isn't obliged
to give you any of those. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 26 Jun 1997 01:57:14 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: use HTTP to get a dir?
Message-Id: <ebohlmanECD1FE.BLz@netcom.com>

Shawn Laemmrich (swlaemmr@mtu.edu) wrote:

: I'm wondering if anyone has some perl (or anything else for that matter)
: code to go to a web site and get the contents of a directory, like so:

: http_get www.blah.com/pub/files

: and have it get everything in the dir.

Whether you can do this or not depends *entirely* on how the server at 
that site is configured to deal with directory requests.  Some sites will 
have the server cobble up an HTML document containing links to the 
various items in the directory; others will send out a default page.  The 
important thing to remember is that HTTP by itself does *not* give you 
access to directories, only to URLs (which are *not* filenames, no matter 
how much they may resemble them).

The LWP module is very useful when writing Perl code to access remote 
HTTP servers.  You might want to take a look at Clinton Wong's _Web 
Client Programming with Perl_ (O'Reilly, 1997).

 


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

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

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