[25243] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7488 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 6 18:05:49 2004

Date: Mon, 6 Dec 2004 15:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 6 Dec 2004     Volume: 10 Number: 7488

Today's topics:
        FAQ 4.25: How do I expand tabs in a string? <comdog@panix.com>
        FAQ 4.68: How can I make the Perl equivalent of a C str <comdog@panix.com>
    Re: FAQ 5.5: How do I make a temporary file name? <zentara@highstream.net>
    Re: FAQ 5.5: How do I make a temporary file name? <comdog@panix.com>
    Re: FAQ 5.5: How do I make a temporary file name? <comdog@panix.com>
    Re: file handle problem <uri@stemsystems.com>
        Generate Squential Numbers? <gobeyondgobeyond@Rem0ve.Yahoo.com>
    Re: Generate Squential Numbers? <1usa@llenroc.ude.invalid>
    Re: Generate Squential Numbers? <jds@atavailcheck.com>
    Re: Generate Squential Numbers? <1usa@llenroc.ude.invalid>
        How to detect an undefined SV* value in XS? (J. Romano)
    Re: How to detect an undefined SV* value in XS? <kalinaubears@iinet.net.au>
    Re: How to handle a HTTP::Request with gzip, deflate he <gisle@activestate.com>
    Re: How to handle a HTTP::Request with gzip, deflate he <leifwessman@hotmail.com>
    Re: How to handle a HTTP::Request with gzip, deflate he <gisle@activestate.com>
        kindergarten array vs. for question <jidanni@jidanni.org>
    Re: Obtaining length of binary string <usenet@morrow.me.uk>
        References and scope. (Adam)
    Re: References and scope. <1usa@llenroc.ude.invalid>
    Re: References and scope. <perl@my-header.org>
    Re: References and scope. xhoster@gmail.com
        RegExp Help <abc@microsoft.com>
        RegExp Help (J. Romano)
    Re: RegExp Help <sbryce@scottbryce.com>
    Re: Regular expression weirdness with upper and lower c <matthew.garrish@sympatico.ca>
    Re: Trouble Passing Array Containing Hash to Subroutine slhecht@attglobal.net
    Re: Trouble Passing Array Containing Hash to Subroutine slhecht@attglobal.net
        Using Perl to align text in an HTML page <sushilover111@hotmail.com>
    Re: Using Perl to align text in an HTML page <1usa@llenroc.ude.invalid>
    Re: write error message to a log file while processing  (Charles DeRykus)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 6 Dec 2004 23:03:03 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.25: How do I expand tabs in a string?
Message-Id: <cp2of7$2el$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.25: How do I expand tabs in a string?

    You can do it yourself:

        1 while $string =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;

    Or you can just use the Text::Tabs module (part of the standard Perl
    distribution).

        use Text::Tabs;
        @expanded_lines = expand(@lines_with_tabs);



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Mon, 6 Dec 2004 17:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.68: How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Message-Id: <cp23c5$n2f$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.68: How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?

    Usually a hash ref, perhaps like this:

        $record = {
            NAME   => "Jason",
            EMPNO  => 132,
            TITLE  => "deputy peon",
            AGE    => 23,
            SALARY => 37_000,
            PALS   => [ "Norbert", "Rhys", "Phineas"],
        };

    References are documented in perlref and the upcoming perlreftut.
    Examples of complex data structures are given in perldsc and perllol.
    Examples of structures and object-oriented classes are in perltoot.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Mon, 06 Dec 2004 11:10:24 -0500
From: zentara <zentara@highstream.net>
Subject: Re: FAQ 5.5: How do I make a temporary file name?
Message-Id: <qd09r01dat6mi2thcn0usf6ju0pvci2j90@4ax.com>

On Sun, 5 Dec 2004 23:03:01 +0000 (UTC), PerlFAQ Server
<comdog@panix.com> wrote:

Is there a syntax error in the following that needs correcting?

