[12453] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6056 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 19 11:33:27 1999

Date: Sat, 19 Jun 99 07:00:19 -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           Sat, 19 Jun 1999     Volume: 8 Number: 6056

Today's topics:
    Re: binary file transfer on Win32 <rosso@uni-paderborn.de>
        Can Perl executables be compiled? (Joe Chan)
    Re: Can Perl executables be compiled? <tchrist@mox.perl.com>
    Re: Clear screen function in Perl? <gellyfish@gellyfish.com>
    Re: cookies <gellyfish@gellyfish.com>
    Re: Cron alternative? <admin@wasi.com>
    Re: Cron alternative? (Bart Lateur)
    Re: Database Management Problem <tchrist@mox.perl.com>
    Re: Losing referrer information when passing through a  <gellyfish@gellyfish.com>
    Re: Multi-screen Perl Script (Marcel Grunauer)
    Re: Newbie need help (Dave Cross)
    Re: Parsing bug in Perl? (Bart Lateur)
    Re: Parsing bug in Perl? <dgris@moiraine.dimensional.com>
    Re: Parsing bug in Perl? (Bart Lateur)
        replacing part of a tab-delimited string (JQ)
    Re: replacing part of a tab-delimited string (Bart Lateur)
    Re: replacing part of a tab-delimited string (brian d foy)
    Re: replacing part of a tab-delimited string (brian d foy)
    Re: replacing part of a tab-delimited string <rick.delaney@home.com>
    Re: Scalar Names (Abigail)
    Re: Scalar Names <tchrist@mox.perl.com>
    Re: Scalar Names (Bart Lateur)
    Re: UNIX: ~name won't work on system() as expected <tchrist@mox.perl.com>
    Re: What is functional difference between .pm and .pl? (Bart Lateur)
    Re: What is functional difference between .pm and .pl? <tchrist@mox.perl.com>
    Re: XS: newSVpv() and malloc <david@s-mart.demon.co.uk>
    Re: XS: newSVpv() and malloc <david@s-mart.demon.co.uk>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 19 Jun 1999 14:39:00 +0200
From: Andreas Geesen <rosso@uni-paderborn.de>
To: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: binary file transfer on Win32
Message-Id: <Pine.GSO.4.10.9906191434440.20851-100000@atm11>

On Wed, 16 Jun 1999, Tom Phoenix wrote:

> On Wed, 16 Jun 1999, Andreas Geesen wrote:
> 
> > Subject: binary file transfer on Win32
> 
> > i can't find a way around the odd CR/LF conversion.
> 
> binmode?
> 
> > 	if (!open(OUTFILE, ">$SAVE_DIR\/$Filename")) {
> 
> > 	binmode( $fh );
> > 	while ($Bytes = read( $fh,$Buffer,1024)) {
> > 		$BytesRead += $Bytes;
> > 		print OUTFILE $Buffer;
> > 	}
> 
> I didn't see that you made OUTFILE binmode. If it's getting binary data on
> a machine that cares, that's vital.

Ah, dumb me! You cracked down a huge brick wall in front of my eyes. I
feel sorry about bothering you at all, now.
Thanks after all and don't you think Win32 is a weird OS, too? (Does it
have the rights to be called an OS??)

Bye		Andreas

