[31377] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2629 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 10 16:09:31 2009

Date: Sat, 10 Oct 2009 13:09:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 10 Oct 2009     Volume: 11 Number: 2629

Today's topics:
    Re: [regexp] Changing lines NOT containing a pattern sln@netherlands.com
    Re: FAQ 4.69 How can I make the Perl equivalent of a C  <hjp-usenet2@hjp.at>
        FAQ 5.17 Is there a leak/bug in glob()? <brian@theperlreview.com>
    Re: FAQ 5.17 Is there a leak/bug in glob()? <hjp-usenet2@hjp.at>
    Re: FAQ 5.17 Is there a leak/bug in glob()? <ben@morrow.me.uk>
        FAQ 5.32 How do I do a "tail -f" in perl? <brian@theperlreview.com>
        FAQ 7.15 How can I pass/return a {Function, FileHandle, <brian@theperlreview.com>
    Re: FAQ 7.15 How can I pass/return a {Function, FileHan <hjp-usenet2@hjp.at>
        FAQ 8.1 How do I find out which operating system I'm ru <brian@theperlreview.com>
    Re: FAQ 8.29 Why can't my script read from STDIN after  <hjp-usenet2@hjp.at>
        Get domain from uri <ryanchan404@gmail.com>
    Re: Get domain from uri <uri@StemSystems.com>
    Re: Get domain from uri tony_curtis32@yahoo.com
    Re: Get domain from uri <ben@morrow.me.uk>
    Re: Get domain from uri <ben@morrow.me.uk>
    Re: grepping thru hashref <user@example.net>
    Re: Perl and packge <cvrčak@banana.com>
    Re: Simple question about CGI response after form data  <no@email.com>
    Re: time format +1 hour (Randal L. Schwartz)
    Re: time format +1 hour <hjp-usenet2@hjp.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 09 Oct 2009 13:17:21 -0700
From: sln@netherlands.com
Subject: Re: [regexp] Changing lines NOT containing a pattern
Message-Id: <156vc552tfkufgsv0mjrjvf3pa9m38jlu8@4ax.com>

On 08 Oct 2009 20:12:04 GMT, azrazer <azeroiu@poupidoup.com> wrote:

>On Wed, 07 Oct 2009 15:39:45 -0700, sln wrote:
>
>> On 06 Oct 2009 21:51:57 GMT, azrazer <azeroiu@poupidoup.com> wrote:
>[...]
>> 
>> Its moderately dificult, depending on what the overal conditions are.
>> Simple lookahead is all this needs. And there are many ways to do this
>> without extended regx's.
>> 
>> -sln
>> -------------------------
>> 
<delete old regex>

>I actually forgot to group my pattern like this (?:(?!word).)* and did (?!
>word).* which did not work...

There is a '\K' option, a sentence from perlre.html docs:
".. it is especially useful in situations where you want to efficiently
remove something following something else in a string."

This would be more efficient to use this in combination with a lookahead.
Compare these:

$string =~ s/^ ( (?:(?! WORD ).)* ;) .* $ /$1/xmg;
$string =~ s/ ^ (?:(?! WORD ).)* ; \K .* $ //xmg;

-sln
---------

use strict;
use warnings;

my $string = "
1 this WORD here; this is ok
2 word2 is not here; delete comment  
3 word3 is not here either; should not see this WORD, ; delete comment
";

$string =~ s/ ^ (?:(?! WORD ).)* ; \K .* $ //xmg;
print $string,"\n";

__END__



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

Date: Sat, 10 Oct 2009 21:40:01 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 4.69 How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?
Message-Id: <slrnhd1ooi.60d.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-08 10:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> 4.69: 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.

Since perl 5.8(?) you can use the fields pragma to allow only specific
fields:


    #!/usr/bin/perl 
    use warnings;
    use strict;

    {
	package Foo;
	use fields qw(bar baz);
	sub new {
	    my ($class) = @_;
	    my $self = fields::new($class);
	    return $self;
	}
    }

    my $foo = Foo->new();
    $foo->{bar} = 1; # this works

    $foo->{gazonk} = 42; # this will cause a run-time error

	hp


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

Date: Fri, 09 Oct 2009 22:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.17 Is there a leak/bug in glob()?
Message-Id: <CnOzm.78309$4t6.4447@newsfe06.iad>

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.17: Is there a leak/bug in glob()?

    Due to the current implementation on some operating systems, when you
    use the glob() function or its angle-bracket alias in a scalar context,
    you may cause a memory leak and/or unpredictable behavior. It's best
    therefore to use glob() only in list context.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Sat, 10 Oct 2009 21:14:18 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 5.17 Is there a leak/bug in glob()?
Message-Id: <slrnhd1n8a.60d.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-09 22:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> 5.17: Is there a leak/bug in glob()?
>
>     Due to the current implementation on some operating systems, when you
>     use the glob() function or its angle-bracket alias in a scalar context,
>     you may cause a memory leak and/or unpredictable behavior. It's best
>     therefore to use glob() only in list context.

What is "the current implementation on some operating systems"? 

The "current implementation" at the time of writing an FAQ entry may or
may not still be current when the entry is read. Since the entries have
no date, the reader cannot know whether the implementation has changed.
And testing is difficult, too, since he doesn't know whether he has
access to any of those "some operating systems".

I think references to bugs in specific versions of perl should
explicitely name these versions.

	hp


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

Date: Sat, 10 Oct 2009 20:39:10 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 5.17 Is there a leak/bug in glob()?
Message-Id: <uf47q6-lip1.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> On 2009-10-09 22:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> > 5.17: Is there a leak/bug in glob()?
> >
> >     Due to the current implementation on some operating systems, when you
> >     use the glob() function or its angle-bracket alias in a scalar context,
> >     you may cause a memory leak and/or unpredictable behavior. It's best
> >     therefore to use glob() only in list context.
> 
> What is "the current implementation on some operating systems"? 

The csh-based implementation, which (except for miniperl) has been
obsolete since 5.6.0.

Ben



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

Date: Sat, 10 Oct 2009 16:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.32 How do I do a "tail -f" in perl?
Message-Id: <7c2Am.139150$Y83.55948@newsfe21.iad>

This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

5.32: How do I do a "tail -f" in perl?

    First try

            seek(GWFILE, 0, 1);

    The statement "seek(GWFILE, 0, 1)" doesn't change the current position,
    but it does clear the end-of-file condition on the handle, so that the
    next "<GWFILE>" makes Perl try again to read something.

    If that doesn't work (it relies on features of your stdio
    implementation), then you need something more like this:

            for (;;) {
              for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) {
                # search for some stuff and put it into files
              }
              # sleep for a while
              seek(GWFILE, $curpos, 0);  # seek to where we had been
            }

    If this still doesn't work, look into the "clearerr" method from
    "IO::Handle", which resets the error and end-of-file states on the
    handle.

    There's also a "File::Tail" module from CPAN.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Sat, 10 Oct 2009 10:00:05 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 7.15 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <FWYzm.7622$eJ4.3817@newsfe07.iad>

