[9312] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2907 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 18 23:07:16 1998

Date: Thu, 18 Jun 98 20:00:30 -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           Thu, 18 Jun 1998     Volume: 8 Number: 2907

Today's topics:
    Re: 2 questions about lists (Larry Rosler)
    Re: 500 Server Error (Abigail)
    Re: ?CGI scripts & Explorer (Larry Rosler)
    Re: AXS 2.0 Date <rootbeer@teleport.com>
    Re: C/XS code to accept oddball Perl constructs? (Ken Fox)
    Re: Ctrl+C disable in perl program  <rootbeer@teleport.com>
    Re: Excel - Perl conversion <Russell_Schulz@locutus.ofB.ORG>
    Re: first language birgitt@my-dejanews.com
        How do you pre-append using "open" <webmaster@triologic.com>
    Re: How to use Socket.pm? (Michael Budash)
    Re: if (something eq "somethingfgjhf") (Bob Trieger)
    Re: if (something eq "somethingfgjhf") (Bob Trieger)
    Re: IIS4.0 won't run perl scripts which call external c <rootbeer@teleport.com>
    Re: Is this WEB-BASED mail script good? <somekidd@slip.net>
    Re: Matching Question (Ron Barnhart)
    Re: Matching Question <psdspss@execpc.com>
    Re: Multi-D Array Sorting <root@ns.asic.net>
    Re: Pod::Text -- Unix only? <mike.schleif@aquila.com>
        Problem using rsh within PERL <Hamish_Eassie@optilink.dsccc.com>
    Re: Question concerning the use of Net::FTP <rainer@demag.rwth-aachen.de>
    Re: regex terminator not allowed in comment in extended (Abigail)
    Re: RegExp Error Under UNIX PERL Runs Under Win32 PERL (Abigail)
    Re: Running a VT100 perl script in Windows 95 <rootbeer@teleport.com>
        Sick things to do in foreach loops (Peter Scott)
    Re: SORTING HASHES (THE NEWBIE WAY!!) (Larry Rosler)
    Re: Sorting IP's - Help! (Larry Rosler)
        the ?PATTERN? match syntax topher67@my-dejanews.com
    Re: Using PERL to do a remote TELNET luong@my-dejanews.com
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Jun 1998 18:29:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: 2 questions about lists
Message-Id: <MPG.ff35eea71b406cd98969e@nntp.hpl.hp.com>

In article <MPG.ff2da4d90ebdac79896c1@nntp.hpl.hp.com>, Larry Rosler 
<lr@hpl.hp.com>says...
 ...
> The distinction between list and array arguments for foreach is that 
> lists cannot move during the iteration, so the refs to their values are 
> valid throughout.  Writing via the refs happens, but has no visible 
> effect because the list values are discarded after the iteration.  But 
> array values persist.

Someone pointed out in a private email that scalar arguments to foreach 
can also be modified (i.e., foreach ($m, $n) { ... }).  Strictly 
speaking, these are not array arguments.  However, they *are* list 
members that are lvalues.

So I think the statement in the documentation (`perldoc perlsyn` or Blue 
Camel, p. 100):

"If LIST is an actual array (as opposed to an expression returning a list 
value), you can modify each element of the array by modifying VAR inside 
the loop.  That's because the foreach loop index is an implicit alias for 
each item in the list that you're looping over."

should be generalized along these lines:

"If any element in LIST is an lvalue, for example by being a member of an 
actual array (as opposed to an expression returning a list value), you 
can modify its value by modifying VAR inside the loop..."

And the examples should include scalars as well as arrays.

If I am correct, please advise whether and how to request a change to the 
documentation (via perlbug?).

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 19 Jun 1998 01:04:47 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: 500 Server Error
Message-Id: <6mcdff$5io$2@client3.news.psi.net>

Drew (drewv@sympatico.ca) wrote on MDCCLII September MCMXCIII in
<URL: news:358a9040.125662493@news1.on.sympatico.ca>:
++ 
++                                                    I am getting a 500 Server
++ Error - The Specified modeule could not be found.
++ 
++ .  Any idea what could be causing  this?

Yes, it's your webserver telling you did something wrong.

Please ask in a more appropriate group. 



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Thu, 18 Jun 1998 18:38:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: ?CGI scripts & Explorer
Message-Id: <MPG.ff36106af93dacd98969f@nntp.hpl.hp.com>

In article <3589F2D5.1367@comenius.ms.mff.cuni.cz>, Jan Krynicky 
<JKRY3025@comenius.ms.mff.cuni.cz>says...
 ...
> Try this script:
> 
> print "Content-type: text/plain\n\n";
> print "<HTML><HEAD><TITLE>Hello world</TITLE></HEAD>\n";
> print "<BODY><H1>Hello world</H1>M$IE</BODY></HTML>\n\n";
> 
> Now what do you see? The HTML coding (which is correct, see the
> Content-type)
> or a page titled "Hello world"?
> 
> M$'s conformance to standards is plainly horrible.
 ...
> Jenda
> (Sorry guys that this went completely off-topic.)

Not completely.  I'm wondering how you got away with that 
undeclared and undefined $IE in the third print statement.  Where was

#!perl -w
use strict;