-------------------------------------------------------------------------------
     Andreas Geesen                             Uni/GH Paderborn
     rosso@uni-paderborn.de                     IRC: Titus (#Paderborn)
     http://titus.home.pages.de/                Phone/SMS: 0177 703 3683
     Key fingerprint = 65 4A 96 3E 21 FF FF 33  33 B2 96 AF 52 EE 7E C6
-------------------------------------------------------------------------------



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

Date: Sat, 19 Jun 1999 09:42:10 GMT
From: joechan25@hotmail.com (Joe Chan)
Subject: Can Perl executables be compiled?
Message-Id: <376b642e.5543921@news.force9.net>

Hi, I was wondering if Perl scripts could be compiled into stand alone
executables for distribution on other PC's without Perl installed.
This would be Windows based PC's.
TIA


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

Date: 19 Jun 1999 05:58:57 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can Perl executables be compiled?
Message-Id: <376b8601@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, joechan25@hotmail.com (Joe Chan) writes:
:Hi, I was wondering if Perl scripts could be compiled into stand alone
:executables for distribution on other PC's without Perl installed.
:This would be Windows based PC's.

Might one inquire as to which part of the standard answer to this standard
question as included in the standard perlfaq3 manpage that ships standard
with every perl distribution did you find particularly opaque?

Best answer: include a perl installation with your program.  Other answer:
use a code generator.

--tom
-- 
    X-Windows: The Cutting Edge of Obsolescence.
	--Jamie Zawinski


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

Date: 19 Jun 1999 12:22:30 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Clear screen function in Perl?
Message-Id: <7kg226$2ga$1@gellyfish.btinternet.com>

On Thu, 17 Jun 1999 10:58:43 GMT David Cantrell wrote:
>
> Although it should be pointed out that any method involving 'clear'
> will only work on a Unix-like system.  

To be fair the original poster did say he was on a Linux system ,,,

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 19 Jun 1999 11:39:15 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: cookies
Message-Id: <7kfvh3$2g3$1@gellyfish.btinternet.com>

On 16 Jun 1999 19:26:18 -0500 Abigail wrote:
> Leonid Goltser (leonid76@erols.com) wrote on MMCXV September MCMXCIII in
> <URL:news:7k8vk8$co4$1@autumn.news.rcn.net>:
> () Where can I find a tutoring about creating cookies with perl?
> 
> 
> Here's one, but it beats me what cookies have to do with Perl.
> 

You could do the recipe up in POD format - I suppose.  I'll try the recipe
later...

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Jun 1999 08:21:20 -0500
From: "RLD" <admin@wasi.com>
Subject: Re: Cron alternative?
Message-Id: <7kg5ja$c3d$1@hyperion.nitco.com>

>If you can't use cron, use at. :-)

Thanks... I've spent a good deal of time this morning trying to look
something up on "at" and you can imagine what searches bring up with that
word :-)  Is there a clear explanation of this function?

>You're right. None of this is Perl-specific. Maybe you should check the
>docs, FAQs, and newsgroups about programming for the CGI environment.


Will do... however... can you give me an example of how you would pass the
command to cron/at from the Perl script?  Where can I find this information?

Thanks again for your help!

RLD




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

Date: Sat, 19 Jun 1999 13:38:27 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Cron alternative?
Message-Id: <376e9b2a.3291490@news.skynet.be>

RLD wrote:

>My understanding is that once the user who initiates the script with the
>browser leaves the page to go on their merry way... the script dies.  If a
>provider will not allow for cron jobs that can be written by the script the
>first time around to execute script 2 in 10 minutes... is there a way to put
>the script to sleep for 10 minutes and then have it check for the response?
>
>Browsers will time out before that time... and we wouldn't want the user to
>wait on one page that long either while the script pushed for 10 minutes
>straight... am I overlooking a simple solution?

Probably. Go to Randal Schwartz' WebTechniques articles, and look for
"fork". The method he uses there, may well be the answer you're looking
for, for this particular application.

index:	http://www.stonehenge.com/merlyn/WebTechniques/
search form:	http://www.stonehenge.com/cgi/wtsearch
cheat link:	http://www.stonehenge.com/cgi/wtsearch?search=fork

Too bad I need cron myself on my webserver... :-/

	Bart.


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

Date: 19 Jun 1999 07:13:10 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Database Management Problem
Message-Id: <376b9766@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, Tim Forman <forman@cybersource.com> writes:
: close(NEWFILE);
: close(DB);
:`mv foo2.txt foo.txt`;
:}

Wicked!  Backticks in a void context!  Discarding errors!
Using a program not a built-in!  Bad!

--tom
-- 
As the trials of life continue to take their toll, remember that there
is always a future in Computer Maintenance.
                --National Lampoon, "Deteriorada"


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

Date: 19 Jun 1999 10:59:26 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Losing referrer information when passing through a perl script...?
Message-Id: <7kft6e$2a3$1@gellyfish.btinternet.com>

[ comp.lang.javascript returned to groups and followups set ]

