[23229] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5450 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 5 18:05:38 2003

Date: Fri, 5 Sep 2003 15:05:07 -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           Fri, 5 Sep 2003     Volume: 10 Number: 5450

Today's topics:
    Re: [newbie] list elements <krahnj@acm.org>
    Re: [newbie] list elements <minceme@start.no>
    Re: Arbitrarily Complex Data Structure (JR)
    Re: Basic Aspects of AI <cwilbur@mithril.chromatico.net>
    Re: Basic Aspects of AI <usenet@dwall.fastmail.fm>
    Re: finding instance of object (Greg Bacon)
    Re: finding instance of object <bharnish@technologist.com>
        How to replace globally a string1 with string2 only if  (giri alamuri)
    Re: How to replace globally a string1 with string2 only <shondell@cis.ohio-state.edu>
    Re: How to replace globally a string1 with string2 only <bharnish@technologist.com>
    Re: My perl script is "Killed" - Ran out of memory (Marcus Brody)
        Perl - Absolute min. environment required. (Prabh)
    Re: PERL, FTP and Browser Upload (TheWizZ)
        problems with charsets <pilsl_usenet@goldfisch.at>
    Re: Regexp Help <postmaster@castleamber.com>
    Re: Regexp Help <print split /!/"d!a!v!i!d!o!@!p!a!c!i!f!i!e!r!.!c!o!m!\n">
    Re: Regexp Help <postmaster@castleamber.com>
    Re: Regexp Help <laocoon@fastmail.fm>
    Re: Repost Search <usenet@dwall.fastmail.fm>
    Re: Repost Search (Jimmy)
    Re: Telling perl to expect input data to be in UTF8 (no <bkennedy@hmsonline.com>
    Re: Telling perl to expect input data to be in UTF8 <flavell@mail.cern.ch>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 05 Sep 2003 19:25:00 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: [newbie] list elements
Message-Id: <3F58E2EE.E867EA87@acm.org>

John Bokma wrote:
> 
> Vlad Tepes wrote:
> 
> @hash{@a} = ( "" ) x @a;
> 
> v.s.
> 
> @hash{@a} = ( undef ) x @a;
> 
> > So setting a hash value to undef at least appears to save about
> > 56 bytes memory compared to storing it as an empty string.
> 
> 56 bytes/element. That is quite some saving. Thanks for sharing.
> I guess that undef just creates a null pointer and an empty string
> creates a list element with an empty string and some info. (Wild guess)

You could just assign the empty list which would use less memory then
either of the above.

@hash{ @a } = ();


John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 5 Sep 2003 20:19:32 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: [newbie] list elements
Message-Id: <bjar4k$o0f$1@troll.powertech.no>

John W. Krahn:
> John Bokma:
>> Vlad Tepes:
>> 
>>> So setting a hash value to undef at least appears to save about
>>> 56 bytes memory compared to storing it as an empty string.
>> 
>> 56 bytes/element. That is quite some saving. Thanks for sharing.
>> I guess that undef just creates a null pointer and an empty string
>> creates a list element with an empty string and some info. (Wild guess)
>
> You could just assign the empty list which would use less memory then
> either of the above.
>
> @hash{ @a } = ();

Indeed! 

When I try to measure this once more, I get these results:

    @a = 1..1e5;

    @hash{@a} = ();                 => 19752 kB
    @hash{@a} = ( undef ) x @a;     => 20840 kB
    @hash{@a} = ( "" ) x @a;        => 26352 kB

Which means that relative sizes of the elements become:
    
    @hash{@a} = ();                 =>     0
    @hash{@a} = ( undef ) x @a;     =>   +11  bytes pr elem
    @hash{@a} = (  ""   ) x @a;     =>   +68  bytes pr elem

( Difference between "" and undef is 57 this time, corresponding
  well with my last attempt to measure the diff. )

Great John, 
your way means less typing too, as usual...

-- 
Vlad


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

Date: 5 Sep 2003 13:44:52 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Arbitrarily Complex Data Structure
Message-Id: <b386d54b.0309051244.77a364ba@posting.google.com>

Vlad Tepes <minceme@start.no> wrote in message news:<bja07u$ev6$1@troll.powertech.no>...
> Bryan Castillo <rook_5150@yahoo.com> wrote:
> > Vlad Tepes <minceme@start.no> wrote
> >> JR <jrolandumuc@yahoo.com> wrote:
> >> >jrolandumuc@yahoo.com (JR) wrote
> >> >>Brian McCauley <nobull@mail.com> wrote
> >> >>> jrolandumuc@yahoo.com (JR) writes:
> >> >>> 
> >> >>>> Hi.  Is it possible to create a subroutine to handle an arbitrarily
> >> >>>> complex data structure (for my purposes, complex only refers to hashes
> >> >>>> and arrays)?
> >> 
> >> I just palyed some small with tarversing. Maybe yo like to have a loko:
> >> 
> >>     sub processitem($) {
> >>         my $indent = shift;
> >>         my $item   = shift || $_;
> >>         print "$indent ", "    " x $indent, $item, "\n";
> >>     }
> >>     
> >>     sub trav(@); # must declare sub to prototype recurs. func.
> >> 
> >>     sub trav {
> >>         my $i = ref $_[0] ? 0 : 1 + shift; # indentation
> >>         foreach ( @_ ) {
> >>             /HASH/  &&  do{ trav $i, %$_;    next }; 
> >>             /ARRAY/ &&  do{ trav $i, @$_;    next }; 
> >>             /CODE/  &&  do{ trav $i, $_->(); next };
> >>             /REF/   &&  do{ trav $i, $$_ ;   next };   
> >>             processitem $i;
> >>         }
> >>     }
> >> 
> >>     trav  \%hoh, \\\\\%hah, \%hah, \%heh;
> >> 
> >     # DON'T TRY DOING THIS THOUGH!
> >     # fyi Data::Dumper handles it
> >
> >     my $a = { name => 'bryan', age => 26 };
> >     $a->{evil_death} = $a;
> >     trav($a);
> 
> Yes, this snippet loops infinitely on circular references. (There are
> also other errors in it.)
> 
> But I can't see how you could use Data::Dumper to print only the values
> of datastructures.
> 
> Regards,

Thanks to everyone for their suggestions, especially Vlad.  The below
constructor is my final product, for now.  I'll leave handling
circular references, and other reference types, for another day.  I
know that the
data structures that will be passed to the script will not contain
circular
references or references to anything other than arrays, hashes, subs,
or
scalars, so the below is fine, for now.  This was an enlightening
project
on which to work.  

--------------
use strict;
package TRAVERSE;

sub new {
   my ($self, $class, @pobj);
   if (caller =~ /main|\.pl/) {  # first call
      $class  = shift;
      $class  = ref($class) || $class; 
   }
   for (@_) {			 # all recursive calls
      if(!ref($_)) {push @pobj, $_; next;} 
      ref($_) eq 'REF'   ? new($$_)    : ref($_) eq 'HASH'   ? 
                                         new(%$_) : 
      ref($_) eq 'ARRAY' ? new(@$_)    : ref($_) eq 'SCALAR' ? 
                                         new($$_) :
      ref($_) eq 'CODE'  ? new($_->()) : 
      print "<<<EXCEPTION: $_>>>\n";
   }
   if (!/^\s*$/) {               # recursion is complete
      $self = [@pobj];           # create reference to data
      bless $self, $class;       # create object
   }
   print "$_\n" for @$self;      # print object
   return $self;                 # return object
}

1;


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

Date: Fri, 05 Sep 2003 18:45:03 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Basic Aspects of AI
Message-Id: <87iso73wt7.fsf@mithril.chromatico.net>

>>>>> "BKS" == Bradley K Sherman <bks@panix.com> writes:

    BKS> In article <3f58ac02@news.victoria.tc.ca>,
    BKS> Arthur T. Murray <uj797@victoria.tc.ca> wrote:
    >> ...  http://www.amazon.com/exec/obidos/ASIN/0595654371/ -- "AI
    >> For You" (AI4U) is an AI textbook that you might consider using
    >> as an AI Lab supplement to pre-Singularity textbooks of
    >> artificial intelligence.  ...

    BKS> Hey guys, over here in comp.human-factors we thought AI died
    BKS> sometime around 1967.  Is that the Sigularity referred to or
    BKS> is there something going on that we should know about?

Arthur T. Murray is a net.kook.  

Charlton



-- 
cwilbur at chromatico dot net
cwilbur at mac dot com


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

Date: Fri, 05 Sep 2003 19:42:27 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Basic Aspects of AI
Message-Id: <Xns93ED9FC72F9F3dkwwashere@216.168.3.30>

Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote:

> Arthur T. Murray is a net.kook.  

And here's me thinking he ran a successful line of dance studios.

-- 
David Wall


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

Date: Fri, 05 Sep 2003 18:28:33 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: finding instance of object
Message-Id: <vlhleh88hp9maa@corp.supernews.com>

In article <3F58B342.468C3B1D@sprintmail.com>,
    Jeff Thies  <cyberjeff@sprintmail.com> wrote:

: I have an object and I like to print the instance of the object;
: [...]  I'd like to print $object_name, can I do that or do I need to
: pass it in directly as a property? [...]
: 
: ...
: 
: I don't remember reading about that in the perl OO guides, but I may
: have missed it.

If I understand your question, to call the printInstance method
(poorly named because the "hey, I operate on an instance" is
implicit -- just plain old print would be sufficient), you need
only invoke it as in

    $obj->printInstance;

Behind the scenes, perl makes $obj the first parameter to the
method.

Hope this helps,
Greg
-- 
Government ought to be as much open to improvement as anything which
appertains to man, instead of which it has been monopolized from age to age,
by the most ignorant and vicious of the human race.
    -- Thomas Paine


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

Date: Fri, 05 Sep 2003 21:32:07 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: finding instance of object
Message-Id: <pan.2003.09.05.21.32.19.719261@technologist.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On Fri, 05 Sep 2003 15:56:18 +0000, Jeff Thies wrote:

>   I have an object and I like to print the instance of the object;
> 
> my $object_name=new MyObj();
> my $object_name2=new MyObj();
> 
> package MyObj;
> 
> sub new{
> my $class = shift;
> my $self = {};
> 
> ...
> 
> sub printInstance{
> my $self=shift;
> 
> print " I'd like to print $object_name, can I do that or do I need to
> pass it in directly as a property?: my $object_name=new
> MyObj('object_name');";
> 
> ...
> 
> I don't remember reading about that in the perl OO guides, but I may
> have missed it.

AFAIK, you can't do that. Take this for example:
my $object_name = new MyObj();
my $another_name = $object_name;

What should $another_name->printInstance() display? Or, what would you
expect to get from "$_->printInstance() for($object_name)"?

You could get the object class (package name) from the instance (would
print MyObj): "sub printInstance { print ref $_[0]; }"

Perhaps you could better outline the problem you're trying to solve with
this method. There may be a better way to solve that problem.

 - Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/WQDdiK/rA3tCpFYRAp8jAJsEe99D4fQ8lyyOLTqVp5EnASJm9gCgrQpa
puEb6RWRqfbRjeru2CzzeJY=
=UeCI
-----END PGP SIGNATURE-----



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

Date: 5 Sep 2003 13:24:46 -0700
From: galamuri81@yahoo.com (giri alamuri)
Subject: How to replace globally a string1 with string2 only if string1 does not have a sub_strig
Message-Id: <1547077a.0309051224.4c0398f1@posting.google.com>

What I want to do is: 

s/begin(^(abc)).*end//xyz/gs

What I meant above is, find string begin which is not followed by abc and 
then followed by any string till it find "end" and replace the whole string 
with "xyz" globally.

That is, I want to replace begin.*end with xyz only if begin is not followed
by "abc". 

I want to do it globally. So, following will not work: 

unless (/beginabc/) {
s/begin(^(abc)).*end//xyz/gs
}


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

Date: 05 Sep 2003 16:43:14 -0400
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: How to replace globally a string1 with string2 only if string1 does not have a sub_strig
Message-Id: <xcwu17rge59.fsf@psi.cis.ohio-state.edu>

galamuri81@yahoo.com (giri alamuri) writes:

> What I want to do is: 
> 
> s/begin(^(abc)).*end//xyz/gs
> 
> What I meant above is, find string begin which is not followed by abc and 
> then followed by any string till it find "end" and replace the whole string 
> with "xyz" globally.
> 
> That is, I want to replace begin.*end with xyz only if begin is not followed
> by "abc". 

I think this is a job for the negative look-ahead assertion, with some
non-greediness added...

s/begin(?!abc).*?end/xyz/g;


Ryan
-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


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

Date: Fri, 05 Sep 2003 21:17:07 GMT
From: Brian Harnish <bharnish@technologist.com>
Subject: Re: How to replace globally a string1 with string2 only if string1 does not have a sub_strig
Message-Id: <pan.2003.09.05.21.17.19.983253@technologist.com>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On Fri, 05 Sep 2003 13:24:46 -0700, giri alamuri wrote:

> What I want to do is: 

Go ahead, we're not going to stop you.

> s/begin(^(abc)).*end//xyz/gs
> 
> What I meant above is, find string begin which is not followed by abc and 
> then followed by any string till it find "end" and replace the whole string 
> with "xyz" globally.
> 
> That is, I want to replace begin.*end with xyz only if begin is not followed
> by "abc". 
> 
> I want to do it globally. So, following will not work: 
> 
> unless (/beginabc/) {
> s/begin(^(abc)).*end//xyz/gs
> }

Try a negative look ahead.

Also, when asking a question in english, the sentence should end with a
question mark (?).

 - Brian
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/WP1aiK/rA3tCpFYRAvtEAJ9X6FNtOuXIgrOHCvXH3SC6BgrEEwCgjrqz
CgXyJBYJrRcmk0Y1ckEXHgM=
=MNE9
-----END PGP SIGNATURE-----



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

Date: 5 Sep 2003 14:48:49 -0700
From: dna@888.nu (Marcus Brody)
Subject: Re: My perl script is "Killed" - Ran out of memory
Message-Id: <1ab76986.0309051348.69e613cd@posting.google.com>

Hey Xho

Well, am I being really patronising re:biological data?  
Are you another biologist by any chance ctcgag@hotmail.com???

If not, its a very wierd coincidence....

Anyways, I have a reasonable idea concerning public microarray data,
if your interested.  Its just a side project at the mo, but I reckon
theres a paper in it...

MB


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

Date: 5 Sep 2003 11:29:05 -0700
From: Prab_kar@hotmail.com (Prabh)
Subject: Perl - Absolute min. environment required.
Message-Id: <e7774537.0309051029.32121c12@posting.google.com>

Hi,
What is the absolute minimum required environment to execute a Perl
program?

I want to execute a .pl on a PC which doesnt have Perl installed.
I was thinking of copying the Perl .exes on to a network drive and
invoke the intepreter from there.
Something along the lines,

    <%>   <path-to-network-drive>\perl.exe    C:\foo.pl

Could anyone, please tell me what all do I need to copy to the
network?
If the Perl install changes the registry, how do I ensure they still
work on User PC?

If this is not possible, is there any Perl-LITE that can be installed
locally?

Thanks,
Prabh


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

Date: 5 Sep 2003 11:20:42 -0700
From: google@jillanddirk.com (TheWizZ)
Subject: Re: PERL, FTP and Browser Upload
Message-Id: <fcc3b382.0309051020.b321f06@posting.google.com>

prsjm3qf <steve@caralan.co.uk> wrote in message news:<3F34A9F9.419CAD8B@caralan.co.uk>...
> Hello out there,
>                       I'm a bit of a Perl newbie and have dropped for
> the job of writing a file upload system.
> I've tried various HTTP solutions with form ACTION=POST but have found
> it unreliable for large files because of server timeout errors and
> anyway, it's a protocol not really designed for the job.
> I'm now thinking that the grown up way to do it has got to be with  FTP.

You have got to try out iBULC (internet Batch UpLoad Component). I
will upload through the browser and support unlimited file size. You
will need to install the free iBULC client though for it to work.
http://www.ibulc.com
> 
> I'd love to get them all to use an ftp client but realistically its not
> going to happen so I want  to have users select files in their browser
> from their local system, press a button and Binary FTP the files into a
> pre created directory on an ftp server. There seem to be various scripts
> around that say they do this but on closer inspection they start getting
> a bit vague and I'm not convinced that they are actually using FTP as
> opposed to HTTP.
> 
> Can anyone point me to a Perl CGI FTP script that will do this - doesn't
> matter if it's a commercial one cos this is worth paying for if it does
> the job. Failing that can anyone give me some pointer ideas on how to
> start writing my own so I can set off in the right direction.
> 
> 
> Thanks for any help
> 
> Steve@caralan.co.uk


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

Date: Fri, 5 Sep 2003 23:50:32 +0200
From: peter pilsl <pilsl_usenet@goldfisch.at>
Subject: problems with charsets
Message-Id: <3f5905a5@e-post.inode.at>


I've a long csv-file that needs to be imported into a sql-database. My 
problem now is, that I dont know the charset this file is encoded in and 
afterwards I would not know how to convert it to what I need (latin1 for 
output and utf8 for storage).
For current transformation unicode<->latin1 the Unicode::String-module is 
what I use but the file seems not to be latin1 after all. (It comes from a 
mac and I'm working on a linux-machine)

I'm aware of the fact that my problem is not really a perl-problem, but I 
use perl to detect and convert the charset, so I hope its ok here.

An example for the text I need to process is available at:
http://www.goldfisch.at/temporary/text.cvs  for download (its only one line 
with 276 bytes).


thnx a lot for your help,
peter





-- 
peter pilsl
pilsl_usenet@goldfisch.at
http://www.goldfisch.at



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

Date: Fri, 05 Sep 2003 20:16:32 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regexp Help
Message-Id: <1062785894.689517@halkan.kabelfoon.nl>

raven wrote:

> The output of lpstat -p on hpux returns this:
> 
> printer sacprn05 is idle.  enabled since Jul 30 12:23
>         fence priority : 0
> 
> I am attempting to grab the printer name and whether or not it is
> idle. The code to do this is:
   ^^^^

idle...

> if (/^printer (\w+).*(enabled|disabled)/)

enabled/disabled... I am confused

> Is there a more efficient way to obtain the desired information using
> a Perl regexp?

Don't know if changing .* to .*? speeds things up.

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Fri, 5 Sep 2003 11:30:35 -0700
From: "David Oswald" <print split /!/"d!a!v!i!d!o!@!p!a!c!i!f!i!e!r!.!c!o!m!\n">
Subject: Re: Regexp Help
Message-Id: <vlhlhs9r28v4e1@corp.supernews.com>


"raven" <raven_riverwind@yahoo.com> wrote in message
> The output of lpstat -p on hpux returns this:

> printer sacprn05 is idle.  enabled since Jul 30 12:23
>         fence priority : 0
>
> I am attempting to grab the printer name and whether or not it is
> idle. The code to do this is:
> if (/^printer (\w+).*(enabled|disabled)/)
> Is there a more efficient way to obtain the desired information using
> a Perl regexp?

You suggested that 'idle' or otherwise is what you were looking for.  But
your regexp suggests that you're looking for 'enabled' or 'disabled'.

So your design specification and your design implementation differ.  That
may or may not be a problem.  Since I don't know what the inverse to "idle"
is (busy? queueing? active?), and since your implementation tells me what
the inverse to enabled is, I can only help you to refine your existing
implementation.

if ( /^printer\s(\w+).*?((?:en|dis)abled)/ )

This will match 'printer' at the beginning of the string, plus a space (any
kind of space, not just a literal space).  I prefer \s over ' ' because \s
is more visible, and though it's not exactly the same thing, in many
situations, it works interchangeably.

Next, it goes on to match any word characters.  I assume that you understand
that '\w' is the same as [a-zA-Z_0-0] unless you're dealing with alternative
character sets or Unicode.  That means that you've stated that a printer
name could look like '94_242ba__67Z'.  That may be more narrow of a range of
possible characters than actually exist for your set of printers, or it may
be too broad.  For example, you might actually mean [a-zA-Z], or you might
mean a much broader definition of what constitutes a printer name.  But I
stuck with your definition.

Next, rather than matching '.*' which means everything until the
enabled/disabled part, I changed it to '.*?' which means everything until
the closest occurrence of enabled or disabled.  In other words, I switched
from greedy matching to non-greedy.  I really think that Perlish regexp
design should have favored non-greedy to begin with (in keeping with Larry
Wall's commentary on Perl 6 regular expressions, and redesigning according
to the Huffman theorm where frequent things are shorter than infrequent
things).  But we're working in reality right now, so for now, it takes an
extra keystroke to make quantifiers non-greedy.  Why bother making it
non-greedy?  Because it's a darn good habbit to get into in order to keep
yourself out of the problem that you would face if you wrote a regexp like
this:  /.*Z?/, where Z would never be a part of the match because the greedy
 .* slurps it up no matter what.  Anyway, back to the point, by making it
non-greedy you don't have to worry as much about the what-ifs.

Next, I used non-capturing parenthesis to constrain the alternation to a
smaller portion of the match.  Alternation is expensive (from a processing
time standpoint) and constraining it to smaller segments usually speeds
things up just a little bit, as it allows the regexp engine to do a little
less backtracking.  As you can see, I alternated only on the prefix of the
word ...abled.

So you end up with a longer, but maybe more robust, and possibly faster
regexp.  Oh, and as before, $1 contains the printer name and $2 contains the
status.

Dave




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

Date: Fri, 05 Sep 2003 20:46:39 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Regexp Help
Message-Id: <1062787701.288254@halkan.kabelfoon.nl>

David Oswald wrote:

> "raven" <raven_riverwind@yahoo.com> wrote in message
> 
>>The output of lpstat -p on hpux returns this:
> 
> 
>>printer sacprn05 is idle.  enabled since Jul 30 12:23
>>        fence priority : 0

[snip]

> be too broad.  For example, you might actually mean [a-zA-Z], or you might

nope, 05 seems to suggest at least digits can appear in the name :-)

Thanks Dave, this was very clear and educational!

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Fri, 5 Sep 2003 20:59:18 +0200
From: Lao Coon <laocoon@fastmail.fm>
Subject: Re: Regexp Help
Message-Id: <bjame5$dhe$00$1@news.t-online.com>

raven_riverwind@yahoo.com (raven) wrote in 
news:7270d1f8.0309050952.3154538e@posting.google.com:

> The output of lpstat -p on hpux returns this:
> 
> printer sacprn05 is idle.  enabled since Jul 30 12:23
>         fence priority : 0
> 
> I am attempting to grab the printer name and whether or not it is
> idle. The code to do this is:
> 
> if (/^printer (\w+).*(enabled|disabled)/)
> 
> Is there a more efficient way to obtain the desired information using
> a Perl regexp?

E.g. /^printer\s(\S+)/. Shorter is usually better, if you have little or 
no variation in the input.

perl -MBenchmark -e "$a = 'printer sacprn05 is idle. enabled since Jul 30 
12:23'; timethese(500000, { 

'First' => '$a =~ /^printer (\w+).*(enabled|disabled)/;',

'Second' => '$a =~ /^printer\s(\S+)/;'

});"