>    If you're committed to creating a temporary file by hand, use the
>    process ID and/or the current time-value. If you need to have many
>    temporary files in one process, use a counter:
>
>        BEGIN {
>            use Fcntl;
>            my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMPDIR} || $ENV{TEMP};
>            my $base_name = sprintf("%s/%d-%d-0000", $temp_dir, $$, time());
>            sub temp_file {
>                local *FH;
>                my $count = 0;
>                until (defined(fileno(FH)) || $count++ > 100) {
>                    $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
>                    # O_EXCL is required for security reasons.
>                    sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT);
>                }
>                if (defined(fileno(FH))
>                    return (*FH, $base_name);
>                } else {
>                    return ();
>                }
>            }
>        }
>

            # O_EXCL is required for security reasons. 
            sysopen( FH, $base_name, O_WRONLY | O_EXCL | O_CREAT );
        }
    #    if ( 
    #        defined( fileno(FH) ) return ( *FH, $base_name ); 
    #    } 

        if (defined( fileno(FH) )){ return ( *FH, $base_name );
        }
        else {
            return ();
        }






-- 
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html


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

Date: Mon, 06 Dec 2004 15:49:38 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: FAQ 5.5: How do I make a temporary file name?
Message-Id: <061220041549385701%comdog@panix.com>

In article <dba8r0tps8g6u47pqme6ulignb2se1qtri@4ax.com>, Michele Dondi
<bik.mido@tiscalinet.it> wrote:

> On Sun, 5 Dec 2004 23:03:01 +0000 (UTC), PerlFAQ Server
> <comdog@panix.com> wrote:
> 
> >5.5: How do I make a temporary file name?
> 
> Could it be worth to mention
> 
>   open my $tmp, '>', undef or die $!
> 
> too?

yes it could.  i'll look into it.  thanks :)

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: Mon, 06 Dec 2004 15:50:38 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: FAQ 5.5: How do I make a temporary file name?
Message-Id: <061220041550389289%comdog@panix.com>

In article <qd09r01dat6mi2thcn0usf6ju0pvci2j90@4ax.com>, zentara
<zentara@highstream.net> wrote:

> On Sun, 5 Dec 2004 23:03:01 +0000 (UTC), PerlFAQ Server
> <comdog@panix.com> wrote:
> 
> Is there a syntax error in the following that needs correcting?

apparently it does: i'll fix it.

thanks :)

-- 
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com


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

Date: Mon, 06 Dec 2004 14:19:44 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: file handle problem
Message-Id: <x71xe38q68.fsf@mail.sysarch.com>

>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

  AS> John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
  >> newbie wrote:
  >> > Thanks guys, I get the point of not putting large file in memory. I got a
  >> > new question. Say I have a bunch of large files, and I want to just get rid
  >> > of the last line of each of these large files. Is there a simpler way
  >> > without reading in and outputing the file?
  >> 
  >> perldoc -f truncate

  AS> ...probably in combination with File::ReadBackwards.

and you can use the tell() method to get the seek location after reading
in the last line. someone has asked me for a method to get the internal
file handle so he doesn't have to reopen the file. i will be adding that
soonish. then the OP can just do this <untested>:

	use File::ReadBackwards ;

	my $rb = File::ReadBackwards->new( 'filename' ) ;

	$rb->readline() ;
	my $tell = $rb->tell() ;
	my $fh->handle() ;
	$fh->truncate( $tell ) ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Mon, 6 Dec 2004 09:34:31 -0600
From: Terry <gobeyondgobeyond@Rem0ve.Yahoo.com>
Subject: Generate Squential Numbers?
Message-Id: <MPG.1c1e38006616575f9896c4@news.tc.umn.edu>

Hi,

I am creating an online form to collect info.  A perl script will be 
executed once the form is submitted and the perl script will generate an 
email message.  

I am wondering if it is possible to create a unique number for each 
email message it creates in the perl script.  Preferably, the number 
will be in sequence like 100, 101, 102, ...

My guess is that I have to create a variable that will remember the last 
number generated.  Is it possible to do so?

Thanks in advance!

Terry


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

Date: 6 Dec 2004 16:34:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Generate Squential Numbers?
Message-Id: <Xns95B775C1DC82Casu1cornelledu@132.236.56.8>