On Fri, 18 Jun 99 20:30:10 GMT Euro Jake wrote:
> 
> Tried this in <head>   ... and in <body> ...
> print "<META HTTP-EQUIV=\"REFRESH\"
> CONTENT=\"1;URL=http://mysitehome/$targetk/index.shtml\">\n";
> 
> and this
> print "<script language=\"javascript\">
>   location.assign (\"http://mysitehome/$targetk/index.shtml\");
>   </script>\n";
> 
> and this
> print "<script language=\"javascript\">
>   window.location.href ='http://mysitehome/$targetk/index.shtml';
>   </script>\n";
> 
> All this transfers to the url i want... just ... the referrer info is
> blank...
> 
> And the referrer is still valid before the redirect happens...
> If the password isnt valid, the redirection instructions are left out
> displaying the error page... where the referrer info is still present
> 
> Im aware the prob isnt sitting in the Perl interface itself... but more in
> the transactions between the documents... and/or the interaction
> HTML/Perl/Javascript
> 
> Sooo... you tell me... where do i start....:)))
> 

As I said before you dont have a Perl problem here at all, you have a
problem with Javascript.  If the people in the Javascript group cant
give you an answer then perhaps it is because what you are trying to
do cant be done.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 19 Jun 1999 11:50:34 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: Multi-screen Perl Script
Message-Id: <37737f46.7968277@enews.newsguy.com>

On Fri, 18 Jun 1999 22:06:28 -0700, Tom Phoenix <rootbeer@redcat.com>
wrote:

>On Sat, 19 Jun 1999, John wrote:
>
>> I know this is a bit off topic, but the PERL/CGI newsgroups were
>> mostly in other languages that I could'nt understand (not English).
>
>What's a PERL/CGI newsgroup? I know of several newsgroups about Perl,
>but none is about the Common Gateway Interface. And there are some about
>CGI programming, but none is specifically about Perl. But maybe you're
>talking about fj.perl-and-cgi or some such.

There's de.comp.lang.perl.cgi, which, together with
de.comp.lang.perl.misc, are descendants from now defunct
de.comp.lang.perl.

Judging by thread names the split even seems to work (i.e. not too
many postings in the wrong group), although even with teutonic
efficiency people seem unable to read the FAQs.

Marcel



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

Date: Sat, 19 Jun 1999 11:14:48 GMT
From: dave@dave.org.uk (Dave Cross)
Subject: Re: Newbie need help
Message-Id: <376b7ac1.11985052@news.demon.co.uk>

On Fri, 18 Jun 1999 22:25:33 -0700, "nightcom"
<farell@startrekmail.com> wrote:

>Hi,
>can somebody help me?
>How do I configure Personal Web Server
>to run cgi scripts?
>I'm running win98 and recently downloaded
>ActivePerl Build 517, though I have no idea how  to run
>the demo cgi(s) included.
>I tried creating a virtual dir. and selected all three permission for
>this dir. but I still can't run any cgi(s).
>Even tried searching on activeperl's website but not much info
>there about PWS.

This isn't a Perl question and, as such, is off topic in this
newsgroup. Perhaps you should ask it in a group that discusses the
configuration of PWS like, for example (checks newsgroup list),
microsoft.public.win98.pws_4 or comp.infosys.www.servers.ms-windows.

One hint tho' - Apache (the definitive web server) is also available
for Win32.

hth,

Dave...

--
Dave Cross <dave@dave.org.uk>
<http://www.dave.org.uk>


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

Date: Sat, 19 Jun 1999 08:52:56 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Parsing bug in Perl?
Message-Id: <376d59d1.2015253@news.skynet.be>

Sean McAfee wrote:

>NNTP-Posting-Date: Sat, 19 Jun 1999 04:05:47 EDT

I don't believe this. Are you guys really posting in the middle of the
night? Tom Phoenix's reply dates from 2 AM local time. Jesus. Over here,
it's almost 11 AM, so for me, it's, er, "natural".

	Bart.


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

Date: 19 Jun 1999 07:17:19 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Parsing bug in Perl?
Message-Id: <m3vhckmisg.fsf@moiraine.dimensional.com>

