[17895] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 55 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 13 06:05:35 2001

Date: Sat, 13 Jan 2001 03:05:11 -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: <979383910-v10-i55@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 13 Jan 2001     Volume: 10 Number: 55

Today's topics:
    Re: $CGI::POST_MAX query fudokai@my-deja.com
    Re: Ada feature borrowed for Perl?? <bart.lateur@skynet.be>
    Re: Delay in accessing web pages on intranet. Looking f <rick.delaney@home.com>
    Re: FAQ 8.37:   How do I make my program run with sh an <johnlin@chttl.com.tw>
    Re: File open problem <rick.delaney@home.com>
    Re: How do I connect to a remote cgi-bin program and se <rick.delaney@home.com>
    Re: How do I connect to a remote cgi-bin program and se <jbritain@home.com>
    Re: Jobs: Senior Software Engineer <mischief@velma.motion.net>
    Re: Jobs: Senior Software Engineer (Randal L. Schwartz)
    Re: Jobs: Senior Software Engineer (Abigail)
    Re: left op of && and || only in scalar context ? <johnlin@chttl.com.tw>
    Re: left op of && and || only in scalar context ? <joe+usenet@sunstarsys.com>
    Re: match from the end or match the last <johnlin@chttl.com.tw>
    Re: Need help with 5.6.0 <randy@theory.uwinnipeg.ca>
    Re: Problem with while loop regexp? <mischief@velma.motion.net>
    Re: Problem with while loop regexp? <rick.delaney@home.com>
    Re: Problem with while loop regexp? (Martien Verbruggen)
    Re: References <johngros.NOSPAM@bigpond.net.au>
    Re: References <johngros.NOSPAM@bigpond.net.au>
    Re: References <joe+usenet@sunstarsys.com>
    Re: References <johngros.NOSPAM@bigpond.net.au>
    Re: regex puzzler <krahnj@acm.org>
        RegExp substitution w/Array Dereference <baldheadedjohn@SpamAnyone?newsguy.com>
    Re: RegExp substitution w/Array Dereference <johngros.NOSPAM@bigpond.net.au>
    Re: Returning a filename from FILEHANDLE <rick.delaney@home.com>
    Re: Returning a filename from FILEHANDLE <mischief@velma.motion.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 13 Jan 2001 08:53:15 GMT
From: fudokai@my-deja.com
Subject: Re: $CGI::POST_MAX query
Message-Id: <93p51q$4gq$1@nnrp1.deja.com>

In article <93n6vp$eog$1@nnrp1.deja.com>,
  dtbaker_dejanews@my-deja.com wrote:
> In article <93n1hb$9qn$1@nnrp1.deja.com>,
>   fudokai@my-deja.com wrote:
> > I'm putting together a Perl CGI script to be installed on my ISP.
> Since users
> > will be able to post messages I want to provide what DOS protection I
> can.
> > I've found docs stating that setting $CGI::POST_MAX to a value limits
> the max
> > size of a posting.
> ----------------------------
>
> I found a bug in older versions of this... it didnt catch oversize
> postings for me either. you have a choice of fixing the source of CGI.pm
> or when you write the uploaded file you can count the bytes your self as
> you save it, and die if you hit your limit.
>
> I posted an example of this a couple weeks ago in an example of
> uploading image files. Try dejanews search for subject containing
> "solution" and "upload" .
>
> D
>
> Sent via Deja.com
> http://www.deja.com/
>

Thanx - i'll check it out. I ought to be on a pretty recent version of perl /
cgi (SuSE 7.0 + latest downloads), tho' GOK what my isp is on. Sorry about
the messy posting - i _did_ preview it in deja and it looked fine in the
preview - line breaks where they should be - i guess deja has problems with
*nix/dos newlines - Alan


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


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

Date: Sat, 13 Jan 2001 10:27:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ada feature borrowed for Perl??
Message-Id: <f1b06tclhlgutv3pvj8jbspgtg0m10tcji@4ax.com>

Abigail wrote:

>While I do use elsif, I don't use it too often. For me, "elsif" is 
>just a shorthand for "else if", and in other languages, I try to 
>avoid to many nested ifs.