Terry <gobeyondgobeyond@Rem0ve.Yahoo.com> wrote in 
news:MPG.1c1e38006616575f9896c4@news.tc.umn.edu:

> My guess is that I have to create a variable that will remember the last 
> number generated.  Is it possible to do so?

What have you tried?

Sinan


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

Date: Mon, 06 Dec 2004 17:37:16 GMT
From: "Julia De Silva" <jds@atavailcheck.com>
Subject: Re: Generate Squential Numbers?
Message-Id: <gN0td.118925$38.101894@fe2.news.blueyonder.co.uk>

> I am creating an online form to collect info.  A perl script will be
> executed once the form is submitted and the perl script will generate an
> email message.
>
> I am wondering if it is possible to create a unique number for each
> email message it creates in the perl script.  Preferably, the number
> will be in sequence like 100, 101, 102, ...
>
> My guess is that I have to create a variable that will remember the last
> number generated.  Is it possible to do so?
>
Lots of possibilities here,
 i.e store value in separate file, rather like a hit counter script.
Use the time as a key so long as you are never likely to get 2 calls in the
same second.
Put the info into a database using an autoincremental key.

Better still don't try to reinvent the wheel - use a 3rd party script with
all the bugs, security risks and other stuff already fixed.

J





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

Date: 6 Dec 2004 17:48:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Generate Squential Numbers?
Message-Id: <Xns95B7825128033asu1cornelledu@132.236.56.8>

"Julia De Silva" <jds@atavailcheck.com> wrote in
news:gN0td.118925$38.101894@fe2.news.blueyonder.co.uk: 

>> I am creating an online form to collect info.  A perl script will be
>> executed once the form is submitted and the perl script will generate
>> an email message.
>>
>> I am wondering if it is possible to create a unique number for each
>> email message it creates in the perl script.  Preferably, the number
>> will be in sequence like 100, 101, 102, ...
>>
>> My guess is that I have to create a variable that will remember the
>> last number generated.  Is it possible to do so?
>>

> Use the time as a key so long as you are never likely to get 2 calls
> in the same second.

'never likely' is not a meaningful statement. Something is either possible 
or not possible. If you cannot rule out the possibility, the fact that the 
probability might be small is not important. 

> Put the info into a database using an autoincremental key.

This is probably preferable to all the other methods.

However, should the OP prefer for a hit counter style script:

http://www.perl.com/pub/a/2002/01/23/cgi.html

Follow the link to nms.

Sinan


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

Date: 6 Dec 2004 12:21:38 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: How to detect an undefined SV* value in XS?
Message-Id: <b893f5d4.0412061221.922a984@posting.google.com>

Dear Perl community,

   I have a problem here and I'm hoping that someone can help.

   I am writing some XS code, and I need to detect whether a value
accessed through an SV pointer is defined or undefined.  I read
"perldoc perlapi", and the closest I could find was this excerpt:

 SvTRUE  Returns a boolean indicating whether Perl would
         evaluate the SV as true or false, defined or unde-
         fined.  Does not handle 'get' magic.

                 bool    SvTRUE(SV* sv)

This is great for discovering a variable's boolean value, but I need
some way of knowing if an SV* was undefined when it was passed in.  I
suppose I could always do this:

      char *valueStr;
      STRLEN valueLen;
      valueStr = SvPV(*value, valueLen);

and then valueStr would be "" and valueLen would be 0 if *value
contains an undefined value.  However, valueStr and valueLen would
both be the same thing if *value pointed to an empty string.  The
line:

      bool truthValue = SvTRUE(*value);

returns false for both undefined values and empty strings, which means
that it can't differentiate between them, either.

   So I can't figure out how to check to see if an SV* value is
defined or not.  Any test I perform (with SvPV, SvTRUE, or SvIV) gives
the same results when used with empty strings and undefined values. 
This causes a problem if I need to know for sure which was passed in.

   For those interested, I tried these commands:

> perl -MDevel::Peek -e '$a = ""; Dump($a)'
SV = PV(0x80f5a84) at 0x80fc9f8
  REFCNT = 1
  FLAGS = (POK,pPOK)
  PV = 0x8102a70 ""\0
  CUR = 0
  LEN = 1

