[24996] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7246 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 14 14:07:06 2004

Date: Thu, 14 Oct 2004 11:05:16 -0700 (PDT)
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, 14 Oct 2004     Volume: 10 Number: 7246

Today's topics:
    Re: [newbie] shtml question (krakle)
    Re: [newbie] shtml question (krakle)
    Re: [newbie] shtml question (krakle)
    Re: [newbie] shtml question <usenet@morrow.me.uk>
        A newbie question <moon@world.universe>
    Re: A newbie question <nobull@mail.com>
    Re: A newbie question <mritty@gmail.com>
    Re: A newbie question <moon@world.universe>
    Re: A newbie question <sbryce@scottbryce.com>
    Re: A newbie question <sbryce@scottbryce.com>
    Re: A newbie question <moon@world.universe>
    Re: A newbie question <nobull@mail.com>
    Re: A newbie question <sbryce@scottbryce.com>
    Re: A newbie question <mritty@gmail.com>
    Re: A newbie question <sbryce@scottbryce.com>
    Re: A newbie question <sbryce@scottbryce.com>
    Re: A newbie question <moon@world.universe>
    Re: A newbie question <mritty@gmail.com>
    Re: A newbie question <shawn.corey@sympatico.ca>
    Re: function overloading in Perl <mjcarman@mchsi.com>
    Re: hard references/arrays <nobull@mail.com>
    Re: hard references/arrays <nobull@mail.com>
    Re: Help with sorting lists of lists <tadmc@augustmail.com>
    Re: How to package my perl scripts (that depend on othe (Markus Dehmann)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 14 Oct 2004 09:44:45 -0700
From: krakle@visto.com (krakle)
Subject: Re: [newbie] shtml question
Message-Id: <237aaff8.0410140844.56b0f514@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2t6133F1sihhbU1@uni-berlin.de>...
> krakle wrote:
> > he SHOULD ask himself why needs to use SSI in the first place...
> 
> Can it possibly be because he has a Perl program that he wants to
> invoke from a static HTML page?

His code is:

<html>
 <!-- #exec cgi="www.yousite.com/cgi-bin/page.cgi" -->
</html>


If that's the ONLY thing on the HTML page why not call the CGI script
directly. Seems pointless otherwise. So again, he SHOULD ask himself
why he needs to use SSI in the first place.


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

Date: 14 Oct 2004 09:46:52 -0700
From: krakle@visto.com (krakle)
Subject: Re: [newbie] shtml question
Message-Id: <237aaff8.0410140846.40d7a7e8@posting.google.com>

Gregory Toomey <nospam@bigpond.com> wrote in message news:<2t6n72F1t6ehdU1@uni-berlin.de>...
> Larry wrote:
> 
> > In article <5aj042-rj5.ln1@osiris.mauzo.dyndns.org>,
> >  Ben Morrow <usenet@morrow.me.uk> wrote:
> > 
> >> Idiot.
> > 
> > 
> > Mr. Ben Morrow , the idiot one is you.
> 
> Hardly, he's well respected in the Perl community, and you are unlikely to
> get meaningful replies to your questions in the future.
> 
> gtoomey

Because he returned the insult he has done wrong? That's, idiotic to
think Gregory Toomey. And Ben Morrow is an idiot for saying what he
did. :)


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

Date: 14 Oct 2004 09:47:25 -0700
From: krakle@visto.com (krakle)
Subject: Re: [newbie] shtml question
Message-Id: <237aaff8.0410140847.201a3117@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2t70iqF1q13kqU1@uni-berlin.de>...
> Gregory Toomey wrote:
> > Larry wrote:
> >> Ben Morrow wrote:
> >>> 
> >>> Idiot.
> >> 
> >> Mr. Ben Morrow , the idiot one is you.
> > 
> > Hardly, he's well respected in the Perl community,
> 
> Which tells us that even well respected persons say idiotic things at
> times.

True.


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

