[12444] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6044 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 18 12:07:21 1999

Date: Fri, 18 Jun 99 09:00:24 -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           Fri, 18 Jun 1999     Volume: 8 Number: 6044

Today's topics:
    Re: A buggy intersection-method (Tad McClellan)
    Re: A buggy intersection-method <thomas@bibsyst.no>
    Re: a thread on threads (the skinny on the schedule) <gbartels@xli.com>
    Re: accessing nested variable names <tchrist@mox.perl.com>
    Re: changing hash keys thru subroutine <rootbeer@redcat.com>
    Re: filenames into an array by pattern matching? (Tad McClellan)
        how to invoke multipart script from a script? <mark@jdcc.com.au>
    Re: localtime function using Activestates perl on NT4 (Larry Rosler)
    Re: localtime function using Activestates perl on NT4 <camerond@mail.uca.edu>
    Re: Locking of simple text file or database <rootbeer@redcat.com>
    Re: Losing referrer information when passing through a  <jde222RemovethiS@iname.com>
    Re: matinal musings and the madrugada (J. Moreno)
        multidimensional arrays with functions push and pop (CDMAFleet)
    Re: Multidimensional Associative (hash) array (Larry Rosler)
    Re: newbie <dgris@moiraine.dimensional.com>
    Re: newbie <dgris@moiraine.dimensional.com>
        No Wait TCP on Internet Sockets zephaar@my-deja.com
    Re: Opening a remote file? <simon@profero.com>
        pattern match by column <mculverhouse@pinnacle.co.uk>
    Re: pattern match by column (Greg Bacon)
        Perl in the device space (was Re: Personal Rant) <rootbeer@redcat.com>
        PerlSpeak (was: Re: Afraid to ask about Y2K!) <rootbeer@redcat.com>
    Re: Printing compound variables (?) <tchrist@mox.perl.com>
        Question <info@datalist.com>
    Re: Remove line from big flatfile? <jphillip@onyx.southwind.net>
    Re: Signature removal regex? (I.J. Garlick)
    Re: Signature removal regex? (I.J. Garlick)
    Re: UNIX: ~name won't work on system() as expected (Tad McClellan)
    Re: Variable substitution problem <tchrist@mox.perl.com>
    Re: Variable substitution problem <tchrist@mox.perl.com>
    Re: Variable substitution problem (Tad McClellan)
    Re: Variable substitution problems <tchrist@mox.perl.com>
    Re: Variable substitution problems <tchrist@mox.perl.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 18 Jun 1999 05:36:46 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A buggy intersection-method
Message-Id: <ev3dk7.mll.ln@magna.metronet.com>

[ Please limit your line lengths to the customary 70-72 characters,
  else they get hard to read after being quoted a few times...
]


Thomas Weholt (thomas@bibsyst.no) wrote:
: >
: > maybe the getEntries function is buggy? we can't tell since you didn't
: > post the code for it.
: >
: > uri


: Here`s the getEntries-method :

: sub getEntries(){
:         my @array = split(/$delim/, lc $index_hash{$_[0]});
:         return @array;
: }


   Well, we still don't know if getEntries is buggy, since we
   don't know what is in $delim.

   Using global variables like that is Very Bad!

   You should pass arguments to the sub instead.

   (if the hash is large, you may want to pass a reference instead,
    see perlref.pod
   )


: I`m pretty new to perl so the idiomatic way of typing things and my code tend to
: be verbose and uneffective. Thanks for the tip by the way!


   You do not need the temporary @array there:


sub getEntries {
   my($key, $delim, %index_hash) = @_;

   return split(/$delim/, lc $index_hash{$key});
}



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 18 Jun 1999 17:36:01 +0200
From: Thomas Weholt <thomas@bibsyst.no>
To: Tad McClellan <tadmc@metronet.com>
Subject: Re: A buggy intersection-method
Message-Id: <376A6761.1EA9C30F@bibsyst.no>

!