> perl -MDevel::Peek -e '$a = undef; Dump($a)'
SV = NULL(0x0) at 0x80fc9f8
  REFCNT = 1
  FLAGS = ()

Unfortunately, I'm not too familiar with Devel::Peek to really know
how to use its "Dump" output to my advantage.  I see that with an
undefined value, SV equals NULL, but according to the debugger, it's
definitely set to some non-NULL value.  Likewise, when I dump an empty
string, the "Dump" output says that LEN equals 1, but according when I
make the following call:

      valueStr = SvPV(*value, valueLen);

valueLen gets set to zero (as it does with an undefined value).

   Maybe the key to checking an undefined value is to check the FLAGS?
 Or is there an easier way to do this that I'm not aware of?

   Any help would be appreciated.

   Thank you.

   -- Jean-Luc


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

Date: Mon, 06 Dec 2004 21:33:08 +0000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: How to detect an undefined SV* value in XS?
Message-Id: <41b4df85$0$25770$5a62ac22@per-qv1-newsreader-01.iinet.net.au>

J. Romano wrote:
> Dear Perl community,
> 
>    I have a problem here and I'm hoping that someone can help.
> 
>    I am writing some XS code, and I need to detect whether a value
> accessed through an SV pointer is defined or undefined.  I read
> "perldoc perlapi", and the closest I could find was this excerpt:
> 
>  SvTRUE  Returns a boolean indicating whether Perl would
>          evaluate the SV as true or false, defined or unde-
>          fined.  Does not handle 'get' magic.
> 
>                  bool    SvTRUE(SV* sv)
> 
> This is great for discovering a variable's boolean value, but I need
> some way of knowing if an SV* was undefined when it was passed in.  I
> suppose I could always do this:
> 
>       char *valueStr;
>       STRLEN valueLen;
>       valueStr = SvPV(*value, valueLen);
> 
> and then valueStr would be "" and valueLen would be 0 if *value
> contains an undefined value.  However, valueStr and valueLen would
> both be the same thing if *value pointed to an empty string.  The
> line:
> 
>       bool truthValue = SvTRUE(*value);
> 
> returns false for both undefined values and empty strings, which means
> that it can't differentiate between them, either.
> 
>    So I can't figure out how to check to see if an SV* value is
> defined or not.  Any test I perform (with SvPV, SvTRUE, or SvIV) gives
> the same results when used with empty strings and undefined values. 
> This causes a problem if I need to know for sure which was passed in.
> 
>    For those interested, I tried these commands:
> 
> 
>>perl -MDevel::Peek -e '$a = ""; Dump($a)'
> 
> SV = PV(0x80f5a84) at 0x80fc9f8
>   REFCNT = 1
>   FLAGS = (POK,pPOK)
>   PV = 0x8102a70 ""\0
>   CUR = 0
>   LEN = 1
> 
> 
>>perl -MDevel::Peek -e '$a = undef; Dump($a)'
> 
> SV = NULL(0x0) at 0x80fc9f8
>   REFCNT = 1
>   FLAGS = ()
> 
> Unfortunately, I'm not too familiar with Devel::Peek to really know
> how to use its "Dump" output to my advantage.  I see that with an
> undefined value, SV equals NULL, but according to the debugger, it's
> definitely set to some non-NULL value.  Likewise, when I dump an empty
> string, the "Dump" output says that LEN equals 1, but according when I
> make the following call:
> 
>       valueStr = SvPV(*value, valueLen);
> 
> valueLen gets set to zero (as it does with an undefined value).
> 

Yep - the trailing '\0' is being ignored in that function call, but 
included in 'LEN'.

>    Maybe the key to checking an undefined value is to check the FLAGS?
>  Or is there an easier way to do this that I'm not aware of?
> 

 From within the XS code I think you need to examine the 'ANY' field 
using the SvANY macro - which you'll find in sv.h, though it's not 
documented *anywhere* afaict.

if(SvANY(sv) == NULL) printf("It's undef");
else printf("It aint undef");

Cheers,
Rob