This is an excerpt from the latest version perlfaq7.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

7.15: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?

    With the exception of regexes, you need to pass references to these
    objects. See "Pass by Reference" in perlsub for this particular
    question, and perlref for information on references.

    See "Passing Regexes", later in perlfaq7, for information on passing
    regular expressions.

    Passing Variables and Functions
        Regular variables and functions are quite easy to pass: just pass in
        a reference to an existing or anonymous variable or function:

                func( \$some_scalar );

                func( \@some_array  );
                func( [ 1 .. 10 ]   );

                func( \%some_hash   );
                func( { this => 10, that => 20 }   );

                func( \&some_func   );
                func( sub { $_[0] ** $_[1] }   );

    Passing Filehandles
        As of Perl 5.6, you can represent filehandles with scalar variables
        which you treat as any other scalar.

                open my $fh, $filename or die "Cannot open $filename! $!";
                func( $fh );

                sub func {
                        my $passed_fh = shift;

                        my $line = <$passed_fh>;
                        }

        Before Perl 5.6, you had to use the *FH or "\*FH" notations. These
        are "typeglobs"--see "Typeglobs and Filehandles" in perldata and
        especially "Pass by Reference" in perlsub for more information.

    Passing Regexes
        To pass regexes around, you'll need to be using a release of Perl
        sufficiently recent as to support the "qr//" construct, pass around
        strings and use an exception-trapping eval, or else be very, very
        clever.

        Here's an example of how to pass in a string to be regex compared
        using "qr//":

                sub compare($$) {
                        my ($val1, $regex) = @_;
                        my $retval = $val1 =~ /$regex/;
                return $retval;
                }
                $match = compare("old McDonald", qr/d.*D/i);

        Notice how "qr//" allows flags at the end. That pattern was compiled
        at compile time, although it was executed later. The nifty "qr//"
        notation wasn't introduced until the 5.005 release. Before that, you
        had to approach this problem much less intuitively. For example,
        here it is again if you don't have "qr//":

                sub compare($$) {
                        my ($val1, $regex) = @_;
                        my $retval = eval { $val1 =~ /$regex/ };
                die if $@;
                return $retval;
                }

                $match = compare("old McDonald", q/($?i)d.*D/);

        Make sure you never say something like this:

                return eval "\$val =~ /$regex/";   # WRONG

        or someone can sneak shell escapes into the regex due to the double
        interpolation of the eval and the double-quoted string. For example:

                $pattern_of_evil = 'danger ${ system("rm -rf * &") } danger';

                eval "\$string =~ /$pattern_of_evil/";

        Those preferring to be very, very clever might see the O'Reilly
        book, *Mastering Regular Expressions*, by Jeffrey Friedl. Page 273's
        Build_MatchMany_Function() is particularly interesting. A complete
        citation of this book is given in perlfaq2.

    Passing Methods
        To pass an object method into a subroutine, you can do this:

                call_a_lot(10, $some_obj, "methname")
                sub call_a_lot {
                        my ($count, $widget, $trick) = @_;
                        for (my $i = 0; $i < $count; $i++) {
                                $widget->$trick();
                        }
                }

        Or, you can use a closure to bundle up the object, its method call,
        and arguments:

                my $whatnot =  sub { $some_obj->obfuscate(@args) };
                func($whatnot);
                sub func {
                        my $code = shift;
                        &$code();
                }

        You could also investigate the can() method in the UNIVERSAL class
        (part of the standard perl distribution).



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Sat, 10 Oct 2009 21:20:15 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 7.15 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <slrnhd1njg.60d.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-10 10:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> 7.15: How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
[...]
>     Passing Regexes
>         To pass regexes around, you'll need to be using a release of Perl
>         sufficiently recent as to support the "qr//" construct, pass around
>         strings and use an exception-trapping eval, or else be very, very
>         clever.
>
>         Here's an example of how to pass in a string to be regex compared
>         using "qr//":
>
>                 sub compare($$) {
>                         my ($val1, $regex) = @_;
>                         my $retval = $val1 =~ /$regex/;
>                 return $retval;
>                 }
>                 $match = compare("old McDonald", qr/d.*D/i);
>
>         Notice how "qr//" allows flags at the end. That pattern was compiled
>         at compile time, although it was executed later. The nifty "qr//"
>         notation wasn't introduced until the 5.005 release.