Benchmark: timing 500000 iterations of First, Second...
     First:  8 wallclock secs ( 7.19 usr +  0.02 sys =  7.21 CPU) @ 
69338.51/s (
n=500000)
    Second:  1 wallclock secs ( 1.76 usr +  0.00 sys =  1.76 CPU) @ 
283607.49/s
(n=500000)


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

Date: Fri, 05 Sep 2003 19:40:27 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Repost Search
Message-Id: <Xns93ED9F70E617Bdkwwashere@216.168.3.30>

John W. Krahn <krahnj@acm.org> wrote:

> "David K. Wall" wrote:
>> 
>> Jimmy <jimmy_armand@hotmail.com> wrote:
>> 
>> > while( <FILEHANDLE> or <FILEHANDLETWO>)
>> 
>> Reads a line from FILEHANDLE, stores it in $_, then reads a line
>> from FILEHANDLETWO and stores it in $_, overwriting the line from
>> FILEHANDLE.
> 
> No, nothing gets stored in $_.
> 
> perldoc perlop
> [snip]
>     Ordinarily you must assign the returned value to a variable,
>     but 
> there
>     is one situation where an automatic assignment happens. If and
>     only 
> if
>     the input symbol is the only thing inside the conditional of a
> `while'
>     statement (even if disguised as a `for(;;)' loop), the value
>     is automatically assigned to the global variable $_,
>     destroying 
> whatever
>     was there previously. (This may seem like an odd thing to you,
>     but you'll use the construct in almost every Perl script you
>     write.) The 
> $_
>     variables is not implicitly localized. You'll have to put a
>     `local 
> $_;'
>     before the loop if you want that to happen.

Ah.  Thanks for the correction.  I wasn't aware of that particular 
feature -- but then I would never have thought to try something like 
'while ( <FH1> or <FH2> )'.  I still should have checked the docs.

-- 
David Wall


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

Date: 5 Sep 2003 14:57:02 -0700
From: jimmy_armand@hotmail.com (Jimmy)
Subject: Re: Repost Search
Message-Id: <72ea1877.0309051357.4e2af07@posting.google.com>

Thank you all. It will help alot!

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3F58CFE1.BF9DD5E8@acm.org>...
> "David K. Wall" wrote:
> > 
> > Jimmy <jimmy_armand@hotmail.com> wrote:
> > 
> > > while( <FILEHANDLE> or <FILEHANDLETWO>)
> > 
> > Reads a line from FILEHANDLE, stores it in $_, then reads a line
> > from FILEHANDLETWO and stores it in $_, overwriting the line from
> > FILEHANDLE.
> 
> No, nothing gets stored in $_.
> 
> perldoc perlop
> [snip]
>     Ordinarily you must assign the returned value to a variable, but
> there
>     is one situation where an automatic assignment happens. If and only
> if
>     the input symbol is the only thing inside the conditional of a
> `while'
>     statement (even if disguised as a `for(;;)' loop), the value is
>     automatically assigned to the global variable $_, destroying
> whatever
>     was there previously. (This may seem like an odd thing to you, but
>     you'll use the construct in almost every Perl script you write.) The
> $_
>     variables is not implicitly localized. You'll have to put a `local
> $_;'
>     before the loop if you want that to happen.
> 
> 
> 
> John


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

Date: Fri, 5 Sep 2003 14:56:26 -0400
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Telling perl to expect input data to be in UTF8 (no HTML this time)
Message-Id: <20qdnRyWAdfGQcWiXTWJjA@giganews.com>


"Graham Wood" <Graham.T.Wood@oracle.com> wrote in message
news:3F58B2BE.F937B9@oracle.com...
> Hi all,
>
> I've got this friend who's using perl 5.6.1 and DBI to import data that
> is in UTF8 and he is unable to display the data successfully
> after it imports from the database.  I read in perldoc perlunicode
> shipped with 5.6.1 that you can't tell perl to expect UTF8 data
> from an external file or source but that it would shortly be addressed
> in a future version.  Can anyone tell me if this has happened
> yet, and if so, in which version of perl it is available?
>

Look into 5.8.0 - you can use the 'open' pragma to set default IO layers
that expect UTF-8, or you can mark file handles as UTF-8 with the standard
open() function, or you can mark existing file handles as UTF-8 with
binmode() - the documentation has examples of all of them (perldoc open,
perldoc -f open, perldoc -f binmode)

--Ben Kennedy




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

Date: Fri, 5 Sep 2003 19:47:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Telling perl to expect input data to be in UTF8
Message-Id: <Pine.LNX.4.53.0309051937320.26374@lxplus090.cern.ch>

On Fri, Sep 5, David K. Wall reveals to the world that:

> Graham Wood <Graham.T.Wood@oracle.com> wrote in a format that's
automatically suppressed by my news filters:

> >data that
> > is in UTF8 and he is unable to display the data successfully after
> > it imports from the database.&nbsp; I read in perldoc perlunicode
> > shipped with 5.6.1 that you can't tell perl to expect UTF8 data
> > from an external file or source but that it would shortly be
> > addressed in a future version.

That's true enough.  5.6.1 has some of the machinery for utf8 support,
but you need 5.8.0 (or later) to get the features integrated into
I/O calls such as open() and binmode()

perldoc perlunicode has the gory detail; perldoc perluniintro is a
useful introduction.  Both can be found at
http://www.perldoc.com/perl5.8.0/pod.html if you don't have your own
5.8.0 installation yet.  Well, sure, they can still be found there
even if you do - but you would also have them nearer at hand.

Works well, as far as I could make out, except for dealing with
Windows-flavoured newlines, which basically had me at a loss (see
earlier discussion of utf-16 formats on Windoze).

good luck


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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.  

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


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