Date: Thu, 14 Oct 2004 17:54:20 +0100
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: [newbie] shtml question
Message-Id: <sin242-8q4.ln1@osiris.mauzo.dyndns.org>


Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
> Ben Morrow wrote:
> > Quoth Larry wrote:
> >> Gregory Toomey wrote:
> >>> Mixing server side includes & cgi can be fraught with danger.
> >>> Try html templates instead.
> >>> http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm
> >>> 
> >>> You might be able to pass a variable by ...page.cgi?k=1000 but
> >>> I dont have a clue how this interacts with ssi.
> >> 
> >> Well, I know what you're talking about.
> >> 
> >> But I badly need to sort this problem out!!!
> >> 
> >> so forget about TEMPLATE...i need to pass a query string to my
> >> cgi script ...
> > 
> > Idiot.
> 
> Would you mind explaining how rejecting that idea makes the OP an
> idiot?

Being rude to someone trying to help is what makes him an idiot, as does
stating (again) on Usenet how urgent the problem is (as though we care),
using multiple exclamation marks, mis-capitalising Perl module names
(Uri of couse gets an honourable exception to this :), and saying 'I
need to pass a query string' when Gregory has just suggested how this
might be done and any further problems he has with this are undoubtedly
with SSI not Perl.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                         - Heraclitus
  ben@morrow.me.uk


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

Date: Thu, 14 Oct 2004 18:51:36 +0200
From: Moon <moon@world.universe>
Subject: A newbie question
Message-Id: <fn4gvs7xkn5f$.g9xdsyepj9fl.dlg@40tude.net>

Hi,

I don't have Perl experience at all, but I would be *VERY* grateful if
someone could translate me the piece of code shown below into a "human
language" :)

$abc = shift;

sub swap($$)
{
    $_ = shift; <- ??
    $e = "." x shift; <- ??
    s/($e)($e)/$2$1/g; <- all I know is that this is a 'regular expression'
    return $_; <- function returns a value, I understand that one
}

Thanks in advance...
Greetz!
-- 
<Moon>
[Reply-To=ROT13]


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

Date: Thu, 14 Oct 2004 17:57:54 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: A newbie question
Message-Id: <ckmau0$sca$2@sun3.bham.ac.uk>

Moon wrote:

> Subject: A newbie question

Please put the subject of your post in the Subject of your post.



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

Date: Thu, 14 Oct 2004 17:07:46 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: A newbie question
Message-Id: <Cnybd.738$%c3.308@trndny09>

"Moon" <moon@world.universe> wrote in message
news:fn4gvs7xkn5f$.g9xdsyepj9fl.dlg@40tude.net...
> Subject: A newbie question
Please put the subject of your post in the Subject of your post.  That
will increase your chances of getting help.  In this case, an
appropriate Subject might have been "Please help translate this code"

> I don't have Perl experience at all,

http://learn.perl.org
http://www.perldoc.com
are two good places to start

> but I would be *VERY* grateful if
> someone could translate me the piece of code shown below into a "human
> language" :)
>
> $abc = shift;
>
> sub swap($$)
> {
>     $_ = shift; <- ??

Set the variable $_ to be equal to the first argument passed to the
swap() function.  Also removes this argument from the argument list.

>     $e = "." x shift; <- ??

Set the variable $e to be a string consisting of a period, repeated the
number of times equivalent to the next argument passed in. Also removes
this argument from the argument list.   (ie, if the second argument was
5, this would set $e = '.....'; )

>     s/($e)($e)/$2$1/g; <- all I know is that this is a 'regular
expression'

Searches for all occurrences of two back-to-back instances of the
variable $e within $_, and swaps those two instances.

This is, of course, completely pointless, as $e can only contain one
value.  This has no net effect on the string in $_ whatsoever.

>     return $_; <- function returns a value, I understand that one
> }
>

Paul Lalli




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

Date: Thu, 14 Oct 2004 19:15:31 +0200
From: Moon <moon@world.universe>
Subject: Re: A newbie question
Message-Id: <1fmgqxmqnh4k7.1kvagf7jxmeeb.dlg@40tude.net>

Dnia Thu, 14 Oct 2004 17:07:46 GMT, postmaniak Paul Lalli odważył się
napisać:

> Please put the subject of your post in the Subject of your post.  That
> will increase your chances of getting help.  In this case, an
> appropriate Subject might have been "Please help translate this code"

Thanks - people learn for the whole life :)