I think 5.005 is old enough that the rest of this section can be
removed:

>         Before that, you
>         had to approach this problem much less intuitively. For example,
>         here it is again if you don't have "qr//":
>
>                 sub compare($$) {
>                         my ($val1, $regex) = @_;
>                         my $retval = eval { $val1 =~ /$regex/ };
>                 die if $@;
>                 return $retval;
>                 }
>
>                 $match = compare("old McDonald", q/($?i)d.*D/);
>
>         Make sure you never say something like this:
>
>                 return eval "\$val =~ /$regex/";   # WRONG
>
>         or someone can sneak shell escapes into the regex due to the double
>         interpolation of the eval and the double-quoted string. For example:
>
>                 $pattern_of_evil = 'danger ${ system("rm -rf * &") } danger';
>
>                 eval "\$string =~ /$pattern_of_evil/";
>
>         Those preferring to be very, very clever might see the O'Reilly
>         book, *Mastering Regular Expressions*, by Jeffrey Friedl. Page 273's
>         Build_MatchMany_Function() is particularly interesting. A complete
>         citation of this book is given in perlfaq2.
>

	hp


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

Date: Sat, 10 Oct 2009 04:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 8.1 How do I find out which operating system I'm running under?
Message-Id: <7FTzm.98254$u76.79250@newsfe10.iad>