$delim is just a character, actually $, used to seperate fields in a record. It is
shared bewteen lots of scripts and I wasn`t sue if the $ was safe to use, so I put it
in a global var and stuffed it in a common file to be sure that the delimiter was the
same in all the scripts.

How is this bad coding?

Thomas Weholt



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

Date: Fri, 18 Jun 1999 10:27:21 -0400
From: Greg Bartels <gbartels@xli.com>
Subject: Re: a thread on threads (the skinny on the schedule)
Message-Id: <376A5749.38DBB266@xli.com>

Uri Guttman wrote:
> what about an application (in c) that used threads and had not a single
> lock or mutex and has been running full bore for over 2 years? i slurps
> in over 5 GB of web pages a day and is rock solid. it is the crawler
> used by northern light and i designed it that way.

I was planning on using threads only so that I could do 
subroutine continuaiton, call a sub, halt it halfway, 
call a second sub, let it finish, then let the first sub
finish. 

I was planning on controlling the threads explicitly so that
only one thread is running at a time. I'm just using it
to start and stop subroutines in mid execution.

this should alleviate any problems normally associated with threads,
as far as stepping on data, whatever.

if there was a way to do this without threads, and without fork,
I'm open to ideas, but it sounds like its one of these two solutions.

Greg


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

Date: 18 Jun 1999 09:09:44 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: accessing nested variable names
Message-Id: <376a6138@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    vectorcalculus@my-deja.com writes:
:With this setup:
:
:$first = 'This is the text I want to get at';
:$second = '$first';
:
:Is there a way I can get to the contents of $first
:by only directly accessing $second?  If I knew
:that $second contained the name of a valid scalar,
:can I get to the contents of the named scalar?

A new day, a new 'variable in a variable' faq.  Grr...

  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
-- 
What's the difference between Country music and Western music?  Well,
Country is about getting drunk, feeling sorry for yourself, and hitting
on your neighbor's wife.  Western, on the other hand, is about riding
the range, wide open spaces, and hitting on your neighbor's sheep.


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

Date: Fri, 18 Jun 1999 08:15:08 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: changing hash keys thru subroutine
Message-Id: <Pine.GSO.4.02A.9906180813580.5420-100000@user2.teleport.com>

On Fri, 18 Jun 1999 irfna@my-deja.com wrote:

> I'm having a problem changing a hash's keys

If you're trying to change the keys of a hash, you're probably not
thinking of the problem correctly.

> globally, through a sub, using typeglobs:

Don't use typeglobs! Use references.

Have fun with Perl.

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



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

Date: Fri, 18 Jun 1999 06:44:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: filenames into an array by pattern matching?
Message-Id: <2u7dk7.spl.ln@magna.metronet.com>

Deamon George Scapin (dscapin@harris.com) wrote:
: Another little question.  I currently use the following statement in order to
: put jpg file names into an array.  How do I add the capablility to get gif
: filenames into the same array?


: @thumbnail = grep /\-a.jpg$/, readdir(DIR);
                     ^  ^
                     ^  ^
                     ^  ^ you need to escape that if you want a literal dot
                     ^  
                     ^ that doesn't do anything...


   First you read 'perlre.pod' and 'perlop.pod', then you
   adjust your regex as required.


      @thumbnail = grep /-a\.(jpg|gif)$/, readdir(DIR);


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 19 Jun 1999 00:35:45 +0930
From: Mark <mark@jdcc.com.au>
Subject: how to invoke multipart script from a script?
Message-Id: <376A6049.8B0EC205@jdcc.com.au>

How do you invoke a multipart perl script from a perl script?
If I use the system command to invoke it how do I send it the multipart
values?

ie.
script a starts a process, invokes script b, completes process,
outputting to screen.
script b processes with some input given from script a (has to be in
multipart format), outputs nothing.



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

Date: Fri, 18 Jun 1999 08:09:26 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: localtime function using Activestates perl on NT4
Message-Id: <MPG.11d400f2bec66850989bfa@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7ka0si$99q$1@hermes.nz.eds.com> on Thu, 17 Jun 1999 17:18:07 
+1200, Garth Cunningham <garth.cunningham@nz.eds.com> says...
> I have the following piece of code.
> my @lt = localtime();
> printf ("%d-%d-%d %d:%d:%d",$lt[3],$lt[4]+1,$lt[5],$lt[2],$lt[1],$lt[0]);
> 
> On my unix system with perl 5.004_04 and the TZ environment variable set
> this returns the correct local date and time.
> Running this code on an NT4 workstation with Activestates perl ( build 509 )
> it returns a time that is an hour fast. The system is set at the correct
> time ( ie type time at the command prompt ).
> Do I need to set or pick up some timezone info ?

I'm not sure why you should have this problem on NT, and I can't test it 
now.  One thing I am sure of is that we can't let Y2K bugs go unnoticed 
at this juncture!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 18 Jun 1999 10:58:01 -0500
From: Cameron Dorey <camerond@mail.uca.edu>
To: Garth Cunningham <garth.cunningham@nz.eds.com>
Subject: Re: localtime function using Activestates perl on NT4
Message-Id: <376A6C89.1E3054B@mail.uca.edu>

[cc'd to gc, but only to clp.misc]

Garth Cunningham wrote:
> 
> Hi,
> 
> I have the following piece of code.
> my @lt = localtime();
> printf ("%d-%d-%d %d:%d:%d",$lt[3],$lt[4]+1,$lt[5],$lt[2],$lt[1],$lt[0]);
> 
> On my unix system with perl 5.004_04 and the TZ environment variable set
> this returns the correct local date and time.
> Running this code on an NT4 workstation with Activestates perl ( build 509 )
> it returns a time that is an hour fast. The system is set at the correct
> time ( ie type time at the command prompt ).
> Do I need to set or pick up some timezone info ?

works just fine on my machine w/o messing with timezones after the
install ( NT4 Workstation(SP3), AS509). What's DST like down there(i.e.,
do you have it?)? Have you set your system clock right in this regard? 

Cameron

-- 
Cameron Dorey
Associate Professor of Chemistry
University of Central Arkansas
Phone: 501-450-5938
camerond@mail.uca.edu


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

Date: Fri, 18 Jun 1999 08:55:31 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Locking of simple text file or database
Message-Id: <Pine.GSO.4.02A.9906180852170.5420-100000@user2.teleport.com>

On Thu, 17 Jun 1999, glchy wrote:

> im trying to lock a simple text file (temporarily serving as
> a database) but cant seem to get it to work. 

> open(NUMBER,"$file") || die $!;
> flock(NUMBER,2);

Just as checking the return value from open can tell you why it's failing
(via the $! special variable), checking the return value from flock will
give a hint as to why it's failing.

In this case, you're asking for an exclusive lock (needed for writing),
but you seem to have opened the file only for reading. Most systems
require you to have write access to obtain an exclusive lock.

I think you could use the methods in Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps! 

   http://www.stonehenge.com/merlyn/WebTechniques/

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



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

Date: Fri, 18 Jun 99 15:21:00 GMT
From: "Euro Jake" <jde222RemovethiS@iname.com>
Subject: Re: Losing referrer information when passing through a perl script...?
Message-Id: <7kdnql$894$1@news3.Belgium.EU.net>


On 18-Jun-1999, "Martin Quensel" <martin@adoma.se> wrote:

> Euro Jake skrev i meddelandet <7kd7g9$mbf$1@news3.Belgium.EU.net>...
> >Hello all,
> >
> >Through javascript, Im trying to use document.referrer to track where a
> >visitor came from on my site. Everything works fine until I have a
> >password
> >access handled by a perl script. Once passed the perl generated html
> >page,
> >the document.referrer info seems blank...
> >
> >Most certainly im overlooking a detail...
> >Anyone give me a hand?
> >Thanks in advance
>
> give you a hand on what?
> All i can say to you is:
> It seems like it doesent work the way you want it to work.
> Maybee you are overlooking a detail, maybee not.
>
> Now, that dident help you much im afraid.
>
> maybee this will help
> http://www.plover.com/~mjd/perl/Questions.html
>
>
> Best regards
> Martin Quensel

I assume the reference you supplied in your answer is an accidental
mistake..., it didnt mention anything related to my problem...
If it is not, I think you will create many friends this way...
Thougt this medium is a way to find information and assistance, apologies if
I am wrong
Nevertheless, thank you for your contribution and your help


-- 
Euro Jake
>RemovethiS< in next line...
Anti spam email  jde222RemovethiS@iname.com


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

Date: Fri, 18 Jun 1999 12:01:41 -0400
From: planb@newsreaders.com (J. Moreno)
Subject: Re: matinal musings and the madrugada
Message-Id: <1dtle4a.1ck93mh1ofosz7N@roxboro0-0040.dyn.interpath.net>

Larry Rosler <lr@hpl.hp.com> wrote:

> David Cantrell <NukeEmUp@ThePentagon.com> says...
> > Greg Bartels <gbartels@xli.com> said:
> > 
> > >course, the Marine Corps always dated their documents YY/MM/DD
> > >(which was a pain in the butt to unlearn in civilian life)
> > >so I dont know that they're the leaders in time standards.
> > 
> > Makes it nice n' easy to sort by date in a language which doesn't
> > support a Date type (see - back on topic!) which is a Good Thing.
> 
> I sense a certain limit to the sortability of that, which the 
> originators of its use didn't concern themselves with, somehow.  Some
> might consider this a Bad Thing.

It depends -- I use it for file naming of faxes and other business docs,
it makes it easy to find them.  The fact that 00/01/01 will sort before
99/12/31 is really immaterial -- I'm looking for faster access not a
timeline, and a lot of them are already arranged by year in the
directories (making it a bit redundant I know, but easier if it's moved
out of it's proper home for one reason or another).

-- 
John Moreno


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

Date: 18 Jun 1999 15:59:41 GMT
From: cdmafleet@aol.com (CDMAFleet)
Subject: multidimensional arrays with functions push and pop
Message-Id: <19990618115941.28993.00001385@ng-cj1.aol.com>

I'm having trouble with getting Perl to see what I want it to see.

Let's say you've got a multidimensional array (an array for each login id on
the machine for example).  So if there's twenty different login ids and you
need to store their phone number, last time logged in, address and few other
things, then the multidimensional array would look something like this:

@myarray = ( [], [], [], [], [] ... and so on).

You could do this through a for loop it seems.  (Which is actually how I create
the blank startup array.)

for ($i = 0; $i < $number_of_login_ids; $i++)
{

  @myarray = (@myarray, []);

}  # end for loop [$i]

(PS.  If my code looks funny, I'm a C coder first, then a Perl scripter next!)

Now let's say I want to add an element to the third sub-array.
So I want to access $myarray[2][?].  More specifically, I'd like to "push" an
element on the end of that array.

push ( ($myarray[2]), $data);

This doesn't work because Perl thinks I am referencing an element
($myarray[2]), not the sub-array itself.  How do I get Perl to "see"
$myarray[2] as a sub-array instead of just another element?

If it's isn't possible through "push", then how else can I do it without
copious amounts of memory copying.  I was thinking about having a "reference"
function that would return the requested sub-array.  This would generate WAY
too much memory copying.

Also, on a side note, how would one get the length (number elements) [1] and
the length (number of characters at a given index)...[2]

I.E.(1)  Size of the array... if the third sub-array in @myarray has twelve
elements, what's the Perl code?  (Usually just the @myarray will give me the
number of element in the main-array @myarray, but will $myarray[2] give me the
right answer?)

I.E.(2) Length of a given index... if the third sub-array has twelve elements
and the fifth element (index 4) is of length 27.  Does this mean length
($myarray[2][4]) == 27?  (Or am I crazy? [That too!])

Thanks,
Kevin.

Sorry about the silly signature (if there is one), I'm NOT an AOL user. 
Unfortunately, I'm a consultant at Fleet Bank stuck with an AOL dial-up account
for Net-Access.... What is the world coming to!?

Needless to say, do me a favor when replying (oh please please please!), please
reply/throw a CC: my way at :

Kevin_C_Arpe@Fleet.com

Thanks again!



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

Date: Fri, 18 Jun 1999 08:03:10 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Multidimensional Associative (hash) array
Message-Id: <MPG.11d3ff6ab3121814989bf9@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <7kd9mi$ejb$1@nnrp1.deja.com> on Fri, 18 Jun 1999 11:14:31 
GMT, jtubaugh@cftnet.com <jtubaugh@cftnet.com> says...
> In article <7k8o2s$quu$1@nnrp1.deja.com>,
>   jtubaugh@cftnet.com wrote:
> > Does anybody know of a way to store a hash array within another hash
> > array?

Not 'hash array', just 'hash' please.

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

# ' -w' to turn on warnings
use strict; # to force you to declare variables

> #Load each occurence of the hash array with its "attribute" values
> #
> $HASH_ARRAY{'A FIRST'} = "ATTR1 This is the first attribute of FIRST";

Don't use all caps for variables.
 ...

> Any comments/critique would be welcomed.

#!/usr/local/bin/perl -w
use strict;

my %hash;

# Line at a time:
$hash{'A FIRST'}{ATTR1} = "This is the first attribute of FIRST";
$hash{'A FIRST'}{ATTR2} = "This is the second attribute of FIRST";
$hash{'A FIRST'}{ATTR3} = "This is the third attribute of FIRST";

# Using a hash slice:
@{$hash{'B SECOND'}}{qw(ATTR1 ATTR2 ATTR3)} = (
    "This is the first attribute of SECOND",
    "This is the second attribute of SECOND",
    "This is the third attribute of SECOND",
);

# Using direct assignment of an anonymous hash:
$hash{'Z ETC'} = {
  ATTR1 => "This is the first attribute of ETC",
  ATTR2 => "This is the second attribute of ETC",
  ATTR3 => "This is the third attribute of ETC",
  ATTR4 =>
   "I may have more or *fewer* ATTRs in multiple occurences of hash"
};

foreach my $key (sort keys %hash) {
  print "-------------------------------\nkey = $key\n";
  print "ATTR_NM = $_\nATTR_VAL = $hash{$key}{$_}\n"
    for sort keys %{$hash{$key}};
}

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Jun 1999 09:47:39 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: newbie
Message-Id: <m3yahho6hw.fsf@moiraine.dimensional.com>

rlb@intrinsix.ca (Lee) writes:

> In article <7kcf3d$6fr$1@nnrp1.deja.com>,
> jvavatara@my-deja.com wrote:
> 
> >Is java overtaking perl?
> 
> Dear alt.rec.pets.cats:
> 
> Is it true that cats are nasty little beasts, and I should get a dog
> instead?

Yes.

HTH.
HAND.

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


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

Date: 18 Jun 1999 09:49:44 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: newbie
Message-Id: <m3so7po6ef.fsf@moiraine.dimensional.com>

jbritain@home.com (Jim Britain) writes:

> >Is java overtaking perl?
> 
> No, Perl use is increasing, and Java use is decreasing, 

Citation, please.  I believe that usage of both languages is
increasing. 

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


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

Date: Fri, 18 Jun 1999 14:01:36 GMT
From: zephaar@my-deja.com
Subject: No Wait TCP on Internet Sockets
Message-Id: <7kdjfp$i1e$1@nnrp1.deja.com>

Hi There,             Fri Jun 18 10:04:28 EDT 1999
Has anyone been able to do no wait IO on Internet sockets?
I am on Solaris 2.6 Ultra Enterprise 1 with Perl 5.004_01.
I checked all my books and cant seem to find any explicit
reference to it. Can I just use Fcntl and connect in perl
like I would in C/C++ to open/read/write/close on a tcp
socket?

Thanks in advance


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 18 Jun 1999 16:48:29 +0100
From: Simon Wistow <simon@profero.com>
Subject: Re: Opening a remote file?
Message-Id: <376A6A4D.9439235A@profero.com>



> use CGI qw(:standard);
> 
> open(DATA, ">http://www.microsoft.com/index.asp">
> print DATA header, start_html("Gone"),
>         "gone for demoronisation", end_html;
> close(DATA);


PHP3 does exctly that. It's quite handy if you're into that sort of thing.

http://www.php3.org

-- 

Simon Wistow                       Development
simon@profero.com                  Profero Ltd
Phone : 0171 700 9960       Fax : 0171 700 9961


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

Date: Fri, 18 Jun 1999 16:20:51 +0100
From: "Michael Culverhouse" <mculverhouse@pinnacle.co.uk>
Subject: pattern match by column
Message-Id: <929719290.28238.0.nnrp-04.9e980b2b@news.demon.co.uk>

I wish to change a certain string say '0101' to '9999' but only in columns
80 through 83.
Does anyone know how this is acheived please?
Many thanks.




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

Date: 18 Jun 1999 15:26:41 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: pattern match by column
Message-Id: <7kdofh$nnb$3@info2.uah.edu>

In article <929719290.28238.0.nnrp-04.9e980b2b@news.demon.co.uk>,
	"Michael Culverhouse" <mculverhouse@pinnacle.co.uk> writes:
: I wish to change a certain string say '0101' to '9999' but only in columns
: 80 through 83.

    % perl -pe 's/^(.{79})0101/${1}9999/' file ...

Greg
-- 
I worry that the person who thought up "Muzac" may be thinking up something
else. 
    -- Lily Tomlin


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

Date: Fri, 18 Jun 1999 08:00:45 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Perl in the device space (was Re: Personal Rant)
Message-Id: <Pine.GSO.4.02A.9906180742190.5420-100000@user2.teleport.com>

On Fri, 18 Jun 1999, Watcher wrote about building Perl into such things as
consumer electronics devices:

> Returning to Perl, I'm wondering if a version can be build for these
> devices?  Eg on CE (I know, I know...)?  Not the whole shebang of
> course, but a interpreter engine that runs pre-build scripts.

Can it be done? Yes, in principle. 

Of course, there will eventually be a de facto standard for such embedded
languages (just as Coke cans and Pepsi cans are sized such that they can
be dispensed from the same machinery; just as VHS wiped out Beta; just as
all credit cards fit in the same slots). Whoever gets a language embedded
in the most products will have a big advantage, just as Adobe did well to 
get PostScript into so many output devices.

And some languages are being pushed by someone with a lot of money to
finance the pushing (and the concomitant hype). No one spent a million
dollars hyping Perl last year. (Don't underestimate the hype. The Godzilla
movie made $400 million, and that wasn't because word of mouth.)

But even if it's not based upon Perl, what's likely to be embedded is not
likely to be (too) language-specific. Instead, it will probably be some
kind of intermediate code (not unlike Perl's opcodes, in fact). To the
extent that Perl can be made to compile to these opcodes, you'll be able
to program these machines with Perl.

Not that it will necessarily be fast or efficient....

Cheers!

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



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

Date: Fri, 18 Jun 1999 08:44:51 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: PerlSpeak (was: Re: Afraid to ask about Y2K!)
Message-Id: <Pine.GSO.4.02A.9906180832550.5420-100000@user2.teleport.com>

On Fri, 18 Jun 1999, Chris Nandor wrote:

> You are blaming the language, which is nonsense.  That's like blaming
> English because people can incite riots using it.

That's the crucial point.

I find it interesting that some people have actually tried to improve upon
English and other languages by creating languages in which certain
concepts simply could not be _expressed_, seemingly under the theory that,
if you can't say "hatred", you can't feel it. Perhaps now we should invent
PerlSpeak, in which there's no such word as "Y2K".

And also no such word as "Jar Jar", for that matter.

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



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

Date: 18 Jun 1999 09:19:35 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Printing compound variables (?)
Message-Id: <376a6387@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, vectorcalculus@my-deja.com writes:
:If I have this:
:
:$one = "text and stuff";
:$two = '$one';

Six times.  SIX FRICKING TIMES.   Have you no sense of 
proportion decency?  Who is this really?  

--tom
-- 
 PS/2 -- Half a computer
 OS/2 -- Half an operating system
 PS/2: Yesterday's hardware today. OS/2: Yesterday's software tomorrow


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

Date: 18 Jun 1999 11:16:27 -0500
From: "carmela" <info@datalist.com>
Subject: Question
Message-Id: <01beb99d$41a9be80$170a0a0a@carmela.idirect.com>


Hello...

Where do I post employment information for the Perl community in Toronto?

Thanks


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

Date: Fri, 18 Jun 1999 15:36:32 GMT
From: John Phillips <jphillip@onyx.southwind.net>
Subject: Re: Remove line from big flatfile?
Message-Id: <4Ita3.3346$A24.118788@typ42b.nn.bcandid.com>

Ken Williams <tekkin@hotmail.com> wrote:
> I have a text file that looks like:

> name12@here.com:h
> text2@there.com:h
> moretext@isp.com:t
> test@aolsucks.com:h
> testname1@alot.com:t

> etc.

> Whats the easiest way to remove all, say "moretext@isp.com" lines while 
> keeping everything else the way it is?  Each line a \r\n after it.  So 
> moretext@isp.com:t is actually moretext@isp.com:t\r\n if that matters.

> Thanks.

-- 
Look at sed.  (stream editor)


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

Date: Fri, 18 Jun 1999 15:03:03 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: Signature removal regex?
Message-Id: <FDJ353.rv@csc.liv.ac.uk>

In article <1dtk0av.syw4gff7uncwN@roxboro0-0013.dyn.interpath.net>,
planb@newsreaders.com (J. Moreno) writes:
> I.J. Garlick <ijg@csc.liv.ac.uk> wrote:
> 
> Why would anybody tell you that?  It's not a sig if it's not preceded by
> a sigdash.

You might think all sigs should start with "-- " on a line, and I would
agree with you. I fear we are in the minority however despite what the
rfc's say.

> I'm not a guru, but what's wrong with
> 
> $msg =~ s/(.+)\n-- \n.+/$1/s; # delete the sig

Tried something like that and I too thought I had it. (I used * though)
but it only works for the last signature found. Unfortunately this will
remove anything resembling a signature anywhere in the message, even the
wrong one.

I worded that badly. Basically what I am trying to do is supply the
ability to save a message into a Draft folder for later completion. I want
to remove the signature of the user but only if it was saved previously
with one in the first place. That's why I said I would know there
signature (assuming they don't change it in the mean time).

-- 
Ian J. Garlick
ijg@csc.liv.ac.uk

The Roman Rule
        The one who says it cannot be done should never interrupt the
        one who is doing it.



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

Date: Fri, 18 Jun 1999 15:06:57 GMT
From: ijg@csc.liv.ac.uk (I.J. Garlick)
Subject: Re: Signature removal regex?
Message-Id: <FDJ3BL.sJ@csc.liv.ac.uk>

In article <376960e5@cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> writes:
>      [courtesy cc of this posting mailed to cited author]
> 
> Here's what I do:

Thank's Tom and Greg. I think I will be able to get something that works
out of that 8-{ (How does one draw a smiley of someone going green at the
gills?) may take a while but I'll get there. TBH I can follow most of it
now, just need to disect the regex's properly to be sure I am not missing
anything.

-- 
Ian J. Garlick
ijg@csc.liv.ac.uk

The Roman Rule
        The one who says it cannot be done should never interrupt the
        one who is doing it.



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

Date: Fri, 18 Jun 1999 05:50:10 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: UNIX: ~name won't work on system() as expected
Message-Id: <io4dk7.mll.ln@magna.metronet.com>


[ Please limit your line lengths to the customary 70-72 characters,
  else they get hard to read after being quoted a few times.
]


Marko Hoepken (marko.hoepken@sican.de) wrote:

: Here I ran into an inconvenients by using full pathes instead of the shorter ~ operator.

: # ~hoepken is in real e.g. /home/users/hoepken
: # In a  C-shell it can be accessed by e.h. cd ~hoepken or so...
    ^^^^^^^^^^^^^


   You should read up on the two functions involved here.

   system() uses the Bourne shell.

   glob() uses the C shell.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 18 Jun 1999 09:17:10 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable substitution problem
Message-Id: <376a62f6@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    vectorcalculus@my-deja.com writes:
:I'm trying to separate the html portion of my
:cgi's into separate files.  

I have this oppressing sense of dij` lu.
And I don't particularly care for it.

