[10787] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4388 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 9 12:07:25 1998

Date: Wed, 9 Dec 98 09:00:19 -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           Wed, 9 Dec 1998     Volume: 8 Number: 4388

Today's topics:
    Re: 80 column conversion (John Moreno)
    Re: Assignment to same variable (Tad McClellan)
    Re: Assignment to same variable <Allan@due.net>
    Re: Assignment to same variable <david.burt@worldnet.att.net>
    Re: Beginner Book? <merlyn@stonehenge.com>
    Re: Better way to get values from a list? (Abigail)
        Can you use multiple formats? <dropzone@mail.utexas.edu>
    Re: Checking if a Dir exists (Tad McClellan)
    Re: Checking if a Dir exists <Allan@due.net>
        Decent Editor <amcnulty@nortel.co.uk>
    Re: Errors with SETUID and Perl Script mike_orourke@em.fcnbd.com
        GD.pm character problem bjorns@my-dejanews.com
    Re: Help!  Possible permissions problem? (Bart Lateur)
        how to ensure script is only run by one user at a time <23_skidoo@geocities.com>
        Perl ARRAYs <gwebb@reedtech.com>
    Re: Perl ARRAYs <hendrik.woerdehoff@sdm.de>
    Re: Perl ARRAYs (Tad McClellan)
        Perl Floating Point Rounding Algorithm? (Harry P Bloomberg)
    Re: Perl-to-C convertor (Andrew M. Langmead)
        problem fetching HTML PAGE <dcc1234@pacific.net.sg>
    Re: problem fetching HTML PAGE (Tad McClellan)
    Re: Redirecting STDIN (Andrew M. Langmead)
    Re: Spliting multiple databases. (Vikram Pant)
    Re: using the command  system() in perl cgi (Tad McClellan)
    Re: Y2K potential problem in localtime() (Bart Lateur)
    Re: Y2K potential problem in localtime() (John Moreno)
    Re: Y2K potential problem in localtime() (Bart Lateur)
    Re: Y2K potential problem in localtime() (John Moreno)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Wed, 9 Dec 1998 10:24:53 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: 80 column conversion
Message-Id: <1djrjzi.ab1pkn7j6bwzN@roxboro0-016.dyn.interpath.net>

Tim Gim Yee <tgy@chocobo.org> wrote:

> John Moreno <phenix@interpath.com> wrote:
> 
> >Tim Gim Yee <tgy@chocobo.org> wrote:
> >
> >> My cat walked across the keyboard, and this is what she came up with:
> >
> >Can I have that cat?
> 
> No, but I have a dog that does Visual Basic if anyone's interested.

No thanks.
 
-snip-

> >>      s/(.{1,$columns}$)|(.{1,$col}(?:\S\s+|-(?=\w)))|(.{$col})/
> >
> >Is this supposed to be taking care of the case where there isn't any
> >place to break?
> 
> Yes, it happens at the last 'or' captured by $3.  That could have been
> written more clearly:

So it does - don't know how I missed it.
 
-snip-

> >And those lines are wrapped using paragraph filling (i.e. the lines with
> >the same prefix are merged into as few or as many lines as is needed to
> >contain all of the text)?
> 
> Yes.  It breaks text into paragraphs, translates newlines in
> paragraphs to spaces, wraps then rejoins.  Whitespace between
> paragraphs is preserved.
> 
> It worked well for my purposes, except that it didn't take care of
> 'personal/ID quotes' such as:
> 
>   >>>>> "LW" == Larry Wall <larry@wall.org> writes:
> 
>     LW> It should be illegal to yell "Y2K" in a crowded economy.  :-)

Well if it works for you it works for you (and I too find the weirder
quoting a problem), but for doing it automatically (when the followup is
being created) I find wrapping without paragraph filling better (with
paragraph filling is best reserved to interactive use).