This is an excerpt from the latest version perlfaq8.pod, which
comes with the standard Perl distribution. These postings aim to 
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

8.1: How do I find out which operating system I'm running under?

    The $^O variable ($OSNAME if you use English) contains an indication of
    the name of the operating system (not its release number) that your perl
    binary was built for.



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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in 
perlfaq.pod.


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

Date: Sat, 10 Oct 2009 21:46:17 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 8.29 Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
Message-Id: <slrnhd1p4a.60d.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-08 16:00, PerlFAQ Server <brian@theperlreview.com> wrote:
> 8.29: Why can't my script read from STDIN after I gave it EOF (^D on Unix, ^Z on MS-DOS)?
>
>     Some stdio's set error and eof flags that need clearing.

I think most perls these days use perlio instead of stdio. So I suggest
changing the first sentence to 

    This happens only if your perl is compiled to use stdio instead of
    perlio. Some stdio's set error and eof flags that need clearing.

Actually I think the sticky error and eof flags are mandated by ANSI-C,
so "some stdio's" should be replaced by "most stdio's" or even "almost
all stdio's".

	hp


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

Date: Sat, 10 Oct 2009 10:45:54 -0700 (PDT)
From: Ryan Chan <ryanchan404@gmail.com>
Subject: Get domain from uri
Message-Id: <919a9129-0c0c-4416-bcff-3166af09ef98@g22g2000prf.googlegroups.com>

Hello,

I want to get the domain from uri, e.g.

http://www.example.com/index.html => example.com
http://foo.example.com/index.html => example.com
http://foo.example.co.uk/index.html => example.co.uk
http://foo.example.company.com => company.com
http://foo.example.company.com.hk => company.com.hk

It seems that URI module does not have this feature yet, any
recommendation?

Thanks.







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

Date: Sat, 10 Oct 2009 14:16:55 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Get domain from uri
Message-Id: <87eipb9krs.fsf@quad.sysarch.com>

>>>>> "RC" == Ryan Chan <ryanchan404@gmail.com> writes:

  RC> Hello,
  RC> I want to get the domain from uri, e.g.

  RC> http://www.example.com/index.html => example.com
  RC> http://foo.example.com/index.html => example.com
  RC> http://foo.example.co.uk/index.html => example.co.uk
  RC> http://foo.example.company.com => company.com
  RC> http://foo.example.company.com.hk => company.com.hk

  RC> It seems that URI module does not have this feature yet, any
  RC> recommendation?

it does have that feature. URI can mung and access any part of any
URI. why would you think it wouldn't have access to something as
important as the host? please rtfm fully before making such a claim.

fron perldoc URI:

       $uri->host
       $uri->host( $new_host )
           Sets and returns the unescaped hostname.

           If the $new_host string ends with a colon and a number, then this
           number also sets the port.

that is further down the doc and it covers URI's that work with servers
and have host parts.

uri (not related to nor named after URI. my name came first! :)

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Sat, 10 Oct 2009 13:22:41 -0500
From: tony_curtis32@yahoo.com
Subject: Re: Get domain from uri
Message-Id: <87r5tbjeha.fsf@yahoo.com>

Ryan Chan <ryanchan404@gmail.com> writes:

> Hello,
>
> I want to get the domain from uri, e.g.
>
> http://www.example.com/index.html => example.com
> http://foo.example.com/index.html => example.com
> http://foo.example.co.uk/index.html => example.co.uk
> http://foo.example.company.com => company.com
> http://foo.example.company.com.hk => company.com.hk
>
> It seems that URI module does not have this feature yet, any
> recommendation?