bart.lateur@skynet.be (Bart Lateur) writes:

> Sean McAfee wrote:
> 
> >NNTP-Posting-Date: Sat, 19 Jun 1999 04:05:47 EDT
> 
> I don't believe this. Are you guys really posting in the middle of the
> night?

What's odd about that?  Night is a nice, peaceful time to spend
hacking without pressures from the Real World.

>        Tom Phoenix's reply dates from 2 AM local time. Jesus. Over here,
> it's almost 11 AM, so for me, it's, er, "natural".

It's 7 am locally, which, so far as I am concerned, is in no way
a `natural' time for a human to be doing anything besides sleeping. :-)

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Sat, 19 Jun 1999 13:18:17 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Parsing bug in Perl?
Message-Id: <376c9880.2609486@news.skynet.be>

Daniel Grisinger wrote:

>It's 7 am locally, which, so far as I am concerned, is in no way
>a `natural' time for a human to be doing anything besides sleeping. :-)

On a saturday? Damn right!

	Bart.


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

Date: Sat, 19 Jun 1999 09:34:48 GMT
From: pigs_can_fly@mindless.com (JQ)
Subject: replacing part of a tab-delimited string
Message-Id: <3776584e.55556001@news.cyberway.com.sg>

Hi

I have a tab-delimited string:

$string = "one	two	three	four";

variants of $substring can be either "one", "two", "three", or "four".

Using s///; how do I get rid of $substring in $string, together with
the [tab] character?


To put it in another way, in one line of code, 
-----------------------------------------------------------------------------
if $substring occurs at the beginning (^) or middle of $string, delete
$substring together with the [tab] character that follows AFTER.

	s/^$substring(/t)//;
	s/$substring(/t)//;

if $substring occurs at the end ($) of $string, delete $substring
together with the [tab] character BEFORE.

	s/(/t)$substring$//;
-----------------------------------------------------------------------------

I have gone through perlre, perlop and FAQ without success.

Also, is there a good online source that covers regular expressions?

Thanks


JQ


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

Date: Sat, 19 Jun 1999 09:48:06 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: replacing part of a tab-delimited string
Message-Id: <376b6471.177627@news.skynet.be>

JQ wrote:

>I have a tab-delimited string:
>
>$string = "one	two	three	four";
>
>variants of $substring can be either "one", "two", "three", or "four".
>
>Using s///; how do I get rid of $substring in $string, together with
>the [tab] character?

Er... does it HAVE to be regular expressions? If not, I'd prefer another
approch. Hey, as long as it works...

	
	$string = join("\t", 
	   grep { $_ ne $substring } split(/\t/,$string));

In short: split into fields, get rid of the field that is equal to
$substr, so ("one","two","three","four") is turned into, say,
("one","two","four"); and recombine into one string.

If you really need to use regexes, try

	s/(?:^|\t)\Q$substring\E(?:\t|$)/\t/;


>Also, is there a good online source that covers regular expressions?

Yup. Go to http://reference.perl.com/, go to the section on regular
expressions, and check out those links, starting with Tom Christiansen's
article, and the PDF of the chapter of the book "Effective Perl
Programming". Excellent stuff. 

	Bart.


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

Date: Sat, 19 Jun 1999 06:21:45 -0400
From: brian@pm.org (brian d foy)
Subject: Re: replacing part of a tab-delimited string
Message-Id: <brian-ya02408000R1906990621450001@news.panix.com>

In article <3776584e.55556001@news.cyberway.com.sg>, pigs_can_fly@mindless.com (JQ) posted:

> I have a tab-delimited string:

> $string = "one  two     three   four";

> variants of $substring can be either "one", "two", "three", or "four".

> Using s///; how do I get rid of $substring in $string, together with
> the [tab] character?

> To put it in another way, in one line of code, 

you could compress this to one line of code, although that's a silly
requirement:

   my $TAB = "TAB";
   
   foreach my $string ( qw(one two three four) )
      {
      $_ = "oneTABtwoTABthreeTABfour\n";
   
      s/
         (?:
             ^ \Q$string\E $TAB
         )
            |
         (?:
            $TAB \Q$string\E $
         )
            |
         (?:
            \Q$string\E $TAB
         )
      //x;
      
      print;
      }

