[11243] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4843 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 7 21:07:14 1999

Date: Sun, 7 Feb 99 18:00:17 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 7 Feb 1999     Volume: 8 Number: 4843

Today's topics:
        contains? (BLUESRIFT)
    Re: contains? (Martien Verbruggen)
    Re: contains? (Warren Jones)
    Re: cookies pointers <patfong@yoyo.cc.monash.edu.au>
    Re: cookies pointers (Martien Verbruggen)
    Re: CREATING TEXT TABLE (John Moreno)
        Device I/O <ken_kuller@adc.com>
        HTML File Upload <a-grayson@nwu.edu>
    Re: Is perl a freeware? (Martien Verbruggen)
        Perl Command Interpreter (Louis Milea)
    Re: Perl Command Interpreter (Martien Verbruggen)
    Re: Perl Command Interpreter (Ken Williams)
        Perl vs. ASP for new project <ssamat@ucsd.edu>
    Re: Perl vs. ASP for new project (Ken Williams)
    Re: Perl vs. ASP for new project (Christopher Spence)
    Re: Problems with shell parsing of exec. (Abigail)
        require and autoloaded module <someone@some.where>
    Re: Sending files via e-mail - please help. <paul@rainbow.nwnet.co.uk>
    Re: submit information with #exec cgi="/cgi-local/busin (brian d foy)
        system() & UNIX socket problem <kalium@gmx.de>
    Re: testing for scalar/list/array (Martien Verbruggen)
    Re: testing for scalar/list/array <rick.delaney@home.com>
        Using a perl script in a perl script <debot@xs4all.nl>
    Re: Using a perl script in a perl script <someone@some.where>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 7 Feb 1999 23:05:25 GMT
From: bluesrift@aol.com (BLUESRIFT)
Subject: contains?
Message-Id: <19990207180525.09188.00001148@ng96.aol.com>

Please forgive me.  I have been unsuccessful looking for an online or
downloadable language reference for writing CGI scripts in perl such as one can
find at Netscape for the JavaScript language versions.  I would greatly
appreciate a link!!!

In the meantime, I would like to learn how to perform a conditional based on a
test of the contents of a query string.  Here's as close as I can get on my own
without such a reference guide:

if ($ENV{QUERY_STRING} contains "this string") {...}

Thank you

Rob




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

Date: Sun, 07 Feb 1999 23:14:19 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: contains?
Message-Id: <f7pv2.63$Bg4.2907@nsw.nnrp.telstra.net>

In article <19990207180525.09188.00001148@ng96.aol.com>,
	bluesrift@aol.com (BLUESRIFT) writes:

> if ($ENV{QUERY_STRING} contains "this string") {...}

Don't do this. perl comes with a module called CGI, which hides all of
the nasties of the interface from you:

use CGI;

Documentation is installed with perl as well:

# perldoc CGI

Of course, you will need to understand what CGI is and does.
www.cgi-resources.com will enlighten.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Very funny Scotty, now beam down my
Commercial Dynamics Pty. Ltd.       | clothes.
NSW, Australia                      | 


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

Date: 7 Feb 1999 15:20:22 -0800
From: wjones@tc.fluke.com (Warren Jones)
Subject: Re: contains?
Message-Id: <79l73m$pup$1@purdy.tc.fluke.com>

bluesrift@aol.com (BLUESRIFT) writes:

> I have been unsuccessful looking for an online or
> downloadable language reference for writing CGI scripts in perl ...

For all but the simplest CGI scripts, your best choice is to use
the CGI module that's included with the standard perl distribution.
For more information, see:

    http://www.genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html

Or if you already have perl installed, just type:

    perldoc cgi

> In the meantime, I would like to learn how to perform a conditional
> based on a test of the contents of a query string.  Here's as close
> as I can get on my own without such a reference guide:
>
> if ($ENV{QUERY_STRING} contains "this string") {...}

  if ( $ENV{QUERY_STRING} =~ /this string/ ) {...}