What are the criteria for whether you go 2- or 3-deep to
get what you consider to be the domain?

As it stands, there doesn't seem to be a purely syntactic
solution, you'll need knowledge of how each TLD is
organized.


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

Date: Sat, 10 Oct 2009 19:21:45 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Get domain from uri
Message-Id: <puv6q6-aoo1.ln1@osiris.mauzo.dyndns.org>


Quoth Ryan Chan <ryanchan404@gmail.com>:
> 
> I want to get the domain from uri, e.g.
> 
> http://www.example.com/index.html => example.com
> http://foo.example.com/index.html => example.com
> http://foo.example.co.uk/index.html => example.co.uk
> http://foo.example.company.com => company.com
> http://foo.example.company.com.hk => company.com.hk
> 
> It seems that URI module does not have this feature yet, any
> recommendation?

Start by using the URI module to extract the hostname part. The rest of
the URI is irrelevant.

Then you will need a list of which TLDs have a policy of using 2LDs,
rather than allocating names directly under the TLD. Depending on your
requirements, that can be quite complicated: for instance,
'devon.sch.uk' is not an organisation-specific name, but a third level
of administrative grouping, and 'nhs.uk' may or may not be a single
organisation depending on what your criteria are (certainly,
'http://www.nhs.uk' is a working website).

One possible heuristic might be to find the first name that both has an
SOA record and has a different canonical nameserver from the final
component alone. So, for example:

    com.        => a.gtld-servers.net
    google.com. => ns1.google.com

    uk.     => ns1.nic.uk
    nhs.uk. => external.nhs.uk

    uk.                         => ns1.nic.uk
    sch.uk                      => ns1.nic.uk
    devon.sch.uk                => no SOA record
    kingedwardvi.devon.sch.uk   => dns0.swgfl.ifl.net

You can use Net::DNS (among other modules) to perform arbitrary DNS
lookups.

Ben



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

Date: Sat, 10 Oct 2009 20:09:02 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Get domain from uri
Message-Id: <en27q6-j8p1.ln1@osiris.mauzo.dyndns.org>


Quoth Ben Morrow <ben@morrow.me.uk>:
> 
> Quoth Ryan Chan <ryanchan404@gmail.com>:
> > 
> > I want to get the domain from uri, e.g.
> 
> One possible heuristic might be to find the first name that both has an
> SOA record and has a different canonical nameserver from the final
> component alone. So, for example:

Thinking again, I think it might be better to start at the top-level,
and keep stripping prefixes off until you get a name that has an SOA
record (taking care to note that name that the SOA record is for: if
www.foo.com is a CNAME for foo.com, an SOA lookup for www.foo.com will
succeed, but return an SOA record for foo.com). This will, for instance,
give wales.nhs.uk as a separate organisation, but put jobs.nhs.uk under
nhs.uk, which is probably correct. It will also separate out names under
e.g. dyndns.org, which is probably correct too.

Ben



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

Date: Fri, 09 Oct 2009 14:23:43 -0400
From: monkeys paw <user@example.net>
Subject: Re: grepping thru hashref
Message-Id: <XfSdnWGrXP0-4lLXnZ2dnUVZ_hti4p2d@insightbb.com>

Thanks both of you. The reverse hash list is excellent advice.

> Quoth monkeys paw <user@example.net>:
>> In the following code i want to grep for a number ($num)  held in 
>> %toplist_hash.
>> If a match is found the program should which key in %toplist_hash 
>> contains the number. The question really boils down to how to use
>> grep to access an element of an array ref inside a hash
>>
>> my %toplist_hash = (
>>            'LTest' => [
>>                         '140105',
> <snip>
>>                        ],
>> );
>>
>> $num = '60403';
>> for (keys %toplist_name) {
>>      if (grep(/^$num$/, @{$toplist_hash{$_}})) {
>>          print $_;
>>      }
>> }
> 
> You have both for and grep setting $_. Since grep can't be changed, you
> need to tell for to use a different variable. Also, if these are numbers
> you should probably be using numeric equality (and not quoting them).
> 
>     for my $k (keys %toplist_hash) {
>         if (grep $num == $_, @{$toplist_hash{$k}}) {
>             print $k;
>         }
>     }
> 
> If you know there's only one matching key, add a 'last' after the
> 'print' so you don't search the rest of the keys. If you are going to be
> doing this at all often, build a reversed hash like
> 
>     my %toplist_num;
>     for my $k (keys %toplist_hash) {
>         for my $n (@{$toplist_hash{$k}}) {
>             $toplist_num{$n} = $k;
>         }
>     }
> 
> so you can perform the lookup directly.
> 
> Ben
> 


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