On the contrary. To me, it's not nested at all: "elsif" is a
short-circuiting variation on "else if". All "elsif"'s are on the same
nesting level.

If anything, "elsif" is the closest thing that Perl has to a select case
/switch construct. It's just that the condition is always explicit, and
not partly integrated in the value that you switch on.


	if($a == 3) {
	    # $a is three
	} elsif($a == 4) {
	    # $a is four
	} elsif($a == 5) {
	    # $a is five
	} else {
	    # default
	}

is much the same as, in extended BASIC:

	select case a
	   case 3
	      ...
	   case 4
	      ...
	   case 5
	      ...
	   default
	      ...
	end select


>OTOH, I don't shy away from chained ?:'s
>and that isn't any better than elsif.

Now, that IS a nested construct. It's just that you don't have to
explicitely close the subparts.

-- 
	Bart.


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

Date: Sat, 13 Jan 2001 05:23:23 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Delay in accessing web pages on intranet. Looking for reasons...
Message-Id: <3A5FEA28.B82C21E1@home.com>


FDShah wrote:
> 
> Does anybody know why there's such a long delay when I access my web pages in
> the root directory of PWS using http://mycomputername/myfilename?

Whatever the reason, it has nothing to do with Perl.  Perhaps there is a
better group to ask this in.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 13 Jan 2001 13:37:14 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: FAQ 8.37:   How do I make my program run with sh and csh?
Message-Id: <93opm0$8dn@netnews.hinet.net>

>   How do I make my program run with sh and csh?
>
>     See the eg/nih script (part of the perl source distribution).

Well, the eg/nih (qouted below) doesn't seem to answer this question.


eval 'exec /usr/bin/perl -Spi.bak $0 ${1+"$@"}'
 if $running_under_some_shell;

# $RCSfile: nih,v $$Revision: 4.1 $$Date: 92/08/07 17:20:27 $

# This script makes #! scripts directly executable on machines that don't
# support #!.  It edits in place any scripts mentioned on the command line.