or

  if ( index($ENV{QUERY_STRING),"this string") >=0 ) {...}

But you'll be much happier in the long run if you use the CGI module
instead.

--------------------------------------------------------------------
Warren Jones              | To keep every cog and wheel is the first
Fluke Corporation         | precaution of intelligent tinkering.
Everett, Washington, USA  |                          -- Aldo Leopold


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

Date: Mon, 8 Feb 1999 10:13:50 +1100
From: Patrick Fong <patfong@yoyo.cc.monash.edu.au>
Subject: Re: cookies pointers
Message-Id: <Pine.OSF.4.00.9902081011130.6273-100000@yoyo.cc.monash.edu.au>

I dont think you can use Perl to read and write cookies... then again I am
newbie :-).

What I did was use javaScript and the document.cookie object. 

function CreateCookie(name,value,expirydate)
function ReadCookie (name)
function ExtractCookieValue(value) <<--- which is in the readCookie
function.

hope this helps.

P.



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

Date: Sun, 07 Feb 1999 23:20:03 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: cookies pointers
Message-Id: <Dcpv2.65$Bg4.2907@nsw.nnrp.telstra.net>

[comp.lang.perl is a long dead newsgroup. Inform your news admin to
remove it]

In article <Pine.OSF.4.00.9902081011130.6273-100000@yoyo.cc.monash.edu.au>,
	Patrick Fong <patfong@yoyo.cc.monash.edu.au> writes:
> I dont think you can use Perl to read and write cookies... then again I am
> newbie :-).

You can use perl to implement the CGI interface and the HTTP protocol.
Cookies are just a bit of data that is sent back and forth between the
brower and the server as part of the HTTP headers. 

Sure you can do that in perl. The CGI module even comes with a bunch
of convenience functions and methods to do exactly that from a CGI
perspective. The LWP modules come with a bunch of functions and
methods to do that from a client perspective.


> What I did was use javaScript and the document.cookie object. 
> 
> function CreateCookie(name,value,expirydate)
> function ReadCookie (name)
> function ExtractCookieValue(value) <<--- which is in the readCookie
> function.

And that, of course, will not work if the client isn't running
JavaScript, while the HTTP header method will work. But then, none of
them will work if the client doesn't do anything with cookies. :)

None of this is really perl specific, except maybe the first remark
above, which I commented on.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: Sun, 7 Feb 1999 20:27:59 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: CREATING TEXT TABLE
Message-Id: <1dmv61k.1hwrc9lxlwep0N@roxboro0-062.dyn.interpath.net>

Abigail <abigail@fnx.com> wrote:

> -- 
> perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
>              "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
>              "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'

What's this supposed to do?  with the -we in it gives a error message,
without it doesn't seem to have any effect.

-- 
John Moreno


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

Date: Sun, 07 Feb 1999 16:35:51 -0600
From: "Kenneth M. Kuller" <ken_kuller@adc.com>
Subject: Device I/O
Message-Id: <36BE1547.EB636E8B@adc.com>

I am a novice at Perl, and rapidly running out of patience on a
particular problem.
I am working on a program that communicates with a device, and am trying
to query various status parameters.  Its replies are ASCII text without
any terminator or delimiting character (such as an end-of-line or
null.)  In some instances, the reply is a variable-length list.

Is there a way to tell in Perl whether a device (/dev/...) has any more
characters waiting?  Is there an input function with a timeout, a
"return all characters" function, an input-available query, or any
similar function?

---
Kenneth M. Kuller
ken_kuller@adc.com



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

Date: Sun, 07 Feb 1999 18:23:53 -0600
From: Adam Grayson <a-grayson@nwu.edu>
Subject: HTML File Upload
Message-Id: <36BE2E99.C8F9DB8F@nwu.edu>