>> $abc = shift;

What about this one? What it 'shifts'?

>>     s/($e)($e)/$2$1/g; [...]

> This is, of course, completely pointless

I understand that if this program wouldn't have this line it would work
completely the same way?

> Paul Lalli
Thanks Paul, greets from Poland!

-- 
<Moon>
[Reply-To=ROT13]


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

Date: Thu, 14 Oct 2004 11:15:56 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A newbie question
Message-Id: <10mtd27s1bm8081@corp.supernews.com>

Paul Lalli wrote:

> This is, of course, completely pointless, as $e can only contain one
> value.  This has no net effect on the string in $_ whatsoever.

In this case, it does. $e contains a string of dots, so it will match 
the first length($e) characters, no matter what they are.



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

Date: Thu, 14 Oct 2004 11:25:40 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A newbie question
Message-Id: <10mtdkg1aib0b02@corp.supernews.com>

Moon wrote:

> sub swap($$)

Declare a new subroutine named 'swap' that expects two values as arguments.

> {
>     $_ = shift;

Set $_ to the first value in the argument list, and remove the first 
argument from the argument list.

>     $e = "." x shift;

Set $e to a string of dots, having the number of dots specified in the 
second argument, which is assumed to be numeric. Also removes the second 
argument from the argument list.

>     s/($e)($e)/$2$1/g;

Swap the first (length of $e) characters in the string with the second 
(length of $e) characters in the string. The 'g' causes the regular 
expression to continue working through the whole string so that the 
third (length of $e) characters will be swapped with the fourth, etc., 
until there are not enough characters remaining in the string to satisfy 
the match.

>     return $_;
> }

swap('abcdefghijklmnop', 3) = defabcjklghimnop



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

Date: Thu, 14 Oct 2004 19:29:06 +0200
From: Moon <moon@world.universe>
Subject: Re: A newbie question
Message-Id: <1w483f1fl8zc7$.1e485p2h4vegg$.dlg@40tude.net>

Dnia Thu, 14 Oct 2004 11:25:40 -0600, postmaniak Scott Bryce odważył się
napisać:

Thanks very much Scott, that's the answer I've been waiting for:)

-- 
<Moon>
[Reply-To=ROT13]


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

Date: Thu, 14 Oct 2004 18:28:51 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: A newbie question
Message-Id: <ckmco3$qs$1@sun3.bham.ac.uk>



Moon wrote:

[ not in the context of a subroutine ]

>$abc = shift;
> 
> 
> What about this one? What it 'shifts'?

Descriptions of the bahaviour of Perl's builting functions can be found 
in the Perl reference manuals.  Specifically in perlfunc.

You can view the documentation for a specific function using 'perldoc -f'

Eg.

perldoc -f shift

[...]  If ARRAY is omitted, shifts the "@_" array within the lexical
scope of subroutines and formats, and [...] at file scopes or [...]

>>>    s/($e)($e)/$2$1/g; [...]
> 
> 
>>This is, of course, completely pointless
>
> 
> I understand that if this program wouldn't have this line it would work
> completely the same way?

That is not a question.

If $e contains no regex metacharacters then the replacement would always 
be the same as the target.

But if $e='.' then it would have the effect of swapping pairs of 
adjacent characters (other than "\n").

"foo\nbarbaz\n" would become "ofo\nabbrza\n"

Actually it also has the side effect of stingifying $_ if the pattern 
matched.  If $_ was already a string (as opossed to one of Perl's more 
exotic types) then this effect can be ignored.



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

Date: Thu, 14 Oct 2004 11:36:20 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A newbie question
Message-Id: <10mte8gngpfq097@corp.supernews.com>

Moon wrote:

>>>$abc = shift;
> 
> 
> What about this one? What it 'shifts'?

It shifts the list stored in @ARGV, that is, it sets $abc to the first 
argument with which the script was called.

You can find documentation for Perl at perldoc.com. Ask here about 
anything in the docs that you don't understand.

>>>    s/($e)($e)/$2$1/g; [...]
> 
> 
>>This is, of course, completely pointless
> 
> 
> I understand that if this program wouldn't have this line it would work
> completely the same way?