-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: 06 Dec 2004 15:14:13 +0100
From: Gisle Aas <gisle@activestate.com>
Subject: Re: How to handle a HTTP::Request with gzip, deflate headers
Message-Id: <87wtvvfr9m.fsf@ask.g.aas.no>

"Leif Wessman" <leifwessman@hotmail.com> writes:

> I get the following error:
> Can't locate object method "decoded_content" via package
> "HTTP::Headers" at (eval 15) line 1.
> I'm using LWP::Parallel::UserAgent. Does that matter?

No, but you need a recent version of LWP itself (v5.802).

-- 
Gisle Aas


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

Date: 6 Dec 2004 06:50:23 -0800
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: How to handle a HTTP::Request with gzip, deflate headers
Message-Id: <1102344623.097317.83000@c13g2000cwb.googlegroups.com>


Gisle Aas wrote:
> "Leif Wessman" <leifwessman@hotmail.com> writes:
>
> > I get the following error:
> > Can't locate object method "decoded_content" via package
> > "HTTP::Headers" at (eval 15) line 1.
> > I'm using LWP::Parallel::UserAgent. Does that matter?
>
> No, but you need a recent version of LWP itself (v5.802).
>
> --
> Gisle Aas

$res->decoded_content now returns the decoded content for webpages with
Content-Encoding: gzip. However, when Content-Encoding is 'deflate' I
get empty content. The website I'm testing on is Amazon.fr (they use
deflate) so I guess the problem is in my code. Should it work with
deflate automatically?



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

Date: 06 Dec 2004 21:04:45 +0100
From: Gisle Aas <gisle@activestate.com>
Subject: Re: How to handle a HTTP::Request with gzip, deflate headers
Message-Id: <87sm6jfb1e.fsf@ask.g.aas.no>

"Leif Wessman" <leifwessman@hotmail.com> writes:

> $res->decoded_content now returns the decoded content for webpages with
> Content-Encoding: gzip. However, when Content-Encoding is 'deflate' I
> get empty content. The website I'm testing on is Amazon.fr (they use
> deflate) so I guess the problem is in my code. Should it work with
> deflate automatically?

Yes, the code is there, but I have not actually tried it on a site
that use 'deflate' yet.  Can you give my an URL to try?

-- 
Gisle Aas


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

Date: Tue, 07 Dec 2004 06:29:33 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: kindergarten array vs. for question
Message-Id: <87y8gbgiwi.fsf@jidanni.org>

my @a=(1,2,3); my @b=(4,5,6);
for((((@a))),(((@b)))){ #What do I have to do to this line to make
  print "new array\n"; #this line get printed only twice, not six times?
  for($_){
    print "element $_\n"}}


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

Date: Sun, 5 Dec 2004 12:46:35 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Obtaining length of binary string
Message-Id: <bicb82-hm5.ln1@osiris.mauzo.dyndns.org>


Quoth "Jürgen Exner" <jurgenex@hotmail.com>:
> 
> However it misses the point. Joe wrote:
> >>If you're not using Unicode, the number of bytes is the same as
> >>the number of characters.
> 
> And this is the statement I still don't agree with.

OK, we're in a Perl group, so let's rewrite that as

If you're not using Perl's Unicode support, the number of bytes is the
same as the number of characters, according to Perl.

I am fairly sure that is what the OP meant by it, and also that you will
not disagree with it.

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                               ben@morrow.me.uk


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

Date: 6 Dec 2004 08:29:37 -0800
From: adam_cheney@hotmail.com (Adam)
Subject: References and scope.
Message-Id: <214d0889.0412060829.52c9f603@posting.google.com>

Hey all,

Forgive what may be a dumb question.

What actually happens when a variable goes out of scope? More
specifically, if I define a variable in a sub-routine (it is thus in
scope only within the subroutine, right?) and explicitly return a
reference to that variable, how can I dereference that return value
outside the subroutine and still have something meaningful?

Hope this makes sense and I can be enlightened!

Adam...


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

Date: 6 Dec 2004 17:05:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: References and scope.
Message-Id: <Xns95B77B0737411asu1cornelledu@132.236.56.8>