I am trying to create an HTML form for uploading graphics, and
understand how to set up the form, print the results into a jpeg file,
but I'm confused on bringing in the actual girth of the image so that I
can print FILE $in{"graphic"}. Any good example of how to do this,
either with cgi.pm or cgi-lib.pl?

Thanks
Adam
-- 

Adam Grayson
Northwestern University, Evanston, IL.  USA
a-grayson@nwu.edu


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

Date: Sun, 07 Feb 1999 22:05:53 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Is perl a freeware?
Message-Id: <57ov2.44$Bg4.1861@nsw.nnrp.telstra.net>

In article <79erdt$muj$1@nnrp1.dejanews.com>,
	finleyd@vrinet.com writes:
> In article <2o5u2.60$_E3.4792@nsw.nnrp.telstra.net>,
> 
>> ...
>> PS. You'll find out that perl is free. Any advice to silly questions
>> on this newsgroup however is charged at a going rate of about $1 - $5 ...
> 
> Martien and all,
> 
> Perl itself is free. But a number of key add-ons, such as the recent IDE from
> activestate are NOT! As Perl gets more "mainstream", you are likely to see
> more of this.

Perl is free. perl is free. The ActiveState IDE is not necessary at
all to make it run. I wouldn't call that a _key_ add-on. 

I have never had any problems getting perl to run and do what I want
it to do (within language limitations), without shelling out any
money. And that won't change. You can probably buy all kinds of things
that will give you point and die interfaces, but they're not necessary
at all.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I took an IQ test and the results were
Commercial Dynamics Pty. Ltd.       | negative.
NSW, Australia                      | 


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

Date: Sun, 7 Feb 1999 04:42:46 GMT
From: lwxyzmilea@carroll.com (Louis Milea)
Subject: Perl Command Interpreter
Message-Id: <36bcb8ac.21172488@165.254.2.53>

I downloaded a perl script which is supposed to pull stock prices off
of Yahoo.  The instuctions that came with the script said I needed a
perl command interpreter to run the script.  Where can I get one, or
is there one built into my browser (Netscape 4.04).  I'm using Win95.
I'd appreciare any suggestions.
Thanks,
Louis Milea
Louis Milea
lwxyzmilea@czyxwarroll.com
Please remove the anit-spam last four letters of the alphabet to reply.


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

Date: Sun, 07 Feb 1999 23:12:21 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl Command Interpreter
Message-Id: <p5pv2.62$Bg4.2907@nsw.nnrp.telstra.net>

In article <36bcb8ac.21172488@165.254.2.53>,
	lwxyzmilea@carroll.com (Louis Milea) writes:
> perl command interpreter to run the script.  Where can I get one, or

http://www.perl.com/

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | In the fight between you and the world,
Commercial Dynamics Pty. Ltd.       | back the world - Franz Kafka
NSW, Australia                      | 


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

Date: Sun, 07 Feb 1999 23:29:05 GMT
From: tekkin@hotmail.com (Ken Williams)
Subject: Re: Perl Command Interpreter
Message-Id: <36be21c5.0@news.cgocable.net>

In article <36bcb8ac.21172488@165.254.2.53>, lwxyzmilea@carroll.com wrote:
>I downloaded a perl script which is supposed to pull stock prices off
>of Yahoo.  The instuctions that came with the script said I needed a
>perl command interpreter to run the script.  Where can I get one, or
>is there one built into my browser (Netscape 4.04).  I'm using Win95.
>I'd appreciare any suggestions.

Sounds cool.  Where did you get the script from?  I want it.

See www.activestate.com for perl for win32


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

Date: Sun, 7 Feb 1999 14:52:47 -0800
From: "Sameer Samat" <ssamat@ucsd.edu>
Subject: Perl vs. ASP for new project
Message-Id: <ZBov2.51162$641.39010@news.san.rr.com>