??? :-)

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 19 Jun 1998 02:43:05 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: AXS 2.0 Date
Message-Id: <Pine.GSO.3.96.980618194020.17544G-100000@user2.teleport.com>

On Thu, 18 Jun 1998 calacreek@my-dejanews.com wrote:

> Does anyone know how to subtract an hour from a variable (in the script,
> it is part of an array $terms)? 

$terms is a scalar, not an array. 

But to subtract an hour, if $fred is a number of hours, use $fred - 1. If
$fred is a number of minutes, use $fred - 60. If $fred is a number of
seconds, use $fred - 3600. If $fred is a number of days, use $fred - 1/24.
If $fred is a number of weeks, use $fred - 1/168. 

I hope that one of those ideas will help you get started. Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 19 Jun 1998 01:17:09 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: Re: C/XS code to accept oddball Perl constructs?
Message-Id: <6mce6l$hk91@eccws1.dearborn.ford.com>

cfchiesa@cyber1.servtech.com (christopher f. chiesa) writes:
> My boss insisted that the "reader" be written in Perl, but the nature
> of the output API requires that it be used from C.

Wow.  What an enlightened boss.  A pointy-haired manager who picks
the best tool for the job?  (Or does he say Perl is good for
everything? ;)

> Despite being new to my job, Unix, Perl, regular expressions, and
> Makefiles, let alone XSUBs and the custom output API, I have managed to
> complete two-thirds of the job ...

I'm not sure whether to congratulate you or ask you to try a less
aggressive solution...

> So now I need to write either Perl or C/XS code to convert the Perl
> representation to a C-array-like form, either before or after passing
> the data to the output API.

You can use pack to create the C data structure or you can use
perlguts functions to pick the data out of Perl arrays from your
XSUB.  I prefer the later approach, but pack is ok as long as
you hide it behind a Perl wrapper layer.

> ... trial-and-error programming I was able to create an XSUB that for
> SMALL ... datasets DOES appear to perform the necessary conversion and
> return it to Perl as a string ...  Unfortunately, when tested on a
> dataset whose dimensions approximate those expected ... [it crashes
> and burns]

The fact that it "works" for small datasets and not large ones
usually indicates that you're just getting lucky on the small
datasets.  You're probably not hitting any Perl bugs.  Your system
can probably handle a few megabytes of memory without swapping to
death.  Most likely it's your code.

> For what it's worth, I HAVE looked at TONS of documentation, but only
> a small percentage even discusses the use of XS or writing of XSUBs

You've read perlxs, perlxstut and perlguts?  That's about 3500 lines
of XS-related documentation.  How much do you think XS needs?! ;)

> of THAT material, essentially NONE of it (except, by implication, the
> perlguts manpage) discusses passing "complex" _Perl_ structures _into_ C

Well, Perl doesn't have "complex" structures.  It only has scalars,
arrays and hashes.  Which aren't documented?

> SV *
> carray(lArray, lNrows, lNcols)
>     void *	lArray

I'd make lArray an SV *.

You're using some funny variable names.  Doesn't your compiler check
type compatibility?  If the variable declaration is far enough away
that you forget what types you have, you're too far gone for naming
conventions to save you.

>     long	lNrows
>     long	lNcols
> 
>     PPCODE:
> 
>     SV *psvBase, *psvRow, *psvEntry, *psvReturn;
>     long lRow, lCol;
>     double *pWorking, *pStorage;
> 
>     printf("Debug: Malloc()'ing... %d bytes\n", 
>             lNrows * lNcols * sizeof (double));
>     printf("That's %d * %d * %d ...\n", lNrows, lNcols, sizeof(double));
> 
>     pWorking = pStorage = (double *) safemalloc(lNrows * lNcols * sizeof(double));
>     printf("pWorking = pStorage = %p\n", pWorking);
>     if (pStorage == 0) 
>     {
>         printf("Couldn't get memory in carray()!\n");
>         exit (-1);
>     }

You might try abort() instead of exit().

Also, that big array you allocate is full of garbage.  You really
should initialize it so that you don't have to worry about filling
in every element.  Just do the simple double-loop to initialize it.
You'll never miss the few extra milliseconds it takes.

>     psvBase = ST(0);

If you declar lArray an SV *, you won't need to mess around with psvBase.