adam_cheney@hotmail.com (Adam) wrote in news:214d0889.0412060829.52c9f603
@posting.google.com:

> if I define a variable in a sub-routine (it is thus in
> scope only within the subroutine, right?) and explicitly return a
> reference to that variable, how can I dereference that return value
> outside the subroutine and still have something meaningful?

In a nutshell: Because Perl's garbage collector keeps a count of references  
to the variable and only deallocates the variable if that count is zero.

Sinan


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

Date: Mon, 06 Dec 2004 18:11:33 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: References and scope.
Message-Id: <l249r0l0dkj5e5lf9hu3u8ojii41f5r43o@4ax.com>

X-Ftn-To: Adam 

adam_cheney@hotmail.com (Adam) wrote:
>Hey all,
>
>Forgive what may be a dumb question.
>
>What actually happens when a variable goes out of scope? More
>specifically, if I define a variable in a sub-routine (it is thus in
>scope only within the subroutine, right?) and explicitly return a
>reference to that variable, how can I dereference that return value
>outside the subroutine and still have something meaningful?

You should dereference it as any other reference. :)

sub oneTwo {
  my @arr = qw/one two/;
  return \@arr;
}

my $aref = oneTwo();
print @$aref;


-- 
Matija


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

Date: 06 Dec 2004 18:25:30 GMT
From: xhoster@gmail.com
Subject: Re: References and scope.
Message-Id: <20041206132530.205$Yx@newsreader.com>

adam_cheney@hotmail.com (Adam) wrote:
> Hey all,
>
> Forgive what may be a dumb question.
>
> What actually happens when a variable goes out of scope?

The variable's reference count is decremented.  If that results in a zero
reference count, then the variable can be destroyed and the space reused.

> More
> specifically, if I define a variable in a sub-routine

I assume you mean that you declare the variable with "my" in a
subroutine.  I wouldn't call that "define", because define seems like
it would be the opposite of undef'ing a variable, which has little to do
with scope.

> (it is thus in
> scope only within the subroutine, right?)

The *name* of the varible is only in scope within the subroutine.
The name of the variable is one thing that refers to the variable, but
not necessarily the only thing which refers to it.

> and explicitly return a
> reference to that variable, how can I dereference that return value
> outside the subroutine and still have something meaningful?

Uh, by using a dereferencing operator or syntax. :)

I don't quite understand your question.  Do you want to know the guts
behind how Perl manages this?  Or the rationale for it?  Or do you just
want reassurance that indeed this is the case?

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Mon, 6 Dec 2004 19:16:33 GMT
From: "Indigo5" <abc@microsoft.com>
Subject: RegExp Help
Message-Id: <I8BEvJ.8G2@news.boeing.com>

This may be a simple question, but how would I use a regular expression to
convert reals to integers whenever possible.  For example, if I had the
following lines

25.010      36.5     20.00
22.3          19.       35.


I would want those converted to

25.010           36.5     20
22.3               19        35

I know I can use something like:

s/\.$//g; to get rid of decimal points at the end of the string, but how do
I get rid of trailing zeros after the decimal point?

Would it be something like

s/\.(\d+)0$//g; ?




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

Date: 6 Dec 2004 14:57:26 -0800
From: jl_post@hotmail.com (J. Romano)
Subject: RegExp Help
Message-Id: <b893f5d4.0412061457.32b2edfb@posting.google.com>

Indigo5 said:
>
> This may be a simple question, but how would I use a
> regular expression to convert reals to integers whenever
> possible.  For example, if I had the following lines
>
> 25.010      36.5     20.00
> 22.3          19.       35.
>
> I would want those converted to
>
> 25.010           36.5     20
> 22.3               19        35


   Try the following two lines together:

      s/(\.\d*?)0*(?!\d)/$1/g;
      s/\.(?!\d)//g;

   The first line looks for a decimal point that's followed by some
