[31378] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2630 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 11 18:09:42 2009

Date: Sun, 11 Oct 2009 15:09:06 -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           Sun, 11 Oct 2009     Volume: 11 Number: 2630

Today's topics:
    Re: FAQ 4.69 How can I make the Perl equivalent of a C  <ben@morrow.me.uk>
    Re: FAQ 4.69 How can I make the Perl equivalent of a C  <hjp-usenet2@hjp.at>
        FAQ 5.12 How can I open a filehandle to a string? <brian@theperlreview.com>
    Re: FAQ 5.17 Is there a leak/bug in glob()? <brian.d.foy@gmail.com>
        FAQ 6.10 What is "/o" really for? <brian@theperlreview.com>
        FAQ 6.19 Why does using $&, $`, or $' slow my program d <brian@theperlreview.com>
        FAQ 6.2 I'm having trouble matching over more than one  <brian@theperlreview.com>
        FAQ 7.14 What is variable suicide and how can I prevent <brian@theperlreview.com>
    Re: FAQ 7.15 How can I pass/return a {Function, FileHan <brian.d.foy@gmail.com>
    Re: FAQ 8.29 Why can't my script read from STDIN after  <brian.d.foy@gmail.com>
        FAQ postings' subjects (was: FAQ 5.17 Is there a leak/b <tim@tim-landscheidt.de>
    Re: Get domain from uri <ryanchan404@gmail.com>
    Re: Get domain from uri <bart.lateur@pandora.be>
    Re: Get domain from uri <ben@morrow.me.uk>
        Insideous non-breaking space, why can't it be called a  sln@netherlands.com
        libusb, use Device::USB; works only as user root? <georg.heiss@gmx.de>
    Re: time format +1 hour <slick.users@gmail.com>
    Re: time format +1 hour (Randal L. Schwartz)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 10 Oct 2009 21:31:53 +0100
From: Ben Morrow <ben@morrow.me.uk>
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: <pi77q6-k7q1.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@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:
> 
> Since perl 5.8(?) you can use the fields pragma to allow only specific
> fields:

fields has been core since 5.005. In 5.10 its implementation was changed
from using pseudohashes (which were deprecated in 5.8) to using
restricted hashes (introduced in 5.8).

I would generally recommend against using fields. It uses too much
internal magic, and requires you use 'base' if you want to subclass
(base and fields know rather too much about each others' internals). If
you just want a struct-like class, there are better constructors on
CPAN: Object::Tiny is a minimal implementation, Object::Tiny::XS,
Class::XSAccessor and Class::Accessor::* provide faster and/or more
featureful implementations, and I'm sure there are more.

If you just want a restricted hash, you can create one directly with
Hash::Util.

Ben



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

Date: Sun, 11 Oct 2009 20:47:09 +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: <slrnhd4a1d.2pb.hjp-usenet2@hrunkner.hjp.at>

On 2009-10-10 20:31, Ben Morrow <ben@morrow.me.uk> wrote:
> I would generally recommend against using fields. It uses too much
> internal magic, and requires you use 'base' if you want to subclass
> (base and fields know rather too much about each others' internals). If
> you just want a struct-like class, there are better constructors on
> CPAN: Object::Tiny is a minimal implementation, Object::Tiny::XS,
> Class::XSAccessor and Class::Accessor::* provide faster and/or more
> featureful implementations, and I'm sure there are more.
>
> If you just want a restricted hash, you can create one directly with
> Hash::Util.

Thanks for the pointers. I'll check them out.

	hp


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

Date: Sat, 10 Oct 2009 22:00:08 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.12 How can I open a filehandle to a string?
Message-Id: <It7Am.41610$Bl2.14421@newsfe14.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.12: How can I open a filehandle to a string?

    (contributed by Peter J. Holzer, hjp-usenet2@hjp.at)

    Since Perl 5.8.0 a file handle referring to a string can be created by
    calling open with a reference to that string instead of the filename.
    This file handle can then be used to read from or write to the string:

            open(my $fh, '>', \$string) or die "Could not open string for writing";
            print $fh "foo\n";
            print $fh "bar\n";      # $string now contains "foo\nbar\n"

            open(my $fh, '<', \$string) or die "Could not open string for reading";
            my $x = <$fh>;  # $x now contains "foo\n"

    With older versions of Perl, the "IO::String" module provides similar
    functionality.



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

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 17:43:44 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.17 Is there a leak/bug in glob()?
Message-Id: <101020091743444804%brian.d.foy@gmail.com>

In article <uf47q6-lip1.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:

> 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.

Thanks, the new answer reads:

=head2 Is there a leak/bug in glob()?
X<glob>

(conributed by brian d foy)

Starting with Perl 5.6.0, C<glob> is implemented internally rather
than relying on an external resource. As such, memory issues with 
C<glob> aren't a problem in modern perls.


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

Date: Sun, 11 Oct 2009 16:00:10 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 6.10 What is "/o" really for?
Message-Id: <einAm.140272$Y83.137094@newsfe21.iad>

This is an excerpt from the latest version perlfaq6.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 .

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

6.10: What is "/o" really for?

    (contributed by brian d foy)

    The "/o" option for regular expressions (documented in perlop and
    perlreref) tells Perl to compile the regular expression only once. This
    is only useful when the pattern contains a variable. Perls 5.6 and later
    handle this automatically if the pattern does not change.

    Since the match operator "m//", the substitution operator "s///", and
    the regular expression quoting operator "qr//" are double-quotish
    constructs, you can interpolate variables into the pattern. See the
    answer to "How can I quote a variable to use in a regex?" for more
    details.

    This example takes a regular expression from the argument list and
    prints the lines of input that match it:

            my $pattern = shift @ARGV;

            while( <> ) {
                    print if m/$pattern/;
                    }

    Versions of Perl prior to 5.6 would recompile the regular expression for
    each iteration, even if $pattern had not changed. The "/o" would prevent
    this by telling Perl to compile the pattern the first time, then reuse
    that for subsequent iterations:

            my $pattern = shift @ARGV;

            while( <> ) {
                    print if m/$pattern/o; # useful for Perl < 5.6
                    }

    In versions 5.6 and later, Perl won't recompile the regular expression
    if the variable hasn't changed, so you probably don't need the "/o"
    option. It doesn't hurt, but it doesn't help either. If you want any
    version of Perl to compile the regular expression only once even if the
    variable changes (thus, only using its initial value), you still need
    the "/o".

    You can watch Perl's regular expression engine at work to verify for
    yourself if Perl is recompiling a regular expression. The "use re
    'debug'" pragma (comes with Perl 5.005 and later) shows the details.
    With Perls before 5.6, you should see "re" reporting that its compiling
    the regular expression on each iteration. With Perl 5.6 or later, you
    should only see "re" report that for the first iteration.

            use re 'debug';

            $regex = 'Perl';
            foreach ( qw(Perl Java Ruby Python) ) {
                    print STDERR "-" x 73, "\n";
                    print STDERR "Trying $_...\n";
                    print STDERR "\t$_ is good!\n" if m/$regex/;
                    }



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

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: Sun, 11 Oct 2009 10:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 6.19 Why does using $&, $`, or $' slow my program down?
Message-Id: <D0iAm.74402$944.51812@newsfe09.iad>