--tom
-- 
    When in doubt, parenthesize.  At the very least it will let some
    poor schmuck bounce on the % key in vi.
            --Larry Wall in the perl man page 


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

Date: 18 Jun 1999 09:18:15 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable substitution problem
Message-Id: <376a6337@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    vectorcalculus@my-deja.com writes:
:I'm trying to separate the html portion of my
:cgi's into separate files.  

Oh for crying out loud, kid.  Get a clue, or hire
a programmer.

ASKING A FAQ FIVE DIFFERENT TIMES IS FIVE TIMES
TOO MANY.

--tom
-- 
 Unix is supported by IBM, like a hanging man is supported by rope
		 - _Life With Unix_  Don Libes & Sandy Ressler


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

Date: Fri, 18 Jun 1999 06:40:25 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Variable substitution problem
Message-Id: <pm7dk7.spl.ln@magna.metronet.com>

vectorcalculus@my-deja.com wrote:

   You are a hair's breadth from getting widely killfiled for
   asking FAQs and posting the same thing multiple times.

   This would be Very Bad for your chances of getting future
   questions answered here.

   You should improve your Usenet manners lest you piss off all
   the folks who might be able to help you.

   Monitor

        news.announce.newusers

   for what is expected of posters to Usenet.


: it doesn't replace the variables named in
: "htmlfile.html".  Is there a way to substitute
: values in for variables named in the html file?


   Perl FAQ, part 4:

      "How can I expand variables in text strings?"


