[26272] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8454 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 25 14:05:42 2005

Date: Sun, 25 Sep 2005 11:05:09 -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, 25 Sep 2005     Volume: 10 Number: 8454

Today's topics:
        complete manual and reference <nomail@nomail.com>
    Re: complete manual and reference <1usa@llenroc.ude.invalid>
    Re: FAQ 4.42 How can I tell whether a certain element i <john@castleamber.com>
    Re: FAQ 4.42 How can I tell whether a certain element i <segraves_f13@mindspring.com>
    Re: Feed a directory listing to a script <timx@spamto.devnul.com>
    Re: How to start Perl application form HTML document, w <jurgenex@hotmail.com>
    Re: Packing/Unpacking bit fields from a byte. <shashank@mia.ece.uic.edu>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <abigail@abigail.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <john@castleamber.com>
    Re: regex, number of matches <john@castleamber.com>
    Re: regex, number of matches <rvtol+news@isolution.nl>
    Re: regex, number of matches <rvtol+news@isolution.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 25 Sep 2005 15:22:27 GMT
From: nobody <nomail@nomail.com>
Subject: complete manual and reference
Message-Id: <TgzZe.17559$pJ6.1185339@news4.tin.it>


where can i get a complete manual and a complete reference for understanding
perl language?

electronics documentation are wellcome as paper publishing

thanks in advance,


-- 
no sign


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

Date: Sun, 25 Sep 2005 15:33:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: complete manual and reference
Message-Id: <Xns96DC758C4E23Aasu1cornelledu@127.0.0.1>

nobody <nomail@nomail.com> wrote in
news:TgzZe.17559$pJ6.1185339@news4.tin.it: 

> where can i get a complete manual and a complete reference for
> understanding perl language?

perldoc -q Perl

perldoc perldoc

perldoc perltoc

http://learn.perl.org/

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


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

Date: 25 Sep 2005 16:23:57 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <Xns96DC736D5591castleamber@130.133.1.4>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> John Bokma  <john@castleamber.com> wrote in comp.lang.perl.misc:
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> 
>> > PerlFAQ Server  <comdog@panix.com> wrote in comp.lang.perl.misc:
>> > 
>> > This is essentially a re-post of my FAQ suggestion in the thread
>> > "scalar and hash slices -- is it supposed to work this way?".
>> 
>> Can't the FAQ be edited using a wiki or something like that? I mean,
>> aren't we programmers :-D.
> 
> I'm sure it can and yes, some of us are.  So far, no one was
> sufficiently motivated to make the preliminary contacts and, perhaps,
> write such a thing.  So what?

Write? Does it have to be in Perl? There is plenty of Wiki software etc. 
out there, probably not written in Perl, but I don't care about that. The 
OS I use is not written in Perl either :-)

So what are the next steps to have a Perl wiki? Especially for the FAQ 
part?

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Sun, 25 Sep 2005 17:36:36 GMT
From: "Bill Segraves" <segraves_f13@mindspring.com>
Subject: Re: FAQ 4.42 How can I tell whether a certain element is contained in a list or array?
Message-Id: <EeBZe.3772$vw6.1679@newsread1.news.atl.earthlink.net>

"John Bokma" <john@castleamber.com> wrote in message
news:Xns96DC736D5591castleamber@130.133.1.4...
<snip>
> Write? Does it have to be in Perl? There is plenty of Wiki software etc.
> out there, probably not written in Perl, but I don't care about that. The
> OS I use is not written in Perl either :-)

OTOH, there is at least one that *is* written in Perl, e.g.,

http://c2.com/cgi/wiki?QuickiWiki
http://c2.com/cgi/wiki?ClusterWiki
http://www.wiki.org/

>
> So what are the next steps to have a Perl wiki? Especially for the FAQ
> part?
>

1. Download and install QuickiWiki.
2. Write a script to extract Usenet clpm postings from the PerlFAQ server
into Wiki format.

Please let us know when you have it up and running, John. ;-)

Cheers.
--
Bill Segraves




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

Date: 25 Sep 2005 22:37:52 +1000
From: Tim X <timx@spamto.devnul.com>
Subject: Re: Feed a directory listing to a script
Message-Id: <874q89mifz.fsf@tiger.rapttech.com.au>

"Shabam" <chalupa@yomama-nospam.com> writes:

> I have a command script that backs up a user account.  This involves moving
> files from different directories into an archive.
> 
> Now, I need that script to back up all user accounts on the system, by going
> through the directory structure and running the backup script on each one.
> Can someone show me how this can be done?  I'm not a perl programmer and
> have only dabbled a bit in it.
> 
> My directory structure is like this:
> 
> /Users/0/
> /Users/1/
> /Users/2/
> /Users/3/
> ... so on...
> 
> User account names reside in those folders, so user jason would be in
> "Users/j/jason".
> 
> Please don't tell me to just tar/gz the /Users/ directory.  That will not
> work for this because it will be greater than 4GBs, and it won't allow me to
> restore accounts individually.
> 