I've got a group that is undertaking quite a large web project.  Up until
now we've been prototyping in ASP but now that we are ready to start 'really
building' this thing we are pausing to evaluate which CGI approach works
best for us.  We need some help with this decision... mainly because I'm the
project manager and while I've been working with ASP for a while now, I
don't know much about Perl.

We will be doing a lot of the following:
           1)  Database Access
           2) setting, getting cookies
           3)  checking HTTP headers
           4) (we would like to maintain some user-state ... a la the ASP
Session object ... I'm not sure if perl has an equivalent??)
           5) Form results parsing (getting form fields from a POST / GET
response)

I know Perl has got modules that will handle 1, 2 and 5.  I can't imagine #3
is too difficult either. ...

my main questions are:

            How does database access performance with perl compare to access
via ADO objects in ASP?
                        How big a role does connection pooling play here?

            Is there any way, via perl, to maintain a session state for a
user across pages? (I didn't think so, but not sure)

          In terms of overall performance, I've heard / read things going
both ways.  There is a cache for compiled ASP scripts,
            what about for PERL? ... each script is recompiled every time?
Is there a way to keep the perl interpreter in memory, or does
            that need to fire up every time as well?

        Is Perl much slower on NT? and does this entire discussion pretty
much come down to 'do you want to use NT or Unix?' ... from some reading
I've done I'm beginning to believe that on NT you want to go the route of
ASP ... but Unix Perl is going to be faster than ASP on NT.

thanks for any help,

Sameer Samat
ssamat@ucsd.edu





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

Date: Sun, 07 Feb 1999 23:25:44 GMT
From: tekkin@hotmail.com (Ken Williams)
Subject: Re: Perl vs. ASP for new project
Message-Id: <36be20fc.0@news.cgocable.net>

In article <ZBov2.51162$641.39010@news.san.rr.com>, "Sameer Samat" <ssamat@ucsd.edu> wrote:
>            How does database access performance with perl compare to access
>via ADO objects in ASP?

Database access from perl is very fast and works well.

>          In terms of overall performance, I've heard / read things going
>both ways.  There is a cache for compiled ASP scripts,
>            what about for PERL? ... each script is recompiled every time?

I don't think perl scripts are compiled everytime, they're parsed.

>Is there a way to keep the perl interpreter in memory, or does
>            that need to fire up every time as well?

>        Is Perl much slower on NT? and does this entire discussion pretty
>much come down to 'do you want to use NT or Unix?' ... from some reading
>I've done I'm beginning to believe that on NT you want to go the route of
>ASP ... but Unix Perl is going to be faster than ASP on NT.

Unix/perl will not be faster than ASP on NT unless your using modperl.  If 
you use modperl, it will be much faster (assuming Apache).  You can't keep the 
interpreter in memory, it will be spawned for each script I think.

Your not comparing apples to apples.  Consider php3(www.php3.net), which 
accomplishes what ASP does but under Unix.  Compile it into apache, and use 
its built in database access capabilities and you have a very fast solution.  
Although php is for Unix, which is obviously perferred anyway for major sites.





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

Date: Mon, 08 Feb 1999 01:01:11 GMT
From: computershoppe@mediaone.net (Christopher Spence)
Subject: Re: Perl vs. ASP for new project
Message-Id: <36be3724.32078085@nntp.ne.mediaone.net>

Active state has a product you can purchase that claims to speed Perl
up by 30 TIMES when used on the web.  perl ex or something, might be a
good idea to look at that.


www.activestate.com


On Sun, 7 Feb 1999 14:52:47 -0800, "Sameer Samat" <ssamat@ucsd.edu>
wrote:

>I've got a group that is undertaking quite a large web project.  Up until
>now we've been prototyping in ASP but now that we are ready to start 'really
>building' this thing we are pausing to evaluate which CGI approach works
>best for us.  We need some help with this decision... mainly because I'm the
>project manager and while I've been working with ASP for a while now, I
>don't know much about Perl.
>
>We will be doing a lot of the following:
>           1)  Database Access
>           2) setting, getting cookies
>           3)  checking HTTP headers
>           4) (we would like to maintain some user-state ... a la the ASP
>Session object ... I'm not sure if perl has an equivalent??)
>           5) Form results parsing (getting form fields from a POST / GET
>response)
>
>I know Perl has got modules that will handle 1, 2 and 5.  I can't imagine #3
>is too difficult either. ...
>
>my main questions are:
>
>            How does database access performance with perl compare to access
>via ADO objects in ASP?
>                        How big a role does connection pooling play here?
>
>            Is there any way, via perl, to maintain a session state for a
>user across pages? (I didn't think so, but not sure)
>
>          In terms of overall performance, I've heard / read things going
>both ways.  There is a cache for compiled ASP scripts,
>            what about for PERL? ... each script is recompiled every time?
>Is there a way to keep the perl interpreter in memory, or does
>            that need to fire up every time as well?
>
>        Is Perl much slower on NT? and does this entire discussion pretty
>much come down to 'do you want to use NT or Unix?' ... from some reading
>I've done I'm beginning to believe that on NT you want to go the route of
>ASP ... but Unix Perl is going to be faster than ASP on NT.
>
>thanks for any help,
>
>Sameer Samat
>ssamat@ucsd.edu
>
>



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

Date: 8 Feb 1999 00:22:38 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Problems with shell parsing of exec.
Message-Id: <79laoe$lnp$1@client2.news.psi.net>

Michael Bowler (mkbowler@nortelnetworks.com) wrote on MCMLXXXIV September
MCMXCIII in <URL:news:36BB02C3.976331A@nortelnetworks.com>:
() I am trying to do the following... (simplified code)
() 
() unless ($pid = fork) {
()   #Child processing...
()    exec("$BinaryExe 1>$stdoutfile 2>$stderrfile");
() }
() #Parent processing...
() kill('HUP', $pid);  #Kill off the child.
() 
() This works fine if I leave off the stdout/stderr redirection from the exec
() statement, however, when the redirection is present, the exec creates a shell
() interpreter which creates another process for $BinaryExe.  In this case
() signalling $pid, kills the shell, but not $BinaryExe.  Any way around this?


Well, how do you expect shell interpretation of special characters is
going to happen, without starting up a shell?



Abigail
-- 
sub f{sprintf$_[0],$_[1],$_[2]}print f('%c%s',74,f('%c%s',117,f('%c%s',115,f(
'%c%s',116,f('%c%s',32,f('%c%s',97,f('%c%s',0x6e,f('%c%s',111,f('%c%s',116,f(
'%c%s',104,f('%c%s',0x65,f('%c%s',114,f('%c%s',32,f('%c%s',80,f('%c%s',101,f(
'%c%s',114,f('%c%s',0x6c,f('%c%s',32,f('%c%s',0x48,f('%c%s',97,f('%c%s',99,f(
'%c%s',107,f('%c%s',101,f('%c%s',114,f('%c%s',10,)))))))))))))))))))))))))


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

Date: Sun, 07 Feb 1999 23:28:23 +0000
From: kostas <someone@some.where>
Subject: require and autoloaded module
Message-Id: <36BE2197.C6427CD1@some.where>

Hi,
I've written a script (script.pl) in which I'm using a module
(Module.pm) that uses Autoloader.
In script.pl I want to use a function (a_function) that is a kept in a
file called function.pl

The autoloaded module also needs to use a_function so I've included
function.pl with a do directive.
I also used require to include a_function in script.pl

So here's how everything looks:

file function.pl:
sub a_function {
 .
 .
 .
}
------------------

file Module.pm:
package Module.pl      #The autoloaded module
do 'function.pl'; #The file containing a_function
require Exporter;
sub new {
 .
a_function(@params);
 .
 .
}
------------------

file script.pl:

use Module;
do 'function.pl'
 .
 .
 .
a_function (@params)
---------------------



The problem is that when the function is called in script.pl Perl for
some reason tries to find it in auto/main/a_function.al and naturally
fails.
The same will happen to Module.pm if I use: require 'function.pl'
instead of: do 'function.pl'


Firstly:
Why doesn't require work with autoloaded modules?

Secondly:
How can I explicitly tell Perl to look for specific functions in
specific files instead of auto/Module/function.al?

I'm using Perl 5.004_4

Thanks in advance, hope I made sense.

Kostas


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

Date: Sun, 07 Feb 1999 23:02:24 +0000
From: Paul Williams <paul@rainbow.nwnet.co.uk>
To: kaboom@gdynia.top.pl
Subject: Re: Sending files via e-mail - please help.
Message-Id: <36BE1B80.880106FD@rainbow.nwnet.co.uk>

I have written a free script which does basically what you want, I
suggest having a look at it (or installing it and then hacking it to
suit your needs :)

http://scripts.marschall.net/

The script is called mail-select


All the best,
-Paul

Marek Wawoczny wrote:
> 
> Hello!
> 
> I would like to send a binary file via e-mail (with sendmail). How to do
> it? I have some code (the subroutine which is sending the files is
> below) in Perl but it is not working. All permissions and stuff like
> that are set correctly. I think that with the code is something wrong.
> Please help.
> 
> --Start--
> open(MAIL,"|$mailprog -t");
> 
> print MAIL "To: $email ($realname)\n";
> print MAIL "From: $fromaddr ($fromname)\n";
> if ($organization) {
>    print MAIL "Organization: $organization\n";
> }
> else {
>    print MAIL "Organization: Auto sent file\n";
> }
> print MAIL "Subject: $file\n";
> print MAIL "X-Courtesy-Of: SendIt! 1.0\n\n";
> open(INPUT,"$filebase/$file")||&error;
> while (<INPUT>) {
>    chop $_;
>    print MAIL $_,"\n";
> }
> close (INPUT);
> close (MAIL);
> --End--
> --
> Marek Wawoczny
> Serwis Internetowy Kaboom
>  WWW: http://www.kaboom.gdynia.top.pl
>  FTP: ftp://ftp.kaboom.gdynia.top.pl
>  E-mail: kaboom@gdynia.top.pl
>  ICQ UIN: 5292063


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

Date: Sun, 07 Feb 1999 18:27:33 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: submit information with #exec cgi="/cgi-local/businessnewsup.pl" command?
Message-Id: <comdog-ya02408000R0702991827330001@news.panix.com>

In article <79imjk$ql6$1@news1.fast.net>, "John Counts" <jcounts@voicenet.com> posted:

> el_pollo_diablo wrote in message <79i0f3$kg4$1@news7.svr.pol.co.uk>...
> >Something like this:
> >
> >#exec cgi="/cgi-local/businessnewsup.pl $county='devon' $town='plymouth"
> >$business='example'"
> 
> you're almost right #exec
> cgi="/cgi-local/businessnewsup.pl?county=devon&town=plymouth&business=exampl
> e"
> 
> just start your list of parameters with a question mark and separate each
> with an & sign.  don't use quotes capitization is up to you.

that's a very server specific (and stupid) solution since it involves
environment contamination.  see the server docs (which might be 
referenced in teh CGI Meta FAQ).

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


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

Date: Sun, 07 Feb 1999 23:32:09 +0100
From: Mark Stier <kalium@gmx.de>
Subject: system() & UNIX socket problem
Message-Id: <36BE1469.4516B9E@gmx.de>

Hello,

when starting a perl sub process from within a perl program with
"system('test.pl >>log 2>&1 &');" the sub process cannot create a
working UNIX socket with "system('mknod',$nodename,'p');". It creates
one but file permissions look like "-rw-r--r--", not like
"prw-r--r--"...

Why?

(SuSE Linux 6.0, Kernel 2.2.1, Perl 5.005_02)

Thank You, Mark Stier


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

Date: Sun, 07 Feb 1999 22:15:47 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: testing for scalar/list/array
Message-Id: <ngov2.46$Bg4.1861@nsw.nnrp.telstra.net>

In article <vxj679h6wc2.fsf@goblin.pdj.renault.fr>,
	Patrick Hayes <Patrick.Hayes.CAP_GEMINI@renault.fr> writes:
> mgjv@comdyn.com.au (Martien Verbruggen) writes:
>> surprising, but explainable :)
> 
> Um, would you mind explaining it?