Usually that would be the case with this regex, but in this case $e 
contains characters that have a special meaning inside of a regex.

See my earlier post in this thread.



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

Date: Thu, 14 Oct 2004 17:37:27 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: A newbie question
Message-Id: <rPybd.833$%c3.458@trndny09>

"Moon" <moon@world.universe> wrote in message
news:1fmgqxmqnh4k7.1kvagf7jxmeeb.dlg@40tude.net...
> >> $abc = shift;
>
> What about this one? What it 'shifts'?

You didn't ask about this one originally. :-)    If you go to the second
site I suggested originally, and lookup the function 'shift', you'll see
this passage:

     If ARRAY is omitted, shifts the @_ array within the lexical scope
of subroutines and formats, and the @ARGV array at file scopes

So this one, not being in a subroutine, is shifting the @ARGV array.
@ARGV is the list of command-line arguments passed to the program.

> >>     s/($e)($e)/$2$1/g; [...]
>
> > This is, of course, completely pointless
>
> I understand that if this program wouldn't have this line it would
work
> completely the same way?

No.  As Brian pointed out, I erred.  I wasn't thinking enough.  My
apologies for this.  In a regular expression, the period is a special
character that means "any character".  So this line will actually take
the first string of characters (of the length passed as the 2nd argument
to the function), and swap it with the next string of characters of the
same length.  It will continue doing this for the remainder of the
string.

Assume, for example, that this function is called with arguments of
'abcdefghijklmnop' and 3.  This function will then return
defabcjklghimnop
That is, it swaps each set of 3 characters it finds.  At the end, it
can't find 6 more characters, so it leaves the remainder alone.

Paul Lalli




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

Date: Thu, 14 Oct 2004 11:39:24 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A newbie question
Message-Id: <10mtee86ou2j5f4@corp.supernews.com>

Moon wrote:

> Dnia Thu, 14 Oct 2004 11:25:40 -0600, postmaniak Scott Bryce odważył się
> napisać:
> 
> Thanks very much Scott, that's the answer I've been waiting for:)

If history repeats itself, someone will point out a mistake or two that 
I made. I'm still learning.



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

Date: Thu, 14 Oct 2004 11:42:41 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: A newbie question
Message-Id: <10mtekdbvm2jpf7@corp.supernews.com>

So, is this thread proof that a total Perl newbie CAN get good help in 
this NG?



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

Date: Thu, 14 Oct 2004 19:55:41 +0200
From: Moon <moon@world.universe>
Subject: Re: A newbie question
Message-Id: <1x59o5uro41gy.tioy05kdg798.dlg@40tude.net>

Dnia Thu, 14 Oct 2004 11:39:24 -0600, postmaniak Scott Bryce odważył się
napisać:

> I'm still learning.

:)
I have one more question though... return $_ returns a value. But which
value? The value created by "$_ = shift;" line? If so, the other two lines
are completely useless, as they don't manipulate on $_.

-- 
<Moon>
[adres Reply-To zaszyfrowany ROT13]


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

Date: Thu, 14 Oct 2004 17:58:26 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: A newbie question
Message-Id: <67zbd.274$HE1.81@trndny01>

"Moon" <moon@world.universe> wrote in message
news:1x59o5uro41gy.tioy05kdg798.dlg@40tude.net...
> Dnia Thu, 14 Oct 2004 11:39:24 -0600, postmaniak Scott Bryce odważył
się
> napisać:

> I have one more question though... return $_ returns a value. But
which
> value? The value created by "$_ = shift;" line? If so, the other two
lines
> are completely useless, as they don't manipulate on $_.

Yes they do.  I wasn't wrong about that part of my original post. :-)
The search-and-replace regular expression directly operates on $_ when
no other string is bound to it:

$str = s/foo/bar/;   #replaces 'foo' with 'bar' within $str
s/foo/bar/;   # replaces 'foo' with 'bar' within $_

Paul Lalli




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

Date: Thu, 14 Oct 2004 13:49:15 -0400
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: A newbie question
Message-Id: <aZybd.26186$hk6.1006634@news20.bellglobal.com>