digits that are trailed by zeroes.  If it finds that pattern, it gets
replaced with the decimal point followed by the digits WITHOUT the
trailing zeroes.  (The ?! is a negative look-ahead:  it means that the
zeroes have to stop when there is a non-digit right after them
(otherwise, 25.5500001 would get changed to 25.551).)  (The *? tells
the * character to be non-greedy.  Without the ? the * would "gobble"
up all the digits so that there would be no zeroes left to be gobbled
up by the 0* (and therefore no digits at all would get removed).)

   The first line alone does not remove the decimal point if it
appears with no trailing digits (like "19."), so that's why I added
the second line:  if there is a decimal point that is not followed by
any digits, remove it.

   I hope this helps.

   -- Jean-Luc


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

Date: Mon, 06 Dec 2004 13:23:54 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: RegExp Help
Message-Id: <8Ladna-WjcBBIincRVn-rg@comcast.com>

Indigo5 wrote:

> This may be a simple question, but how would I use a regular expression to
> convert reals to integers whenever possible.  For example, if I had the
> following lines
> 
> 25.010      36.5     20.00
> 22.3          19.       35.
> 
> 
> I would want those converted to
> 
> 25.010           36.5     20
> 22.3               19        35

No regex needed:

use strict;
use warnings;

my $x1 = '1.9';
my $x2 = '2.00';
my $x3 = '3.';

print "x1 = $x1, x2 = $x2, x3 = $x3\n";

$x1 += 0;
$x2 += 0;
$x3 += 0;

print "x1 = $x1, x2 = $x2, x3 = $x3\n";



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

Date: Mon, 6 Dec 2004 15:04:26 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Regular expression weirdness with upper and lower case
Message-Id: <8X2td.17858$dC3.353296@news20.bellglobal.com>


<semovrs@concord.edu> wrote in message 
news:1102361207.030353.177070@f14g2000cwb.googlegroups.com...
> Hello, everyone!
> I would appreciate any input or advice on the following quite simple
> issue:
> If I search through a file list using grep -E '.*[^(JPG|png)]$' it will
> not pull files ending in JPG and files ending in png which is fine.
> However, I have some files ending in jpg (note - lower case) and it
> will not display them either. Why is that? Am I doing something wrong
> here and if so - what?
> It obviously is a regexp issue and not a grep issue because I tried
> this in vim and it acts the same way.
> Any advice would be greatly appreciated.
>

Probably because you're not doing what you think you're doing. You're 
creating a negated *character class* and checking for files that don't end 
with one of those characters. You're not looking for files that don't end in 
JPG or png, even though that might seem to be working. And since .jpg end 
with "g"...

Since you're not asking a Perl question, I'll leave it to you to make it 
work for grep.

Matt 




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

Date: 6 Dec 2004 11:35:02 -0800
From: slhecht@attglobal.net
Subject: Re: Trouble Passing Array Containing Hash to Subroutine
Message-Id: <1102361702.095632.244150@f14g2000cwb.googlegroups.com>

As (violently) suggested, I added "use strict;" and was able to
determine the problem.  Thanks for the suggestions...I will try to be
much more careful in my posts in the future...sorry for any trouble...



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

Date: 6 Dec 2004 11:36:03 -0800
From: slhecht@attglobal.net
Subject: Re: Trouble Passing Array Containing Hash to Subroutine
Message-Id: <1102361763.136267.225520@z14g2000cwz.googlegroups.com>

As (violently) suggested, I added "use strict;" and was able to
determine the problem.  Thanks for the suggestions...I will try to be
much more careful in my posts in the future...sorry for any trouble...



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

Date: 6 Dec 2004 10:45:29 -0800
From: "Rob" <sushilover111@hotmail.com>
Subject: Using Perl to align text in an HTML page
Message-Id: <1102358729.380110.198540@z14g2000cwz.googlegroups.com>

Hi,

My final objective is to create a Word doc (formatted the way I want
it) that is a collection of names contained in a MySQL database. My
approach has been to output the information to a web page, then copy &
paste it into my Word doc (basically because all the info is getting
inputted by a web page and web pages are easy to deal with...I'm not
married to this approach).

I have a situation where I want to print:

Lastname   Firstname
Firstname2