Date: Fri, 9 Oct 2009 20:26:39 +0200
From: "cvrčak" <cvrčak@banana.com>
Subject: Re: Perl and packge
Message-Id: <hanv8u$ae7$1@news.metronet.hr>

thanks 




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

Date: Fri, 09 Oct 2009 22:33:43 +0100
From: Brian Wakem <no@email.com>
Subject: Re: Simple question about CGI response after form data has been processed.
Message-Id: <7j9ohoF351lfgU1@mid.individual.net>

Ted Byers wrote:

> I have searched through my books, the FAQs I could find, the CGI
> documentation, and have not found the answer, probably just an
> oversight in the documentation I have examined.
> 
> For the most part, I have found it extremely easy to use the CGI
> packages.
> 
> My frustration is that, while it is trivially easy to get form
> parameters in my CGI scripts, I have not found how to either forward
> or redirect the user to the HTML form he had just used to submit the
> data my script had just processed.  The script is just to move the
> data into a DB, send an error page if there is a problem, and
> otherwise return the user to the form ready to enter more data.  The
> form itself is static, and so exists as a simple HTML file in htdocs
> (I'm using Apache's httpd).
> 
> I found something about just printing "Location: some_uri", but unless
> the sources I read are mistaken, that needs a full path, and, as the
> code will be moved from my development machine to a final home, I can
> only know the relative path.
> 
> I know I could have the contents of the HTML file in the cgi file too,
> but that carries its own problems WRT maintenance, and having the
> script read the file and then print it carries performance issues.
> 
> What is the best option here?
> 
> Thanks
> 
> Ted


use CGI;
my $query = new CGI;

print $query->redirect( -location => '/myform.html' );



-- 
Brian Wakem


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

Date: Fri, 09 Oct 2009 13:22:02 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Slickuser <slick.users@gmail.com>
Subject: Re: time format +1 hour
Message-Id: <86eipcpbbp.fsf@blue.stonehenge.com>

>>>>> "Slickuser" == Slickuser  <slick.users@gmail.com> writes:

Slickuser> Forgot to mention that original time is fixed and get modify to a
Slickuser> new one (not local time).

Slickuser> An example below.

Slickuser> 	my $time_org = "20091009090832";
Slickuser> 	my $time_mod = "20091009100832";

Is this GMT, or a local time?  If a local time, which timezone, and
under what DST rules?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


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

Date: Sat, 10 Oct 2009 20:51:03 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: time format +1 hour
Message-Id: <slrnhd1lso.60d.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-09 07:13, Josef Moellers <josef.moellers@ts.fujitsu.com> wrote:
> Jürgen Exner wrote:
>> Slickuser <slick.users@gmail.com> wrote:
>>> I have this value:
>>> 20091008155222
>>> YYYY_MM_DD_HH_MM_SS
>>>
>>> Is there any module out there if I add 1 hour to my current timestamp,
>>> it will also roll over to DD, MM, and year if possible.
>>> This might happen at 23 hours (0-23), 0-6 days, 0-12 months..
>>>
>>>    my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
>>> localtime(time);
>> 
>> What's wrong with a simple 
>> 
>> 	my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
>> = localtime(time + 3600);
>
> It will work in 99.99999% of all cases until you fall over one of these 
> years where they add/subtract a leap second ;-)

No. The unix time_t value ignores leap seconds. A day is always counted
as 86400 seconds (it wouldn't be possible to compute the time_t value
for future dates otherwise).

	hp


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 2629
***************************************


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