Firstly, if your not a perl programmer, why do you plan to use perl
for this task? This could easily be done with just a bash script.

Secondly, your statement about not being able to extract individual
account data from a single tar file is incorrect. You can extract
individual files or groups of files from a tar archive.

The basic building blocks for your script are two loops. The outer
loop goes through the outer list of directories and for each of those,
the inner loop goes through the user accounts in each directory and
processes them in whatever way you want. 

The perl functions you probably want are opendir and readdir. Try
perldoc -f readdir, but to be honest, if your not a perl programmer,
save yourself time and just use bash (unless you want to learn perl). 

Tim



-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!


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

Date: Sun, 25 Sep 2005 10:52:01 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to start Perl application form HTML document, with Internet Explorer without installed Apache Web server?
Message-Id: <ljvZe.2524$211.1751@trnddc08>

Katharina wrote:
> How to start Perl application form HTML document, with Internet
> Explorer without installed Apache Web server?

The way you phrased your question it doesn't make any sense.

You start a Perl script interactively bey entering its name on the command 
line or maybe by clicking on the icon in a GUI or programatically from 
another application, etc.

HTML forms do not start any program and neither does IE (well, except for 
ActiveX Controls). What they do is submit an HTTP request to a web server 
and wait for response.
Just think about it: someone could write a simple HTML document, that would 
be able to launch any program like e.g. "format" or "rm". Would you want to 
use a browser that allows that?

As for the Apache Web server: you don't need Apache to run Perl applications 
or to run IE or to view HTML forms. For submitting HTML forms you need to 
connect to some web server somewhere, but that has nothing to do with Perl.

Therefore the way you combined those four components in your question (Perl, 
HTML forms, IE, Apache) doesn't make sense because they have nothing to do 
with each other.

I am sensing an X-Y problem here. You want to solve problem X, believe that 
Y is the best way to do it, and therefore you are asking about how to do Y.
What is th original X that you are trying to solve? Chances are it is much 
easier to solve that problem than the riddle of your question Y above.

jue 




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

Date: Sun, 25 Sep 2005 11:54:14 -0500
From: Shashank Khanvilkar <shashank@mia.ece.uic.edu>
Subject: Re: Packing/Unpacking bit fields from a byte.
Message-Id: <Pine.LNX.4.61.0509251146480.25177@mia.ece.uic.edu>

Hi,

I just found that the below solution may not work for me. Here is a test 
case.

for example:
perl -MData::Dumper -e "print Dumper unpack 'B4B4B4B4B*','abcd'"
$VAR1 = '0110';
$VAR2 = '0110';
$VAR3 = '0110';
$VAR4 = '0110';
$VAR5 = '';

Here the string abcd corresponds to 4 ascii characters.
a = 0x61 = 0110 0001
b = 0x62 = 0110 0010
c = 0x63 = 0110 0011
d = 0x64 = 0110 0100

So i want the output to print something like
$VAR1 = '0110';
$VAR2 = '0001';
$VAR3 = '0110';
$VAR4 = '0011';
$VAR5 = '0110001101100100';

I gues the unpack function seeks byte boundaries for every conversion.
Will appreciate if someone can verify this.
All alternate solutions are also welcome.
Shank







>> Shashank R Khanvilkar wrote:
>>
>> ...
>>> I have to parse a file which has a header. This header is say 4 bytes long
>>> and contains many fields which are not byte aligned. For example
>>>
>>> struct header {
>>> 	#fieldname: Size(bits)
>>> 	fld1: 12
>>> 	fld2: 1
>>> 	fld3: 2
>>> ...
>>> }
>>>
>>> I have already written a lengthy routing to unpack these fileds from the
>>> header (using shifts and masks). However i was wondering if the same could
>>> have been achieved using the pack and unpack functions?
>>> For example:
>>>
>>> @hdr = unpack("B12B1B2....", $header);
>>>
>>> I find that this does not work.
>>
>> Why do you think that doesn't work?  It seems to work to me:
>>
>> C:>perl -MData::Dumper -e "print Dumper unpack 'B12B1B2','abcd'"
>> $VAR1 = '011000010110';
>> $VAR2 = '0';
>> $VAR3 = '01';
>>
> Thanks.. I guess it is taking the ascii values of a(=61 = 0x01100001)..
>
> Thanks for your help
> Shank
>
>
>
>> C:\Temp>
>> ...
>>> Shashank
>> --
>> Bob Walton
>> Email: http://bwalton.com/cgi-bin/emailbob.pl
>>
>


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