Where the names are names of people in a family. These names reside in
my database. I want them aligned nicely, as I've shown. I repeat this
process for many families. I'm using a Perl script to go get the info
from the database and send it to a web page. The problem I'm having is
the two firstnames don't align nicely. I can't simply place Firstname2
over a certain number of spaces since Lastname varies in length,
especially since it is in bold (and firstnames are not).

I don't want to use a table since if I paste that into a Word doc the
table shows up in Word, which I don't want.

I tried using:

<SCRIPT LANGUAGE='Javascript'>
document.write("<XMP>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</XMP>")
</SCRIPT>

Which I found on the web. In a "normal" web page it works great. I
added it to my Perl script:

#!C:/Perl/bin/Perl.exe

print qq(
<html>
<SCRIPT LANGUAGE='Javascript'>
document.write("<PRE>")
document.write("100 Meter\t400 Meter\t1500 Meter\r")
document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
document.write("Javelin\t\tPole Vault\tShot Put\r")
document.write("Discus")
document.write("</PRE>")
</SCRIPT>
</html>);
exit;

and it seems like the web page simply ignores it - it doesn't print
*anything*, let alone the tabs.

Any thoughts?
Thanks! Rob.



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

Date: 6 Dec 2004 18:51:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Using Perl to align text in an HTML page
Message-Id: <Xns95B78D0EE23B7asu1cornelledu@132.236.56.8>

"Rob" <sushilover111@hotmail.com> wrote in news:1102358729.380110.198540
@z14g2000cwz.googlegroups.com:

> Which I found on the web. In a "normal" web page it works great. I
> added it to my Perl script:
> 
> #!C:/Perl/bin/Perl.exe
> 
> print qq(
> <html>
> <SCRIPT LANGUAGE='Javascript'>
> document.write("<PRE>")
> document.write("100 Meter\t400 Meter\t1500 Meter\r")
> document.write("110 Hurdles\tHigh Jump\tlong Jump\r")
> document.write("Javelin\t\tPole Vault\tShot Put\r")
> document.write("Discus")
> document.write("</PRE>")
> </SCRIPT>
> </html>);
> exit;
> 
> and it seems like the web page simply ignores it - it doesn't print
> *anything*, let alone the tabs.
> 
> Any thoughts?


Yes. Learn HTML, Javascript and Perl individually first, before you try to 
intermingle them like this to create a Frankenstein.

Sinan.


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

Date: Mon, 6 Dec 2004 21:00:31 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: write error message to a log file while processing the ftp command
Message-Id: <I8BJov.Cy1@news.boeing.com>

In article <815c0a36.0412031711.7a5578a7@posting.google.com>,
Jing <jingchai@gmail.com> wrote:
>The system admin. has a problem to configure the Makefile.pl for
>Net::FTP module. my program need to ftp a local files to a remote
>server. Since i can't use Net::FTP, i try to use ftp command instead.
>I got trouble to write error message to a log file while processing
>the ftp command. Here is my code for ftp files.
>#!/opt/perl/bin/perl -w
>
>use File::Copy;
>$remotehost1    ="a";
>$remotepath    ="/b";                 
>$remoteuser    ="c";
>$remotepass    ="d";
>$fileftp = "test.txt";
>$dirfrom="/e";
>$cmd="ftp -n";
>
>     my   $ftp_commands =
>         "  open $remotehost1
>            user $remoteuser $remotepass
>            lcd $dirfrom
>            cd $remotepath
>            asc
>            put $fileftp
>            bye
>     	 ";
>     	 open (CMD, "|$cmd");
>         print CMD $ftp_commands;
>     close (CMD);
>         print "Ftp commands : $ftp_commands";
>      	 print "File $fileftp has been transferred \n";
>         $finish = 'temp';
>        copy ("$fileftp","./$finish/$fileftp");

Just launching a backticked command instead of IPC::Open3  
may be simpler and just as good in some (not all) cases. 
(perldoc -q capture for details).

my $ftp_output = qx/ $ftp_commands 2>&1 / ;      
if ($?) { $sig= $? & 127; $err= $?>>8; die "ftp: err=$err sig=$sig\n;" } 


--
Charles DeRykus


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7488
***************************************


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