One of the advantage of doing the wrapping on a user selection is that
it is possible to handle (somewhat at least) the personal/id quotes by
comparing adjacent lines for the prefix (I'm not currently doing this
but it's not too hard) without having to delve to deeply into what to
exclude.  Of course whatever you come up with is bound to fail sometimes
-- quoting is done in so many ways that even human judgement is
insufficient to be 100% correct.

-- 
John Moreno


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

Date: Wed, 9 Dec 1998 08:58:07 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Assignment to same variable
Message-Id: <v53m47.hu4.ln@magna.metronet.com>

Allan M. Due (Allan@due.net) wrote:
: Tad McClellan wrote in message ...
: >Darren Ward (dward@pla.net.au) wrote:
: >: How can we grow a join in a loop?
: >: I'm trying to use:
: >: while ($loop ge 1) {
: >               ^^
: >               ^^  ge tests *strings*.  >= tests numbers
: >    Looks like that loop will run for a really really long time...



: Not that I am recommending this, it but Perl is amazingly clever.


   No cleverness there.

   '2' *is* less than '6' when interpreted as an ASCII string.

   '2' however is *greater* than '10'...


: while ($loop le 6) {
:     print "$loop ";
:     $loop++;
: }

: prints:
:  1 2 3 4 5 6
: and stops.


   I'm not sure if you are commenting on the "infinite loop" part,
   or on the ge vs. >= part since you quoted both.

   Try your loop with:

      while ($loop le 10) {

   it stops a little early  ;-)


   ( though I don't expect an IP to have 10 parts...  ;-)


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


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

Date: Wed, 9 Dec 1998 10:39:47 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Assignment to same variable
Message-Id: <74m5ae$k2s$1@camel18.mindspring.com>

Tad McClellan wrote in message ...
>Allan M. Due (Allan@due.net) wrote:
>: Tad McClellan wrote in message ...
>: >Darren Ward (dward@pla.net.au) wrote:
>: >: How can we grow a join in a loop?
>: >: I'm trying to use:
>: >: while ($loop ge 1) {
>: >               ^^
>: >               ^^  ge tests *strings*.  >= tests numbers
>: >    Looks like that loop will run for a really really long time...
>
>: Not that I am recommending this, it but Perl is amazingly clever.
>   No cleverness there.
>   '2' *is* less than '6' when interpreted as an ASCII string.
>   '2' however is *greater* than '10'...


I know, I know.  I wanted to take it back as soon as I clicked the send
button.  In fact I cancelled it right away but it was way too late.  Sorry.
Never mind.  Brain dead.  Not enough coffee.  Not enough knowledge.  Take
your pick.

AmD




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

Date: Wed, 09 Dec 1998 10:41:54 -0500
From: "Burt, David J" <david.burt@worldnet.att.net>
Subject: Re: Assignment to same variable
Message-Id: <01be238a$4449aa50$2611cfa8@oh02burtdj>

I may not be helping but anyway.
eq and >= are not the same.

eq does a literal comparison   (1 ge 1)  but not (1 ge 1.0) 
>= does a numeric comparison  (1>= 1)  and  (1 >= 1.0)  are both true



Tad McClellan <tadmc@metronet.com> wrote in article
<v53m47.hu4.ln@magna.metronet.com>...
> Allan M. Due (Allan@due.net) wrote:
> : Tad McClellan wrote in message ...
> : >Darren Ward (dward@pla.net.au) wrote:
> : >: How can we grow a join in a loop?
> : >: I'm trying to use:
> : >: while ($loop ge 1) {
> : >               ^^
> : >               ^^  ge tests *strings*.  >= tests numbers
> : >    Looks like that loop will run for a really really long time...
> 
> 
> 
> : Not that I am recommending this, it but Perl is amazingly clever.
> 
> 
>    No cleverness there.
> 
>    '2' *is* less than '6' when interpreted as an ASCII string.
> 
>    '2' however is *greater* than '10'...
> 
> 
> : while ($loop le 6) {
> :     print "$loop ";
> :     $loop++;
> : }
> 
> : prints:
> :  1 2 3 4 5 6
> : and stops.
> 
> 
>    I'm not sure if you are commenting on the "infinite loop" part,
>    or on the ge vs. >= part since you quoted both.
> 
>    Try your loop with:
> 
>       while ($loop le 10) {
> 
>    it stops a little early  ;-)
> 
> 
>    ( though I don't expect an IP to have 10 parts...  ;-)
> 
> 
> --
>     Tad McClellan                          SGML Consulting
>     tadmc@metronet.com                     Perl programming
>     Fort Worth, Texas
> 


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

Date: Wed, 09 Dec 1998 16:05:34 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Beginner Book?
Message-Id: <8cu2z5z4g1.fsf@gadget.cscaper.com>

>>>>> "Ronald" == Ronald J Kimball <rjk@linguist.dartmouth.edu> writes:

Ronald> With one significant caveat; someone who is using the book to
Ronald> learn Perl probably will not recognize technical errors in the
Ronald> book.

Ronald> What the book teaches is just as important as whether the book
Ronald> teaches.

My biggest fear is that someone will read a badly techreviewed Perl
book and then blame problems they've found on Perl and not the book.

That's why I have a standing open offer to techreview ANY perl book,
regardless of whether or not it competes with my market share.  It's
more important for me to have the Perl community have good docs than
for me to worry about a few bucks.  (And I've been taken up on that
offer a few times already.)

print "Just another Perl book hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 9 Dec 1998 16:38:01 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Better way to get values from a list?
Message-Id: <74m919$h6l$1@client3.news.psi.net>

Karl G. Jensen (karl_jensen@hp.com) wrote on MCMXXV September MCMXCIII in
<URL:news:366DB24B.EE889DFA@hp.com>:
++ I'm looking for suggestions for a better way to code something.
++ 
++ I have an array with values in it of the form "a=b". The first entry in
++ the array is a string with no "=" which I don't want to propagate.
++ 
++ I want an array with values in it of the form "b".
++ 
++ Here's how I did it:
++ 
++         foreach (@AB) {
++                 ($label, $field) = split('=');
++                 if ($field eq "") {
++                         next;   # Skip lines not of the form "a=b"
++                 }
++                 push @B, $field;
++         }
++ 
++ I expect that there is a way to do this in PERL with one line, without
++ having to interate through the first array. Can someone kindly show me
++ how?


@B = grep {/=./s} @AB;


Abigail


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

Date: Wed, 09 Dec 1998 09:45:39 -0600
From: Forrest Reynolds <dropzone@mail.utexas.edu>
Subject: Can you use multiple formats?
Message-Id: <366E9B1E.7B6E7B14@mail.utexas.edu>

Is it possible to define and use two or more FORMAT statements in a
program, not including FORMAT_TOP, footers, etc.?

I can't get it to work. I'm trying add subtotals to a program that
didn't have them and I want to use something like this:

format LOGREPORT =
~                    @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$print_dest
~@< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<       @>>>>>
@>>>>>
$save_src_state, $save_src_name, $total_transcr, $total_acknowl
~~  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $other_codes
 .
format SUBTOTAL =
~                                                  @>>>>>>>>>  @>>>>>
@>>>>>
    $subtotal, $dotty, $dotty
~                                                              @>>>>>
@>>>>>
    $subtotal_t, $subtotal_a
 .


                  Thanks, Forrest



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

Date: Wed, 9 Dec 1998 09:01:08 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Checking if a Dir exists
Message-Id: <kb3m47.hu4.ln@magna.metronet.com>

Allan M. Due (Allan@due.net) wrote:

: (-e $dirname) ? print "It is a file" : print "Not a file either, do we need
    ^
    ^  s/e/f/;


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


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

Date: Wed, 9 Dec 1998 10:42:10 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Checking if a Dir exists
Message-Id: <74m5es$lf8$1@camel18.mindspring.com>

Tad McClellan wrote in message ...
>Allan M. Due (Allan@due.net) wrote:
>
>: (-e $dirname) ? print "It is a file" : print "Not a file either, do we
need
>    ^
>    ^  s/e/f/;


Well sure, if you think being right is more important than being fast.
Sorry again.  Seem to have hit a bad streak here this morning.  Thank god
Tad is around to keep me in line.

AmD




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

Date: Wed, 9 Dec 1998 16:05:41 -0000
From: "Antony" <amcnulty@nortel.co.uk>
Subject: Decent Editor
Message-Id: <74m73h$sa5@bmdhh222.europe.nortel.com>

Anyone remeber the QBASIC DOS editor.

It was great for it's time.

I'd really like to have an editing program for my PERL scripts that shows
each subroutine as different pages, or something similar to that.
I'm not really sure if I'm explaing that well or not.


Anyway, Anyone got any knowledge of where I may find such an editor ??
Doesn't need to be PERL  specific.



Cheers
Antony




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

Date: Wed, 09 Dec 1998 15:14:44 GMT
From: mike_orourke@em.fcnbd.com
Subject: Re: Errors with SETUID and Perl Script
Message-Id: <74m451$60g$1@nnrp1.dejanews.com>

In article <74ki3b$sqj$1@nnrp1.dejanews.com>,
  mike_orourke@em.fcnbd.com wrote:
> In article <74k85g$k4t$1@nnrp1.dejanews.com>,
>   mike_orourke@em.fcnbd.com wrote:
> > In article <74juha$7lu$1@camel18.mindspring.com>,
> >   "Allan M. Due" <Allan@due.net> wrote:
> > > mike_orourke@em.fcnbd.com wrote in message
> > > <74jtnh$ana$1@nnrp1.dejanews.com>...
> > >
> > > [snip]
> > >
> > > >Below is an example of the code that I am using :
> > > >
> > > >$old_path = $ENV{"PATH"} ; $directory = "/export/home/lddv" ; $filename =
> > > >"test_chmod.txt" ; $file_owner = "lao7" ; if ($filename =~
/^([-\@\w.]+)$/)
> > > {
> > > > $filename = $1 ; } else {  die "Bad data in $filename" ; } if
($file_owner
> > > >=~ /^([-\@\w.]+)$/) {  $file_owner = $1 ; } else {  die "Bad data in
> > > >$file_owner" ; } if ($directory =~ /^([\/\-\@\w.]+)$/) {  $directory = $1
}
> > > >else { die "Bad data in $directory" ; } $ENV{"PATH"} =
> > > "/usr/sbin:/usr/bin";
> > > >system("chown  $file_owner '$directory/$filename'") && die "Could not run
> > > >CHMOD" ; $ENV{"PATH"} = $old_path ; exit ;
> > >
> > > Ow, ow, ow.  My head, my poor head hurts.  Just a little formatting
please.
> > >
> > > AmD
> > >
> > > Sorry.... Cut and paste didn't come out so clean
> >
> > Here is a better copy of the code :
> >
> > $old_path = $ENV{"PATH"} ; $directory = "/export/home/lddv" ; $filename =
> > "test_chmod.txt" ; $file_owner = "lao7" ; if ($filename =~ /^([-\@\w.]+)$/)
{
> >  $filename = $1 ; } else {  die "Bad data in $filename" ; } if ($file_owner
> > =~ /^([-\@\w.]+)$/) {  $file_owner = $1 ; } else {  die "Bad data in
> > $file_owner" ; } if ($directory =~ /^([\/\-\@\w.]+)$/) {  $directory = $1 }
> > else {	die "Bad data in $directory" ; } $ENV{"PATH"} =
> "/usr/sbin:/usr/bin";
> > system("chown  $file_owner '$directory/$filename'") && die "Could not run
> > CHMOD" ; $ENV{"PATH"} = $old_path ; exit ;
> >
> > -----------== Posted via Deja News, The Discussion Network ==----------
> > http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own
> >
> Is it three strikes and your out ?
>
> Let me try again.....
>
> $old_path = $ENV{"PATH"} ;  > $directory = "/export/home/lddv" ;  > $filename
> = "test_chmod.txt" ;  >  > $file_owner = "lao7" ;  > if ($filename =~
> /^([-\@\w.]+)$/) {  >  $filename = $1 ;  > } else {  >	die "Bad data in
> $filename" ;  > }  > if ($file_owner =~ /^([-\@\w.]+)$/) {  >  $file_owner =
> $1 ;  > } else {  >  die "Bad data in $file_owner" ;  > }  > if ($directory
> =~ /^([\/\-\@\w.]+)$/) {  >  $directory = $1  > } else {  >  die "Bad data in
> $directory" ;  > }  > $ENV{"PATH"} = "/usr/sbin:/usr/bin";  > system("chown
> $file_owner '$directory/$filename'") && die "Could not run CHMOD" ;  >
> $ENV{"PATH"} = $old_path ;  > exit ;  >
>
> No listed is the code that reads in a seperate file with a list of directories
> that can be modified ($directory). I also verify that $file_owner is a valid
> user on the server (getpwnam).
>
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own

As you can tell by now, I am new to this web site. The "preview" always looks
O.K.

However, I am not going to give up on this.

I will get this thing formatted correctly if its the only thing I do today.

> > $old_path = $ENV{"PATH"} ;
>
> > $directory = "/export/home/lddv" ;
>
> > $filename> = "test_chmod.txt" ;
>
> > $file_owner = "lao7" ;
>
> > if ($filename =~> /^([-\@\w.]+)$/) {
> >   $filename = $1 ;
> > } else {
> >   die "Bad data in $filename" ;
> > }
>
> > if ($file_owner =~ /^([-\@\w.]+)$/) {
> >   $file_owner = $1 ;
> > } else {
> >   die "Bad data in $file_owner" ;
> > }

>
> > if ($directory =~ /^([\/\-\@\w.]+)$/) {
> >   $directory = $1 ;
> > } else {
> >   die "Bad data in $directory" ;
> > }
>
> > $ENV{"PATH"} = "/usr/sbin:/usr/bin";
>
> > system("chown $file_owner '$directory/$filename'") && die "Could not run
CHMOD" ;

> > $ENV{"PATH"} = $old_path ;
> > exit ;

> No listed is the code that reads in a seperate file with a list of directories
> that can be modified ($directory). I also verify that $file_owner is a valid
> user on the server (getpwnam).

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 09 Dec 1998 14:54:07 GMT
From: bjorns@my-dejanews.com
Subject: GD.pm character problem
Message-Id: <74m2ue$4s9$1@nnrp1.dejanews.com>

Hi all,

GD.pm seems to have problems with many of the ASCII characters 161-255, for
example: the copyright symbol, the pipe, the trademark symbol, e and E
(Swedish characters) Not all, but many!

Is this correct?
Is there any work-arounds or hacks that anyone know of?

I'm using ActiveState 5.005_02 and have tried it on both NT4 (Swedish) and
win95 (English). Here's some example code:

    use locale; # Makes no difference
    use Strict;
    use GD;
        $gifout = "GD_bug_temp.gif" ;
        $texten = "Some problematic ASCII characters for GD.pm : )&eE!%";
        $text1 = "ASCII codes 161-255: !"#$%&'()*+,-./0123456789:;<=>?-";
        $text2 = "@ABCDEFGHIJKLMOPQRSTUVWXYZ[\]^_";
        $text3 = "`abcdefghiklmnopqrstuvwxyz{|}~";
        $im = new GD::Image(450,100);
        $white = $im->colorAllocate(255,255,255);
        $black = $im->colorAllocate(0,0,0);
        $red = $im->colorAllocate(255,0,0);
        $im->rectangle(0,0,449,99,$black);
        $im->string(gdLargeFont,10,10,"$texten",$red);
        # The font makes no difference
        $im->string(gdMediumBoldFont,10,30,"$text1",$black);
        $im->string(gdMediumBoldFont,10,50,"$text2",$red);
        $im->string(gdMediumBoldFont,10,70,"$text3",$black);
        open (MYGIF,">$gifout") || die  ("Problem open file $gifout");
        binmode MYGIF;
        print MYGIF $im->gif;
        close MYGIF;

My example output can be seen at http://www.sna.se/test/GD_bug_temp.gif
--------------
Bjorn Svensson
--------------

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 09 Dec 1998 14:55:21 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Help!  Possible permissions problem?
Message-Id: <36708c7e.1124534@news.skynet.be>

Sean McAfee wrote:

>>mkdir("$dir/$num") || die "Cannot mkdir $dir/$num: $!";
>
>Not enough arguments for mkdir at -e line 1, at end of line
>
>ITYM:
>
>mkdir("$dir/$num", 0777);

That's right. 

It's remarkable that you even need the second parameter on systems that
know nothing about this kind of file permissions, such as Macintosh and
DOS. (probably on Win32 too, but untested).
	Bart.


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

Date: Wed, 09 Dec 1998 15:35:32 +0000
From: 23_skidoo <23_skidoo@geocities.com>
Subject: how to ensure script is only run by one user at a time
Message-Id: <366E98C2.57D6@geocities.com>

i'm writing a cgi script which opens and updates a number of files, if
two people run this script simultaneously it can lead to errors. while
this doesn't happen very often as the script runs quite quickly, i'd
like to avoid it happening at all and would like one of the users to
have to wait until the other user has finished.
 
would an acceptable way to do this be to open and lock a file at the
start of the script and unlock it again at the end? this could be a
non-related file that didn't need to be read or written to but would
just serve as a way to hold up user #2. 

will this work, is it a good idea or would it make me the king of cruft? 
any other suggestions? 

-23


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

Date: Wed, 09 Dec 1998 10:33:33 -0500
From: Garth Webb <gwebb@reedtech.com>
Subject: Perl ARRAYs
Message-Id: <366E984C.D969DD92@reedtech.com>

I have a problem referencing Perl arrays that I used to know the answer
to, but now I can't remember or figure out how its done.
    Say you have an array:

my @a = ("foo")
my $ref = ref(@a);

The variable $ref now contains the string:

'ARRAY(0x2a79ac)'

How do I access the array '@a' using only the text contained by $ref?
I've tried:

@bar = @{$ref}
\@bar = $$ref;

and others, but I can't seem to get my original array.  Can anyone
remind me how this is done?  Thanks!

Garth Webb


----------------------
Garth Webb
Software Developer
Reed Technology and Information Services
gwebbQ@Qreedtech.com

(To reply to me, please remove the 'Q's from my email address.  Thanks.)





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

Date: Wed, 09 Dec 1998 17:08:44 +0100
From: Hendrik Woerdehoff <hendrik.woerdehoff@sdm.de>
Subject: Re: Perl ARRAYs
Message-Id: <366EA08C.74C5@sdm.de>

Garth Webb wrote:
> 
> I have a problem referencing Perl arrays that I used to know the answer
> to, but now I can't remember or figure out how its done.
>     Say you have an array:
> 
> my @a = ("foo")
> my $ref = ref(@a);
> 
> The variable $ref now contains the string:
> 
> 'ARRAY(0x2a79ac)'
> 
> How do I access the array '@a' using only the text contained by $ref?
> I've tried:
> 
> @bar = @{$ref}
> \@bar = $$ref;
> 
> and others, but I can't seem to get my original array.  Can anyone
> remind me how this is done?  Thanks!
> 
> Garth Webb

Please read "perldoc perlref" and "perldoc -f ref"!

The latter says:
  =item ref EXPR
  Returns a TRUE value if EXPR is a reference, FALSE otherwise. ...

ref() does not create a reference. It only tells you if your expression
is a reference.

To create a reference you need the operator \.

For example:
my @a = ("foo")
my $ref = \@a;
print @$ref, "\n";

And: There is NO way to get to the referenced variable using the textual
representation ('ARRAY(0x2a79ac)') of a reference.

Yours
  Hendrik


Pursuant to US Code, Title 47, Chapter 5, Subchapter II, Sec. 227,
any and all unsolicited commercial E-mail sent to this address
is subject to a download and archival fee in the amount of $500
US (per infraction).  E-mailing denotes acceptance of these terms.

--
Hendrik W"ordehoff         |s  |d &|m  |  software design & management
                           |   |   |   |  GmbH & Co. KG                :
woerdehoff@sdm.de          |   |   |   |  Thomas-Dehler-Str. 27      >B)
Tel/Fax (089) 63812-337/515               81737 M"unchen               :


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

Date: Wed, 9 Dec 1998 09:59:13 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl ARRAYs
Message-Id: <ho6m47.ld5.ln@magna.metronet.com>

Garth Webb (gwebb@reedtech.com) wrote:
: I have a problem referencing Perl arrays that I used to know the answer
: to, but now I can't remember or figure out how its done.


   And for some reason you are unable to read the documentation
   about references (perlref.pod) that are on your hard disk?

   How to take a reference is covered very near the top...



:     Say you have an array:

: my @a = ("foo")
: my $ref = ref(@a);

: The variable $ref now contains the string:

: 'ARRAY(0x2a79ac)'


   No it doesn't.

   print "'$ref'\n";   # See?

   You should look up ref() in the perlfunc.pod man page if
   you want to use ref()...



-----------------
#!/usr/bin/perl -w

my @a = qw(foo bar);

my $ref = \@a;        # take a reference

foreach (@$ref)       # derefernece it
   {print "$_\n"}
-----------------


   You don't need to make @a first either:


-----------------
#!/usr/bin/perl -w

my $ref = [ qw(foo bar) ];    # take a reference to an anonymous array

foreach (@$ref)              # derefernece it
   {print "$_\n"}
-----------------


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


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

Date: 9 Dec 1998 16:01:05 GMT
From: hpb+@pitt.edu (Harry P Bloomberg)
Subject: Perl Floating Point Rounding Algorithm?
Message-Id: <74m6s1$e0e$1@usenet01.srv.cis.pitt.edu>

   How does Perl round floating point numbers when they are output with
print or sprint?

   I did search the Perl FAQ, and there is a short section there on
rounding, but it does not specify the rounding method, and in fact
suggests not trusting Perl rounding if the application is critical. 
However, I'm still curious as to the default Perl rounding behavior. 

Thanks,
Harry Bloomberg
hpb+@pitt.edu


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

Date: Wed, 9 Dec 1998 15:35:56 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Perl-to-C convertor
Message-Id: <F3pFBw.Fu7@world.std.com>

Wasan Pattara-atikom <wapst7@pitt.edu> writes:

>	Does anyone know if there is a utility to convert perl source code or.
>If anybody has any clue, please pleas please let me know. I seriously
>need it.

There are two perl to C translators in perl 5.005. They are brand new
and have a few problems still.

Just to check, what do you "seriously need it" for. If it is for:

Faster Performance: There will likely be now significant increase in
speed. Many parts of the perl language revolve around run-time
evaluation, and a conversion to C will not be able to change that.

Decreased Code Size: A Perl program translated into C and compiled
still needs the perl library around. When your code calls a perl
function, lets say "grep", it still needs perl's "grep" code around.

Decreased Memory Usage: One problem that perl has over programs
compiled to machine code is that on systems that use modern memory
management techniques. The program is shared between all simultaneous
instances of the running program. Unfortunately, for interpreted and
intermediate code languages like perl, the interpreter itself is
shared, but all simultaneous invokations of the script have their own
in memory copy of the code the interprter uses. Theoretically, the
result of the perl to C code code be part of the "initialized data"
section of the executable file and shared. In the current form though,
that is not the case. There are certain fixups that are done when the
compiled code starts, which means that each instance of the program
would need its own copy to write to. (Or more accurately, the kernel
will replace the shared copy to a newly allocated piece of memory as
soon as the instance of the program writes to it.) (The problem of
many instances of the same program running at the same time sounds a
lot like the common case for CGI programs on a web server. Luckily
there are things like Apache's modperl that deal with the problem from
another angle.)

To make a long story short (too late Andrew!) In most cases, the perl
to C compiler is not what you are looking for.

You might want to check the FAQ for the entry about the perl to C
compiler, and check Deja News <URL:http://www.dejanew.com/> for the
previous discussions on the topic. (Some people have some very strong
feelings about some of the reasons why people are looking for
perlcc. You might want to read the previous debates so you can
understand the sides of the argument ahead of time.)
-- 
Andrew Langmead


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

Date: Wed, 09 Dec 1998 22:44:24 +0800
From: DAVID CHEW <dcc1234@pacific.net.sg>
Subject: problem fetching HTML PAGE
Message-Id: <366E8CC7.EAE6101C@pacific.net.sg>

hI,
Anybody can help?.
Can the following lines fetch a  html page from a remote site ?
It doesnt seem to work properly for all pages

           use  lwp::Simple;
           $html = get($URL);

Anybody knows a better way to fetch a html page.
Would appreciate that the reply be directed to my email,
as I dont offeN go into the discussion group
Thanks
David




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

Date: Wed, 9 Dec 1998 10:04:56 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: problem fetching HTML PAGE
Message-Id: <837m47.ld5.ln@magna.metronet.com>

DAVID CHEW (dcc1234@pacific.net.sg) wrote:

: Can the following lines fetch a  html page from a remote site ?

   No.


: It doesnt seem to work properly for all pages


   I'd be surprised if it worked properly for *any* pages...


:            use  lwp::Simple;
                  ^^^
                  ^^^  s/(lwp)/\U$1/;


:            $html = get($URL);
                         ^^^^

   You need to put a value in that variable first.


: Anybody knows a better way to fetch a html page.


   No, that way works fine if you use it correctly.



: Would appreciate that the reply be directed to my email,
: as I dont offeN go into the discussion group


   Oh.

   In that case ignore all of the above, and go ask somewhere else.


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


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

Date: Wed, 9 Dec 1998 15:06:50 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Redirecting STDIN
Message-Id: <F3pDzE.I51@world.std.com>

Ernst-Udo Wallenborn <wallenborn@phys.chem.ethz.ch> writes:

>aml@world.std.com (Andrew M. Langmead) writes:
[an example showing perl's magic open() semantics]

>another way would be using IO

>use IO::Handle;
>use IO::File;

>and then


>my ($in,$out);
>if ($infile eq '-') {

I was demonstrating (and referencing the relevent documentation) that
the second parameter of open() automatically opens standard input when
the second parameter is the single charater "-". Since IO::File is a
wrapper around perl's open(), it has the same feature. I don't know
why you are going through all the convolutions for something that can
be done just by saying:

$in = IO::File->new($infile) || die "Can't open $infile: $@\n";

even if $infile is "-".
-- 
Andrew Langmead


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

Date: Wed, 9 Dec 1998 11:42:52 -0500
From: nospam@wam.umd.edu (Vikram Pant)
Subject: Re: Spliting multiple databases.
Message-Id: <MPG.10d8729b1ea7061c9896ab@news.wam.umd.edu>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

Will take a look.

Thanks,
Vikram

In article <366DCC3D.CA79D7B3@spider.herston.uq.edu.au>, 
metcher@spider.herston.uq.edu.au says...
> Check out the docs for $/ ($INPUT_RECORD_SEPARATOR) and <> (angle
> operator).  I think you'll be pleased.
> 
> -- 
> Jaime Metcher
> 
> Vikram Pant wrote:
> > 
> > I doing a simple script that makes pages on the fly from three different
> > txt files that contain information.
> > 
> > I have info.txt, pictures.txt and sounds.txt.  All three have different
> > split delimiters (such as /t and |).
> > 
> > I am trying to make it easier and having just one txt file.  The problem
> > is I am having problems doing multiple splitting.
> > 
> > I have a big text file like so (it's three smaller txt files put
> > together) - (... breaks apart the three files)
> > 
> > Title   Heat
> > Dir     M. Mann
> > ...
> > 1|deniro.wav|25KB
> > 2|pacino.wav|45KB
> > ...
> > 1|picture.jpg|picture_tn.jpg|150|100|25KB
> > ...
> > 
> > I was wondering how I can go about splitting it.
> > I have tried something like
> > ($Info, $Sounds, $Pics) = split(/.../, $TheInput, 3)
> > 
> > I have tried other versions, I just cannot split multiple txt files.
> > 
> > Any help would be greatly apprieciated,
> > Vikram Pant
> 


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

Date: Wed, 9 Dec 1998 08:08:13 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: using the command  system() in perl cgi
Message-Id: <d80m47.cl4.ln@magna.metronet.com>

Liew Fook Sin (lfs97@tm.net.my) wrote:

: My problem is when I execute the Perl cgi script manually it works nicely.
: However, when I execute the same script via a  URL in a HTML form, the
: script runs but command
: embed inside the system() command simply does not respond.

: Can anybody please tell me what is wrong, and how can this be solved.


   1) check the return value of the system call

      system("pgp filename") && die "could not run system()  $!";


   2) use the full path to the executable

      system("/usr/local/bin/pgp filename") && die "could not run system()  $!";


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


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

Date: Wed, 09 Dec 1998 14:55:14 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <36728ead.1684000@news.skynet.be>

John Moreno wrote:

>>| if ($year > 99)
>>| {
>>|  $year = $year - 100;
>>|  if ($year < 10)
>>|  {
>>|   $year = "0$year";
>>|  }
>>| }
>
>Which is a Y3K, bug

No it isn't. It's a Y2K1 bug: it fails from year 2100 on.

And I think the next is compacter.

   $year = substr(sprintf('%02d',$year),-2);

	Bart.


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

Date: Wed, 9 Dec 1998 10:38:15 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <1djrmml.12i6ea7pw47zyN@roxboro0-016.dyn.interpath.net>

Bart Lateur <bart.lateur@skynet.be> wrote:

> John Moreno wrote:
> 
> >>| if ($year > 99)
> >>| {
> >>|  $year = $year - 100;
> >>|  if ($year < 10)
> >>|  {
> >>|   $year = "0$year";
> >>|  }
> >>| }
> >
> >Which is a Y3K, bug
> 
> No it isn't. It's a Y2K1 bug: it fails from year 2100 on.

That's what I was thinking of but it didn't seem to come out that way.

> And I think the next is compacter.
> 
>    $year = substr(sprintf('%02d',$year),-2);

It's a lot more compact than his, and a bit more compact than my
equivalent -- but I don't think it's as clear.  But that's probably just
my personal style.

-- 
John Moreno


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

Date: Wed, 09 Dec 1998 16:36:35 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <366ea6a5.7810719@news.skynet.be>

John Moreno wrote:

>> And I think the next is compacter.
>> 
>>    $year = substr(sprintf('%02d',$year),-2);
>
>It's a lot more compact than his, and a bit more compact than my
>equivalent -- but I don't think it's as clear.  But that's probably just
>my personal style.

I've thought of a better alternative after I posted mine. This probably
will get your approval.

    $year = sprintf('%02d',$year % 100);


Note taht this will fail for years before 1900... :-)

	Bart.


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

Date: Wed, 9 Dec 1998 11:57:35 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <1djrqb4.siolgcx2xt8tN@roxboro0-059.dyn.interpath.net>

Bart Lateur <bart.lateur@skynet.be> wrote:

> John Moreno wrote:
> 
> >> And I think the next is compacter.
> >> 
> >>    $year = substr(sprintf('%02d',$year),-2);
> >
> >It's a lot more compact than his, and a bit more compact than my
> >equivalent -- but I don't think it's as clear.  But that's probably just
> >my personal style.
> 
> I've thought of a better alternative after I posted mine. This probably
> will get your approval.
> 
>     $year = sprintf('%02d',$year % 100);

Yeah, that's better (and it's even more compact).

> Note taht this will fail for years before 1900... :-)

Arggh, I've just discovered a year 1904 bug -- no matter what I do I
can't get localtime to return a date before Jan 1, 1904 on my Mac.  :)

-- 
John "You mean the documentation explains that? Who cares?" Moreno


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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