Date: Sun, 25 Sep 2005 10:12:55 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh5t7s.1g0.1@news.isolution.nl>

Tad McClellan:
> Dr.Ruud:

>> I find it hard to think of a reason why the first use of $& should
>> harm all other pattern matches.
>
> Because a whole bunch of characters must be stored for
> every (successful) pattern match.

In the circumstances we were discussing, an offset plus length on the
input buffer is all you need there (and those are known values).

I think that the alternatives "s/(\S+)/$1/g" and "s/\S+/$&/g" don't need
behave differently.

Does something like "use caveats" exists, that warns against common
missing rewrites?
;)

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 25 Sep 2005 09:30:15 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: regex, number of matches
Message-Id: <slrndjcrh7.9lk.abigail@alexandra.abigail.nl>

Dr.Ruud (rvtol+news@isolution.nl) wrote on MMMMCDVIII September MCMXCIII
in <URL:news:dh5t7s.1g0.1@news.isolution.nl>:
{}  Tad McClellan:
{} > Dr.Ruud:
{}  
{} >> I find it hard to think of a reason why the first use of $& should
{} >> harm all other pattern matches.
{} >
{} > Because a whole bunch of characters must be stored for
{} > every (successful) pattern match.
{}  
{}  In the circumstances we were discussing, an offset plus length on the
{}  input buffer is all you need there (and those are known values).

But it's not easy to determine those special circumstances. In general
an offset won't do as the string might change. Consider:

    my $line = "Hello, world";
    if ($line =~ /\w+$/) {
        substr ($line, 7) = "earthlings";
        print $&, "\n";
    }

{}  I think that the alternatives "s/(\S+)/$1/g" and "s/\S+/$&/g" don't need
{}  behave differently.

True, if there are no further references to $&. But that's a special case,
and perl doesn't spend CPU cycles to find out. You're welcome to provide
a patch, although with all the warnings against using $& already in the
documentation, I'm not sure the patch will be accepted.



Abigail
-- 
INIT  {print "Perl "   }
END   {print "Hacker\n"}
CHECK {print "another "}
BEGIN {print "Just "   }


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

Date: Sun, 25 Sep 2005 12:21:15 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh64s8.198.1@news.isolution.nl>

Abigail schreef:
> Dr.Ruud:

>> In the circumstances we were discussing, an offset plus length on
>> the input buffer is all you need there (and those are known
>> values).
>
> But it's not easy to determine those special circumstances. In general
> an offset won't do as the string might change.

OK.

>> I think that the alternatives "s/(\S+)/$1/g" and "s/\S+/$&/g"
>> don't need to behave differently.
>
> True, if there are no further references to $&. But that's a special
> case, and perl doesn't spend CPU cycles to find out. You're welcome
> to provide a patch, although with all the warnings against using $&
> already in the documentation, I'm not sure the patch will be accepted.

Maybe as an example, coming with a general addition of optimization
types...
Or a syntax-coloring tool that highlights things that the documentation
warns against.
OK, let me read Apocalypse-5 first.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Sun, 25 Sep 2005 12:58:56 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh677c.1gc.1@news.isolution.nl>

Dr.Ruud schreef:

> OK, let me read Apocalypse-5 first.

Looks good:
  my $foo = +/.../;   # numeric context, return count of matches

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Sun, 25 Sep 2005 13:23:52 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh69o6.1e8.1@news.isolution.nl>

Abigail schreef:

> if you use $& [...], Perl doesn't know in advance to
> which regex they will refer (you need to be able to solve
> the halting problem to determine this).

I don't understand this yet. What is the cost of dealing with this per
regex?


> [benchmark]
>             Rate   sub list2  list while
>     sub   2619/s    --  -23%  -26%  -61%
>     list2 3398/s   30%    --   -4%  -49%
>     list  3523/s   34%    4%    --  -47%
>     while 6698/s  156%   97%   90%    --
>
>             Rate   sub list2  list while
>     sub   2559/s    --  -23%  -28%  -44%
>     list2 3339/s   30%    --   -6%  -28%
>     list  3556/s   39%    6%    --  -23%
>     while 4610/s   80%   38%   30%    --
>
> Note the difference in iteration rate of the while - it dropped almost
> by a third.

Yep, (6698-4610)/6698 = 31%.


> Note also that the 'sub', 'list' and 'list2' regexes run at almost the
> same rate - this is because they use parenthesis (the list ones have
> implicate parens because the /\S+/g is in list context, and doesn't
> have parens itself). But the 'while /\S+/g' doesn't have parens, and
> is penalized because of the $&.

Nice show again!

xs6-results (v5.8.6 built for i386-freebsd-64int)

        Rate   sub list2  list while