>     if (SvROK(psvBase) && (SvTYPE(psvBase) == SVt_RV))
>     {

This just checks psvBase (twice) to see if it's a reference.  You need
to check to see if it's an *array* reference.  Use this instead:

  if (SvROK(psvBase) && (SvTYPE(SvRV(psvBase)) == SVt_PVAV))

Also, it would be convienient if you converted the array reference to
an AV *.  Try this:

  AV *matrix = (AV *)SvRV(psvBase);

That will make your code much easier to read.

>         for (lRow = 0; lRow < lNrows; lRow++)
>         {

You shouldn't trust lNrows and lNcols.  Perl arrays carry the size
with them.  Use this instead:

  lNrows = AvFILL(matrix) + 1;

>             psvRow = *av_fetch(SvRV(psvBase), lRow, 0);

You're kidding me right?  You check the malloc() above which
practically never fails, but then you just dereference a pointer
that can very likely be null?  You *have* to check for null -- array
elements in perl default to that.  Use this instead:

  SV **element = av_fetch(matrix, lRow, 0);
  if (element)
  {
     ...

>             if (SvROK(psvRow) && (SvTYPE(psvRow) == SVt_RV))
>             {

Same problem here as above.  Use this:

  if (SvROK(*element) && (SvTYPE(SvRV(*element)) == SVt_PVAV))
  AV *row = (AV *)SvRV(*element);

>                 printf("%3d: ", lRow); 
>                 for (lCol = 0; lCol < lNcols; lCol++)
>                 {

Don't trust lNcols either.  (You also have to handle the situation
where rows are different lengths.)  Use:

  lNcols = AvFILL(row) + 1;

>                     psvEntry = *av_fetch(SvRV(psvRow), lCol, 0);

You really like to live life on the edge, don't you?  Fix this code
the same way I fixed it above.

>                     /* This test is essentially unnecessary... */
>                     if (SvIOK(psvEntry) || SvNOK(psvEntry))
>                     {
>                         /* Value is now SvNV(psvEntry) or SvIV(psvEntry) */
>                         /* depending on datatype!                        */

This whole chunk of code is not quite right.  Perl will automatically
convert to numeric type for you.  If you need a real number, just use
SvNV() -- you'll get a real number, even if perl has to use atof() on
a string to do it.  Use this instead:

  *pWorking++ = SvNV(psvEntry);

You really can't use a simple pointer increment here.  You might not
like it, but the rows don't have to be all the same length.  A short
row will give you wrong numbers in the matrix and a long row will
likely crash.

Just use an array index like this:

  pWorking[row * max_column_length + col] = SvNV(psvEntry);

If you don't like the multiple, then keep track of the offset
of the current row and just add the col.

You can calculate max_column_length by taking two passes over
the matrix.  The first pass just calculates the matrix size and
the second pass fills it in.  You could also require that
max_column_length be passed in -- but then you must insert a
test to verify that col never exceeds max_column_length.  You
could just warn() if that happens and ignore the rest of the
row.

>                 /* Create and return output entity! */
>                 psvReturn = newSVpv((char *) pStorage,
>                     (lNrows * lNcols * sizeof(double)));
>                 XPUSHs(psvReturn);

This looks fine to me.  If this is the only code you have, I doubt
you have a memory leak in C.  You might have a memory leak because
of your of Perl code though.  Make sure that you aren't saving
return results somewhere and preventing the garbage collector from
reclaiming your temporary arrays.

One last suggestion.  Since you are encoding data in a scalar, i.e.
just using a scalar as a blob of memory, you run the risk of munging
the scalar from other code.  For example, if you accidentally run a
search/replace on it you'll corrupt your carefully encoded matrix of
doubles.

It might be better if you return a blessed reference instead of a
scalar.  That way it is much harder to corrupt the data and other
XSUBs can typecheck the arguments they get.

- Ken

-- 
Ken Fox (kfox@ford.com)                  | My opinions or statements do
                                         | not represent those of, nor are
Ford Motor Company, Powertrain           | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section             | "Is this some sort of trick
                                         |  question or what?" -- Calvin


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

Date: Fri, 19 Jun 1998 02:46:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Ctrl+C disable in perl program 
Message-Id: <Pine.GSO.3.96.980618194354.17544H-100000@user2.teleport.com>

On Thu, 18 Jun 1998, Li Xiaoning wrote:

> I am writing a system configuration program in perl, I want to disable
> control+C in program. appreciate for any idea on that.

Perl doesn't know anything about control-C, but it may be that your system
is set up to deliver a signal when a control-C is entered. In that case,
you could either change the system to not send the signal, trap the signal
when it arrives, or ignore the signal. See the %SIG variable in the
perlvar manpage and the perlipc manpage for information about signal
handlers in Perl. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 19 Jun 1998 01:07:27 +0100
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: Excel - Perl conversion
Message-Id: <19980619.010727.2Y2.rnr.w164w@locutus.ofB.ORG>

>> I am looking for a script that will convert excel into perl.
>
> Euhm.. How do you imagine that? Excel is a spreadsheet program, and
> Perl is a programming language.

I assume the desire is to convert something like this:
      A        B        C
1     3
2             =1+A1
3                      =1/B2

into:

  array[1][1]=3;
  array[2][2]=1+array[1][1];
  array[3][3]=1/array[2][2];

> It's like asking for a tire that will convert your chair into a
> banana.

well, I have written two such translators for work (neither converts
the calculations into perl, though).
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


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

Date: Fri, 19 Jun 1998 01:28:49 GMT
From: birgitt@my-dejanews.com
Subject: Re: first language
Message-Id: <6mcesh$aep$1@nnrp1.dejanews.com>

[might be considered a bit off-topic, I don't know]

In article <6mbktf$5qp$1@msunews.cl.msu.edu>,
  Dan Nguyen <nguyend7@egr.msu.edu> wrote:
>
> Rich Morin <rdm@cfcl.com> wrote:
> : In article <6malar$iee$9@client3.news.psi.net>, abigail@fnx.com wrote:
>
> : > Find someone to teach you *programming*.  (Not a language, *programming*).
>
> : Bingo!
>
> [snip]

>
> :   Fortran has few constructs and little interaction, so it is pretty
> :   simple.  Pascal has few constructs and more interaction, making it more
> :   complex.  Ada and Perl have many constructs and high interaction, and
> :   are therefore *really* complex.
>
> Pascal, IMHO is a good language to learn as your first language.
> Especially if your planning on learning C along the way.  Its been my
> experience that learning the first language is always the hardest.
> Learning new ones is simply a making connections with previous
> language.  i.e.  I did it this way in this language, and in this one
> these things act like those things, and this keyword is like that
> keyword.  e.g.  Pascal and C
>
> PASCAL                 C                    Perl
> while( i > 0 )         while( i > 0 )       while( $i > 0 )
> begin		       {                    {
>   .                      .                      .
>   .                      .                      .
>   .                      .                      .
> end;                   }                    }
>
> The perivous examples show how things you can make connections, and
> make your programming experience more enjoyable.
>

I just put the same question through c.l.p.m. a couple of weeks ago
and took the advice I got (hmm, you are really making progress to
explain the advantages and disadvantages of Perl being first language
to learn programming with 8-).

Now, also being a Unix newbie, I find myself with *many* books I read
at the same time, starting with C shell, bash shell, shell scripting,
AWK, sed, which then leads me into C books and at the same time I like to
read everyhting about regular expressions. This comes somehow naturally
when reading. (and all the time I am a bit mad that I still can't
start with Perl 8-).

I have difficulties to force myself through a Pascal book and don't
know why. (It's the book most probably, not the language, too early
to tell). On the other hand, I miss something which is much more
mathematical and abstract.

I have the feeling that all of the above I could learn by myself,
but I miss structured teaching of designing algorithm, data structures,
procedural and data abstraction. For those subjects, I think I would
rather like to go to school and have been put through it.

I also find that I need something about PC Architecture. I found
a  book I like and is helpful (PC Architecture from Assembly Language
to C).

So, my question to the experts is, are you all gone through
a cs/math/engineering department ? I have seen pretty strong programmers
who are not. (hmm, of course, I can't judge how good a programmer is).

Who has really learned everything by himself without schools (and
without ten to twenty years of exposure in the unix world on a technical
level or without having played with programs since age nine 8-).

Birgitt Funk



-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 19 Jun 1998 01:17:20 GMT
From: Nick Forte <webmaster@triologic.com>
Subject: How do you pre-append using "open"
Message-Id: <3589BA7D.6D1C249C@triologic.com>

I'm trying to pre-append a record to a flat file. I want the record to
be inserted on the first line everytime instead of appending it to the
end. Can someone help me?

Thanks!



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

Date: Thu, 18 Jun 1998 17:27:52 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: How to use Socket.pm?
Message-Id: <mbudash-1806981727520001@d200.pm6.sonic.net>

my thanks to all who responded! case closed...

-- 
Michael Budash, Owner * Michael Budash Consulting
707-255-5371 * 707-258-7800 x7736
mbudash@sonic.net


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

Date: Fri, 19 Jun 1998 00:12:22 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: if (something eq "somethingfgjhf")
Message-Id: <6mcagi$9dn$1@ligarius.ultra.net>

[ posted and mailed ]

ptimmins@netserv.unmc.edu (Patrick Timmins) wrote:

-> Why eq ? Why not regex? eg:

Because regex takes atleast 3 times longer.

Both will do the job but getting it done faster is usually better.

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: Fri, 19 Jun 1998 00:37:53 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: if (something eq "somethingfgjhf")
Message-Id: <6mcc0c$uge$1@strato.ultra.net>


sowmaster@juicepigs.com (Bob Trieger) wrote:
-> [ posted and mailed ]
-> 
-> ptimmins@netserv.unmc.edu (Patrick Timmins) wrote:
-> 
-> -> Why eq ? Why not regex? eg:
-> 
-> Because regex takes atleast 3 times longer.


oops, I lied. but it does take about twice as long.

#!/usr/bin/perl
use Benchmark;
$foo = "something wicked this way comes.";
$bar = "something";

timethese 1000000, {
        regex   => sub {
                die if ($foo !~ /^\Q$bar\E/);
        },
        eq      => sub {
                die if (substr($foo,0,7) ne substr($bar,0,7));
        }
};


Benchmark: timing 1000000 iterations of eq, regex...
       ne: 21 secs (20.36 usr  0.00 sys = 20.36 cpu)
     regex: 39 secs (39.04 usr  0.00 sys = 39.04 cpu)

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: Fri, 19 Jun 1998 02:35:13 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: IIS4.0 won't run perl scripts which call external commands
Message-Id: <Pine.GSO.3.96.980618193439.17544F-100000@user2.teleport.com>

On Thu, 18 Jun 1998 postmanager@my-dejanews.com wrote:

> This script worked fine in IIS3.0 but seems to fail in IIS4.0.

So, it's not a Perl problem.

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 CPAN.

   http://www.perl.com/CPAN/
   http://www.perl.org/CPAN/
   http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
   http://www.perl.org/CPAN/doc/manual/html/pod/

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 18 Jun 1998 18:36:44 -0000
From: "Slip.Net User" <somekidd@slip.net>
Subject: Re: Is this WEB-BASED mail script good?
Message-Id: <6mcfql$i58$1@owl.slip.net>

I'll do it for $70 dollars an hour!  Aren't I nice?
Marc Lamoureux wrote in message <358562CE.8EAE5542@total.net>...
>What only 80$/hour... what kind of cheap laber are you ?!
>
>Aaron Baugher wrote:
>
>> "David A. Lyons" <lyonsd@atl.hp.com> writes:
>>
>> > Ala Qumsieh wrote:
>> > >
>> > > Paul van der Pan wrote:
>> > >
>> > > > I found this perl cgi-script for Web based email
>> > > > (should work on Linux) on the net,
>> > > > can somebody tell me if there are big security holes
>> > > > in this script?
>> > > >
>> > >
>> > >  I will ... if you pay me $100/hr ;-)
>> >
>> > Paul, don't let this guy rip you off!  I'll do it for $90/hr!  ;^)
>>
>> Bob, I'll say $80/hr!  [applause, applause]
>>
>> --
>> Aaron Baugher
>> Extreme Systems Consulting
>> CGI, Perl, Java, and Unix Administration
>> http://haruchai.rnet.com/esc/
>
>
>




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

Date: Thu, 18 Jun 1998 23:58:40 GMT
From: barnhart@freewwweb.com (Ron Barnhart)
Subject: Re: Matching Question
Message-Id: <3589a71c.91383515@news.smart1.net>

Your assesment of the situation was right on target.  I didn't stick
with it long enough.  I hadn't even finished the first chapter.  I
wondered if I might find the answer later in the book.  However, I'm
glad I posted the question.  I received a couple of emails and your
response as well.  I had no perception of the usefulness of regular
execptions while I was reading the book. But from the comments I've
recieved, I can tell that they are fairly important.  Thanks for your
help.

Ron Barnhart
barnhart@freewwweb.com

On Thu, 18 Jun 1998 17:59:27 -0400, linberg@literacy.upenn.edu (Steve
Linberg) wrote:

>In article <358985f0.82890282@news.smart1.net>, barnhart@freewwweb.com
>(Ron Barnhart) wrote:
>
>>How do you know which is supposed to be a normal
>> oporator and which is pattern symbols?  They all seem to use similar
>> or same characters (all of those forward and back slashes are really
>> confusing too).  If any one could offer some advice/assistance on
>> this, it would be greatly appreciated.  Thanks
>
>Putting this as gently as possible, I'd suggest sticking with it a little
>longer.  It actually makes all kinds of sense.  So much sense it will
>boggle your mind.  You will have to work at it, though.



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

Date: Thu, 18 Jun 1998 21:36:42 -0500
From: Deva Seetharam <psdspss@execpc.com>
Subject: Re: Matching Question
Message-Id: <6mcic4$kj0@newsops.execpc.com>



Ron Barnhart wrote:

> Hello,
>
>         I have just purchased the Programming Perl book by Larry Wall.
> In the first chapter, he describes pattern matching.  However, it
> doesn't make a lot of sense.  I understand the concept of it, but the
> syntax used seems extremely involved.  Is there a resource or list
> about pattern matching?  An explanation of use may also be helpful.  I
> guess the hardest part are all of the different symbols and what they
> mean.  I looked at an example in the book: /<(.*?)>.*?<\/\1>/  I was
> totally lost.  How do you know which is supposed to be a normal
> oporator and which is pattern symbols?  They all seem to use similar
> or same characters (all of those forward and back slashes are really
> confusing too).  If any one could offer some advice/assistance on
> this, it would be greatly appreciated.  Thanks

Programming Perl is too intense.

Please look at the preface of the Programming perl book (p xvi) in the
preface.

Let me present it here for your convenience
"Learning Perl by Randal Schwartz is a companion to Programming Perl.
It is more of a tutorial, whereas this book is more of a *reference*.
If the tutorial section of Programming Perl is too short or assumes too
much
about your background, try Learning Perl for a kinder, gentler
introduction to
the language."

Learning perl has a very pleasant chapter on Regular Expressions.
Although, it is not comprehensive, it makes your perl regex fundamentals
strong.

If you want an indepth treatment of Regexes, look at
Master Regular Expressions by Jeffrey Friedl.

Hope that helps.
Deva



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

Date: 19 Jun 1998 00:52:38 GMT
From: root <root@ns.asic.net>
Subject: Re: Multi-D Array Sorting
Message-Id: <6mccom$2sh$1@news.att.co.kr>

pugs5@my-dejanews.com wrote:
> I need help here.

> bytestohost{$i,$j} where I need to sort that for the same value of $i.

> If anyone could help. Thanks a bundle!

> Jason Pugsley

> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading



I did it in very simply way.
Suppose you have 2-dimemsional array, and want to sort by first field and if first field is same, sort by second field.


@x=( [1, 2], [9, 3], [5, 6], [3, 4], [3, 2]);
@y = sort { 
        if( $a->[0] == $b->[0]) {
                 $a->[1] <=> $b->[1];
        }
        else {
                 $a->[0] <=> $b->[0];
        }
} @x;

print "@x\n";
print "@y\n";

That's it!
Good luck



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

Date: Fri, 19 Jun 1998 02:31:06 GMT
From: "Michael D. Schleif" <mike.schleif@aquila.com>
Subject: Re: Pod::Text -- Unix only?
Message-Id: <3589CCAD.C9D65096@aquila.com>

I don't presume to speak for Tom -- we have had our share of words
between us -- but, anybody care to ship Tom a Mac?

It sure would deprive him of another excuse, although I don't know where
he'll find room to plug it in . . .

Brad Murray wrote:
> 
> It seems Tom Christiansen  suggested...
> >Portable doesn't mean "runs on a Mac".   I code for corss-platform
> >use.  That means my code works on Linux, BSD, SunOS, *and* Solaris
> >-- and probably any other profession/open/POSIX/Unix-like system.
> >If you want more than that, you'll have to write the program yourself.
> 
> Maybe it should mean "runs on a Mac" or anything else for that matter.

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "


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

Date: Thu, 18 Jun 1998 17:31:03 -0700
From: Hamish_Eassie <Hamish_Eassie@optilink.dsccc.com>
Subject: Problem using rsh within PERL
Message-Id: <3589B147.4B63F2A8@optilink.dsccc.com>

Hi,

I am writing a queueing system using PERL (Version 5) to run on solaris
machines (SunOS 5.5.1) and am having a problem when using 'rsh' to batch

off jobs in the background.   I always batch off a csh script, but the
problem is that if this shell script executes another shell script then
the PERL script waits for all commands to complete, whereas if the csh
script executes a compiled binary then the job is executed in the
background as desired.

The PERL script first of all creates a command file (a csh script called

 .submit.command) which contains setenv statements to copy the
environment from the shell which calls it and has the command to be
executed at the end of the file.  The script then rshells this script in

the background as follows :

`rsh -n $best_host $logdir/\.submit\.command &`;

where $best_host is determined earlier as the best host to batch off to,

and $logdir is the place the command file was created.

So the problem is that if .submit.command calls a compiled binary (in
our case, the synopsys dc_shell) for example :


#!/bin/csh
setenv AB_CARDCATALOG "/usr/dt/share/answerbooks/C/ab_cardcatalog"
setenv DISPLAY ":0.0"
  <MORE setenv statements>
       .
setenv DESIGN_NAME "TEST"
unalias cd
cd /home/hw5/synopsys/log/TEST
dc_shell -f /home/hw5/synopsys/scripts/test.scr >
/home/hw5/synopsys/log/TEST/TEST_test.log


then the  PERL script starts the dc_shell job off, then moves on the the

next PERL command, which is what we want.  But if the .submit.command
calls another shell script, eg :

#!/bin/csh
setenv AB_CARDCATALOG "/usr/dt/share/answerbooks/C/ab_cardcatalog"
setenv DISPLAY ":0.0"
  <MORE setenv statements>
       .
setenv dtstart_sessionlogfile "/dev/null"
unalias cd
cd /home/hw5/
/home/hw5/shell_scripts/script.scr > /home/hw5/test/log/shell.log

then the PERL script waits for the commands in script.scr to be
completed before continuing.
Any ideas ?

Thanks,

Hamish Eassie.

PS Please mail me direct as well as to the group :
Hamish_Eassie@optilink.dsccc.com





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

Date: Fri, 19 Jun 1998 02:00:41 +0200
From: Rainer Finocchiaro <rainer@demag.rwth-aachen.de>
Subject: Re: Question concerning the use of Net::FTP
Message-Id: <3589AA29.93D22632@demag.rwth-aachen.de>

Jeffrey R. Drumm wrote:
> 
> [posted and mailed]
> 
> On Thu, 18 Jun 1998 15:15:25 +0200, Rainer Finocchiaro
> <rainer@demag.rwth-aachen.de> wrote:
> 
> >Hi all,
> >
> >I want to upload a file to the cgidir of a remote Webserver AND make it
> >executable.
> >
> >No problem with the upload, works flawlessly, but I can't seem to figure
> >out how to set the file to another mode like rwxr-x-r-x. I tried the
> >following
> >
> >my $ftp = new Net::FTP($ip) || &io_error("Cannot connect to $ip");
> >$ftp->login($login, $pass);
> >$ftp->type("binary");
> >$ftp->mkdir(dirname($dest_file),true);
> >$ftp->put($source, $dest_file);
> >$mode = 0755;
> >$ftp->quot(chmod $mode $dest_file);
> >...
> 
> In this case, Perl's internal chmod is being evaluated and is probably failing
> with a 'missing operator' error . . .
> 
> >
> >and
> >
> >$ftp->command(CHMOD, $mode, $dest_file);
> >...
> 
> This actually turned out to be a little more difficult than I expected. Here's
> a solution that worked for me:
> 
> $ftp->quot('site chmod 0777', $dest_file);
> 
> Note the quotes, and the fact that quot is being supplied with a list.
> 
> >but everything had no effect. I have no idea how to continue and would
> >appreciate any help.
> >
> >Thanks in advance
> >
> >Rainer
> 
> --
>                                Jeffrey R. Drumm, Systems Integration Specialist
>                        Maine Medical Center - Medical Information Systems Group
>                                                             drummj@mail.mmc.org
> "Broken? Hell no! Uniquely implemented!" - me

Thank you very much for your kind help!

I got it to run for the first time with your example after hours and
days of trying (almost!) every possible syntax!
Now I am using
 $ftp->quot("site chmod $mode", $dest_file);
which allows me to set the mode according to the one of the sourcefile
on my machine.

Rainer

-- 
Rainer Finocchiaro
Hainbuchenstr. 2
52072 Aachen
Deutschland

Email: rainer@demag.rwth-aachen.de
Talk: rainer@vanadium.demag.rwth-aachen.de


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

Date: 19 Jun 1998 01:00:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: regex terminator not allowed in comment in extended regex?
Message-Id: <6mcd82$5io$1@client3.news.psi.net>

Tom Phoenix (rootbeer@teleport.com) wrote on MDCCLII September MCMXCIII
in <URL: news:Pine.GSO.3.96.980618094301.13348F-100000@user2.teleport.com>:
++ 
++ Here's another; how (and when?) should Perl recognize that the second
++ slash is part of a comment?
++ 
++     $comment = $something ? '' : '#';
++     $x_mode = $otherthing ? '' : '(?x)';
++     if (/do what	$comment $x_mode /
++       I mean/) {
++ 	print "How did you manage to parse that!\n";
++     }
++ 
++ You have to parse the pattern at compile time, but you may not know about
++ /x extensions, comments, or other contents until runtime. So the solution
++ seems to be the status quo. Of course, using paired delimiters is
++ generally a good idea here!


Uhm, I don't follow this. Who is suggesting perl should do
string interpolation before parsing?



Abigail
-- 
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'


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

Date: 19 Jun 1998 01:09:51 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: RegExp Error Under UNIX PERL Runs Under Win32 PERL
Message-Id: <6mcdov$5io$3@client3.news.psi.net>

John Kane (jdkane@akanewmedia.com) wrote on MDCCLII September MCMXCIII in
<URL: news:6mbmkt$gnd$1@newsmaster.pathcom.com>:
++ I have created an attribute-parsing function (which I have included below
++ for
++ reference purposes). It is meant to parse HTML tag attributes. It compiles
++ under my Win32 version of PERL, but not under the UNIX version. The
++ following error message is produced on the UNIX machine...
++ 
++ # perl cgi-bin/test/aka-parser.cgi
++ /(\w+\s*=\s*"(?:.*?(?:"{2})*)*")/: regexp *+ operand could be empty at
++ cgi-bin/t
++ est/aka-parser.cgi line 133.
++ 
++ My ISP is using v5.004_03 of PERL.
++ I am using Win32 Build 316  v5.003_07.
++ 
++ I don't understand the regular expression error. Can someone enlighten me.
++ Any help would be appreciated. Thanks.

It's exactly saying what it means: you're applying * or + to something
that can be empty. Like a <something>*.

Don't do that, unless you're willing to wait a few million years.


As for the attempt of your regex, it's hopelessly wrong. 
Do yourself a favour and use HTML::Parser for that.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Fri, 19 Jun 1998 02:48:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Running a VT100 perl script in Windows 95
Message-Id: <Pine.GSO.3.96.980618194711.17544I-100000@user2.teleport.com>

On 18 Jun 1998, Phoenixl wrote:

> Can someone tell me where I could find cursor
> movement strings for the MS-DOS window?

I think you're looking for documentation, rather than the strings
themselves. Perhaps the docs, FAQs, and newsgroups about MS-DOS could be
of some help to you. I'm not sure why you asked in a newsgroup about Perl,
though, since those strings are the same no matter what language you're
using. You're giving us Phoenixes a bad name. :-)  Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 18 Jun 1998 18:48:39 GMT
From: psf@euclid.jpl.nasa.gov (Peter Scott)
Subject: Sick things to do in foreach loops
Message-Id: <6mbne7$q9k@netline.jpl.nasa.gov>

[First of all I would like to apologize for not reading the
obvious documentation in my question about why subscripting qw//
generated a message about split(); I read the entry on split, I
grepped through the docs for "subscript", I read the entry on the
error in perldiag, I even looked up the error in the source to try
and understand what triggers it, but for some inexplicable reason,
I never bothered to look up qw//... oh well...]

I had a reason to want to extend the list in a foreach loop, and
to my pleasant surprise, I found that I could actually push elements
onto the end of the list while in the loop and still have the loop
iterate over them.  It's not clear to me that this would be implied
by the fact that the loop element was an alias for the actual list
element.  So, for instance:

@list = qw(zero one two three four five six);
print "Adding element to end every third iteration\n";
$i = 0;
@a = @list;
foreach $elem (@a) {
  push @a, "NEW" if $i % 3 == 0;
  print $i++, " $elem\n";
}

Adding element to end every third iteration
0 zero
1 one
2 two
3 three
4 four
5 five
6 six
7 NEW
8 NEW
9 NEW
10 NEW

This made me curious; how does Perl keep track of where it is in
the list if the list can change during the loop?  I looked in perlsyn,
but it doesn't appear to shed any light on the matter in the section
on loops.  So I did a little experimenting.  I think the first three
tests below speak for themselves.  As for the last one... can anyone
help me figure out where to look in the docs?

#/usr/local/bin/perl -w

@list = qw(zero one two three four five six);

@a = @list;
print "Removing first element every iteration\n";
$i = 0;
foreach $elem (@a) {
  shift @a;
  print $i++, " $elem\n";
}

print "Removing last element every iteration\n";
@a = @list;
$i = 0;
foreach $elem (@a) {
  pop @a;
  print $i++, " $elem\n";
}

print "Removing last element every iteration with array assignment\n";
$i = 0;
foreach $elem (@a = @list) {
  pop @a;
  print $i++, " $elem\n";
}

Removing first element every iteration
0 zero
1 two
2 four
3 six
Removing last element every iteration
0 zero
1 one
2 two
3 three
Removing last element every iteration with array assignment
0 zero
1 one
2 two
3 three
Use of uninitialized value at /tmp/foo line 25.
4 
Attempt to free unreferenced scalar at /tmp/foo line 23.
Bad free() ignored at /tmp/foo line 23.
Attempt to free unreferenced scalar at /tmp/foo line 23.
[Another 26 lines of the same]
Bad free() ignored at /tmp/foo line 23.
Use of uninitialized value at /tmp/foo line 25.
5 
Segmentation fault (core dumped)

This is perl, version 5.004_04 built for sun4-solaris

Solaris 2.5.1...

-- 
This is news.  This is your      |  Peter Scott, NASA/JPL/Caltech
brain on news.  Any questions?   |  (psf@euclid.jpl.nasa.gov)

Disclaimer:  These comments are the personal opinions of the author, and 
have not been adopted, authorized, ratified, or approved by JPL.


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

Date: Thu, 18 Jun 1998 19:22:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SORTING HASHES (THE NEWBIE WAY!!)
Message-Id: <MPG.ff36b3ca8e22c639896a0@nntp.hpl.hp.com>

In article <358981A5.7206@hotkey.net.au>, Stephan Carydakis 
<steph@hotkey.net.au>says...
 ...
>    foreach $key (sort {$ta_sort{$b} <=> $ta_sort{$a}} keys %ta_sort) {
>      print "$key: $ta_sort{$key}<br>";
>    }
> 
> What I don't understand is why I'm getting the hash sorted on the values
> and not the keys?? Not that I'm complaining because that is exactly what
> I wanted. :]

The keys get plugged into $a and $b; the sort compares the values 
$ta_sort{$a} and $ta_sort($b}, and returns the keys as a list sorted by 
these values.  I hope you understand now.  (This is only about the second 
level of non-trivial sort.  There are many higher degrees of difficulty.)

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 18 Jun 1998 19:38:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting IP's - Help!
Message-Id: <MPG.ff36ee8944d615c9896a2@nntp.hpl.hp.com>

In article <3589744E.794B@boeing.com>, David Pitts 
<david.pitts@boeing.com>says...
 ...
> @keys = sort { $ip1{$a} <=> $ip1{$b} } keys %ip1 or
> sort { $ip2{$a} <=> $ip2{$b} } keys %ip2 or
> sort { $ip3{$a} <=> $ip3{$b} } keys %ip3 or
> sort { $ip4{$a} <=> $ip4{$b} } keys %ip4;
> 
> 
> So, does anyone have a sorter that will work or see why this does not?

It is clear why this one does not.  'sort' in list context returns a 
list.  The value it returns in scalar context (for 'or') is undefined, so 
the evaluation continues, etc.

What you want is something like this:

@keys = sort { ... <=> ... || ... <=> ... || etc } keys %some_hash;

You can write '||' as 'or' if you prefer.

You should be able to work out the details from here.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 19 Jun 1998 01:15:36 GMT
From: topher67@my-dejanews.com
Subject: the ?PATTERN? match syntax
Message-Id: <6mce3p$96f$1@nnrp1.dejanews.com>

Here's my 2 cents worth:

The match syntax "?PATTERN?" is very useful and should *not* be removed from
perl.  Furthermore, an additional option should be added to the match
operator which does the same thing as "?PATTERN?", perhaps "f".  Then
you could do something like "/(?f)PATTERN/".

-Chris

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 19 Jun 1998 01:49:10 GMT
From: luong@my-dejanews.com
Subject: Re: Using PERL to do a remote TELNET
Message-Id: <6mcg2n$bqt$1@nnrp1.dejanews.com>

In article <6mbj85$qgj$1@demon.uunet.ca>,
  "Kenneth" <kenkim@gncom.com> wrote:
I don't know if it is the key, but the username and the password your program
entered did not seem to have \n at the end (to simulate the Enter keystroke).
Good luck
Pham Thuc Truong Luong
>
> I am having some troubles getting perl in UNIX to telnet to a remote host
> and grab necessary information and then exit.. Maybe I am doing something
> wrong, but it won't even get to the LOGIN prompt before it exits.
>
> This is basically what I am doing:
>
> open (TEL,"|telnet somesite.com");
> while (<TEL>)
> {
>         $dum = <TEL>;
>         if ($dum =~ /login/i)
>         {
>                 print TEL "username";
>         }
>         if ($dum =~ /pass/i)
>         {
>             print TEL "password";
>         }
>         print "$dum";
> }
>
> But all I seem to get from this is:
>
> Trying somesite.com..
> Connected to somesite.com...
> Escape Character is '^]'...
> Connection to host has been closed.
>
> Thanks for any info regarding this matter.
>
> Gorkem Yuksel
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

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

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