it's less typing to do something like

   my $TAB = "TAB";
   
   foreach my $string ( qw(one two three four) )
      {
      $_ = "oneTABtwoTABthreeTABfour\n";
   
      $_ = join $TAB, grep !/\Q$string/, split /\Q$TAB/;
      
      print;
      }

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>


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

Date: Sat, 19 Jun 1999 07:11:32 -0400
From: brian@pm.org (brian d foy)
Subject: Re: replacing part of a tab-delimited string
Message-Id: <brian-ya02408000R1906990711320001@news.panix.com>

In article <376b6471.177627@news.skynet.be>, bart.lateur@skynet.be (Bart Lateur) posted:

> JQ wrote:
> 
> >I have a tab-delimited string:
> >
> >$string = "one two     three   four";
> >
> >variants of $substring can be either "one", "two", "three", or "four".

> If you really need to use regexes, try
> 
>         s/(?:^|\t)\Q$substring\E(?:\t|$)/\t/;

that regex won't work because it will leave leading and trailing
tabs when it replaces the first and last items respectively.

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>


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

Date: Sat, 19 Jun 1999 13:16:21 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: replacing part of a tab-delimited string
Message-Id: <376B97E4.30E0FC3@home.com>

[posted & mailed]

Bart Lateur wrote:
> 
>         $string = join("\t",
>            grep { $_ ne $substring } split(/\t/,$string));

Watch those trailing null fields!

    split(/\t/, $string, -1)

-- 
Rick Delaney
rick.delaney@home.com


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

Date: 18 Jun 1999 22:12:34 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Scalar Names
Message-Id: <slrn7mm2kv.gnv.abigail@alexandra.delanet.com>

Troy Knight (troyknight@troyknight.eurobell.co.uk) wrote on MMCXVIII
September MCMXCIII in <URL:news:7ken8f$k1m$1@aub.eurobell.net>:
'' At last I've found a decent perl newsgroups, been searching for one for
'' ages!

Maybe you should have *READ* the group as well. Not more than 10 minutes,
as your question only gets asked 5 times a day.

'' I have a script where I would like to assign a value to an scalar whose name
'' is an a followed by a number which is dependant on something, how would I do
'' this? If you place two scalar names together such as $a$two it comes up with
'' an error, and I can't really see how to it. I'd appreciate some help from
'' someone more experienced than me, Cheers.
'' 

Read the FAQ. Read dejanews. Or read this "decent" group.
What good is a decent group if you don't read it?



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 19 Jun 1999 05:51:04 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Scalar Names
Message-Id: <376b8428@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    "Troy Knight" <troyknight@troyknight.eurobell.co.uk> writes:
:At last I've found a decent perl newsgroups, been searching for one for
:ages! [BAD WRAP OR BAD PARAGRAPH?]
:I have a script where I would like to assign a value to an scalar whose name
:is an a followed by a number which is dependant on something, how would I do
:this? If you place two scalar names together such as $a$two it comes up with
:an error, and I can't really see how to it. I'd appreciate some help from
:someone more experienced than me, Cheers.