sub   2965/s    --  -39%  -43%  -65%
list2 4874/s   64%    --   -7%  -42%
list  5245/s   77%    8%    --  -38%
while 8404/s  183%   72%   60%    --

        Rate   sub list2  list while
sub   2912/s    --  -39%  -43%  -57%
list2 4738/s   63%    --   -8%  -30%
list  5143/s   77%    9%    --  -24%
while 6796/s  133%   43%   32%    --

(8404-6796)/8404 = 20%.


xs1-results (idem)

         Rate   sub list2  list while
sub    5357/s    --  -23%  -27%  -52%
list2  6990/s   30%    --   -4%  -38%
list   7303/s   36%    4%    --  -35%
while 11263/s  110%   61%   54%    --

        Rate   sub list2  list while
sub   5397/s    --  -21%  -23%  -33%
list2 6817/s   26%    --   -2%  -16%
list  6990/s   30%    3%    --  -14%
while 8095/s   50%   19%   16%    --

(11263-8095)/11263 = 28%


I tried some
subst-variants like "/()(\S+)/$2/g" and "/((\S+))/$2/g" and
while-variants like "/\S+\s*/" and "/\G\s*\S+/g"
just to see how they behave: no spectacular results.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Sun, 25 Sep 2005 14:35:00 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh6cob.1g0.1@news.isolution.nl>

Abigail schreef:

> [$&
> it's not easy to determine those special circumstances.

How about something like '\&' that can only be used in the replace-part?

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Sun, 25 Sep 2005 16:53:54 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh6ktk.1j4.1@news.isolution.nl>

Brian Wakem schreef:

> The fastest way is to substitute a match with itself.


Not for (counting) random words, the destructive
substition 's/\S+/./g' is faster than 's/(\S+)/\1/'.
(even 50% faster than the '++ while /\S+/g')

  list  => '$list  = 0; $list  += ()     = (/\S+/g) for @data;',
  sub   => '$sub   = 0; $sub   +=     s/(\S+)/$1/g  for @data;',
  sub2  => '$sub2  = 0; $sub2  +=     s/(\S+)/\1/g  for @data;',
  sub3  => '$sub3  = 0; $sub3  +=        s/\S+/./g  for @data;',
  while => '$while = 0; do {$while++ while  /\S+/g} for @data;',

           Rate   sub  sub2  list while  sub3
  sub    5318/s    --   -2%  -24%  -52%  -68%
  sub2   5420/s    2%    --  -22%  -51%  -68%
  list   6990/s   31%   29%    --  -37%  -58%
  while 11120/s  109%  105%   59%    --  -34%
  sub3  16809/s  216%  210%  140%   51%    --

-- 
Affijn, Ruud

"Gewoon is een tijger."





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

Date: 25 Sep 2005 16:21:09 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: regex, number of matches
Message-Id: <Xns96DC72F3C4D92castleamber@130.133.1.4>

"Dr.Ruud" <rvtol+news@isolution.nl> wrote:

> Dr.Ruud schreef:
> 
>> OK, let me read Apocalypse-5 first.
> 
> Looks good:
>   my $foo = +/.../;   # numeric context, return count of matches

Yup, I would prefer that over the t thingy :-)

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 25 Sep 2005 16:21:57 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: regex, number of matches
Message-Id: <Xns96DC73164E0EAcastleamber@130.133.1.4>

"Dr.Ruud" <rvtol+news@isolution.nl> wrote:

> Abigail schreef:
> 
>> [$&
>> it's not easy to determine those special circumstances.
> 
> How about something like '\&' that can only be used in the replace-part?

Just because you don't want to use () in the regexp part?

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Sun, 25 Sep 2005 18:53:36 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh6s5e.v8.1@news.isolution.nl>

John Bokma schreef:
> Dr.Ruud:
>> Dr.Ruud:

>>> OK, let me read Apocalypse-5 first.
>>
>> Looks good:
>>   my $foo = +/.../;   # numeric context, return count of matches
>
> Yup, I would prefer that over the t thingy :-)

See Apocalypse-5:
http://www.perl.com/pub/a/2002/06/04/apo5.html?page=18
"If it turns out we do need an option, it'll probably be: n."

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: Sun, 25 Sep 2005 19:26:00 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: regex, number of matches
Message-Id: <dh6uc0.ok.1@news.isolution.nl>

John Bokma schreef:
> Dr.Ruud:
>> Abigail:
>>
>>> [$&]
>>> it's not easy to determine those special circumstances.
>>
>> How about something like '\&' that can only be used in the
>> replace-part?
>
> Just because you don't want to use () in the regexp part?

The answer is in "can only be used in the replace-part".

With () you need $1, and that involves setting up a variable.

So no, not only because I etc.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

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


Administrivia:

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

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

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

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

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


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


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