Scott Bryce wrote:
> In this case, it does. $e contains a string of dots, so it will match 
> the first length($e) characters, no matter what they are.

Except for "\n" unless the /s modifier is set, which it is not in this case.

	--- Shawn


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

Date: Thu, 14 Oct 2004 10:52:45 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: function overloading in Perl
Message-Id: <ckm7cf$94d1@onews.rockwellcollins.com>

wana wrote:
> I read something about function/method overloading in Perl relating to
> OOP, but I was wondering about how to do it normally.

In Perl OO different classes can have methods with the same name that do
different things, but I don't consider that overloading.

> I have two functions that basically do the same thing.
> 
> In C++ I would give them the same name and the parameter list would
> differentiate the two (function overloading).  In Perl, there is no
> parameter list as far as I have learned.

Of course there's a parameter list, that's how we pass arguments. What
there is not is strong typing and compile-time type checking that would
allow perl to resolve the ambiguity between two subs with the same name.
So you can't overload functions in Perl.

> What would be the best way to incorporate these functions into one
> function if overloading is not possible?
> 
> I mean so it can be called as SaveToFile(\@myarray,$filename) or
> SaveToFile('my string',$filename) with the appropriate results.

Perl doesn't have strong typing, but it does distinguish between three
basic data types: scalars, arrays, and hashes. You can use this to check
the reference type of the first argument, e.g.

sub SaveToFile {
  if (! ref($_[0])) {
    # process data as string
  }
  elsif (ref($_[0]) eq 'ARRAY') {
    # process data as array
  }
  else {
    # error: unexpected ref type
  }
}

-mjc


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

Date: Thu, 14 Oct 2004 17:50:21 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: hard references/arrays
Message-Id: <ckmafs$sca$1@sun3.bham.ac.uk>



Brian McCauley wrote:

> Tintin wrote:

>> Using repeated code like that is a red warning sign saying that it can 
>> be compacted,

I forgot to comment on that.

Yes, karma++



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

Date: Thu, 14 Oct 2004 18:02:01 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: hard references/arrays
Message-Id: <ckmb5o$sm6$1@sun3.bham.ac.uk>

Tintin wrote:

> "Paul Lalli" <mritty@gmail.com> wrote in message 
> news:Bm9bd.5421$275.4070@trndny01...
 >
>>Why would you want to loop through the *names* of the arrays instead of
>>the arrays themselves?
> 
> Because I wanted to use the array name along with its data.

>                      [...] let me wind the clock right back 
> and explain what I'm trying to do, ie: X.

[snip a lot of stuff that does not include any operations that use the 
array name along with its data ]

> Hopefully that explains things a little better.

No, it does not.



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

Date: Thu, 14 Oct 2004 08:42:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help with sorting lists of lists
Message-Id: <slrncmt0he.45d.tadmc@magna.augustmail.com>

Shawn Corey <shawn.corey@sympatico.ca> wrote:


> The problem with perldoc is its lack of adequate searching.


Use something else for searching then.

Any OS worth its salt can easily search in the *.pod files for you.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 14 Oct 2004 08:54:24 -0700
From: markus.cl@gmx.de (Markus Dehmann)
Subject: Re: How to package my perl scripts (that depend on other utils)
Message-Id: <c1e48b51.0410140754.15bcaf58@posting.google.com>

Jim Keenan <jkeen_via_google@yahoo.com> wrote in message news:<9ykbd.91$4V3.31@trndny01>...
> Markus Dehmann wrote:
> 
> > I have written a piece of software. It's some perl scripts and modules
> > which depend on jconv, latex and some special latex packages.
> > 
> > What is the best way to distribute such a thing? Just include jconv
> > and the latex packages? Is there a suitable installation routine, or
> > do I have write own installation scripts? Could I possibly use the
> > perl packager (not sure what it is exactly).
> > 
> > It should be as easy as possible for users to install on their
> > machine.
> > 
> 
> Assuming it's for a *nix-like environment, have you considered writing 
> an rpm?

I thought I could maybe use the Perl Packager, given that the part I
wrote is perl. But an RPM is a good idea, too. On the other hand,
LaTeX packages are not available as RPMs as far as I know. So, it
would be difficult to state the dependencies...


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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