This is an excerpt from the latest version perlfaq6.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 .

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

6.19: Why does using $&, $`, or $' slow my program down?

    (contributed by Anno Siegel)

    Once Perl sees that you need one of these variables anywhere in the
    program, it provides them on each and every pattern match. That means
    that on every pattern match the entire string will be copied, part of it
    to $`, part to $&, and part to $'. Thus the penalty is most severe with
    long strings and patterns that match often. Avoid $&, $', and $` if you
    can, but if you can't, once you've used them at all, use them at will
    because you've already paid the price. Remember that some algorithms
    really appreciate them. As of the 5.005 release, the $& variable is no
    longer "expensive" the way the other two are.

    Since Perl 5.6.1 the special variables @- and @+ can functionally
    replace $`, $& and $'. These arrays contain pointers to the beginning
    and end of each match (see perlvar for the full story), so they give you
    essentially the same information, but without the risk of excessive
    string copying.

    Perl 5.10 added three specials, "${^MATCH}", "${^PREMATCH}", and
    "${^POSTMATCH}" to do the same job but without the global performance
    penalty. Perl 5.10 only sets these variables if you compile or execute
    the regular expression with the "/p" modifier.



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

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: Sun, 11 Oct 2009 22:00:08 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 6.2 I'm having trouble matching over more than one line.  What's wrong?
Message-Id: <IzsAm.88045$4t6.23956@newsfe06.iad>

This is an excerpt from the latest version perlfaq6.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 .

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

6.2: I'm having trouble matching over more than one line.  What's wrong?

    Either you don't have more than one line in the string you're looking at
    (probably), or else you aren't using the correct modifier(s) on your
    pattern (possibly).

    There are many ways to get multiline data into a string. If you want it
    to happen automatically while reading input, you'll want to set $/
    (probably to '' for paragraphs or "undef" for the whole file) to allow
    you to read more than one line at a time.

    Read perlre to help you decide which of "/s" and "/m" (or both) you
    might want to use: "/s" allows dot to include newline, and "/m" allows
    caret and dollar to match next to a newline, not just at the end of the
    string. You do need to make sure that you've actually got a multiline
    string in there.

    For example, this program detects duplicate words, even when they span
    line breaks (but not paragraph ones). For this example, we don't need
    "/s" because we aren't using dot in a regular expression that we want to
    cross line boundaries. Neither do we need "/m" because we aren't wanting
    caret or dollar to match at any point inside the record next to
    newlines. But it's imperative that $/ be set to something other than the
    default, or else we won't actually ever have a multiline record read in.

            $/ = '';                # read in whole paragraph, not just one line
            while ( <> ) {
                    while ( /\b([\w'-]+)(\s+\1)+\b/gi ) {   # word starts alpha
                            print "Duplicate $1 at paragraph $.\n";
                    }
            }

    Here's code that finds sentences that begin with "From " (which would be
    mangled by many mailers):

            $/ = '';                # read in whole paragraph, not just one line
            while ( <> ) {
                    while ( /^From /gm ) { # /m makes ^ match next to \n
                    print "leading from in paragraph $.\n";
                    }
            }

    Here's code that finds everything between START and END in a paragraph:

            undef $/;               # read in whole file, not just one line or paragraph
            while ( <> ) {
                    while ( /START(.*?)END/sgm ) { # /s makes . cross line boundaries
                        print "$1\n";
                    }
            }



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

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: Sun, 11 Oct 2009 04:00:03 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 7.14 What is variable suicide and how can I prevent it?
Message-Id: <7LcAm.27774$tG1.21269@newsfe22.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.14: What is variable suicide and how can I prevent it?

    This problem was fixed in perl 5.004_05, so preventing it means
    upgrading your version of perl. ;)

    Variable suicide is when you (temporarily or permanently) lose the value
    of a variable. It is caused by scoping through my() and local()
    interacting with either closures or aliased foreach() iterator variables
    and subroutine arguments. It used to be easy to inadvertently lose a
    variable's value this way, but now it's much harder. Take this code:

            my $f = 'foo';
            sub T {
                    while ($i++ < 3) { my $f = $f; $f .= "bar"; print $f, "\n" }
                    }

            T;
            print "Finally $f\n";

    If you are experiencing variable suicide, that "my $f" in the subroutine
    doesn't pick up a fresh copy of the $f whose value is <foo>. The output
    shows that inside the subroutine the value of $f leaks through when it
    shouldn't, as in this output:

            foobar
            foobarbar
            foobarbarbar
            Finally foo

    The $f that has "bar" added to it three times should be a new $f "my $f"
    should create a new lexical variable each time through the loop. The
    expected output is:

            foobar
            foobar
            foobar
            Finally foo



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

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 17:38:42 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 7.15 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?
Message-Id: <101020091738426677%brian.d.foy@gmail.com>

In article <slrnhd1njg.60d.hjp-usenet2@hrunkner.hjp.at>, Peter J.
Holzer <hjp-usenet2@hjp.at> wrote:

> 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}?

> 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,

done, thanks


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

Date: Sat, 10 Oct 2009 17:47:24 -0500
From: brian d foy <brian.d.foy@gmail.com>
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: <101020091747247967%brian.d.foy@gmail.com>

In article <slrnhd1p4a.60d.hjp-usenet2@hrunkner.hjp.at>, Peter J.
Holzer <hjp-usenet2@hjp.at> wrote:

> 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.

fixed, thanks.


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

Date: Sun, 11 Oct 2009 17:42:25 +0000
From: Tim Landscheidt <tim@tim-landscheidt.de>
Subject: FAQ postings' subjects (was: FAQ 5.17 Is there a leak/bug in glob()?)
Message-Id: <m3tyy5u8se.fsf_-_@passepartout.tim-landscheidt.de>

"Peter J. Holzer" <hjp-usenet2@hjp.at> 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.

BTW, in other newsgroups subjects for FAQ postings are often
pre-/postfixed with the date of the last change, e. g. "In-
foposting d.e.n. <2001-05-14>" so you can killfile the re-
curring articles once you have read them yet you do not miss
any new information.

  Would it be possible to handle this here in the same way?

Tim


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

Date: Sat, 10 Oct 2009 21:59:07 -0700 (PDT)
From: Ryan Chan <ryanchan404@gmail.com>
Subject: Re: Get domain from uri
Message-Id: <37478d0d-3429-4041-8ae2-501f671dc1cd@s21g2000prm.googlegroups.com>

On Oct 11, 2:22=A0am, tony_curti...@yahoo.com wrote:

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

Think about Alexa, they map subdomains (with many level) into a single
domain and generate the ranking

e.g.

http://uk.finance.yahoo.com =3D> yahoo.com


What I want to do is something like that.


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

Date: Sun, 11 Oct 2009 12:36:24 +0200
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Get domain from uri
Message-Id: <u4d3d5lthckh8qs1db052p07a4eq19bics@4ax.com>

tony_curtis32@yahoo.com wrote:

>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.

Oh, I would totally have missed the original question, if it wasn't for
this reply.

I found this:

	Net::Domain::TLD
	http://search.cpan.org/perldoc?Net::Domain::TLD

which is a module to reduce a domain name to its core domain name.

-- 
	Bart.


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

Date: Sun, 11 Oct 2009 16:17:32 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Get domain from uri
Message-Id: <ch99q6-9412.ln1@osiris.mauzo.dyndns.org>


Quoth Bart Lateur <bart.lateur@pandora.be>:
> 
> Oh, I would totally have missed the original question, if it wasn't for
> this reply.
> 
> I found this:
> 
> 	Net::Domain::TLD
> 	http://search.cpan.org/perldoc?Net::Domain::TLD
> 
> which is a module to reduce a domain name to its core domain name.

No it's not. It gives you a list of valid TLDs, which is not the same.

Ben



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

Date: Sat, 10 Oct 2009 14:33:24 -0700
From: sln@netherlands.com
Subject: Insideous non-breaking space, why can't it be called a whitespace \s and be done with it?
Message-Id: <bur1d5puk0mtkj5vic4p5h5bv151inu683@4ax.com>

I'm not sure how the below sample will look under your newsreader.
I am using Agent. I usually don't look at raw nntp messages.
I made the mistake of cut n' pasting a sample picked up on this
group, into Notepad to try it out. It should have worked but didn't.
Unfortunately, the sample was from Google news reader.

As I went back and toggled Agent into 'raw', the =A0 showed up of
course. Interrestingly, Notepad and Word shows it as A0 & 7f = 20 = ' '.

This didn't bother me too much but got me thinking.
All my instincts are telling me not to ask this because A0 > 7F,
and A0 is distinct in meaning but here goes.

As far as I know, Perl has no significant meaning for A0,
its just another character.
Just for this specific character, why can't it be a whitespace
at least in context of regex's and possibly when the source is
parsed?

As it is now, parsed regex's allow embedded A0, but all other
places generate "unknown character in source" error.
And I'm not sure that a Word edited source cannot contain
embedded non-breaking spaces.

End of stupid question..

-sln
-----------
use strict;
use warnings;

my @strings = ('     ', ' 	  ');
for my $str (@strings)
{
	print "\nstring = '$str'\n";
	print "all whitespaces\n" if ($str =~ /^\s+$/);
	for (map {ord $_} split //,$str) {
		printf "%02x & 0x7f = %02x\n", $_, ($_ & 0x7f);
	}
}
print "\n";

if ( "some_text" =~ /
  ^     # begin string
    .*  # anything or nothing
  $     # end string
  /x )
{ print "matched\n" }
   else
{ print "didn't match anything/nothing\n" }

print "\n";

if ( "some_text" =~ /
  ^     # begin string
    .*  # anything or nothing
  $     # end string
  /x )
{ print "matched\n" }
   else
{ print "didn't match anything/nothing\n" }

__END__

Output:

c:\temp>perl jj.pl

string = ' á á '
20 & 0x7f = 20
a0 & 0x7f = 20
20 & 0x7f = 20
a0 & 0x7f = 20
20 & 0x7f = 20

string = '        '
all whitespaces
20 & 0x7f = 20
09 & 0x7f = 09
20 & 0x7f = 20
20 & 0x7f = 20

didn't match anything/nothing

matched

c:\temp>



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

Date: Sun, 11 Oct 2009 02:54:36 -0700 (PDT)
From: "georg.heiss@gmx.de" <georg.heiss@gmx.de>
Subject: libusb, use Device::USB; works only as user root?
Message-Id: <477cd60d-0a19-479f-9d9a-77a6659a186c@v36g2000yqv.googlegroups.com>

Hi, why does the attached Script only works as user root?

running as user root i get:
root@siduxbox:/home/gh# perl usb.pl
Device: 1781:0A98
Manufactured by raphnet.net
 Product: USBTenki


running as default user i get a empty result set:
gh@siduxbox:~$ perl usb.pl
Device: 1781:0A98
Manufactured by
 Product:

Kind Regards
Georg

use Device::USB;
my $Vendor= '1781';
my $Product= '0a98';
my $intVendor = unpack("n", pack("H4", $Vendor)); #hex2int
my $intProduct = unpack("n", pack("H4", $Product)); #hex2int
#print "$intProduct\n";

my $usb = Device::USB->new();
my @devices = $usb->list_devices_if( sub { Device::USB::CLASS_HUB ==
$_->bDeviceClass() } );
#print "@devices\n";

    my $dev = $usb->find_device( $intVendor, $intProduct );
    printf "Device: %04X:%04X\n", $dev->idVendor(), $dev->idProduct();
    $dev->open();
    print "Manufactured by ", $dev->manufacturer(), "\n",
          " Product: ", $dev->product(), "\n";




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

Date: Sat, 10 Oct 2009 22:31:58 -0700 (PDT)
From: Slickuser <slick.users@gmail.com>
Subject: Re: time format +1 hour
Message-Id: <674e7960-66c7-48df-8f60-b7f3844c3d57@d9g2000prh.googlegroups.com>

I have this string fixed (opened from a text document) as
"20091009090832" (YYYY_MM_DD_HH_MM_SS).

Now I want +1 hour to this string so it can be "20091009100832".

Sorry for the confusion.


On Oct 9, 1:22=A0pm, mer...@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Slickuser" =3D=3DSlickuser=A0<slick.us...@gmail.com> writes:
>
> Slickuser> Forgot to mention that original time is fixed and get modify t=
o aSlickuser> new one (not local time).
>
> Slickuser> An example below.
>
> Slickuser> =A0 my $time_org =3D "20091009090832";Slickuser> =A0 my $time_=
mod =3D "20091009100832";
>
> Is this GMT, or a local time? =A0If a local time, which timezone, and
> under what DST rules?
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 00=
95
> <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> Seehttp://methodsandmessages.vox.com/for Smalltalk and Seaside discussion



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

Date: Sun, 11 Oct 2009 08:27:53 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Slickuser <slick.users@gmail.com>
Subject: Re: time format +1 hour
Message-Id: <86aazylzly.fsf@blue.stonehenge.com>

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

Slickuser> I have this string fixed (opened from a text document) as
Slickuser> "20091009090832" (YYYY_MM_DD_HH_MM_SS).

Slickuser> Now I want +1 hour to this string so it can be "20091009100832".

Slickuser> Sorry for the confusion.

You simply restated the problem without answering my question, and the answer
to you depends on you answering my question, which I will now ask again.  If
you don't know the answer to it, then you don't know enough to solve your
problem, and should ask the person who asked you to solve this:

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

Please answer that.  You *need* to know that to "add an hour".  Really, you
do.

print "Just another Perl hacker,"; # the original

-- 
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: 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 2630
***************************************


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