A new day, a new 'variable in a variable' faq.  Short answer: don't
use a hack when you need a data structure.  Long answer:

  How can I use a variable as a variable name?

    Beginners often think they want to have a variable contain the
    name of a variable.

        $fred    = 23;
        $varname = "fred";
        ++$$varname;         # $fred now 24

    This works *sometimes*, but it is a very bad idea for two
    reasons.

    The first reason is that they *only work on global variables*.
    That means above that if $fred is a lexical variable created
    with my(), that the code won't work at all: you'll accidentally
    access the global and skip right over the private lexical
    altogether. Global variables are bad because they can easily
    collide accidentally and in general make for non-scalable and
    confusing code.

    Symbolic references are forbidden under the `use strict' pragma.
    They are not true references and consequently are not reference
    counted or garbage collected.

    The other reason why using a variable to hold the name of
    another variable a bad idea is that the question often stems
    from a lack of understanding of Perl data structures,
    particularly hashes. By using symbolic references, you are just
    using the package's symbol-table hash (like `%main::') instead
    of a user-defined hash. The solution is to use your own hash or
    a real reference instead.

        $fred    = 23;
        $varname = "fred";
        $USER_VARS{$varname}++;  # not $$varname++

    There we're using the %USER_VARS hash instead of symbolic
    references. Sometimes this comes up in reading strings from the
    user with variable references and wanting to expand them to the
    values of your perl program's variables. This is also a bad idea
    because it conflates the program-addressable namespace and the
    user-addressable one. Instead of reading a string and expanding
    it to the actual contents of your program's own variables:

        $str = 'this has a $fred and $barney in it';
        $str =~ s/(\$\w+)/$1/eeg;             # need double eval

    Instead, it would be better to keep a hash around like
    %USER_VARS and have variable references actually refer to
    entries in that hash:

        $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all

    That's faster, cleaner, and safer than the previous approach. Of
    course, you don't need to use a dollar sign. You could use your
    own scheme to make it less confusing, like bracketed percent
    symbols, etc.

        $str = 'this has a %fred% and %barney% in it';
        $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all

    Another reason that folks sometimes think they want a variable
    to contain the name of a variable is because they don't know how
    to build proper data structures using hashes. For example, let's
    say they wanted two hashes in their program: %fred and %barney,
    and to use another scalar variable to refer to those by name.

        $name = "fred";
        $$name{WIFE} = "wilma";     # set %fred

        $name = "barney";           
        $$name{WIFE} = "betty";     # set %barney

    This is still a symbolic reference, and is still saddled with
    the problems enumerated above. It would be far better to write:

        $folks{"fred"}{WIFE}   = "wilma";
        $folks{"barney"}{WIFE} = "betty";

    And just use a multilevel hash to start with.

    The only times that you absolutely *must* use symbolic
    references are when you really must refer to the symbol table.
    This may be because it's something that can't take a real
    reference to, such as a format name. Doing so may also be
    important for method calls, since these always go through the
    symbol table for resolution.

    In those cases, you would turn off `strict 'refs'' temporarily
    so you can play around with the symbol table. For example:

        @colors = qw(red blue green yellow orange purple violet);
        for my $name (@colors) {
            no strict 'refs';  # renege for the block
            *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
        } 

    All those functions (red(), blue(), green(), etc.) appear to be
    separate, but the real code in the closure actually was compiled
    only once.

    So, sometimes you might want to use symbolic references to
    directly manipulate the symbol table. This doesn't matter for
    formats, handles, and subroutines, because they are always
    global -- you can't use my() on them. But for scalars, arrays,
    and hashes -- and usually for subroutines -- you probably want
    to use hard references only.

--tom

-- 
"Unix is the answer, but only if you phrase the question very carefully."
				- Belinda Asbell


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

Date: Sat, 19 Jun 1999 12:03:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Scalar Names
Message-Id: <376b86b9.2334916@news.skynet.be>

Troy Knight wrote:

>I have a script where I would like to assign a value to an scalar whose name
>is an a followed by a number which is dependant on something, how would I do
>this?

Why? I cannot possibly understand why you want a user's data trample all
over your program's variables, or why an array (or hash) won't do.

	Bart.


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

Date: 19 Jun 1999 05:54:16 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: UNIX: ~name won't work on system() as expected
Message-Id: <376b84e8@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    Rick Delaney <rick.delaney@home.com> writes:
:Apparently <'$test'> is OWTDI (though it is very misleading).

There seems to be some unannounced level of interpolation going
on here.

--tom
-- 
    "That government is best which governs least."
	--Thomas Jefferson


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

Date: Sat, 19 Jun 1999 11:30:07 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: What is functional difference between .pm and .pl?
Message-Id: <376b7ead.274679@news.skynet.be>

Abigail wrote:

>Where did I say my editor does syntax highlighting? I don't need that.
>I know what I type.

So what does "editor mode" mean, if it's not syntax highlighting?
Keyword completion?

>>I use .pl because that makes my editor jump into the appropriate mode. :)

	Bart.


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

Date: 19 Jun 1999 06:15:56 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: What is functional difference between .pm and .pl?
Message-Id: <376b89fc@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    bart.lateur@skynet.be (Bart Lateur) writes:
:>Where did I say my editor does syntax highlighting? I don't need that.
:>I know what I type.
:
:So what does "editor mode" mean, if it's not syntax highlighting?
:Keyword completion?

%editor_mode = (	# samples only
    'hacking' => q{
			set sw=4 ai 
			map! ^O {^M}^[O^T
		  },
    'text'    => q{
			set wraplen=75
    } 
    'html'    => q{
			abbr =bl <BLOCKQUOTE></BLOCKQUOTE>^[F<i
    },
);

$filetype = `file $file`;
if ( $filetype =~ /(C(\+\+)? program|(perl|awk) command) text/) {
    tmp_exrc('hacking');
EOF
} 
elsif ($filetype =~ /(ASCII|International language|English|news or mail) text/) {
    tmp_exrc('text');
} 
elsif ($filetype =~ /(exported SGML document|HTML document) text/) { 
    tmp_exrc('text');
} 
else....


-- 
 "My philosophy of life is that the meek shall inherit
  nothing but debasement, frustration, and ignoble deaths..." - Harlan Ellison


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

Date: Sat, 19 Jun 1999 09:58:15 +0000
From: David Coles <david@s-mart.demon.co.uk>
Subject: Re: XS: newSVpv() and malloc
Message-Id: <376B69B7.D80D5EAF@s-mart.demon.co.uk>

Elf Sternberg wrote:

> >Nope.  There are .*use.* functions which make a copy.  They may
> >realloc() things though so that they can put a '\0' at the end, so a
> >reasonable malloc() will help.
> 
>         Hmm.. My reading of the API seems to be the other way around.
> The newSVpv() function makes a copy, sv_usepvn uses the pointer you
> pass it.  I'm not sure how you would create a new SV and use strings
> you created.  Something like:
> 
>         SV * nsv = newmortal();
>         SvPOK_on(nsv);
>         sv_usepvn(nsv, string, strlen(string) + 1);

Hi,

My question seems related to this, so I hope you don't mind me hijacking
the thread ;)

I'm new to XSUB, and I was wondering if anyone could help me with
clarification of something. I want to use XSUB to create a perl
interface to a C library we have for our database system. The data
I get back from calls to this can contain nulls in the returned record
so I can't just treat it as a string - it would just get terminated at
the first null. Is there some way I can retrieve arbitrary length
binary data from a call to an XSUB? What kind of typemap rules would I
have to use.

If you can give me any pointers, please CC: to my mail address.

Thanks for your time!

--David Coles


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

Date: Sat, 19 Jun 1999 10:10:44 +0000
From: David Coles <david@s-mart.demon.co.uk>
Subject: Re: XS: newSVpv() and malloc
Message-Id: <376B6CA4.3134D1EF@s-mart.demon.co.uk>

Elf Sternberg wrote:

> >Nope.  There are .*use.* functions which make a copy.  They may
> >realloc() things though so that they can put a '\0' at the end, so a
> >reasonable malloc() will help.
> 
>         Hmm.. My reading of the API seems to be the other way around.
> The newSVpv() function makes a copy, sv_usepvn uses the pointer you
> pass it.  I'm not sure how you would create a new SV and use strings
> you created.  Something like:
> 
>         SV * nsv = newmortal();
>         SvPOK_on(nsv);
>         sv_usepvn(nsv, string, strlen(string) + 1);

Hi,

My question seems related to this, so I hope you don't mind me hijacking
the thread ;)

I'm new to XSUB, and I was wondering if anyone could help me with
clarification of something. I want to use XSUB to create a perl
interface to a C library we have for our database system. The data
I get back from calls to this can contain nulls in the returned record
so I can't just treat it as a string - it would just get terminated at
the first null. Is there some way I can retrieve arbitrary length
binary data from a call to an XSUB? What kind of typemap rules would I
have to use.

If you can give me any pointers, please CC: to my mail address.

Thanks for your time!

--David Coles


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

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

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