s[^#!(.*)]
 [#!$1\neval 'exec $1 -S \$0 \${1+"\$@"}'\n\tif \$running_under_some_shell;]
 if $. == 1;


Best regards.

John Lin





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

Date: Sat, 13 Jan 2001 05:41:24 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: File open problem
Message-Id: <3A5FEE61.F36B431F@home.com>


Kai Jang wrote:
> 
> The problem I am having is with the second part of the
> program. 

We can't see that part from here.

> I want it to open the files and serch through them and rename
> any links to reflect the changes.  I tried a global subistitution using
> a regular expression, but to no avail.  

Please post the specific part of the code that is not doing what you
expect and explain what it is that you do expect.

> Maybe I am going about it wrong.  How would you guys aproach this 
> problem?

Global substitution sounds ok to me.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 13 Jan 2001 05:21:09 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: How do I connect to a remote cgi-bin program and send it the form  data from within my perl script?
Message-Id: <3A5FE9A1.ECBAE4C7@home.com>

[posted & mailed]

Merlin wrote:
> 
> I'm trying to discover how I can send data from a web page, that is passed
> back to my perl script,  to a remote cgi-bin program that expects it.
> I know how a FORM does it from a web page of course, but how to I do the
> same thing from within a perl script.

I don't know how a FORM does it from a web page.  Presumably it sends
text in HTTP protocol to a web server which launches the script.  If
that's what you want you may want to look into the LWP modules.

Or you may just want one of the many functions to call external
programs:  system, exec, open, qx//, do, etc.
 
> do makepayment {
> ....
> ....
> ...
> }
> 
> sort of thing?

Not sure what that's supposed to be.  Using do() to call subroutines was
deprecated a long time ago.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 13 Jan 2001 08:03:14 GMT
From: Jim Britain <jbritain@home.com>
Subject: Re: How do I connect to a remote cgi-bin program and send it the form data from within my perl script?
Message-Id: <8ApgOl6Ni4bzLtJRqqB17Loff1Sk@4ax.com>

[posted and mailed]
On Sat, 13 Jan 2001 14:21:38 +1000, "Merlin" <robert@chalmers.com.au>
wrote:

>I'm trying to discover how I can send data from a web page, that is passed
>back to my perl script,  to a remote cgi-bin program that expects it.
>I know how a FORM does it from a web page of course, but how to I do the
>same thing from within a perl script.

See: perldoc LWP
   and
     perldoc lwpcook

Print them out.

Now's your chance to learn some really neat and powerful prebuilt
tools.




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

Date: Sat, 13 Jan 2001 05:15:28 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <t5vp3gdb1d4obc@corp.supernews.com>

Alan Barclay <gorilla@elaine.furryape.com> wrote:
> In article <t5uf51mvut2i71@corp.supernews.com>,
> Chris Stith  <mischief@velma.motion.net> wrote:
>>If I were a recruiter wanting to make use of this newsgroup, I'd
>>use the group itself AS a resume. Even if I knew nothing of Perl,
>>I could go through and count how many answers a poster gave that
>>went uncorrected, and could, from the context of the posts around
>>a certain person's posts, figure out approximately how much experience
>>they have.

> That doesn't sound terribly reliable. By your method, Larry Wall has
> no experience in Perl, because he never posts here. 

Note I said `wanting to make use of this newsgroup', not that it
is the most reliable method. If Larry never posts here, he probably
never reads here and therefore wouldn't see a rude job offering
post either. Whether or not any of us could afford to hire
Larry as a Perl programmer is beyond the scope of this post. ;)

On the other hand, Tom C., Randal S., Ilya Z., Mark Jason D., and
others do post here. I couldn't offer any of them enough money,
either, but they do participate in the group and therefore
could be considered part of the target market for recruiting
from this group. I'd say they each have plenty of Perl experience.

Based on what I read in the group, there are others I'd rank up with
those mentioned earlier or just below when considering on whom to
spend my imaginary personnel budget. There are even reasons I'd
consider taking someone else over a couple of the people listed
above which stem from reading this group. I have nothing against
any of the people listed above, but I'm not sure if I'd rather
choose someone who knows the most or someone who knows a bit less
and is especially willing and able to teach what they know. One
magnificent programmer is great and cool. Two damn good programmers
cover your ass if one is sick. 

Chris

-- 
Christopher E. Stith

Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: 12 Jan 2001 22:05:52 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <m1vgrkq94v.fsf@halfdome.holdit.com>

>>>>> "Jon" == Jon Bell <jtbell@presby.edu> writes:

>> If anything, you'll be told "it should be misc.jobs.offered.perl", and
>> then they'll wonder why Perl is so special that people can't simply
>> grep for "perl" in misc.jobs.offered.

Jon> They can't do that any more (grep through misc.jobs.offered).  That group
Jon> has been voted out of existence, 170 to 14, as announced in
Jon> news.announce.newgroups on 28 November 2000.  For the RFD and CFV, see

Jon> <ftp://ftp.isc.org/pub.usenet/news.announce.newgroups/misc/misc.jobs.offered>

Jon> and scroll down a ways.

Jon> There *is* a misc.jobs.fields hierarchy with subgroups (so far) for
Jon> chemistry and legal jobs.  Maybe misc.jobs.fields.programming.perl?

See what happens when I'm not subscribed to news.admin.announce?

Thanks for the pointer.  Terrance... now's your chance!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 13 Jan 2001 09:06:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Jobs: Senior Software Engineer
Message-Id: <slrn9606jq.f3e.abigail@tsathoggua.rlyeh.net>

Chris Stith (mischief@velma.motion.net) wrote on MMDCXCII September
MCMXCIII in <URL:news:t5vp3gdb1d4obc@corp.supernews.com>:
|| 
|| On the other hand, Tom C., Randal S., Ilya Z., Mark Jason D., and
|| others do post here. I couldn't offer any of them enough money,
|| either, but they do participate in the group and therefore
|| could be considered part of the target market for recruiting
|| from this group. I'd say they each have plenty of Perl experience.


I post here as well. But I won't let myself be hired by someone who is
clueless. Posting job ads here shows cluelessness.



Abigail
-- 
BEGIN {$^H {q} = sub {$_ [1] =~ y/S-ZA-IK-O/q-tc-fe-m/d; $_ [1]}; $^H = 0x28100}
print "Just another PYTHON hacker\n";


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

Date: Sat, 13 Jan 2001 14:57:12 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: left op of && and || only in scalar context ?
Message-Id: <93oubs$eac@netnews.hinet.net>

"Anno Siegel" wrote
> When a chain of boolean operations is in list context,
> so is the last (and only the last) expression in the chain.  At
> least that's what some tests seem to show.  As you say, it makes
> no sense.

Do you mean:

my @a = ('a','b');
my @b = ('c','d','e');
my @c = ();

my @d = @a || @b || @c;
my @e = @c || @b || @a;
my @f = @c || localtime;

print "@d\n@e\n@f\n";

__END__
2
3
47 37 14 13 0 101 6 12 0


To me, the following answer makes more sense (more intuitive).

a b
c d e
47 37 14 13 0 101 6 12 0

And it would be hard to understand (seems contradictive) why
@f gets list result but @e gets scalar?

Maybe it's an excellent feature of Perl?

Thank you.

John Lin





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

Date: 13 Jan 2001 02:33:16 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: left op of && and || only in scalar context ?
Message-Id: <m3lmsf29fn.fsf@mumonkan.sunstarsys.com>

"John Lin" <johnlin@chttl.com.tw> writes:

> my @a = ('a','b');
> my @b = ('c','d','e');
> my @c = ();
> 
> my @d = @a || @b || @c;
> my @e = @c || @b || @a;
> my @f = @c || localtime;
>
 
[...snipped actual output...]

> To me, the following answer makes more sense (more intuitive).
> 
> a b
> c d e
> 47 37 14 13 0 101 6 12 0
> 

That's already doable, though; just replace: 

@a || @b -> @a ? @a : @b  (note the conservation of asymmetry :)

e.g.

@d = @a ? @a : @b ? @b : @c;
 ...


> And it would be hard to understand (seems contradictive) why
> @f gets list result but @e gets scalar?

Technically, @e gets a list containing a single (boolean) scalar.
That's not any more contradictory than

@e = 1;  # scalar in a list context, same as @e = (1);

> Maybe it's an excellent feature of Perl?

You bet- variety is the spice of life.

-- 
Joe Schaefer


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

Date: Sat, 13 Jan 2001 15:54:20 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: match from the end or match the last
Message-Id: <93p1mv$i9j@netnews.hinet.net>

"Martien Verbruggen" wrote

> I think the conclusions will be something like: reversing the string is
> the best general purpose way.

Ya!  Then we can develop a Schwartzian Transform:

$_ = 'good better best never let it lest';
s/.est/rest/b;    # /b is invented, not real

we can do it by [reverse - s// - reverse]  (like map - sort - map)

$_ = reverse;  s/tse./tser/;  $_ = reverse;


In other threads I ever talked about a NOT operation for qr// .
Now here comes another, the REVERSE operation for qr// .

My point is, for users who are not quite familiar with regular expressions
they might be unable to write accurately correct NOT or REVERSE regex.
If someone (or team) who has such complex brains that can master
regular expression very well would provide a module to manipulate regex
that would be very useful to the world.  Those operators would also be
valuable in theory.

Thank you.

John Lin





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

Date: Sat, 13 Jan 2001 00:54:48 -0600
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Need help with 5.6.0
Message-Id: <93ouep$blj$1@canopus.cc.umanitoba.ca>

"Rob" <a565a87@my-deja.com> wrote in
   message news:93nf6s$mv1$1@nnrp1.deja.com...
> I'm compiling 5.6.0 using MSVC 6.0 nmake.  After a few minutes, when it
> comes time for the build to link, I get this:
>
>      cd .. && miniperl minimod.pl > lib\ExtUtils\Miniperl.pm
>      The system cannot find the path specified.
>      NMAKE : fatal error U1077: 'cd' : return code '0x1'
>      Stop.
[ .. ]
> I'm brand new at perl, and I've never compiled it before.  (I'm only
> doing it because the Active State perl doesn't work with mod_perl,
> which I'd like to learn to use.)  Any advice?

Hi,
    I'm not sure what the problem might be, but if you're mainly
interested in just getting mod_perl, there's ppm packages
available through http://perl.apache.org/distributions.html that work
with Win32 ActivePerls based on perl-5.6 (builds 6xx).

best regards,
randy kobes





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

Date: Sat, 13 Jan 2001 05:30:38 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Problem with while loop regexp?
Message-Id: <t5vpvujfhf8600@corp.supernews.com>

Gary K. Nitzberg <gknitz@nitzspace.com> wrote:


> I am using Perl 5.6.0 and I was expecting the code below to go through the
> while loop only once.  But the while loop executes twice. It appears that
> once I do the substitution the regexp starts over at the beginning.   Why
> does it go through the loop twice?   Thanks.

I'm not sure you should change a pattern while using /go on it.
If you really only want to do things once, why not use if()
instead of while()?

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

> use strict;
> use File::Basename;

> my $data   = q(<IMG SRC="/images/picture.gif">);


> while ($data =~ /<IMG SRC=["'](.*?)["']/igos) {
>     my $href = $1;
>     my $file = basename($href);

>     $data =~ s/<IMG SRC=\"$href\"/<IMG SRC="$file"/igos;
>     print "IMAGE: $href, DATA: $data\n";
> }
> -----------------------------------------------------------------------

Chris

-- 
Christopher E. Stith

Programming is a tool. A tool is neither good nor evil. It is
the user who determines how it is used and to what ends.



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

Date: Sat, 13 Jan 2001 05:36:54 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Problem with while loop regexp?
Message-Id: <3A5FED53.A7C46317@home.com>

[posted & mailed]

"Gary K. Nitzberg" wrote:
> 
> Why does it go through the loop twice?

Because the substitution resets pos($data).

> #!/usr/local/bin/perl
> 
> use strict;
> use File::Basename;
> 
> my $data   = q(<IMG SRC="/images/picture.gif">);
> 
> while ($data =~ /<IMG SRC=["'](.*?)["']/igos) {

The /o modifier is doing nothing here.

>     my $href = $1;
>     my $file = basename($href);
> 
>     $data =~ s/<IMG SRC=\"$href\"/<IMG SRC="$file"/igos;

Here /o is probably wrong unless you only want to change the paths for
the one image only.  See perlfaq6:

    What is /o really for?

>     print "IMAGE: $href, DATA: $data\n";
> }

Instead of performing a substitution when the match succeeds you could
just combine the two operations:

$data =~ s/<IMG SRC=["'](.*?)["']/
             q(<IMG SRC=") . basename($1) . q(")
         /gsie;

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 13 Jan 2001 16:42:06 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Problem with while loop regexp?
Message-Id: <slrn95vqle.50v.mgjv@martien.heliotrope.home>

On Fri, 12 Jan 2001 20:06:12 -0800,
	Gary K. Nitzberg <gknitz@NitzSpace.com> wrote:
> 
> 
> I am using Perl 5.6.0 and I was expecting the code below to go through the
> while loop only once.  But the while loop executes twice. It appears that
> once I do the substitution the regexp starts over at the beginning.   Why
> does it go through the loop twice?   Thanks.

> #!/usr/local/bin/perl

no -w or use warnings. Bad.

> use strict;

strict!. Good :)

> use File::Basename;
> 
> my $data   = q(<IMG SRC="/images/picture.gif">);
> 
> while ($data =~ /<IMG SRC=["'](.*?)["']/igos) {

You shouldn't be using the /o modifier. You don't need it, since your RE
doesn't contain any variables. Using modifiers without reason is
slightly misleading. Also, the only thing the /s modifier will allow you
to do in this is to match file names that have newlines in them.

>     my $href = $1;
>     my $file = basename($href);
> 
>     $data =~ s/<IMG SRC=\"$href\"/<IMG SRC="$file"/igos;

With this replacement you change the position of the last match and all
kinds of other things. You shouldn't do that. You can't match a regular
expression inside of a loop like this, this way.

The perlop documentation talks a bit about what /g does, and how it
should be used. I'm not certain whether it actually wanrs you not to use
nested /g modifiers with different regular expressions against the same
string.

>     print "IMAGE: $href, DATA: $data\n";

I believe that your intent is to replace every href with only its
basename part? You should be able to do this with a single s///ge. One
way to do that:

s/(<IMG SRC=["'])(.*?)(["'])/$1.basename($2).$3/ieg;

You need the /e modifier. If you don't like all that capturing:

s/(?<=<IMG SRC=["'])(.*?)(?=["'])/basename($1)/ieg;

The perlre documentation explains the look-ahead and look-behind
assertions.

Oh, I forgot the standard disclaimer: If this is HTML you are parsing,
you should probably consider using a full parser, instead of regular
expressions. Also: None of the above is flexible enough to allow certain
valid constructs in HTML, like:

<IMG
SRC="/foo/bar.gif">

You probably want something like \s+ instead of a single space. I also
believe, but am not certain, that HTML allows spacing in other places
there. I am certain that the following is valid as well, and you won't
catch it:

<IMG width=12 height=12 src="/foo/tiny.gif">

If you are certain you don't have to deal with these cases, use the RE.
Otherwise, I suggest you use a parser.

And many others.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Sat, 13 Jan 2001 05:25:39 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: References
Message-Id: <nFR76.57714$xW4.465577@news-server.bigpond.net.au>


"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote in message
news:PsR76.57700$xW4.465562@news-server.bigpond.net.au...
> Now I am calling add(topleftcell,$i) using a regex to check if cell is in
Sorry the call is add('topleftcell',$i).





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

Date: Sat, 13 Jan 2001 05:49:59 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: References
Message-Id: <b0S76.57734$xW4.466037@news-server.bigpond.net.au>


"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote in message
news:PsR76.57700$xW4.465562@news-server.bigpond.net.au...
>   $array = "\\@cell";
>  }
>  if (/old/){
>   $array = "\\@old";
>  }
>  if (/mask/){
>   $array = "\\@mask";
>  }
>  if (defined($_[2])){
>   $array[$xaxis[$_[2]] + $modx][$yaxis[$_[2]] + $ mody] =
> $array[$xaxis[$_[2]] + $modx][$yaxis[$_[2]] + $ mody] + $_[1];
>  }else{
>   $array[$xaxis + $modx][$yaxis + $mody] = $array[$xaxis + $modx][$yaxis +
> $mody] + $_[1];
>  }
> }
Having found the solution I don't understand how my first subs worked.
I should have been using $array->[$xaxis][$yaxis].




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

Date: 13 Jan 2001 01:04:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: References
Message-Id: <m3u2740yyq.fsf@mumonkan.sunstarsys.com>

"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> writes:

> "John Boy Walton" <johngros.NOSPAM@bigpond.net.au> wrote in message
> news:PsR76.57700$xW4.465562@news-server.bigpond.net.au...
> >   $array = "\\@cell";
       ^^^^^^^^^^^
Don't you want 

$array_ref = \@cell;

here?

> >  }
> >  if (/old/){
> >   $array = "\\@old";

$array_ref = \@old;

> >  }
> >  if (/mask/){
> >   $array = "\\@mask";

$array_ref = \@mask;

> >  }
> >  if (defined($_[2])){
> >   $array[$xaxis[$_[2]] + $modx][$yaxis[$_[2]] + $ mody] =
> > $array[$xaxis[$_[2]] + $modx][$yaxis[$_[2]] + $ mody] + $_[1];
> >  }else{
> >   $array[$xaxis + $modx][$yaxis + $mody] = $array[$xaxis + $modx][$yaxis +
> > $mody] + $_[1];
> >  }
> > }
> Having found the solution I don't understand how my first subs worked.
> I should have been using $array->[$xaxis][$yaxis].

$array_ref->[$xaxis][$yaxis]

is perhaps a better choice.

btw - are "xaxis" and "yaxis" scalars or arrays? Also, did you 

use strict;

?

-- 
Joe Schaefer


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

Date: Sat, 13 Jan 2001 09:02:08 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: References
Message-Id: <kQU76.58266$xW4.467307@news-server.bigpond.net.au>


"Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
news:m3u2740yyq.fsf@mumonkan.sunstarsys.com...
> "John Boy Walton" <johngros.NOSPAM@bigpond.net.au> writes:
> > >   $array = "\\@cell";
>        ^^^^^^^^^^^
> Don't you want
>
> $array_ref = \@cell;
>
> here?
Yes I fixed that too.
> btw - are "xaxis" and "yaxis" scalars or arrays? Also, did you
>
> use strict;
xaxis and yaxis are both arrays and scalars.
I was trying to access them as arrays if an indice was passed to the sub and
as scalars if no indice was passed.
Yes I used strict.
The problem was not using the ref correctly.
But my previous subs used the same syntax and worked.
I thought I figured out the diff (the ref being passed to the sub instead of
created by the sub) but I was using $_[0][$xaxis][$yaxis] which is the same
as $array[$xaxis][$yaxis] so I dunno.





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

Date: Sat, 13 Jan 2001 10:23:38 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: regex puzzler
Message-Id: <3A602D76.6EF43C2B@acm.org>

Richard J Bragg wrote:
> 
> rule is that if input contains ": " (colonspace) then I want what
> follows the ": " else
> I want the whole string.
> 
> e.g.
> hello: world  ---> world
> hello world   ---> hello world

$x = 'hello: world';
if ( ( $y = index $x, ": " ) >= 0 ) {
    print substr( $x, $y + 2 ), "\n";
    }
else { print "$x\n"; }'


John


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

Date: Fri, 12 Jan 2001 23:26:09 -0800
From: Bald Headed John <baldheadedjohn@SpamAnyone?newsguy.com>
Subject: RegExp substitution w/Array Dereference
Message-Id: <TdVfOtM9I=zcsSr+VjnUzjiPvSby@4ax.com>


hi there kids

I've got a little regexp problem, maybe you could give me a hand...

please forgive any typos, the regex works other than this problem;

here's a scalar: 

$SuperString = "+Reply-To:tzf@here.to\n CC:tzf@there.tv,tzf@where.tv\n
BCC:tzf@elsewhere.fr\n\n Subject:'the subject' body:'thebody'\n "

here's an array:

@Change = @_ # incoming change data
and $Change[0] holds "tzf@farfaraway.cz" or whatever.

here's the substitution regex expression: 

THE PROBLEM EXPRESSION:
$SuperString = (s/Reply-To:.*?\\n/Reply-To:$Change[0]\\n/)

THE PROBLEMATIC RESULT:
the problem is that the $Change[0] doesn't dereference; it apears in
$SuperString literally. 

If I use a scalar "$Other" that DOES deref properly.

If I put a space between To: and $Change[0] it works, but I can't have
a space in the output string (and it puts one there). 

If I delimit $Change[0] with single-quotes, it works but a
single-quoted FQDN in a reply-to is a bad thing - it doesn't work. 

I've tried \ in several places, with various weird effects.

I could assign the relevant array member to a scalar, then use the
scalar, but that seems inelegant.

I could actually use the space delimiter as mentioned above, but I'm
not sure that it won't break something else...

 ...more than a fix, I'd REALLY like an explanation of what the
interpreter is thinking. Is it taking [0] as a character class? If so,
what's the general way to tell it not to? 

thx in adv, 
tzf


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

Date: Sat, 13 Jan 2001 09:12:43 GMT
From: "John Boy Walton" <johngros.NOSPAM@bigpond.net.au>
Subject: Re: RegExp substitution w/Array Dereference
Message-Id: <f_U76.58284$xW4.467838@news-server.bigpond.net.au>


"Bald Headed John" <baldheadedjohn@SpamAnyone?newsguy.com> wrote in message
news:TdVfOtM9I=zcsSr+VjnUzjiPvSby@4ax.com...
>
> hi there kids
>
> I've got a little regexp problem, maybe you could give me a hand...
>
> please forgive any typos, the regex works other than this problem;
>
> here's a scalar:
>
> $SuperString = "+Reply-To:tzf@here.to\n CC:tzf@there.tv,tzf@where.tv\n
> BCC:tzf@elsewhere.fr\n\n Subject:'the subject' body:'thebody'\n "
>
> here's an array:
>
> @Change = @_ # incoming change data
> and $Change[0] holds "tzf@farfaraway.cz" or whatever.
>
> here's the substitution regex expression:
>
> THE PROBLEM EXPRESSION:
> $SuperString = (s/Reply-To:.*?\\n/Reply-To:$Change[0]\\n/)
$SuperString =~ s/Reply-To:.*?\\n/Reply-To:$Change[0]\\n/;
Is the usual way to do a substitution in a variable.
Plus it loses the subject body.





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

Date: Sat, 13 Jan 2001 06:12:02 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Returning a filename from FILEHANDLE
Message-Id: <3A5FF58E.577598B1@home.com>


Martien Verbruggen wrote:
> 
> I don't think I've ever seen this question (the original one) on this
> group, but the standard answer on other groups, more related to Unix, is
> that you just keep the file name around. In C you'd wrap the file name
> and its associated handle in a struct. In perl you'd probably wrap it as
> an object.

And just for fun and since I have overload.pm on the brain, here is such
an object:

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

use strict;
package KeepFile;
use overload '""' => sub { ${*{$_[0]} } };

sub open {
    my $class = shift;
    my $file  = shift;
    my $fh;
    open($fh, $file) or return;
    ${*$fh} = $file;
    bless $fh => $class;
}

package main;
my $fh = KeepFile->open($0) or die $!;
print "$fh:$_" while <$fh>;

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 13 Jan 2001 07:00:09 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Returning a filename from FILEHANDLE
Message-Id: <t5vv7pjpmbk9dc@corp.supernews.com>

Julian Cook/Sherab Gyatso <president@webticker.com> wrote:
> Hi folks!
> My thanks in advance to all who make this a great place to
> be. I have certainly gotten more than my fair share of free advice.

> Is there a function is PERL  that will return what a filehandle is
> associated with?

> Where <FILES> refers to "files.txt" Could I somehow ask <FILES>
> to give me what it's reading?

Not without some contortions. You could use syscall to call
something nonportable if that's an option.

If you know what directory you opened the file in but not the
particular file, you could try something like this:

###############################################################
#!/usr/bin/perl

$match = 0;
if( $ARGV[1] ) {
   $dir = $ARGV[1];
} else {
   $dir = '.';
}

open(File, "$ARGV[0]") || die "Can't open file $ARGV[0]: $!\n";
opendir(Dir, "$dir") || die "Can't open directory $dir: $!\n";
@file = readdir(Dir);
close(Dir);
for(@file) {
    if( ((stat(File))[1]) == ((stat("$dir/$_"))[1]) ) {
        print "File opened is $_\n";
        $match = 1;
        last;
    }
}
unless( $match ) {
    print "Never found opened file in the directory $dir.";
}
close(File);
###############################################################


Basically I choose the directory I think the file is in, then
compare the inode reported by stat() for the filehandle to the
inode reported by stat() for the file names returned by readdir().

If a file name and file handle both use the same inode, they are
the same file (unless something really funky is going on). If you
are more paranoid, stat() returns a bunch of stuff. I'd say if
fields 0 through 7 don't satisfy you, then you're pretty much
out of luck, although if you just have to, you could compare the
whole thing.

Another operator (set of them, actually) that work(s) on both
filehandles and file names (?:is|are) the -x operators(s).
Two files with the same values returned by -s, -M, -A, and -C
are probably the same file. If you're paranoid, you could
run the gamut of all the -x ops until they all match up or don't.

If something might be a special file, you could test for that with
the -x ops first.

Hopefully this helps (or at least entertains) someone, if not the
OP.

-- 
Christopher E. Stith

Product shown enlarged to make you think you're getting more.



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

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


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