scalar context gets the last element of the list, which is an array,
which in scalar context returns the number of elements.

The surprising part is that the order in which things happen is not
entirely intuitive.

I expected this:
sub: flattens list, then checks for context

	return scalar (1, 2, 'a', 'b', 'c', 'd');
	
But this is what happens:
sub: checks for context, returns most appropriate part

	return scalar (1, 2, @three);

You can see the same effect with the following:

# perl -l
@three = qw(a b c d);
print scalar (1, 2, 'a', 'b', 'c', 'd');
print scalar (1, 2, @three);
__END__
d
4
# 

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | Make it idiot proof and someone will
Commercial Dynamics Pty. Ltd.       | make a better idiot.
NSW, Australia                      | 


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

Date: Sun, 07 Feb 1999 23:41:01 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: testing for scalar/list/array
Message-Id: <36BE265E.BB38A8C0@home.com>

Martien Verbruggen wrote:
> 
> The surprising part is that the order in which things happen is not
> entirely intuitive.

I would have to agree.
 
> I expected this:
> sub: flattens list, then checks for context
> 
>         return scalar (1, 2, 'a', 'b', 'c', 'd');
> 
> But this is what happens:
> sub: checks for context, returns most appropriate part
> 
>         return scalar (1, 2, @three);

Good explanation.  Now try this one:
 