: Thanks.

   Uh huh.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 18 Jun 1999 09:10:46 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable substitution problems
Message-Id: <376a6176@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, vectorcalculus@my-deja.com writes:
:If I have a scalar which contains the name of
:another scalar:

You already posted this, and I already answered you.
Please don't make duplicate postings.

--tom
-- 
If you are not part of the solution, you are part of the precipitate.


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

Date: 18 Jun 1999 09:16:12 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Variable substitution problems
Message-Id: <376a62bc@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    vectorcalculus@my-deja.com writes:
:I'm trying to separate the html portion of my
:cgi's into separate files.  

What, not once, not twice, but *THREE TIMES*.

Fine, that which I tell you three times is true:
you don't put variables in text files.  Period.

NAME
    perlfaq4 - Data Manipulation ($Revision: 1.49 $, $Date:
    1999/05/23 20:37:49 $)

DESCRIPTION
    The section of the FAQ answers question related to the
    manipulation of data as numbers, dates, strings, arrays, hashes,
    and miscellaneous data issues.

    ...

  How do I expand function calls in a string?

    This is documented in the perlref manpage. In general, this is
    fraught with quoting and readability problems, but it is
    possible. To interpolate a subroutine call (in list context)
    into a string:

        print "My sub returned @{[mysub(1,2,3)]} that time.\n";

    If you prefer scalar context, similar chicanery is also useful
    for arbitrary expressions:

        print "That yields ${\($n + 5)} widgets\n";

    Version 5.004 of Perl had a bug that gave list context to the
    expression in `${...}', but this is fixed in version 5.005.

    See also ``How can I expand variables in text strings?'' in this
    section of the FAQ.

    ...

  How can I expand variables in text strings?

    Let's assume that you have a string like:

        $text = 'this has a $foo in it and a $bar';

    If those were both global variables, then this would suffice:

        $text =~ s/\$(\w+)/${$1}/g;  # no /e needed

    But since they are probably lexicals, or at least, they could
    be, you'd have to do this:

        $text =~ s/(\$\w+)/$1/eeg;
        die if $@;                  # needed /ee, not /e

    It's probably better in the general case to treat those
    variables as entries in some special hash. For example:

        %user_defs = ( 
            foo  => 23,
            bar  => 19,
        );
        $text =~ s/\$(\w+)/$user_defs{$1}/g;

    See also ``How do I expand function calls in a string?'' in this
    section of the FAQ.

:But if I simply load
:in and print the file
:
:open (IN, "htmlfile.html");
:while <IN> {
:  print;
:}
:close (IN);
:
:it doesn't replace the variables named in
:"htmlfile.html".  Is there a way to substitute
:values in for variables named in the html file?
:(And by variables, I mean scalars)

See "Creating HTML Templates" in Chapter 20 of the Ram 
book.  Download its code from 

    ftp://ftp.oreilly.com/published/oreilly/perl/cookbook/

Meanwhile, read this again:

NAME
    perlfaq7 - Perl Language Issues ($Revision: 1.28 $, $Date:
    1999/05/23 20:36:18 $)

DESCRIPTION
    This section deals with general Perl language issues that don't
    clearly fit into any of the other sections.

    ...

  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
-- 
"There is no such thing as an underestimate of average intelligence."
				- Henry Adams


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

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

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