#!/usr/local/bin/perl -w

sub test {
    $one = 1;
    $two = 2;
    @three = qw(a b c d);
    $ref_inside = \($one, $two, @three);

    print 'Inside:  ', ref $ref_inside, "\n";

    return ($one, $two, @three);
}

$ref_outside = \test();
print 'Outside:  ', ref $ref_outside, "\n";
__END__
Inside:  ARRAY
Outside:  SCALAR

I'm guessing it has something to do with this special case from perlref,

    As a special case, \(@foo) returns a list of references to the
    contents of @foo, not a reference to @foo itself. Likewise for
    %foo.

but I still don't see it.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Mon, 08 Feb 1999 01:03:45 +0100
From: Frank de Bot <debot@xs4all.nl>
Subject: Using a perl script in a perl script
Message-Id: <36BE29E0.D303502@xs4all.nl>

I've a little problem.
I have a banner script and an other script (banner.cgi and XX.cgi);

How can I use banner.cgi in xx.cgi ( Just like as in a SSI file )
I don't want to copy anything of the code's.

Thanks,




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

Date: Mon, 08 Feb 1999 01:17:04 +0000
From: kostas <someone@some.where>
To: Frank de Bot <debot@xs4all.nl>
Subject: Re: Using a perl script in a perl script
Message-Id: <36BE3B10.619B389B@some.where>

You can use:
'require' or 'do'

To include banner.cgi in XX.cgi include the following in the XX.cgi:

require 'banner.cgi';


if that doesn't work try:
do 'banner.cgi';

instead.

Make sure that banner.cgi is in Perl path by including its full
directory by saying:
BEGIN{unshift(@INC,"/the/full/path/banners");};


somewhere in the beggining of your XX.cgi.


good luck,
Kostas


Frank de Bot wrote:
> 
> I've a little problem.
> I have a banner script and an other script (banner.cgi and XX.cgi);
> 
> How can I use banner.cgi in xx.cgi ( Just like as in a SSI file )
> I don't want to copy anything of the code's.
> 
> Thanks,


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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